From 1b2ec35b8ded8399cc3d47642121e090ef353f65 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Wed, 22 Nov 2017 12:58:11 +0100 Subject: [PATCH 1/4] Update imgui_draw.cpp --- imgui_draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 28d25e2d7..481014443 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -237,8 +237,8 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f); colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f); From 7763ab3fcc1f728f35919aae2225c05b084f16c4 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 22 Nov 2017 12:26:50 +0100 Subject: [PATCH 2/4] Menu bar: better software clipping to handle small windows, in particular child window don't have the minimum constraint added in e9a7e73bbaacec886f9b39130428b81b7f95bf16 so we need to render clipped menus better. --- imgui.cpp | 23 ++++++++++++++--------- imgui_internal.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2323dce02..c1361f735 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4460,16 +4460,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot); // Title bar - const bool is_focused = g.NavWindow && window->RootNonPopupWindow == g.NavWindow->RootNonPopupWindow; + const bool window_is_focused = g.NavWindow && window->RootNonPopupWindow == g.NavWindow->RootNonPopupWindow; if (!(flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32(is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImDrawCornerFlags_Top); + window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(window_is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImDrawCornerFlags_Top); // Menu bar if (flags & ImGuiWindowFlags_MenuBar) { ImRect menu_bar_rect = window->MenuBarRect(); - window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top); - if (style.FrameBorderSize > 0.0f) + menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them. + window->DrawList->AddRectFilled(menu_bar_rect.Min, menu_bar_rect.Max, GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top); + if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y) window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize); } @@ -9231,14 +9232,18 @@ bool ImGui::BeginMenuBar() if (!(window->Flags & ImGuiWindowFlags_MenuBar)) return false; - ImGuiContext& g = *GImGui; IM_ASSERT(!window->DC.MenuBarAppending); BeginGroup(); // Save position PushID("##menubar"); - ImRect rect = window->MenuBarRect(); - rect.Max.x = ImMax(rect.Min.x, rect.Max.x - g.Style.WindowRounding); - PushClipRect(ImVec2(ImFloor(rect.Min.x+0.5f), ImFloor(rect.Min.y + window->WindowBorderSize + 0.5f)), ImVec2(ImFloor(rect.Max.x+0.5f), ImFloor(rect.Max.y+0.5f)), false); - window->DC.CursorPos = ImVec2(rect.Min.x + window->DC.MenuBarOffsetX, rect.Min.y);// + g.Style.FramePadding.y); + + // We don't clip with regular window clipping rectangle as it is already set to the area below. However we clip with window full rect. + // We remove 1 worth of rounding to Max.x to that text in long menus don't tend to display over the lower-right rounded area, which looks particularly glitchy. + ImRect bar_rect = window->MenuBarRect(); + ImRect clip_rect(ImFloor(bar_rect.Min.x + 0.5f), ImFloor(bar_rect.Min.y + window->WindowBorderSize + 0.5f), ImFloor(ImMax(bar_rect.Min.x, bar_rect.Max.x - window->WindowRounding) + 0.5f), ImFloor(bar_rect.Max.y + 0.5f)); + clip_rect.ClipWith(window->Rect()); + PushClipRect(clip_rect.Min, clip_rect.Max, false); + + window->DC.CursorPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffsetX, bar_rect.Min.y);// + g.Style.FramePadding.y); window->DC.LayoutType = ImGuiLayoutType_Horizontal; window->DC.MenuBarAppending = true; AlignTextToFramePadding(); diff --git a/imgui_internal.h b/imgui_internal.h index e54936a5b..f155abf74 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -746,6 +746,7 @@ public: ImGuiID GetID(const void* ptr); ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); + // We don't use g.FontSize because the window may be != g.CurrentWidow. ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x+Size.x, Pos.y+Size.y); } float CalcFontSize() const { return GImGui->FontBaseSize * FontWindowScale; } float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + GImGui->Style.FramePadding.y * 2.0f; } From 6bd3b45b34476b77e95874db1934b95e910db189 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 24 Nov 2017 09:23:17 +0100 Subject: [PATCH 3/4] Sisyphus says: tweaked comments about not using old-style OpenGL examples (#1459, #1394 etc.) --- examples/README.txt | 13 +++++++------ examples/opengl2_example/imgui_impl_glfw.cpp | 13 +++++++------ examples/opengl2_example/imgui_impl_glfw.h | 5 +++-- examples/opengl2_example/main.cpp | 5 +++-- imgui.cpp | 3 +-- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/examples/README.txt b/examples/README.txt index 35490b5b6..8ec8e7528 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -46,12 +46,13 @@ Also note that some setup or GPU drivers may be causing extra lag (possibly by e leaving you with no option but sadness/anger (Intel GPU drivers were reported as such). opengl2_example/ - *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* - GLFW + OpenGL example (old, fixed graphic pipeline). - This is mostly provided as a reference to learn how ImGui integration works, because it is easier to read. - If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything - more complicated, will require your code to reset every single OpenGL attributes to their initial state, - and might confuse your GPU driver. Prefer using opengl3_example. + **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** + **Prefer using the code in the opengl3_example/ folder** + GLFW + OpenGL example (legacy fixed graphic pipeline). + This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. + If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more + complicated, will require your code to reset every single OpenGL attributes to their initial state, and might + confuse your GPU driver. opengl3_example/ GLFW + OpenGL example (programmable pipeline, binding modern functions with GL3W). diff --git a/examples/opengl2_example/imgui_impl_glfw.cpp b/examples/opengl2_example/imgui_impl_glfw.cpp index 52962c19e..b6bb56a31 100644 --- a/examples/opengl2_example/imgui_impl_glfw.cpp +++ b/examples/opengl2_example/imgui_impl_glfw.cpp @@ -1,12 +1,13 @@ -// ImGui GLFW binding with OpenGL +// ImGui GLFW binding with OpenGL (legacy fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* -// This is mostly provided as a reference to learn how ImGui integration works, because it is easier to read. -// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything -// more complicated, will require your code to reset every single OpenGL attributes to their initial state, -// and might confuse your GPU driver. Prefer using opengl3_example. +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** +// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. +// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more +// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might +// confuse your GPU driver. // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. diff --git a/examples/opengl2_example/imgui_impl_glfw.h b/examples/opengl2_example/imgui_impl_glfw.h index f17833ae1..22f910eaa 100644 --- a/examples/opengl2_example/imgui_impl_glfw.h +++ b/examples/opengl2_example/imgui_impl_glfw.h @@ -1,8 +1,9 @@ -// ImGui GLFW binding with OpenGL +// ImGui GLFW binding with OpenGL (legacy fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** // See imgui_impl_glfw.cpp for details. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. diff --git a/examples/opengl2_example/main.cpp b/examples/opengl2_example/main.cpp index 1f3336d21..ed8f1a7b6 100644 --- a/examples/opengl2_example/main.cpp +++ b/examples/opengl2_example/main.cpp @@ -1,8 +1,9 @@ -// ImGui - standalone example application for GLFW + OpenGL 2, using fixed pipeline +// ImGui - standalone example application for GLFW + OpenGL2, using legacy fixed pipeline // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the opengl3_example/ folder** // See imgui_impl_glfw.cpp for details. #include diff --git a/imgui.cpp b/imgui.cpp index c1361f735..0c209b67b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -103,8 +103,7 @@ - Add the Dear ImGui source files to your projects, using your preferred build system. It is recommended you build the .cpp files as part of your project and not as a library. - You can later customize the imconfig.h file to tweak some compilation time behavior, such as integrating imgui types with your own maths types. - - See examples/ folder for standalone sample applications. To understand the integration process, you can read examples/opengl2_example/ because - it is short, then switch to the one more appropriate to your use case. + - See examples/ folder for standalone sample applications. - You may be able to grab and copy a ready made imgui_impl_*** file from the examples/. - When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them. From ef5dd30625913d8aef7083d4bc2f711131f7a86c Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 24 Nov 2017 09:27:45 +0100 Subject: [PATCH 4/4] Sisyphus says: tweaked comments about not using old-style OpenGL examples (#1459, #1394 etc.) --- examples/README.txt | 19 +++++++++++-------- examples/opengl2_example/imgui_impl_glfw.cpp | 2 +- examples/opengl2_example/imgui_impl_glfw.h | 2 +- .../sdl_opengl2_example/imgui_impl_sdl.cpp | 13 +++++++------ examples/sdl_opengl2_example/imgui_impl_sdl.h | 6 +++++- examples/sdl_opengl2_example/main.cpp | 3 ++- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/examples/README.txt b/examples/README.txt index 8ec8e7528..1f00756f1 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -48,7 +48,7 @@ leaving you with no option but sadness/anger (Intel GPU drivers were reported as opengl2_example/ **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** **Prefer using the code in the opengl3_example/ folder** - GLFW + OpenGL example (legacy fixed graphic pipeline). + GLFW + OpenGL example (legacy, fixed pipeline). This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more complicated, will require your code to reset every single OpenGL attributes to their initial state, and might @@ -57,7 +57,7 @@ opengl2_example/ opengl3_example/ GLFW + OpenGL example (programmable pipeline, binding modern functions with GL3W). This uses more modern OpenGL calls and custom shaders. - Prefer using that if you are using modern OpenGL3/4 in your application. + Prefer using that if you are using modern OpenGL in your application (anything with shaders, vbo, vao, etc.). directx9_example/ DirectX9 example, Windows only. @@ -76,15 +76,18 @@ apple_example/ Synergy keyboard integration is rather hacky. sdl_opengl2_example/ - *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* - SDL2 + OpenGL example (old fixed pipeline). - This is mostly provided as a reference to learn how ImGui integration works, because it is easier to read. - If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything - more complicated, will require your code to reset every single OpenGL attributes to their initial state, - and might confuse your GPU driver. Prefer using sdl_opengl3_example. + **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** + **Prefer using the code in the sdl_opengl3_example/ folder** + SDL2 + OpenGL example (legacy, fixed pipeline). + This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. + If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more + complicated, will require your code to reset every single OpenGL attributes to their initial state, and might + confuse your GPU driver. sdl_opengl3_example/ SDL2 + OpenGL3 example. + This uses more modern OpenGL calls and custom shaders. + Prefer using that if you are using modern OpenGL in your application (anything with shaders, vbo, vao, etc.). allegro5_example/ Allegro 5 example. diff --git a/examples/opengl2_example/imgui_impl_glfw.cpp b/examples/opengl2_example/imgui_impl_glfw.cpp index b6bb56a31..364d92889 100644 --- a/examples/opengl2_example/imgui_impl_glfw.cpp +++ b/examples/opengl2_example/imgui_impl_glfw.cpp @@ -1,4 +1,4 @@ -// ImGui GLFW binding with OpenGL (legacy fixed pipeline) +// ImGui GLFW binding with OpenGL (legacy, fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) diff --git a/examples/opengl2_example/imgui_impl_glfw.h b/examples/opengl2_example/imgui_impl_glfw.h index 22f910eaa..d04a84fa8 100644 --- a/examples/opengl2_example/imgui_impl_glfw.h +++ b/examples/opengl2_example/imgui_impl_glfw.h @@ -1,4 +1,4 @@ -// ImGui GLFW binding with OpenGL (legacy fixed pipeline) +// ImGui GLFW binding with OpenGL (legacy, fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) diff --git a/examples/sdl_opengl2_example/imgui_impl_sdl.cpp b/examples/sdl_opengl2_example/imgui_impl_sdl.cpp index 2982f8dee..66f3ed5a8 100644 --- a/examples/sdl_opengl2_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl2_example/imgui_impl_sdl.cpp @@ -1,12 +1,13 @@ -// ImGui SDL2 binding with OpenGL +// ImGui SDL2 binding with OpenGL (legacy, fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* -// This is mostly provided as a reference to learn how ImGui integration works, because it is easier to read. -// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything -// more complicated, will require your code to reset every single OpenGL attributes to their initial state, -// and might confuse your GPU driver. Prefer using sdl_opengl3_example. +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** +// This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. +// If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more +// complicated, will require your code to reset every single OpenGL attributes to their initial state, and might +// confuse your GPU driver. // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. diff --git a/examples/sdl_opengl2_example/imgui_impl_sdl.h b/examples/sdl_opengl2_example/imgui_impl_sdl.h index ea94f69a7..32d7bc0e9 100644 --- a/examples/sdl_opengl2_example/imgui_impl_sdl.h +++ b/examples/sdl_opengl2_example/imgui_impl_sdl.h @@ -1,7 +1,11 @@ -// ImGui SDL2 binding with OpenGL +// ImGui SDL2 binding with OpenGL (legacy, fixed pipeline) // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. // (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** +// See imgui_impl_sdl.cpp for details. + // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. diff --git a/examples/sdl_opengl2_example/main.cpp b/examples/sdl_opengl2_example/main.cpp index cfa43e8e8..77241a5ba 100644 --- a/examples/sdl_opengl2_example/main.cpp +++ b/examples/sdl_opengl2_example/main.cpp @@ -2,7 +2,8 @@ // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) -// *DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL* +// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** +// **Prefer using the code in the sdl_opengl3_example/ folder** // See imgui_impl_sdl.cpp for details. #include