playground/ExampleApps/ExampleAppMainMenuBar.cpp
// Note that shortcuts are currently provided for display only
// (future version will add explicit flags to BeginMenu() to request processing shortcuts)
Note that shortcuts are currently provided for display only
(future version will add explicit flags to BeginMenu() to request processing shortcuts)
Note that shortcuts are currently provided for display only ( future version will add explicit flags to BeginMenu () to request processing shortcuts )
static void ShowExampleMenuFile()
{
    DEMO_MARKER("Examples/Menu File");
    ImGui::MenuItem("(demo menu)", NULL, false, false);
    if (ImGui::MenuItem("New")) {}
    if (ImGui::MenuItem("Open", "Ctrl+O")) {}
    if (ImGui::BeginMenu("Open Recent"))
    {
        DEMO_MARKER("Examples/Menu File/Open Recent");
        ImGui::MenuItem("fish_hat.c");
        ImGui::MenuItem("fish_hat.inl");
        ImGui::MenuItem("fish_hat.h");
        if (ImGui::BeginMenu("More.."))
        {
            DEMO_MARKER("Examples/Menu File/Open Recent/More");
            ImGui::MenuItem("Hello");
            ImGui::MenuItem("Sailor");
            if (ImGui::BeginMenu("Recurse.."))
            {
                ShowExampleMenuFile();
                ImGui::EndMenu();
            }
            ImGui::EndMenu();
        }
        ImGui::EndMenu();
    }
    if (ImGui::MenuItem("Save", "Ctrl+S")) {}
    if (ImGui::MenuItem("Save As..")) {}
    ImGui::Separator();
    if (ImGui::BeginMenu("Options"))
    {
        DEMO_MARKER("Examples/Menu File/Options");
        static bool enabled = true;
        ImGui::MenuItem("Enabled", "", &enabled);
        ImGui::BeginChild("child", ImVec2(0, 60), true);
        for (int i = 0; i < 10; i++)
            ImGui::Text("Scrolling Text %d", i);
        ImGui::EndChild();
        static float f = 0.5f;
        static int n = 0;
        ImGui::SliderFloat("Value", &f, 0.0f, 1.0f);
        ImGui::InputFloat("Input", &f, 0.1f);
        ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0");
        ImGui::EndMenu();
    }
    if (ImGui::BeginMenu("Colors"))
    {
        DEMO_MARKER("Examples/Menu File/Colors");
        float sz = ImGui::GetTextLineHeight();
        for (int i = 0; i < ImGuiCol_COUNT; i++)
        {
            const char* name = ImGui::GetStyleColorName((ImGuiCol)i);
            ImVec2 p = ImGui::GetCursorScreenPos();
            ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + sz, p.y + sz), ImGui::GetColorU32((ImGuiCol)i));
            ImGui::Dummy(ImVec2(sz, sz));
            ImGui::SameLine();
            ImGui::MenuItem(name);
        }
        ImGui::EndMenu();
    }
    if (ImGui::BeginMenu("Options")) 
    {
        DEMO_MARKER("Examples/Menu File/Append to an existing menu");
        static bool b = true;
        ImGui::Checkbox("SomeOption", &b);
        ImGui::EndMenu();
    }
    if (ImGui::BeginMenu("Disabled", false)) 
    {
        IM_ASSERT(0);
    }
    DEMO_MARKER("Examples/Menu File/Checked item");
    if (ImGui::MenuItem("Checked", NULL, true)) {}
    if (ImGui::MenuItem("Quit", "Alt+F4")) {}
}
static void ShowExampleMenuFile ( ) { DEMO_MARKER ( " " ) ; ImGui :: MenuItem ( " " , NULL , false , false ) ; if ( ImGui :: MenuItem ( " " ) ) { } if ( ImGui :: MenuItem ( " " , " " ) ) { } if ( ImGui :: BeginMenu ( " " ) ) { DEMO_MARKER ( " " ) ; ImGui :: MenuItem ( " " ) ; ImGui :: MenuItem ( " " ) ; ImGui :: MenuItem ( " " ) ; if ( ImGui :: BeginMenu ( " " ) ) { DEMO_MARKER ( " " ) ; ImGui :: MenuItem ( " " ) ; ImGui :: MenuItem ( " " ) ; if ( ImGui :: BeginMenu ( " " ) ) { ShowExampleMenuFile ( ) ; ImGui :: EndMenu ( ) ; } ImGui :: EndMenu ( ) ; } ImGui :: EndMenu ( ) ; } if ( ImGui :: MenuItem ( " " , " " ) ) { } if ( ImGui :: MenuItem ( " " ) ) { } ImGui :: Separator ( ) ; if ( ImGui :: BeginMenu ( " " ) ) { DEMO_MARKER ( " " ) ; static bool enabled = true ; ImGui :: MenuItem ( " " , " " , & enabled ) ; ImGui :: BeginChild ( " " , ImVec2 ( 0 , 60 ) , true ) ; for ( int i = 0 ; i < 10 ; i ++ ) ImGui :: Text ( " " , i ) ; ImGui :: EndChild ( ) ; static float f = 0.5f ; static int n = 0 ; ImGui :: SliderFloat ( " " , & f , 0.0f , 1.0f ) ; ImGui :: InputFloat ( " " , & f , 0.1f ) ; ImGui :: Combo ( " " , & n , " \0 \0 \0 \0 " ) ; ImGui :: EndMenu ( ) ; } if ( ImGui :: BeginMenu ( " " ) ) { DEMO_MARKER ( " " ) ; float sz = ImGui :: GetTextLineHeight ( ) ; for ( int i = 0 ; i < ImGuiCol_COUNT ; i ++ ) { const char * name = ImGui :: GetStyleColorName ( ( ImGuiCol ) i ) ; ImVec2 p = ImGui :: GetCursorScreenPos ( ) ; ImGui :: GetWindowDrawList ( ) -> AddRectFilled ( p , ImVec2 ( p . x + sz , p . y + sz ) , ImGui :: GetColorU32 ( ( ImGuiCol ) i ) ) ; ImGui :: Dummy ( ImVec2 ( sz , sz ) ) ; ImGui :: SameLine ( ) ; ImGui :: MenuItem ( name ) ; } ImGui :: EndMenu ( ) ; } if ( ImGui :: BeginMenu ( " " ) ) { DEMO_MARKER ( " " ) ; static bool b = true ; ImGui :: Checkbox ( " " , & b ) ; ImGui :: EndMenu ( ) ; } if ( ImGui :: BeginMenu ( " " , false ) ) { IM_ASSERT ( 0 ) ; } DEMO_MARKER ( " " ) ; if ( ImGui :: MenuItem ( " " , NULL , true ) ) { } if ( ImGui :: MenuItem ( " " , " " ) ) { } }
Note that shortcuts are currently provided for display only
(future version will add explicit flags to BeginMenu() to request processing shortcuts)
Note that shortcuts are currently provided for display only ( future version will add explicit flags to BeginMenu () to request processing shortcuts )
// Here we demonstrate appending again to the "Options" menu (which we already created above) // Of course in this demo it is a little bit silly that this function calls BeginMenu("Options") twice. // In a real code-base using it would make senses to use this feature from very different code locations. // <-- Append! // Disabled