Flix01 / imgui

Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
https://github.com/Flix01/imgui/wiki/ImGui-Addons-Branch-Home
MIT License
396 stars 34 forks source link

Add optional default_pos parameter to BeginDock. #46

Closed tom-seddon closed 6 years ago

tom-seddon commented 6 years ago

I got annoyed at dock windows opening in windowed mode at (0,0), because they'd then appear on top of the menu bar. With this extra optional BeginDock parameter, I can make them open at (10,30) instead.

(Interestingly, there doesn't appear to be any way to query the exact dear imgui menu bar height. This is noted only for the record... feels like fixing this would be out of scope for this fork. And it's hardly a major problem anyway.)

When not specified, the window will open at (0,0) as before.

--Tom

Flix01 commented 6 years ago

Thanks Tom.

Interestingly, there doesn't appear to be any way to query the exact dear imgui menu bar height.

Yes, what we use in examples/addon_examples/main2.cpp is an approach like this:

static ImVec2 gMainMenuBarSize(0,0);
static void ShowExampleAppMainMenuBar() {
    if (ImGui::BeginMainMenuBar())  {
        if (ImGui::BeginMenu("Edit"))   {
            if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
            if (ImGui::MenuItem("Redo", "CTRL+Y", false, false)) {}  // Disabled item
            ImGui::Separator();
            if (ImGui::MenuItem("Cut", "CTRL+X")) {}
            if (ImGui::MenuItem("Copy", "CTRL+C")) {}
            if (ImGui::MenuItem("Paste", "CTRL+V")) {}
            ImGui::EndMenu();
        }
        gMainMenuBarSize = ImGui::GetWindowSize();
        ImGui::EndMainMenuBar();
    }
}

However this needs ShowExampleAppMainMenuBar() to be called before BeginDock()

As an alternative in addons/imguihelper/imguihelper.h is present:

float CalcMainMenuHeight()  {
    // Warning: according to https://github.com/ocornut/imgui/issues/252 this approach can fail [Better call ImGui::GetWindowSize().y from inside the menu and store the result somewhere]
    if (GImGui->FontBaseSize>0) return GImGui->FontBaseSize + GImGui->Style.FramePadding.y * 2.0f;
    else {
        ImGuiIO& io = ImGui::GetIO();
        ImGuiStyle& style = ImGui::GetStyle();
        ImFont* font = ImGui::GetFont();
        if (!font) {
            if (io.Fonts->Fonts.size()>0) font = io.Fonts->Fonts[0];
            else return (14)+style.FramePadding.y * 2.0f;
        }
        return (io.FontGlobalScale * font->Scale * font->FontSize) + style.FramePadding.y * 2.0f;
    }
}

However, as noted in the code comment, according to https://github.com/ocornut/imgui/issues/252, the first solution is the preferred one.