@@ -216,8 +216,9 @@ static void ShowExampleMenuFile();
216
216
217
217
// We split the contents of the big ShowDemoWindow() function into smaller functions
218
218
// (because the link time of very large functions tends to grow non-linearly)
219
- static void ShowDemoWindowWidgets();
220
- static void ShowDemoWindowMultiSelect();
219
+ struct DemoWindowData;
220
+ static void ShowDemoWindowWidgets(DemoWindowData* demo_data);
221
+ static void ShowDemoWindowMultiSelect(DemoWindowData* demo_data);
221
222
static void ShowDemoWindowLayout();
222
223
static void ShowDemoWindowPopups();
223
224
static void ShowDemoWindowTables();
@@ -332,6 +333,32 @@ static ExampleTreeNode* ExampleTree_CreateDemoTree()
332
333
// [SECTION] Demo Window / ShowDemoWindow()
333
334
//-----------------------------------------------------------------------------
334
335
336
+ struct DemoWindowData
337
+ {
338
+ // Examples Apps (accessible from the "Examples" menu)
339
+ bool ShowMainMenuBar = false;
340
+ bool ShowAppAssetsBrowser = false;
341
+ bool ShowAppConsole = false;
342
+ bool ShowAppCustomRendering = false;
343
+ bool ShowAppDocuments = false;
344
+ bool ShowAppLog = false;
345
+ bool ShowAppLayout = false;
346
+ bool ShowAppPropertyEditor = false;
347
+ bool ShowAppSimpleOverlay = false;
348
+ bool ShowAppAutoResize = false;
349
+ bool ShowAppConstrainedResize = false;
350
+ bool ShowAppFullscreen = false;
351
+ bool ShowAppLongText = false;
352
+ bool ShowAppWindowTitles = false;
353
+
354
+ // Dear ImGui Tools (accessible from the "Tools" menu)
355
+ bool ShowMetrics = false;
356
+ bool ShowDebugLog = false;
357
+ bool ShowIDStackTool = false;
358
+ bool ShowStyleEditor = false;
359
+ bool ShowAbout = false;
360
+ };
361
+
335
362
// Demonstrate most Dear ImGui features (this is big function!)
336
363
// You may execute this function to experiment with the UI and understand what it does.
337
364
// You may then search for keywords in the code when you are interested by a specific feature.
@@ -344,58 +371,36 @@ void ImGui::ShowDemoWindow(bool* p_open)
344
371
// Verify ABI compatibility between caller code and compiled version of Dear ImGui. This helps detects some build issues.
345
372
IMGUI_CHECKVERSION();
346
373
374
+ // Stored data
375
+ static DemoWindowData demo;
376
+
347
377
// Examples Apps (accessible from the "Examples" menu)
348
- static bool show_app_main_menu_bar = false;
349
- static bool show_app_assets_browser = false;
350
- static bool show_app_console = false;
351
- static bool show_app_custom_rendering = false;
352
- static bool show_app_documents = false;
353
- static bool show_app_log = false;
354
- static bool show_app_layout = false;
355
- static bool show_app_property_editor = false;
356
- static bool show_app_simple_overlay = false;
357
- static bool show_app_auto_resize = false;
358
- static bool show_app_constrained_resize = false;
359
- static bool show_app_fullscreen = false;
360
- static bool show_app_long_text = false;
361
- static bool show_app_window_titles = false;
362
-
363
- if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
364
- if (show_app_documents) ShowExampleAppDocuments(&show_app_documents);
365
- if (show_app_assets_browser) ShowExampleAppAssetsBrowser(&show_app_assets_browser);
366
- if (show_app_console) ShowExampleAppConsole(&show_app_console);
367
- if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering);
368
- if (show_app_log) ShowExampleAppLog(&show_app_log);
369
- if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
370
- if (show_app_property_editor) ShowExampleAppPropertyEditor(&show_app_property_editor);
371
- if (show_app_simple_overlay) ShowExampleAppSimpleOverlay(&show_app_simple_overlay);
372
- if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize);
373
- if (show_app_constrained_resize) ShowExampleAppConstrainedResize(&show_app_constrained_resize);
374
- if (show_app_fullscreen) ShowExampleAppFullscreen(&show_app_fullscreen);
375
- if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text);
376
- if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles);
378
+ if (demo.ShowMainMenuBar) { ShowExampleAppMainMenuBar(); }
379
+ if (demo.ShowAppDocuments) { ShowExampleAppDocuments(&demo.ShowAppDocuments); }
380
+ if (demo.ShowAppAssetsBrowser) { ShowExampleAppAssetsBrowser(&demo.ShowAppAssetsBrowser); }
381
+ if (demo.ShowAppConsole) { ShowExampleAppConsole(&demo.ShowAppConsole); }
382
+ if (demo.ShowAppCustomRendering) { ShowExampleAppCustomRendering(&demo.ShowAppCustomRendering); }
383
+ if (demo.ShowAppLog) { ShowExampleAppLog(&demo.ShowAppLog); }
384
+ if (demo.ShowAppLayout) { ShowExampleAppLayout(&demo.ShowAppLayout); }
385
+ if (demo.ShowAppPropertyEditor) { ShowExampleAppPropertyEditor(&demo.ShowAppPropertyEditor); }
386
+ if (demo.ShowAppSimpleOverlay) { ShowExampleAppSimpleOverlay(&demo.ShowAppSimpleOverlay); }
387
+ if (demo.ShowAppAutoResize) { ShowExampleAppAutoResize(&demo.ShowAppAutoResize); }
388
+ if (demo.ShowAppConstrainedResize) { ShowExampleAppConstrainedResize(&demo.ShowAppConstrainedResize); }
389
+ if (demo.ShowAppFullscreen) { ShowExampleAppFullscreen(&demo.ShowAppFullscreen); }
390
+ if (demo.ShowAppLongText) { ShowExampleAppLongText(&demo.ShowAppLongText); }
391
+ if (demo.ShowAppWindowTitles) { ShowExampleAppWindowTitles(&demo.ShowAppWindowTitles); }
377
392
378
393
// Dear ImGui Tools (accessible from the "Tools" menu)
379
- static bool show_tool_metrics = false;
380
- static bool show_tool_debug_log = false;
381
- static bool show_tool_id_stack_tool = false;
382
- static bool show_tool_style_editor = false;
383
- static bool show_tool_about = false;
384
-
385
- if (show_tool_metrics)
386
- ImGui::ShowMetricsWindow(&show_tool_metrics);
387
- if (show_tool_debug_log)
388
- ImGui::ShowDebugLogWindow(&show_tool_debug_log);
389
- if (show_tool_id_stack_tool)
390
- ImGui::ShowIDStackToolWindow(&show_tool_id_stack_tool);
391
- if (show_tool_style_editor)
392
- {
393
- ImGui::Begin("Dear ImGui Style Editor", &show_tool_style_editor);
394
+ if (demo.ShowMetrics) { ImGui::ShowMetricsWindow(&demo.ShowMetrics); }
395
+ if (demo.ShowDebugLog) { ImGui::ShowDebugLogWindow(&demo.ShowDebugLog); }
396
+ if (demo.ShowIDStackTool) { ImGui::ShowIDStackToolWindow(&demo.ShowIDStackTool); }
397
+ if (demo.ShowAbout) { ImGui::ShowAboutWindow(&demo.ShowAbout); }
398
+ if (demo.ShowStyleEditor)
399
+ {
400
+ ImGui::Begin("Dear ImGui Style Editor", &demo.ShowStyleEditor);
394
401
ImGui::ShowStyleEditor();
395
402
ImGui::End();
396
403
}
397
- if (show_tool_about)
398
- ImGui::ShowAboutWindow(&show_tool_about);
399
404
400
405
// Demonstrate the various window flags. Typically you would just use the default!
401
406
static bool no_titlebar = false;
@@ -455,24 +460,24 @@ void ImGui::ShowDemoWindow(bool* p_open)
455
460
if (ImGui::BeginMenu("Examples"))
456
461
{
457
462
IMGUI_DEMO_MARKER("Menu/Examples");
458
- ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar );
463
+ ImGui::MenuItem("Main menu bar", NULL, &demo.ShowMainMenuBar );
459
464
460
465
ImGui::SeparatorText("Mini apps");
461
- ImGui::MenuItem("Assets Browser", NULL, &show_app_assets_browser );
462
- ImGui::MenuItem("Console", NULL, &show_app_console );
463
- ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering );
464
- ImGui::MenuItem("Documents", NULL, &show_app_documents );
465
- ImGui::MenuItem("Log", NULL, &show_app_log );
466
- ImGui::MenuItem("Property editor", NULL, &show_app_property_editor );
467
- ImGui::MenuItem("Simple layout", NULL, &show_app_layout );
468
- ImGui::MenuItem("Simple overlay", NULL, &show_app_simple_overlay );
466
+ ImGui::MenuItem("Assets Browser", NULL, &demo.ShowAppAssetsBrowser );
467
+ ImGui::MenuItem("Console", NULL, &demo.ShowAppConsole );
468
+ ImGui::MenuItem("Custom rendering", NULL, &demo.ShowAppCustomRendering );
469
+ ImGui::MenuItem("Documents", NULL, &demo.ShowAppDocuments );
470
+ ImGui::MenuItem("Log", NULL, &demo.ShowAppLog );
471
+ ImGui::MenuItem("Property editor", NULL, &demo.ShowAppPropertyEditor );
472
+ ImGui::MenuItem("Simple layout", NULL, &demo.ShowAppLayout );
473
+ ImGui::MenuItem("Simple overlay", NULL, &demo.ShowAppSimpleOverlay );
469
474
470
475
ImGui::SeparatorText("Concepts");
471
- ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize );
472
- ImGui::MenuItem("Constrained-resizing window", NULL, &show_app_constrained_resize );
473
- ImGui::MenuItem("Fullscreen window", NULL, &show_app_fullscreen );
474
- ImGui::MenuItem("Long text display", NULL, &show_app_long_text );
475
- ImGui::MenuItem("Manipulating window titles", NULL, &show_app_window_titles );
476
+ ImGui::MenuItem("Auto-resizing window", NULL, &demo.ShowAppAutoResize );
477
+ ImGui::MenuItem("Constrained-resizing window", NULL, &demo.ShowAppConstrainedResize );
478
+ ImGui::MenuItem("Fullscreen window", NULL, &demo.ShowAppFullscreen );
479
+ ImGui::MenuItem("Long text display", NULL, &demo.ShowAppLongText );
480
+ ImGui::MenuItem("Manipulating window titles", NULL, &demo.ShowAppWindowTitles );
476
481
477
482
ImGui::EndMenu();
478
483
}
@@ -485,17 +490,17 @@ void ImGui::ShowDemoWindow(bool* p_open)
485
490
#else
486
491
const bool has_debug_tools = false;
487
492
#endif
488
- ImGui::MenuItem("Metrics/Debugger", NULL, &show_tool_metrics , has_debug_tools);
489
- ImGui::MenuItem("Debug Log", NULL, &show_tool_debug_log , has_debug_tools);
490
- ImGui::MenuItem("ID Stack Tool", NULL, &show_tool_id_stack_tool , has_debug_tools);
491
- ImGui::MenuItem("Style Editor", NULL, &show_tool_style_editor );
493
+ ImGui::MenuItem("Metrics/Debugger", NULL, &demo.ShowMetrics , has_debug_tools);
494
+ ImGui::MenuItem("Debug Log", NULL, &demo.ShowDebugLog , has_debug_tools);
495
+ ImGui::MenuItem("ID Stack Tool", NULL, &demo.ShowIDStackTool , has_debug_tools);
496
+ ImGui::MenuItem("Style Editor", NULL, &demo.ShowStyleEditor );
492
497
bool is_debugger_present = ImGui::GetIO().ConfigDebugIsDebuggerPresent;
493
498
if (ImGui::MenuItem("Item Picker", NULL, false, has_debug_tools && is_debugger_present))
494
499
ImGui::DebugStartItemPicker();
495
500
if (!is_debugger_present)
496
501
ImGui::SetItemTooltip("Requires io.ConfigDebugIsDebuggerPresent=true to be set.\n\nWe otherwise disable the menu option to avoid casual users crashing the application.\n\nYou can however always access the Item Picker in Metrics->Tools.");
497
502
ImGui::Separator();
498
- ImGui::MenuItem("About Dear ImGui", NULL, &show_tool_about );
503
+ ImGui::MenuItem("About Dear ImGui", NULL, &demo.ShowAbout );
499
504
ImGui::EndMenu();
500
505
}
501
506
ImGui::EndMenuBar();
@@ -620,7 +625,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
620
625
IMGUI_DEMO_MARKER("Configuration/Style");
621
626
if (ImGui::TreeNode("Style"))
622
627
{
623
- ImGui::Checkbox("Style Editor", &show_tool_style_editor );
628
+ ImGui::Checkbox("Style Editor", &demo.ShowStyleEditor );
624
629
ImGui::SameLine();
625
630
HelpMarker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function.");
626
631
ImGui::TreePop();
@@ -668,7 +673,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
668
673
}
669
674
670
675
// All demo contents
671
- ShowDemoWindowWidgets();
676
+ ShowDemoWindowWidgets(&demo );
672
677
ShowDemoWindowLayout();
673
678
ShowDemoWindowPopups();
674
679
ShowDemoWindowTables();
@@ -683,7 +688,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
683
688
// [SECTION] ShowDemoWindowWidgets()
684
689
//-----------------------------------------------------------------------------
685
690
686
- static void ShowDemoWindowWidgets()
691
+ static void ShowDemoWindowWidgets(DemoWindowData* demo_data )
687
692
{
688
693
IMGUI_DEMO_MARKER("Widgets");
689
694
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
@@ -1561,7 +1566,7 @@ static void ShowDemoWindowWidgets()
1561
1566
ImGui::TreePop();
1562
1567
}
1563
1568
1564
- ShowDemoWindowMultiSelect();
1569
+ ShowDemoWindowMultiSelect(demo_data );
1565
1570
1566
1571
// To wire InputText() with std::string or any other custom string type,
1567
1572
// see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file.
@@ -3071,7 +3076,7 @@ struct ExampleDualListBox
3071
3076
// Also read: https://github.com/ocornut/imgui/wiki/Multi-Select
3072
3077
//-----------------------------------------------------------------------------
3073
3078
3074
- static void ShowDemoWindowMultiSelect()
3079
+ static void ShowDemoWindowMultiSelect(DemoWindowData* demo_data )
3075
3080
{
3076
3081
IMGUI_DEMO_MARKER("Widgets/Selection State & Multi-Select");
3077
3082
if (ImGui::TreeNode("Selection State & Multi-Select"))
@@ -3366,7 +3371,8 @@ static void ShowDemoWindowMultiSelect()
3366
3371
// See ShowExampleAppAssetsBrowser()
3367
3372
if (ImGui::TreeNode("Multi-Select (tiled assets browser)"))
3368
3373
{
3369
- ImGui::BulletText("See 'Examples->Assets Browser' in menu");
3374
+ ImGui::Checkbox("Assets Browser", &demo_data->ShowAppAssetsBrowser);
3375
+ ImGui::Text("(also access from 'Examples->Assets Browser' in menu)");
3370
3376
ImGui::TreePop();
3371
3377
}
3372
3378
0 commit comments