Skip to content

Commit 57eea67

Browse files
committed
Demo: moved some fields inside a struct.
1 parent 2546d0a commit 57eea67

File tree

1 file changed

+79
-73
lines changed

1 file changed

+79
-73
lines changed

imgui_demo.cpp

+79-73
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ static void ShowExampleMenuFile();
216216

217217
// We split the contents of the big ShowDemoWindow() function into smaller functions
218218
// (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);
221222
static void ShowDemoWindowLayout();
222223
static void ShowDemoWindowPopups();
223224
static void ShowDemoWindowTables();
@@ -332,6 +333,32 @@ static ExampleTreeNode* ExampleTree_CreateDemoTree()
332333
// [SECTION] Demo Window / ShowDemoWindow()
333334
//-----------------------------------------------------------------------------
334335

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+
335362
// Demonstrate most Dear ImGui features (this is big function!)
336363
// You may execute this function to experiment with the UI and understand what it does.
337364
// 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)
344371
// Verify ABI compatibility between caller code and compiled version of Dear ImGui. This helps detects some build issues.
345372
IMGUI_CHECKVERSION();
346373

374+
// Stored data
375+
static DemoWindowData demo;
376+
347377
// 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); }
377392

378393
// 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);
394401
ImGui::ShowStyleEditor();
395402
ImGui::End();
396403
}
397-
if (show_tool_about)
398-
ImGui::ShowAboutWindow(&show_tool_about);
399404

400405
// Demonstrate the various window flags. Typically you would just use the default!
401406
static bool no_titlebar = false;
@@ -455,24 +460,24 @@ void ImGui::ShowDemoWindow(bool* p_open)
455460
if (ImGui::BeginMenu("Examples"))
456461
{
457462
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);
459464

460465
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);
469474

470475
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);
476481

477482
ImGui::EndMenu();
478483
}
@@ -485,17 +490,17 @@ void ImGui::ShowDemoWindow(bool* p_open)
485490
#else
486491
const bool has_debug_tools = false;
487492
#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);
492497
bool is_debugger_present = ImGui::GetIO().ConfigDebugIsDebuggerPresent;
493498
if (ImGui::MenuItem("Item Picker", NULL, false, has_debug_tools && is_debugger_present))
494499
ImGui::DebugStartItemPicker();
495500
if (!is_debugger_present)
496501
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.");
497502
ImGui::Separator();
498-
ImGui::MenuItem("About Dear ImGui", NULL, &show_tool_about);
503+
ImGui::MenuItem("About Dear ImGui", NULL, &demo.ShowAbout);
499504
ImGui::EndMenu();
500505
}
501506
ImGui::EndMenuBar();
@@ -620,7 +625,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
620625
IMGUI_DEMO_MARKER("Configuration/Style");
621626
if (ImGui::TreeNode("Style"))
622627
{
623-
ImGui::Checkbox("Style Editor", &show_tool_style_editor);
628+
ImGui::Checkbox("Style Editor", &demo.ShowStyleEditor);
624629
ImGui::SameLine();
625630
HelpMarker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function.");
626631
ImGui::TreePop();
@@ -668,7 +673,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
668673
}
669674

670675
// All demo contents
671-
ShowDemoWindowWidgets();
676+
ShowDemoWindowWidgets(&demo);
672677
ShowDemoWindowLayout();
673678
ShowDemoWindowPopups();
674679
ShowDemoWindowTables();
@@ -683,7 +688,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
683688
// [SECTION] ShowDemoWindowWidgets()
684689
//-----------------------------------------------------------------------------
685690

686-
static void ShowDemoWindowWidgets()
691+
static void ShowDemoWindowWidgets(DemoWindowData* demo_data)
687692
{
688693
IMGUI_DEMO_MARKER("Widgets");
689694
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
@@ -1561,7 +1566,7 @@ static void ShowDemoWindowWidgets()
15611566
ImGui::TreePop();
15621567
}
15631568

1564-
ShowDemoWindowMultiSelect();
1569+
ShowDemoWindowMultiSelect(demo_data);
15651570

15661571
// To wire InputText() with std::string or any other custom string type,
15671572
// see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file.
@@ -3071,7 +3076,7 @@ struct ExampleDualListBox
30713076
// Also read: https://github.com/ocornut/imgui/wiki/Multi-Select
30723077
//-----------------------------------------------------------------------------
30733078

3074-
static void ShowDemoWindowMultiSelect()
3079+
static void ShowDemoWindowMultiSelect(DemoWindowData* demo_data)
30753080
{
30763081
IMGUI_DEMO_MARKER("Widgets/Selection State & Multi-Select");
30773082
if (ImGui::TreeNode("Selection State & Multi-Select"))
@@ -3366,7 +3371,8 @@ static void ShowDemoWindowMultiSelect()
33663371
// See ShowExampleAppAssetsBrowser()
33673372
if (ImGui::TreeNode("Multi-Select (tiled assets browser)"))
33683373
{
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)");
33703376
ImGui::TreePop();
33713377
}
33723378

0 commit comments

Comments
 (0)