@@ -72,6 +72,7 @@ Index of this file:
72
72
// [SECTION] Helpers
73
73
// [SECTION] Helpers: ExampleTreeNode, ExampleMemberInfo (for use by Property Editor & Multi-Select demos)
74
74
// [SECTION] Demo Window / ShowDemoWindow()
75
+ // [SECTION] ShowDemoWindowMenuBar()
75
76
// [SECTION] ShowDemoWindowWidgets()
76
77
// [SECTION] ShowDemoWindowMultiSelect()
77
78
// [SECTION] ShowDemoWindowLayout()
@@ -217,6 +218,7 @@ static void ShowExampleMenuFile();
217
218
// We split the contents of the big ShowDemoWindow() function into smaller functions
218
219
// (because the link time of very large functions tends to grow non-linearly)
219
220
struct DemoWindowData;
221
+ static void ShowDemoWindowMenuBar(DemoWindowData* demo_data);
220
222
static void ShowDemoWindowWidgets(DemoWindowData* demo_data);
221
223
static void ShowDemoWindowMultiSelect(DemoWindowData* demo_data);
222
224
static void ShowDemoWindowLayout();
@@ -443,68 +445,11 @@ void ImGui::ShowDemoWindow(bool* p_open)
443
445
}
444
446
445
447
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
446
- // e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
447
- //ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f);
448
- // e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
449
- ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
448
+ ImGui::PushItemWidth(ImGui::GetFontSize() * -12); // e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
449
+ //ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f); // e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
450
450
451
451
// Menu Bar
452
- if (ImGui::BeginMenuBar())
453
- {
454
- if (ImGui::BeginMenu("Menu"))
455
- {
456
- IMGUI_DEMO_MARKER("Menu/File");
457
- ShowExampleMenuFile();
458
- ImGui::EndMenu();
459
- }
460
- if (ImGui::BeginMenu("Examples"))
461
- {
462
- IMGUI_DEMO_MARKER("Menu/Examples");
463
- ImGui::MenuItem("Main menu bar", NULL, &demo.ShowMainMenuBar);
464
-
465
- ImGui::SeparatorText("Mini apps");
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);
474
-
475
- ImGui::SeparatorText("Concepts");
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);
481
-
482
- ImGui::EndMenu();
483
- }
484
- //if (ImGui::MenuItem("MenuItem")) {} // You can also use MenuItem() inside a menu bar!
485
- if (ImGui::BeginMenu("Tools"))
486
- {
487
- IMGUI_DEMO_MARKER("Menu/Tools");
488
- #ifndef IMGUI_DISABLE_DEBUG_TOOLS
489
- const bool has_debug_tools = true;
490
- #else
491
- const bool has_debug_tools = false;
492
- #endif
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);
497
- bool is_debugger_present = ImGui::GetIO().ConfigDebugIsDebuggerPresent;
498
- if (ImGui::MenuItem("Item Picker", NULL, false, has_debug_tools && is_debugger_present))
499
- ImGui::DebugStartItemPicker();
500
- if (!is_debugger_present)
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.");
502
- ImGui::Separator();
503
- ImGui::MenuItem("About Dear ImGui", NULL, &demo.ShowAbout);
504
- ImGui::EndMenu();
505
- }
506
- ImGui::EndMenuBar();
507
- }
452
+ ShowDemoWindowMenuBar(&demo);
508
453
509
454
ImGui::Text("dear imgui says hello! (%s) (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM);
510
455
ImGui::Spacing();
@@ -684,6 +629,71 @@ void ImGui::ShowDemoWindow(bool* p_open)
684
629
ImGui::End();
685
630
}
686
631
632
+ //-----------------------------------------------------------------------------
633
+ // [SECTION] ShowDemoWindowMenuBar()
634
+ //-----------------------------------------------------------------------------
635
+
636
+ static void ShowDemoWindowMenuBar(DemoWindowData* demo_data)
637
+ {
638
+ IMGUI_DEMO_MARKER("Menu");
639
+ if (ImGui::BeginMenuBar())
640
+ {
641
+ if (ImGui::BeginMenu("Menu"))
642
+ {
643
+ IMGUI_DEMO_MARKER("Menu/File");
644
+ ShowExampleMenuFile();
645
+ ImGui::EndMenu();
646
+ }
647
+ if (ImGui::BeginMenu("Examples"))
648
+ {
649
+ IMGUI_DEMO_MARKER("Menu/Examples");
650
+ ImGui::MenuItem("Main menu bar", NULL, &demo_data->ShowMainMenuBar);
651
+
652
+ ImGui::SeparatorText("Mini apps");
653
+ ImGui::MenuItem("Assets Browser", NULL, &demo_data->ShowAppAssetsBrowser);
654
+ ImGui::MenuItem("Console", NULL, &demo_data->ShowAppConsole);
655
+ ImGui::MenuItem("Custom rendering", NULL, &demo_data->ShowAppCustomRendering);
656
+ ImGui::MenuItem("Documents", NULL, &demo_data->ShowAppDocuments);
657
+ ImGui::MenuItem("Log", NULL, &demo_data->ShowAppLog);
658
+ ImGui::MenuItem("Property editor", NULL, &demo_data->ShowAppPropertyEditor);
659
+ ImGui::MenuItem("Simple layout", NULL, &demo_data->ShowAppLayout);
660
+ ImGui::MenuItem("Simple overlay", NULL, &demo_data->ShowAppSimpleOverlay);
661
+
662
+ ImGui::SeparatorText("Concepts");
663
+ ImGui::MenuItem("Auto-resizing window", NULL, &demo_data->ShowAppAutoResize);
664
+ ImGui::MenuItem("Constrained-resizing window", NULL, &demo_data->ShowAppConstrainedResize);
665
+ ImGui::MenuItem("Fullscreen window", NULL, &demo_data->ShowAppFullscreen);
666
+ ImGui::MenuItem("Long text display", NULL, &demo_data->ShowAppLongText);
667
+ ImGui::MenuItem("Manipulating window titles", NULL, &demo_data->ShowAppWindowTitles);
668
+
669
+ ImGui::EndMenu();
670
+ }
671
+ //if (ImGui::MenuItem("MenuItem")) {} // You can also use MenuItem() inside a menu bar!
672
+ if (ImGui::BeginMenu("Tools"))
673
+ {
674
+ IMGUI_DEMO_MARKER("Menu/Tools");
675
+ #ifndef IMGUI_DISABLE_DEBUG_TOOLS
676
+ const bool has_debug_tools = true;
677
+ #else
678
+ const bool has_debug_tools = false;
679
+ #endif
680
+ ImGui::MenuItem("Metrics/Debugger", NULL, &demo_data->ShowMetrics, has_debug_tools);
681
+ ImGui::MenuItem("Debug Log", NULL, &demo_data->ShowDebugLog, has_debug_tools);
682
+ ImGui::MenuItem("ID Stack Tool", NULL, &demo_data->ShowIDStackTool, has_debug_tools);
683
+ ImGui::MenuItem("Style Editor", NULL, &demo_data->ShowStyleEditor);
684
+ bool is_debugger_present = ImGui::GetIO().ConfigDebugIsDebuggerPresent;
685
+ if (ImGui::MenuItem("Item Picker", NULL, false, has_debug_tools && is_debugger_present))
686
+ ImGui::DebugStartItemPicker();
687
+ if (!is_debugger_present)
688
+ 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.");
689
+ ImGui::Separator();
690
+ ImGui::MenuItem("About Dear ImGui", NULL, &demo_data->ShowAbout);
691
+ ImGui::EndMenu();
692
+ }
693
+ ImGui::EndMenuBar();
694
+ }
695
+ }
696
+
687
697
//-----------------------------------------------------------------------------
688
698
// [SECTION] ShowDemoWindowWidgets()
689
699
//-----------------------------------------------------------------------------
0 commit comments