From c077dd4872f435dd959feb024e5a9adb2c7df20c Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 31 Aug 2019 19:59:51 +0200 Subject: [PATCH 001/384] Fixed missing IMGUI_API for IsMouseDragPastThreshold(). --- imgui_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index e9139d60..f13aeedc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1579,7 +1579,7 @@ namespace ImGui IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel); // Inputs - inline bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); + IMGUI_API bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { const int key_index = GImGui->IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } inline bool IsNavInputDown(ImGuiNavInput n) { return GImGui->IO.NavInputs[n] > 0.0f; } inline bool IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode) { return GetNavInputAmount(n, mode) > 0.0f; } From cc288e073c64114058269d227d4038cf211db2e5 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 16 Sep 2019 12:08:23 +0200 Subject: [PATCH 002/384] Backends: OpenGL3: Tweaked initialization code allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before ImGui_ImplOpenGL3_NewFrame() if for some reason they wanted. --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_opengl3.cpp | 24 +++++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a34aef92..09381fd5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -51,6 +51,8 @@ Other Changes: - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636) +- Backends: OpenGL3: Tweaked initialization code allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() + before ImGui_ImplOpenGL3_NewFrame() if for some reason they wanted. - Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count, would generally make the debug layer complain (Added in 1.72). - Backends: Vulkan: Added support for specifying multisample count. diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 9585215c..199638e8 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call. // 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. // 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop. @@ -164,7 +165,7 @@ void ImGui_ImplOpenGL3_Shutdown() void ImGui_ImplOpenGL3_NewFrame() { - if (!g_FontTexture) + if (!g_ShaderHandle) ImGui_ImplOpenGL3_CreateDeviceObjects(); } @@ -613,20 +614,13 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects() void ImGui_ImplOpenGL3_DestroyDeviceObjects() { - if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); - if (g_ElementsHandle) glDeleteBuffers(1, &g_ElementsHandle); - g_VboHandle = g_ElementsHandle = 0; - - if (g_ShaderHandle && g_VertHandle) glDetachShader(g_ShaderHandle, g_VertHandle); - if (g_VertHandle) glDeleteShader(g_VertHandle); - g_VertHandle = 0; - - if (g_ShaderHandle && g_FragHandle) glDetachShader(g_ShaderHandle, g_FragHandle); - if (g_FragHandle) glDeleteShader(g_FragHandle); - g_FragHandle = 0; - - if (g_ShaderHandle) glDeleteProgram(g_ShaderHandle); - g_ShaderHandle = 0; + if (g_VboHandle) { glDeleteBuffers(1, &g_VboHandle); g_VboHandle = 0; } + if (g_ElementsHandle) { glDeleteBuffers(1, &g_ElementsHandle); g_ElementsHandle = 0; } + if (g_ShaderHandle && g_VertHandle) { glDetachShader(g_ShaderHandle, g_VertHandle); } + if (g_ShaderHandle && g_FragHandle) { glDetachShader(g_ShaderHandle, g_FragHandle); } + if (g_VertHandle) { glDeleteShader(g_VertHandle); g_VertHandle = 0; } + if (g_FragHandle) { glDeleteShader(g_FragHandle); g_FragHandle = 0; } + if (g_ShaderHandle) { glDeleteProgram(g_ShaderHandle); g_ShaderHandle = 0; } ImGui_ImplOpenGL3_DestroyFontsTexture(); } From 3cf519c9cbbfc2f4e91883d8f14e62e82e5d6765 Mon Sep 17 00:00:00 2001 From: Bagrat Dabaghyan Date: Mon, 16 Sep 2019 06:03:42 +0400 Subject: [PATCH 003/384] Fix DragScalar for unsigned types (#2780) decreasing the value was broken on arm64 --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 09381fd5..cf03be73 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -46,6 +46,7 @@ Other Changes: Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right. - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] - DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. +- DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] - ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740) - Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a91268b3..e3441ac0 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1975,12 +1975,12 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const // Offset + round to user desired precision, with a curve on the v_min..v_max range to get more precision on one side of the range FLOATTYPE v_old_norm_curved = ImPow((FLOATTYPE)(v_cur - v_min) / (FLOATTYPE)(v_max - v_min), (FLOATTYPE)1.0f / power); FLOATTYPE v_new_norm_curved = v_old_norm_curved + (g.DragCurrentAccum / (v_max - v_min)); - v_cur = v_min + (TYPE)ImPow(ImSaturate((float)v_new_norm_curved), power) * (v_max - v_min); + v_cur = v_min + (SIGNEDTYPE)ImPow(ImSaturate((float)v_new_norm_curved), power) * (v_max - v_min); v_old_ref_for_accum_remainder = v_old_norm_curved; } else { - v_cur += (TYPE)g.DragCurrentAccum; + v_cur += (SIGNEDTYPE)g.DragCurrentAccum; } // Round to user desired precision based on format string From b05f6f6f502752586bb82afb01b942475953677e Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 9 Sep 2019 18:09:41 +0900 Subject: [PATCH 004/384] Nav, Scrolling: Added support for Home/End key. (#787) --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 7 +++-- imgui.cpp | 73 ++++++++++++++++++++++++++++++++++------------ imgui_internal.h | 5 ++-- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index cf03be73..5bc49ac7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,6 +34,7 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Other Changes: +- Nav, Scrolling: Added support for Home/End key. (#787) - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). diff --git a/docs/TODO.txt b/docs/TODO.txt index f289ebab..70c64c40 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -300,12 +300,14 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font/opt: Considering storing standalone AdvanceX table as 16-bit fixed point integer? - font/opt: Glyph currently 40 bytes (2+9*4). Consider storing UV as 16 bits integer? (->32 bytes). X0/Y0/X1/Y1 as 16 fixed-point integers? Or X0/Y0 as float and X1/Y1 as fixed8_8? + - nav: some features such as PageUp/Down/Home/End should probably work without ImGuiConfigFlags_NavEnableKeyboard? (where do we draw the line?) + - nav: configuration flag to disable global shortcuts (currently only CTRL-Tab) ? + - nav: Home/End behavior when navigable item is not fully visible at the edge of scrolling? should be backtrack to keep item into view? - nav: NavScrollToBringItemIntoView() with item bigger than view should focus top-right? Repro: using Nav in "About Window" - nav: wrap around logic to allow e.g. grid based layout (pressing NavRight on the right-most element would go to the next row, etc.). see internal's NavMoveRequestTryWrapping(). - nav: patterns to make it possible for arrows key to update selection - - nav: restore/find nearest navid when current one disappear (e.g. pressed a button that disappear, or perhaps auto restoring when current button change name) + - nav: restore/find nearest NavId when current one disappear (e.g. pressed a button that disappear, or perhaps auto restoring when current button change name) - nav: SetItemDefaultFocus() level of priority, so widget like Selectable when inside a popup could claim a low-priority default focus on the first selected iem - - nav: allow input system to be be more tolerant of io.DeltaTime=0.0f - nav: ESC within a menu of a child window seems to exit the child window. - nav: NavFlattened: ESC on a flattened child should select something. - nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child. @@ -323,7 +325,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - nav: esc/enter default behavior for popups, e.g. be able to mark an "ok" or "cancel" button that would get triggered by those keys. - nav: when activating a button that changes label (without a static ID) or disappear, can we somehow automatically recover into a nearest highlight item? - nav: there's currently no way to completely clear focus with the keyboard. depending on patterns used by the application to dispatch inputs, it may be desirable. - - nav: configuration flag to disable global shortcuts (currently only CTRL-tab) ? - focus: preserve ActiveId/focus stack state, e.g. when opening a menu and close it, previously selected InputText() focus gets restored (#622) - focus: SetKeyboardFocusHere() on with >= 0 offset could be done on same frame (else latch and modulate on beginning of next frame) - focus: unable to use SetKeyboardFocusHere() on clipped widgets. (#787) diff --git a/imgui.cpp b/imgui.cpp index 89541b2f..1dc4862a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1078,7 +1078,7 @@ static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& // Navigation static void NavUpdate(); static void NavUpdateWindowing(); -static void NavUpdateWindowingList(); +static void NavUpdateWindowingOverlay(); static void NavUpdateMoveResult(); static float NavUpdatePageUpPageDown(int allowed_dir_flags); static inline void NavUpdateAnyRequestFlag(); @@ -4184,8 +4184,8 @@ void ImGui::EndFrame() End(); // Show CTRL+TAB list window - if (g.NavWindowingTarget) - NavUpdateWindowingList(); + if (g.NavWindowingTarget != NULL) + NavUpdateWindowingOverlay(); // Drag and Drop: Elapse payload (if delivered, or if source stops being submitted) if (g.DragDropActive) @@ -8074,7 +8074,7 @@ void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const Im { ImGuiContext& g = *GImGui; IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_None); - ImGui::NavMoveRequestCancel(); + NavMoveRequestCancel(); g.NavMoveDir = move_dir; g.NavMoveClipDir = clip_dir; g.NavMoveRequestForward = ImGuiNavForward_ForwardQueued; @@ -8410,10 +8410,10 @@ static void ImGui::NavUpdate() g.NavMoveRequestFlags = ImGuiNavMoveFlags_None; if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { - if ((allowed_dir_flags & (1<RectRel.Min + result->Window->Pos, result->RectRel.Max + result->Window->Pos); - ImVec2 delta_scroll = ScrollToBringRectIntoView(result->Window, rect_abs); + ImVec2 delta_scroll; + if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_ScrollToEdge) + { + float scroll_target = (g.NavMoveDir == ImGuiDir_Up) ? result->Window->ScrollMax.y : 0.0f; + delta_scroll.y = result->Window->Scroll.y - scroll_target; + SetScrollY(result->Window, scroll_target); + } + else + { + ImRect rect_abs = ImRect(result->RectRel.Min + result->Window->Pos, result->RectRel.Max + result->Window->Pos); + delta_scroll = ScrollToBringRectIntoView(result->Window, rect_abs); + } // Offset our result position so mouse position can be applied immediately after in NavUpdate() result->RectRel.TranslateX(-delta_scroll.x); @@ -8565,6 +8576,7 @@ static void ImGui::NavUpdateMoveResult() g.NavMoveFromClampedRefRect = false; } +// Handle PageUp/PageDown/Home/End keys static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags) { ImGuiContext& g = *GImGui; @@ -8574,9 +8586,11 @@ static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags) return 0.0f; ImGuiWindow* window = g.NavWindow; - bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && (allowed_dir_flags & (1 << ImGuiDir_Up)); - bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && (allowed_dir_flags & (1 << ImGuiDir_Down)); - if (page_up_held != page_down_held) // If either (not both) are pressed + const bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && (allowed_dir_flags & (1 << ImGuiDir_Up)); + const bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && (allowed_dir_flags & (1 << ImGuiDir_Down)); + const bool home_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_Home]) && (allowed_dir_flags & (1 << ImGuiDir_Up)); + const bool end_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_End]) && (allowed_dir_flags & (1 << ImGuiDir_Down)); + if (page_up_held != page_down_held || home_pressed != end_pressed) // If either (not both) are pressed { if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll) { @@ -8585,26 +8599,49 @@ static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags) SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight()); else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true)) SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight()); + else if (home_pressed) + SetScrollY(window, 0.0f); + else if (end_pressed) + SetScrollY(window, window->ScrollMax.y); } else { - const ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer]; + ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer]; const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight()); float nav_scoring_rect_offset_y = 0.0f; if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageUp], true)) { nav_scoring_rect_offset_y = -page_offset_y; - g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item) + g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset up, we request the down direction (so we can always land on the last item) g.NavMoveClipDir = ImGuiDir_Up; g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet; } else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true)) { nav_scoring_rect_offset_y = +page_offset_y; - g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item) + g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset down, we request the up direction (so we can always land on the last item) g.NavMoveClipDir = ImGuiDir_Down; g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet; } + else if (home_pressed) + { + // FIXME-NAV: handling of Home/End is assuming that the top/bottom most item will be visible with Scroll.y == 0/ScrollMax.y + // Scrolling will be handled via the ImGuiNavMoveFlags_ScrollToEdge flag, we don't scroll immediately to avoid scrolling happening before nav result. + // Preserve current horizontal position if we have any. + nav_rect_rel.Min.y = nav_rect_rel.Max.y = -window->Scroll.y; + if (nav_rect_rel.IsInverted()) + nav_rect_rel.Min.x = nav_rect_rel.Max.x = 0.0f; + g.NavMoveDir = ImGuiDir_Down; + g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge; + } + else if (end_pressed) + { + nav_rect_rel.Min.y = nav_rect_rel.Max.y = window->ScrollMax.y + window->SizeFull.y - window->Scroll.y; + if (nav_rect_rel.IsInverted()) + nav_rect_rel.Min.x = nav_rect_rel.Max.x = 0.0f; + g.NavMoveDir = ImGuiDir_Up; + g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge; + } return nav_scoring_rect_offset_y; } } @@ -8800,7 +8837,7 @@ static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window) } // Overlay displayed when using CTRL+TAB. Called by EndFrame(). -void ImGui::NavUpdateWindowingList() +void ImGui::NavUpdateWindowingOverlay() { ImGuiContext& g = *GImGui; IM_ASSERT(g.NavWindowingTarget != NULL); diff --git a/imgui_internal.h b/imgui_internal.h index f13aeedc..9c87d2a1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -497,7 +497,8 @@ enum ImGuiNavMoveFlags_ ImGuiNavMoveFlags_WrapX = 1 << 2, // On failed request, request from opposite side one line down (when NavDir==right) or one line up (when NavDir==left) ImGuiNavMoveFlags_WrapY = 1 << 3, // This is not super useful for provided for completeness ImGuiNavMoveFlags_AllowCurrentNavId = 1 << 4, // Allow scoring and considering the current NavId as a move target candidate. This is used when the move source is offset (e.g. pressing PageDown actually needs to send a Up move request, if we are pressing PageDown from the bottom-most item we need to stay in place) - ImGuiNavMoveFlags_AlsoScoreVisibleSet = 1 << 5 // Store alternate result in NavMoveResultLocalVisibleSet that only comprise elements that are already fully visible. + ImGuiNavMoveFlags_AlsoScoreVisibleSet = 1 << 5, // Store alternate result in NavMoveResultLocalVisibleSet that only comprise elements that are already fully visible. + ImGuiNavMoveFlags_ScrollToEdge = 1 << 6 }; enum ImGuiNavForward @@ -960,7 +961,7 @@ struct ImGuiContext ImGuiNavMoveFlags NavMoveRequestFlags; ImGuiNavForward NavMoveRequestForward; // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu) ImGuiDir NavMoveDir, NavMoveDirLast; // Direction of the move request (left/right/up/down), direction of the previous move request - ImGuiDir NavMoveClipDir; + ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename? ImGuiNavMoveResult NavMoveResultLocal; // Best move request candidate within NavWindow ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag) ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag) From 3dcf323c35a20914930f6068002e3d4c4815bb87 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 16 Sep 2019 19:03:20 +0200 Subject: [PATCH 005/384] Columns: Separator: Fixed a bug where non-visible separators within columns would alter the next row position differently than visible ones. Fixed rounding issues also leading to change of ScrollMax depending on visible items (in particular negative coordinate would be rounded differently) --- docs/CHANGELOG.txt | 2 ++ imgui_demo.cpp | 2 +- imgui_widgets.cpp | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5bc49ac7..6e487ae5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -45,6 +45,8 @@ Other Changes: (before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations). - TabBar: improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right. +- Columns, Separator: Fixed a bug where non-visible separators within columns would alter the next row position + differently than visible ones. - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] - DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. - DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] diff --git a/imgui_demo.cpp b/imgui_demo.cpp index d5bc96c5..fd1d85a3 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1451,7 +1451,7 @@ static void ShowDemoWindowWidgets() ImGui::PushID("set2"); static float values2[4] = { 0.20f, 0.80f, 0.40f, 0.25f }; const int rows = 3; - const ImVec2 small_slider_size(18, (160.0f-(rows-1)*spacing)/rows); + const ImVec2 small_slider_size(18, (float)(int)((160.0f - (rows - 1) * spacing) / rows)); for (int nx = 0; nx < 4; nx++) { if (nx > 0) ImGui::SameLine(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index e3441ac0..35ce1436 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1261,7 +1261,10 @@ void ImGui::SeparatorEx(ImGuiSeparatorFlags flags) if (!ItemAdd(bb, 0)) { if (columns) + { PopColumnsBackground(); + columns->LineMinY = window->DC.CursorPos.y; + } return; } @@ -5624,7 +5627,7 @@ bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_item // We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild(). ImVec2 size; size.x = 0.0f; - size.y = GetTextLineHeightWithSpacing() * height_in_items_f + style.FramePadding.y * 2.0f; + size.y = ImFloor(GetTextLineHeightWithSpacing() * height_in_items_f + style.FramePadding.y * 2.0f); return ListBoxHeader(label, size); } From 561e7dd49098f2d6c16a21dad7701f73f78545a3 Mon Sep 17 00:00:00 2001 From: Qix Date: Tue, 17 Sep 2019 09:21:09 +0200 Subject: [PATCH 006/384] Fix signed types warning in pasteboard handler (#2786) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 1dc4862a..c5039d63 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9689,7 +9689,7 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) ItemCount item_count = 0; PasteboardGetItemCount(main_clipboard, &item_count); - for (int i = 0; i < item_count; i++) + for (ItemCount i = 0; i < item_count; i++) { PasteboardItemID item_id = 0; PasteboardGetItemIdentifier(main_clipboard, i + 1, &item_id); From e7e88ed413502f1b603e35d389186d3d73a8147a Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Tue, 17 Sep 2019 10:04:40 +0200 Subject: [PATCH 007/384] Examples: SDL/GLFW + OpenGL3: Fixes for Makefile (#2774) - append CXXFLAGS instead of overwriting them - add glad.c build rule --- examples/example_glfw_opengl3/Makefile | 9 +++++---- examples/example_sdl_opengl3/Makefile | 14 ++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index e8cf4614..7e17476c 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -35,12 +35,11 @@ CXXFLAGS += -I../libs/gl3w ## Using OpenGL loader: glew ## (This assumes a system-wide installation) -# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW +# CXXFLAGS += -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW ## Using OpenGL loader: glad -## (You'll also need to change the rule at line ~77 of this Makefile to compile/link glad.c/.o) # SOURCES += ../libs/glad/src/glad.c -# CXXFLAGS = -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD +# CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM @@ -87,7 +86,9 @@ endif $(CXX) $(CXXFLAGS) -c -o $@ $< %.o:../libs/gl3w/GL/%.c -# %.o:../libs/glad/src/%.c + $(CC) $(CFLAGS) -c -o $@ $< + +%.o:../libs/glad/src/%.c $(CC) $(CFLAGS) -c -o $@ $< all: $(EXE) diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 76601a1b..9e84df92 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -35,12 +35,11 @@ CXXFLAGS += -I../libs/gl3w ## Using OpenGL loader: glew ## (This assumes a system-wide installation) -# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW +# CXXFLAGS += -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW ## Using OpenGL loader: glad -## (You'll also need to change the rule at line ~77 of this Makefile to compile/link glad.c/.o) # SOURCES += ../libs/glad/src/glad.c -# CXXFLAGS = -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD +# CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM @@ -50,7 +49,7 @@ ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" LIBS += -lGL -ldl `sdl2-config --libs` - CXXFLAGS += -I../libs/gl3w `sdl2-config --cflags` + CXXFLAGS += `sdl2-config --cflags` CFLAGS = $(CXXFLAGS) endif @@ -59,7 +58,7 @@ ifeq ($(UNAME_S), Darwin) #APPLE LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs` LIBS += -L/usr/local/lib -L/opt/local/lib - CXXFLAGS += -I../libs/gl3w `sdl2-config --cflags` + CXXFLAGS += `sdl2-config --cflags` CXXFLAGS += -I/usr/local/include -I/opt/local/include CFLAGS = $(CXXFLAGS) endif @@ -68,7 +67,7 @@ ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) ECHO_MESSAGE = "MinGW" LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2` - CXXFLAGS += -I../libs/gl3w `pkg-config --cflags sdl2` + CXXFLAGS += `pkg-config --cflags sdl2` CFLAGS = $(CXXFLAGS) endif @@ -88,6 +87,9 @@ endif %.o:../libs/gl3w/GL/%.c $(CC) $(CFLAGS) -c -o $@ $< +%.o:../libs/glad/src/%.c + $(CC) $(CFLAGS) -c -o $@ $< + all: $(EXE) @echo Build complete for $(ECHO_MESSAGE) From 404dc0367e03a220279bb34e3fe3cb758cd1d4a4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 10:41:11 +0200 Subject: [PATCH 008/384] BeginTabItem: Fixed case where right-most tab would create an extraneous draw calls (probably related to other tab fitting code in 1.73 wip) --- imgui_widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 35ce1436..ba3bac87 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6932,7 +6932,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImRect bb(pos, pos + size); // We don't have CPU clipping primitives to clip the CloseButton (until it becomes a texture), so need to add an extra draw call (temporary in the case of vertical animation) - bool want_clip_rect = (bb.Min.x < tab_bar->BarRect.Min.x) || (bb.Max.x >= tab_bar->BarRect.Max.x); + bool want_clip_rect = (bb.Min.x < tab_bar->BarRect.Min.x) || (bb.Max.x > tab_bar->BarRect.Max.x); if (want_clip_rect) PushClipRect(ImVec2(ImMax(bb.Min.x, tab_bar->BarRect.Min.x), bb.Min.y - 1), ImVec2(tab_bar->BarRect.Max.x, bb.Max.y), true); From 45405f0dc9f2a3a08883748319aeba9a5afed6e3 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 5 Sep 2019 12:59:43 +0300 Subject: [PATCH 009/384] Font: implement a way to draw narrow ellipsis without relying on hardcoded 1 pixel dots. (#2775) This changeset implements several pieces of the puzzle that add up to a narrow ellipsis rendering. ## EllipsisCodePoint `ImFontConfig` and `ImFont` received `ImWchar EllipsisCodePoint = -1;` field. User may configure `ImFontConfig::EllipsisCodePoint` a unicode codepoint that will be used for rendering narrow ellipsis. Not setting this field will automatically detect a suitable character or fall back to rendering 3 dots with minimal spacing between them. Autodetection prefers codepoint 0x2026 (narrow ellipsis) and falls back to 0x0085 (NEXT LINE) when missing. Wikipedia indicates that codepoint 0x0085 was used as ellipsis in some older windows fonts. So does default Dear ImGui font. When user is merging fonts - first configured and present ellipsis codepoint will be used, ellipsis characters from subsequently merged fonts will be ignored. ## Narrow ellipsis Rendering a narrow ellipsis is surprisingly not straightforward task. There are cases when ellipsis is bigger than the last visible character therefore `RenderTextEllipsis()` has to hide last two characters. In a subset of those cases ellipsis is as big as last visible character + space before it. `RenderTextEllipsis()` tries to work around this case by taking free space between glyph edges into account. Code responsible for this functionality is within `if (text_end_ellipsis != text_end_full) { ... }`. ## Fallback (manually rendered dots) There are cases when font does not have ellipsis character defined. In this case RenderTextEllipsis() falls back to rendering ellipsis as 3 dots, but with reduced spacing between them. 1 pixel space is used in all cases. This results in a somewhat wider ellipsis, but avoids issues where spaces between dots are uneven (visible in larger/monospace fonts) or squish dots way too much (visible in default font where dot is essentially a pixel). This fallback method obsoleted `RenderPixelEllipsis()` and this function was removed. Note that fallback ellipsis will always be somewhat wider than it could be, however it will fit in visually into every font used unlike what `RenderPixelEllipsis()` produced. --- imgui.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++---- imgui.h | 2 + imgui_draw.cpp | 39 +++++++++++++------- imgui_internal.h | 1 - 4 files changed, 117 insertions(+), 21 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c5039d63..7921b1d1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2489,7 +2489,7 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons // Another overly complex function until we reorganize everything into a nice all-in-one helper. // This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display. // This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move. -void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known) +void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known) { ImGuiContext& g = *GImGui; if (text_end_full == NULL) @@ -2503,15 +2503,42 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, // min max ellipsis_max // <-> this is generally some padding value - // FIXME-STYLE: RenderPixelEllipsis() style should use actual font data. const ImFont* font = draw_list->_Data->Font; const float font_size = draw_list->_Data->FontSize; - const int ellipsis_dot_count = 3; - const float ellipsis_width = (1.0f + 1.0f) * ellipsis_dot_count - 1.0f; const char* text_end_ellipsis = NULL; + const ImFontGlyph* glyph; + int ellipsis_char_num = 1; + ImWchar ellipsis_codepoint = font->EllipsisCodePoint; + if (ellipsis_codepoint != (ImWchar)-1) + glyph = font->FindGlyph(ellipsis_codepoint); + else + { + ellipsis_codepoint = (ImWchar)'.'; + glyph = font->FindGlyph(ellipsis_codepoint); + ellipsis_char_num = 3; + } + + float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side + float ellipsis_width = ellipsis_glyph_width; // Full width of entire ellipsis + float push_left = 1.f; + + if (ellipsis_char_num > 1) + { + const float spacing_between_dots = 1.f * (draw_list->_Data->FontSize / font->FontSize); + ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; + // Full ellipsis size without free spacing after it. + ellipsis_width = ellipsis_glyph_width * (float)ellipsis_char_num - spacing_between_dots; + if (glyph->X0 > 1.f) + { + // Pushing ellipsis to the left will be accomplished by rendering the dot (X0). + push_left = 0.f; + } + } + float text_width = ImMax((pos_max.x - ellipsis_width) - pos_min.x, 1.0f); float text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; + if (text == text_end_ellipsis && text_end_ellipsis < text_end_full) { // Always display at least 1 character if there's no room for character + ellipsis @@ -2524,11 +2551,66 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, text_end_ellipsis--; text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte } + + if (text_end_ellipsis != text_end_full) + { + // +---- First invisible character we arrived at. + // / +-- Character that we hope to be first invisible. + // [l][i] + // |||| + // \ \__ extra_spacing when two characters got hidden + // \___ extra_spacing when one character got hidden + unsigned c = 0; + float extra_spacing = 0; + const char* text_end_ellipsis_prev = text_end_ellipsis; + text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); + if (c && !ImCharIsBlankW(c)) + { + const ImFontGlyph* hidden_glyph = font->FindGlyph(c); + // Free space after first invisible glyph + extra_spacing = hidden_glyph->AdvanceX - hidden_glyph->X1; + c = 0; + text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); + if (c && !ImCharIsBlankW(c)) + { + hidden_glyph = font->FindGlyph(text_end_ellipsis[1]); + // Space before next invisible glyph. This intentionally ignores space from the first invisible + // glyph as that space will serve as spacing between ellipsis and last visible character. Without + // doing this we may get into awkward situations where ellipsis pretty much sticks to the last + // visible character. This issue manifests with the default font for word "Brocolli" there both i + // and l are very thin. Unfortunately this makes fonts with wider gaps (like monospace) look a bit + // worse, but it is a fair middle ground. + extra_spacing = hidden_glyph->X0; + } + } + + if (extra_spacing > 0) + { + // Repeat calculation hoping that we will get extra character visible + text_width += extra_spacing; + // Text length calculation is essentially an optimized version of this: + // text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; + // It avoids calculating entire width of the string. + text_size_clipped_x += font->CalcTextSizeA(font_size, text_width - text_size_clipped_x, 0.0f, text_end_ellipsis_prev, text_end_full, &text_end_ellipsis).x; + } + else + text_end_ellipsis = text_end_ellipsis_prev; + } + RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f)); - const float ellipsis_x = pos_min.x + text_size_clipped_x + 1.0f; - if (ellipsis_x + ellipsis_width - 1.0f <= ellipsis_max_x) - RenderPixelEllipsis(draw_list, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_dot_count); + // This variable pushes ellipsis to the left from last visible character. This is mostly useful when rendering + // ellipsis character contained in the font. If we render ellipsis manually space is already adequate and extra + // spacing is not needed. + float ellipsis_x = pos_min.x + text_size_clipped_x + push_left; + if (ellipsis_x + ellipsis_width - push_left <= ellipsis_max_x) + { + for (int i = 0; i < ellipsis_char_num; i++) + { + font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_codepoint); + ellipsis_x += ellipsis_glyph_width; + } + } } else { diff --git a/imgui.h b/imgui.h index 42ee5340..d4a81c3b 100644 --- a/imgui.h +++ b/imgui.h @@ -2011,6 +2011,7 @@ struct ImFontConfig bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights. unsigned int RasterizerFlags; // 0x00 // Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. float RasterizerMultiply; // 1.0f // Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable. + ImWchar EllipsisCodePoint; // -1 // Explicitly specify unicode codepoint of ellipsis character. When fonts are being merged first specified ellipsis will be used. // [Internal] char Name[40]; // Name (strictly to ease debugging) @@ -2192,6 +2193,7 @@ struct ImFont float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) bool DirtyLookupTables; // 1 // out // + ImWchar EllipsisCodePoint; // -1 // out // // Override a codepoint used for ellipsis rendering. // Methods IMGUI_API ImFont(); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3eb1067e..b4801c26 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1428,6 +1428,7 @@ ImFontConfig::ImFontConfig() RasterizerMultiply = 1.0f; memset(Name, 0, sizeof(Name)); DstFont = NULL; + EllipsisCodePoint = (ImWchar)-1; } //----------------------------------------------------------------------------- @@ -1618,6 +1619,9 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize); } + if (new_font_cfg.DstFont->EllipsisCodePoint == (ImWchar)-1) + new_font_cfg.DstFont->EllipsisCodePoint = font_cfg->EllipsisCodePoint; + // Invalidate texture ClearTexData(); return new_font_cfg.DstFont; @@ -1652,6 +1656,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template) font_cfg.SizePixels = 13.0f * 1.0f; if (font_cfg.Name[0] == '\0') ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf, %dpx", (int)font_cfg.SizePixels); + font_cfg.EllipsisCodePoint = (ImWchar)0x0085; const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault(); @@ -2196,6 +2201,26 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas) for (int i = 0; i < atlas->Fonts.Size; i++) if (atlas->Fonts[i]->DirtyLookupTables) atlas->Fonts[i]->BuildLookupTable(); + + // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis). + // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character. + for (int i = 0; i < atlas->Fonts.size(); i++) + { + ImFont* font = atlas->Fonts[i]; + if (font->EllipsisCodePoint == (ImWchar)-1) + { + const ImWchar ellipsis_variants[] = {(ImWchar)0x2026, (ImWchar)0x0085, (ImWchar)0}; + for (int j = 0; ellipsis_variants[j] != (ImWchar) 0; j++) + { + ImWchar ellipsis_codepoint = ellipsis_variants[j]; + if (font->FindGlyph(ellipsis_codepoint) != font->FallbackGlyph) // Verify glyph exists + { + font->EllipsisCodePoint = ellipsis_codepoint; + break; + } + } + } + } } // Retrieve list of range (2 int per range, values are inclusive) @@ -2474,6 +2499,7 @@ ImFont::ImFont() Scale = 1.0f; Ascent = Descent = 0.0f; MetricsTotalSurface = 0; + EllipsisCodePoint = (ImWchar)-1; } ImFont::~ImFont() @@ -3012,7 +3038,6 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderMouseCursor() // - RenderArrowPointingAt() // - RenderRectFilledRangeH() -// - RenderPixelEllipsis() //----------------------------------------------------------------------------- void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor) @@ -3122,18 +3147,6 @@ void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, Im draw_list->PathFillConvex(col); } -// FIXME: Rendering an ellipsis "..." is a surprisingly tricky problem for us... we cannot rely on font glyph having it, -// and regular dot are typically too wide. If we render a dot/shape ourselves it comes with the risk that it wouldn't match -// the boldness or positioning of what the font uses... -void ImGui::RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, ImU32 col, int count) -{ - ImFont* font = draw_list->_Data->Font; - const float font_scale = draw_list->_Data->FontSize / font->FontSize; - pos.y += (float)(int)(font->DisplayOffset.y + font->Ascent * font_scale + 0.5f - 1.0f); - for (int dot_n = 0; dot_n < count; dot_n++) - draw_list->AddRectFilled(ImVec2(pos.x + dot_n * 2.0f, pos.y), ImVec2(pos.x + dot_n * 2.0f + 1.0f, pos.y + 1.0f), col); -} - //----------------------------------------------------------------------------- // [SECTION] Decompression code //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 9c87d2a1..ea8a4099 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1635,7 +1635,6 @@ namespace ImGui IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor = ImGuiMouseCursor_Arrow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); - IMGUI_API void RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, ImU32 col, int count); #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS // 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while. From 57623c15ddae10a6b0ba6b206d2502e7951dd705 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 10:00:28 +0200 Subject: [PATCH 010/384] Font: Narrow ellipsis: various minor stylistic tweaks (#2775) --- docs/CHANGELOG.txt | 4 +++ docs/TODO.txt | 1 + imgui.cpp | 61 ++++++++++++++++++++-------------------------- imgui.h | 6 ++--- imgui_demo.cpp | 3 ++- imgui_draw.cpp | 29 ++++++++++------------ 6 files changed, 49 insertions(+), 55 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6e487ae5..36ba83ba 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,10 @@ Other Changes: - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] - DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. - DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] +- Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly + unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. + Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow + as possible. (#2775) [@rokups] - ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740) - Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when diff --git a/docs/TODO.txt b/docs/TODO.txt index 70c64c40..df413b7e 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -275,6 +275,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font: MergeMode: flags to select overwriting or not (this is now very easy with refactored ImFontAtlasBuildWithStbTruetype) - font: free the Alpha buffer if user only requested RGBA. !- font: better CalcTextSizeA() API, at least for simple use cases. current one is horrible (perhaps have simple vs extended versions). + - font: for the purpose of RenderTextEllipsis(), it might be useful that CalcTextSizeA() can ignore the trailing padding? - font: a CalcTextHeight() helper could run faster than CalcTextSize().y - font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX - font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data diff --git a/imgui.cpp b/imgui.cpp index 7921b1d1..4a606daa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2506,38 +2506,32 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con const ImFont* font = draw_list->_Data->Font; const float font_size = draw_list->_Data->FontSize; const char* text_end_ellipsis = NULL; - const ImFontGlyph* glyph; - int ellipsis_char_num = 1; - ImWchar ellipsis_codepoint = font->EllipsisCodePoint; - if (ellipsis_codepoint != (ImWchar)-1) - glyph = font->FindGlyph(ellipsis_codepoint); - else + ImWchar ellipsis_char = font->EllipsisChar; + int ellipsis_char_count = 1; + if (ellipsis_char == (ImWchar)-1) { - ellipsis_codepoint = (ImWchar)'.'; - glyph = font->FindGlyph(ellipsis_codepoint); - ellipsis_char_num = 3; + ellipsis_char = (ImWchar)'.'; + ellipsis_char_count = 3; } + const ImFontGlyph* glyph = font->FindGlyph(ellipsis_char); - float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side - float ellipsis_width = ellipsis_glyph_width; // Full width of entire ellipsis - float push_left = 1.f; + float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side + float ellipsis_total_width = ellipsis_glyph_width; // Full width of entire ellipsis + float push_left = 1.0f; - if (ellipsis_char_num > 1) + if (ellipsis_char_count > 1) { - const float spacing_between_dots = 1.f * (draw_list->_Data->FontSize / font->FontSize); - ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; // Full ellipsis size without free spacing after it. - ellipsis_width = ellipsis_glyph_width * (float)ellipsis_char_num - spacing_between_dots; - if (glyph->X0 > 1.f) - { - // Pushing ellipsis to the left will be accomplished by rendering the dot (X0). - push_left = 0.f; - } + const float spacing_between_dots = 1.0f * (draw_list->_Data->FontSize / font->FontSize); + ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; + ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots; + if (glyph->X0 > 1.0f) + push_left = 0.0f; // Pushing ellipsis to the left will be accomplished by rendering the dot (X0). } - float text_width = ImMax((pos_max.x - ellipsis_width) - pos_min.x, 1.0f); - float text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; + float text_avail_width = ImMax((pos_max.x - ellipsis_total_width) - pos_min.x, 1.0f); + float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; if (text == text_end_ellipsis && text_end_ellipsis < text_end_full) { @@ -2547,7 +2541,7 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con } while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1])) { - // Trim trailing space before ellipsis + // Trim trailing space before ellipsis (FIXME: Supporting non-ascii blanks would be nice, for this we need a function to backtrack in UTF-8 text) text_end_ellipsis--; text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte } @@ -2560,16 +2554,15 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con // |||| // \ \__ extra_spacing when two characters got hidden // \___ extra_spacing when one character got hidden - unsigned c = 0; - float extra_spacing = 0; + unsigned int c = 0; + float extra_spacing = 0.0f; const char* text_end_ellipsis_prev = text_end_ellipsis; text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); if (c && !ImCharIsBlankW(c)) { - const ImFontGlyph* hidden_glyph = font->FindGlyph(c); // Free space after first invisible glyph + const ImFontGlyph* hidden_glyph = font->FindGlyph((ImWchar)c); extra_spacing = hidden_glyph->AdvanceX - hidden_glyph->X1; - c = 0; text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); if (c && !ImCharIsBlankW(c)) { @@ -2587,11 +2580,11 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con if (extra_spacing > 0) { // Repeat calculation hoping that we will get extra character visible - text_width += extra_spacing; + text_avail_width += extra_spacing; // Text length calculation is essentially an optimized version of this: // text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; // It avoids calculating entire width of the string. - text_size_clipped_x += font->CalcTextSizeA(font_size, text_width - text_size_clipped_x, 0.0f, text_end_ellipsis_prev, text_end_full, &text_end_ellipsis).x; + text_size_clipped_x += font->CalcTextSizeA(font_size, text_avail_width - text_size_clipped_x, 0.0f, text_end_ellipsis_prev, text_end_full, &text_end_ellipsis).x; } else text_end_ellipsis = text_end_ellipsis_prev; @@ -2603,14 +2596,12 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con // ellipsis character contained in the font. If we render ellipsis manually space is already adequate and extra // spacing is not needed. float ellipsis_x = pos_min.x + text_size_clipped_x + push_left; - if (ellipsis_x + ellipsis_width - push_left <= ellipsis_max_x) - { - for (int i = 0; i < ellipsis_char_num; i++) + if (ellipsis_x + ellipsis_total_width - push_left <= ellipsis_max_x) + for (int i = 0; i < ellipsis_char_count; i++) { - font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_codepoint); + font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char); ellipsis_x += ellipsis_glyph_width; } - } } else { diff --git a/imgui.h b/imgui.h index d4a81c3b..9e875f89 100644 --- a/imgui.h +++ b/imgui.h @@ -2011,7 +2011,7 @@ struct ImFontConfig bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights. unsigned int RasterizerFlags; // 0x00 // Settings for custom font rasterizer (e.g. ImGuiFreeType). Leave as zero if you aren't using one. float RasterizerMultiply; // 1.0f // Brighten (>1.0f) or darken (<1.0f) font output. Brightening small fonts may be a good workaround to make them more readable. - ImWchar EllipsisCodePoint; // -1 // Explicitly specify unicode codepoint of ellipsis character. When fonts are being merged first specified ellipsis will be used. + ImWchar EllipsisChar; // -1 // Explicitly specify unicode codepoint of ellipsis character. When fonts are being merged first specified ellipsis will be used. // [Internal] char Name[40]; // Name (strictly to ease debugging) @@ -2188,12 +2188,12 @@ struct ImFont ImFontAtlas* ContainerAtlas; // 4-8 // out // // What we has been loaded into const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont. - ImWchar FallbackChar; // 2 // in // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() + ImWchar FallbackChar; // 2 // in // = '?' // Replacement character if a glyph isn't found. Only set via SetFallbackChar() + ImWchar EllipsisChar; // 2 // out // = -1 // Character used for ellipsis rendering. float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) bool DirtyLookupTables; // 1 // out // - ImWchar EllipsisCodePoint; // -1 // out // // Override a codepoint used for ellipsis rendering. // Methods IMGUI_API ImFont(); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index fd1d85a3..e8e87469 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3283,7 +3283,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SameLine(); HelpMarker("Note than the default embedded font is NOT meant to be scaled.\n\nFont are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime.\n\n(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)"); ImGui::InputFloat("Font offset", &font->DisplayOffset.y, 1, 1, "%.0f"); ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); - ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar); + ImGui::Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar); + ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar); const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface); ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt); for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b4801c26..dd21523e 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1426,9 +1426,9 @@ ImFontConfig::ImFontConfig() MergeMode = false; RasterizerFlags = 0x00; RasterizerMultiply = 1.0f; + EllipsisChar = (ImWchar)-1; memset(Name, 0, sizeof(Name)); DstFont = NULL; - EllipsisCodePoint = (ImWchar)-1; } //----------------------------------------------------------------------------- @@ -1619,8 +1619,8 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize); } - if (new_font_cfg.DstFont->EllipsisCodePoint == (ImWchar)-1) - new_font_cfg.DstFont->EllipsisCodePoint = font_cfg->EllipsisCodePoint; + if (new_font_cfg.DstFont->EllipsisChar == (ImWchar)-1) + new_font_cfg.DstFont->EllipsisChar = font_cfg->EllipsisChar; // Invalidate texture ClearTexData(); @@ -1656,7 +1656,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template) font_cfg.SizePixels = 13.0f * 1.0f; if (font_cfg.Name[0] == '\0') ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf, %dpx", (int)font_cfg.SizePixels); - font_cfg.EllipsisCodePoint = (ImWchar)0x0085; + font_cfg.EllipsisChar = (ImWchar)0x0085; const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85(); const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault(); @@ -2204,22 +2204,19 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas) // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis). // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character. + // FIXME: Also note that 0x2026 is currently seldomly included in our font ranges. Because of this we are more likely to use three individual dots. for (int i = 0; i < atlas->Fonts.size(); i++) { ImFont* font = atlas->Fonts[i]; - if (font->EllipsisCodePoint == (ImWchar)-1) - { - const ImWchar ellipsis_variants[] = {(ImWchar)0x2026, (ImWchar)0x0085, (ImWchar)0}; - for (int j = 0; ellipsis_variants[j] != (ImWchar) 0; j++) + if (font->EllipsisChar != (ImWchar)-1) + continue; + const ImWchar ellipsis_variants[] = { (ImWchar)0x2026, (ImWchar)0x0085 }; + for (int j = 0; j < IM_ARRAYSIZE(ellipsis_variants); j++) + if (font->FindGlyphNoFallback(ellipsis_variants[j]) != NULL) // Verify glyph exists { - ImWchar ellipsis_codepoint = ellipsis_variants[j]; - if (font->FindGlyph(ellipsis_codepoint) != font->FallbackGlyph) // Verify glyph exists - { - font->EllipsisCodePoint = ellipsis_codepoint; - break; - } + font->EllipsisChar = ellipsis_variants[j]; + break; } - } } } @@ -2490,6 +2487,7 @@ ImFont::ImFont() FontSize = 0.0f; FallbackAdvanceX = 0.0f; FallbackChar = (ImWchar)'?'; + EllipsisChar = (ImWchar)-1; DisplayOffset = ImVec2(0.0f, 0.0f); FallbackGlyph = NULL; ContainerAtlas = NULL; @@ -2499,7 +2497,6 @@ ImFont::ImFont() Scale = 1.0f; Ascent = Descent = 0.0f; MetricsTotalSurface = 0; - EllipsisCodePoint = (ImWchar)-1; } ImFont::~ImFont() From 1c951dca977e24018110aff7374d7cb3a062e5da Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 11:11:14 +0200 Subject: [PATCH 011/384] Font: Narrow ellipsis: once we know an ellipsis is going to be drawn, we can claim the space between pos_max.x and ellipsis_max.x which gives us enough extra space to not requires the further (and otherwise valid) optimizations. Gets us vastly simplified code, yay. (#2775) --- imgui.cpp | 64 ++++++++----------------------------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4a606daa..80e8a280 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2496,6 +2496,10 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con text_end_full = FindRenderedTextEnd(text); const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_end_full, false, 0.0f); + //draw_list->AddLine(ImVec2(pos_max.x, pos_min.y - 4), ImVec2(pos_max.x, pos_max.y + 4), IM_COL32(0, 0, 255, 255)); + //draw_list->AddLine(ImVec2(ellipsis_max_x, pos_min.y-2), ImVec2(ellipsis_max_x, pos_max.y+2), IM_COL32(0, 255, 0, 255)); + //draw_list->AddLine(ImVec2(clip_max_x, pos_min.y), ImVec2(clip_max_x, pos_max.y), IM_COL32(255, 0, 0, 255)); + // FIXME: We could technically remove (last_glyph->AdvanceX - last_glyph->X1) from text_size.x here and save a few pixels. if (text_size.x > pos_max.x - pos_min.x) { // Hello wo... @@ -2518,7 +2522,6 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side float ellipsis_total_width = ellipsis_glyph_width; // Full width of entire ellipsis - float push_left = 1.0f; if (ellipsis_char_count > 1) { @@ -2526,13 +2529,11 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con const float spacing_between_dots = 1.0f * (draw_list->_Data->FontSize / font->FontSize); ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots; - if (glyph->X0 > 1.0f) - push_left = 0.0f; // Pushing ellipsis to the left will be accomplished by rendering the dot (X0). } - float text_avail_width = ImMax((pos_max.x - ellipsis_total_width) - pos_min.x, 1.0f); + // We can now claim the space between pos_max.x and ellipsis_max.x + const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f); float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; - if (text == text_end_ellipsis && text_end_ellipsis < text_end_full) { // Always display at least 1 character if there's no room for character + ellipsis @@ -2546,57 +2547,10 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte } - if (text_end_ellipsis != text_end_full) - { - // +---- First invisible character we arrived at. - // / +-- Character that we hope to be first invisible. - // [l][i] - // |||| - // \ \__ extra_spacing when two characters got hidden - // \___ extra_spacing when one character got hidden - unsigned int c = 0; - float extra_spacing = 0.0f; - const char* text_end_ellipsis_prev = text_end_ellipsis; - text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); - if (c && !ImCharIsBlankW(c)) - { - // Free space after first invisible glyph - const ImFontGlyph* hidden_glyph = font->FindGlyph((ImWchar)c); - extra_spacing = hidden_glyph->AdvanceX - hidden_glyph->X1; - text_end_ellipsis += ImTextCharFromUtf8(&c, text_end_ellipsis, text_end_full); - if (c && !ImCharIsBlankW(c)) - { - hidden_glyph = font->FindGlyph(text_end_ellipsis[1]); - // Space before next invisible glyph. This intentionally ignores space from the first invisible - // glyph as that space will serve as spacing between ellipsis and last visible character. Without - // doing this we may get into awkward situations where ellipsis pretty much sticks to the last - // visible character. This issue manifests with the default font for word "Brocolli" there both i - // and l are very thin. Unfortunately this makes fonts with wider gaps (like monospace) look a bit - // worse, but it is a fair middle ground. - extra_spacing = hidden_glyph->X0; - } - } - - if (extra_spacing > 0) - { - // Repeat calculation hoping that we will get extra character visible - text_avail_width += extra_spacing; - // Text length calculation is essentially an optimized version of this: - // text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; - // It avoids calculating entire width of the string. - text_size_clipped_x += font->CalcTextSizeA(font_size, text_avail_width - text_size_clipped_x, 0.0f, text_end_ellipsis_prev, text_end_full, &text_end_ellipsis).x; - } - else - text_end_ellipsis = text_end_ellipsis_prev; - } - + // Render text, render ellipsis RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f)); - - // This variable pushes ellipsis to the left from last visible character. This is mostly useful when rendering - // ellipsis character contained in the font. If we render ellipsis manually space is already adequate and extra - // spacing is not needed. - float ellipsis_x = pos_min.x + text_size_clipped_x + push_left; - if (ellipsis_x + ellipsis_total_width - push_left <= ellipsis_max_x) + float ellipsis_x = pos_min.x + text_size_clipped_x; + if (ellipsis_x + ellipsis_total_width <= ellipsis_max_x) for (int i = 0; i < ellipsis_char_count; i++) { font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char); From 7d5a17e5e4a36f2cabccfb97e9da4db0983eec56 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 11:33:18 +0200 Subject: [PATCH 012/384] Remove trailing spaces (grep for ' \r?$' in visual studio) --- imconfig.h | 6 +++--- imgui.cpp | 42 +++++++++++++++++++++--------------------- imgui.h | 14 +++++++------- imgui_demo.cpp | 8 ++++---- imgui_draw.cpp | 4 ++-- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 36 ++++++++++++++++++------------------ 7 files changed, 57 insertions(+), 57 deletions(-) diff --git a/imconfig.h b/imconfig.h index 22a21db0..45e75ecf 100644 --- a/imconfig.h +++ b/imconfig.h @@ -17,7 +17,7 @@ //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts -//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows +//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows // Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. //#define IMGUI_API __declspec( dllexport ) //#define IMGUI_API __declspec( dllimport ) @@ -64,9 +64,9 @@ operator MyVec4() const { return MyVec4(x,y,z,w); } */ -//---- Using 32-bits vertex indices (default is 16-bits) is one way to allow large meshes with more than 64K vertices. +//---- Using 32-bits vertex indices (default is 16-bits) is one way to allow large meshes with more than 64K vertices. // Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bits indices). -// Another way to allow large meshes while keeping 16-bits indices is to handle ImDrawCmd::VtxOffset in your renderer. +// Another way to allow large meshes while keeping 16-bits indices is to handle ImDrawCmd::VtxOffset in your renderer. // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. //#define ImDrawIdx unsigned int diff --git a/imgui.cpp b/imgui.cpp index c5039d63..b1d8522c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -575,17 +575,17 @@ CODE Q: Where is the documentation? A: This library is poorly documented at the moment and expects of the user to be acquainted with C/C++. - Run the examples/ and explore them. - - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. - - The demo covers most features of Dear ImGui, so you can read the code and see its output. + - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. + - The demo covers most features of Dear ImGui, so you can read the code and see its output. - See documentation and comments at the top of imgui.cpp + effectively imgui.h. - - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ + - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder to explain how to integrate Dear ImGui with your own engine/application. - - Your programming IDE is your friend, find the type or function declaration to find comments + - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. Q: Which version should I get? - A: I occasionally tag Releases (https://github.com/ocornut/imgui/releases) but it is generally safe - and recommended to sync to master/latest. The library is fairly stable and regressions tend to be + A: I occasionally tag Releases (https://github.com/ocornut/imgui/releases) but it is generally safe + and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. You may also peak at the 'docking' branch which includes: - Docking/Merging features (https://github.com/ocornut/imgui/issues/2109) - Multi-viewport features (https://github.com/ocornut/imgui/issues/1542) @@ -597,11 +597,11 @@ CODE for a list of games/software which are publicly known to use dear imgui. Please add yours if you can! Q: Why the odd dual naming, "Dear ImGui" vs "ImGui"? - A: The library started its life as "ImGui" due to the fact that I didn't give it a proper name when - when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI - (immediate-mode graphical user interface) was coined before and is being used in variety of other - situations (e.g. Unity uses it own implementation of the IMGUI paradigm). - To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, + A: The library started its life as "ImGui" due to the fact that I didn't give it a proper name when + when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI + (immediate-mode graphical user interface) was coined before and is being used in variety of other + situations (e.g. Unity uses it own implementation of the IMGUI paradigm). + To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. Please try to refer to this library as "Dear ImGui". @@ -2488,7 +2488,7 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons // Another overly complex function until we reorganize everything into a nice all-in-one helper. // This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display. -// This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move. +// This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move. void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known) { ImGuiContext& g = *GImGui; @@ -2996,8 +2996,8 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg) { // Navigation processing runs prior to clipping early-out // (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget - // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests - // unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of + // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests + // unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of // thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame. // We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able // to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick). @@ -4044,7 +4044,7 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d return; } - // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. + // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. // May trigger for you if you are using PrimXXX functions incorrectly. IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size); IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size); @@ -4053,7 +4053,7 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d // Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window) // If this assert triggers because you are drawing lots of stuff manually: - // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds. + // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds. // Be mindful that the ImDrawList API doesn't filter vertices. Use the Metrics window to inspect draw list contents. // - If you want large meshes with more than 64K vertices, you can either: // (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'. @@ -4062,9 +4062,9 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d // (B) Or handle 32-bits indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h. // Most example back-ends already support this. For example, the OpenGL example code detect index size at compile-time: // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); - // Your own engine or render API may use different parameters or function calls to specify index sizes. + // Your own engine or render API may use different parameters or function calls to specify index sizes. // 2 and 4 bytes indices are generally supported by most graphics API. - // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching + // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching // the 64K limit to split your draw commands in multiple draw lists. if (sizeof(ImDrawIdx) == 2) IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above"); @@ -4381,7 +4381,7 @@ int ImGui::GetKeyIndex(ImGuiKey imgui_key) // Note that imgui doesn't know the semantic of each entry of io.KeysDown[]. Use your own indices/enums according to how your back-end/engine stored them into io.KeysDown[]! bool ImGui::IsKeyDown(int user_key_index) { - if (user_key_index < 0) + if (user_key_index < 0) return false; ImGuiContext& g = *GImGui; IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); @@ -5741,7 +5741,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->OuterRectClipped.ClipWith(host_rect); // Inner rectangle - // Not affected by window border size. Used by: + // Not affected by window border size. Used by: // - InnerClipRect // - ScrollToBringRectIntoView() // - NavUpdatePageUpPageDown() @@ -5819,7 +5819,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) render_decorations_in_parent = true; if (render_decorations_in_parent) window->DrawList = parent_window->DrawList; - + // Handle title bar, scrollbar, resize grips and resize borders const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow; const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight); diff --git a/imgui.h b/imgui.h index 42ee5340..6118d537 100644 --- a/imgui.h +++ b/imgui.h @@ -328,7 +328,7 @@ namespace ImGui IMGUI_API ImU32 GetColorU32(ImU32 col); // retrieve given color with style alpha applied // Parameters stacks (current window) - IMGUI_API void PushItemWidth(float item_width); // set width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width, + IMGUI_API void PushItemWidth(float item_width); // set width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width, IMGUI_API void PopItemWidth(); IMGUI_API void SetNextItemWidth(float item_width); // set width of the _next_ common large "item+label" widget. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side) IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position. NOT necessarily the width of last item unlike most 'Item' functions. @@ -1764,7 +1764,7 @@ struct ImColor // Draw callbacks for advanced uses. // NB: You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering, -// you can poke into the draw list for that! Draw callback may be useful for example to: +// you can poke into the draw list for that! Draw callback may be useful for example to: // A) Change your GPU render state, // B) render a complex 3D scene inside a UI element without an intermediate texture/render target, etc. // The expected behavior from your rendering function is 'if (cmd.UserCallback != NULL) { cmd.UserCallback(parent_list, cmd); } else { RenderTriangles() }' @@ -1795,7 +1795,7 @@ struct ImDrawCmd ImDrawCmd() { ElemCount = 0; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; } }; -// Vertex index +// Vertex index // (to allow large meshes with 16-bits indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end) // (to use 32-bits indices: override with '#define ImDrawIdx unsigned int' in imconfig.h) #ifndef ImDrawIdx @@ -1826,7 +1826,7 @@ struct ImDrawChannel }; // Split/Merge functions are used to split the draw list into different layers which can be drawn into out of order. -// This is used by the Columns api, so items of each column can be batched together in a same draw call. +// This is used by the Columns api, so items of each column can be batched together in a same draw call. struct ImDrawListSplitter { int _Current; // Current channel number (0) @@ -1867,7 +1867,7 @@ enum ImDrawListFlags_ // Draw command list // This is the low-level list of polygons that ImGui:: functions are filling. At the end of the frame, // all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering. -// Each dear imgui window contains its own ImDrawList. You can use ImGui::GetWindowDrawList() to +// Each dear imgui window contains its own ImDrawList. You can use ImGui::GetWindowDrawList() to // access the current window draw list and draw custom primitives. // You can interleave normal ImGui:: calls and adding primitives to the current draw list. // All positions are generally in pixel coordinates (top-left at (0,0), bottom-right at io.DisplaySize), but you are totally free to apply whatever transformation matrix to want to the data (if you apply such transformation you'll want to apply it to ClipRect as well) @@ -2126,9 +2126,9 @@ struct ImFontAtlas // [BETA] Custom Rectangles/Glyphs API //------------------------------------------- - // You can request arbitrary rectangles to be packed into the atlas, for your own purposes. + // You can request arbitrary rectangles to be packed into the atlas, for your own purposes. // After calling Build(), you can query the rectangle position and render your pixels. - // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), + // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), // so you can render e.g. custom colorful icons and use them as regular glyphs. // Read misc/fonts/README.txt for more details about using colorful icons. IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList diff --git a/imgui_demo.cpp b/imgui_demo.cpp index fd1d85a3..3a652a16 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -17,7 +17,7 @@ // In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is // essentially like a global variable but declared inside the scope of the function. We do this as a way to gather code and data // in the same place, to make the demo source code faster to read, faster to write, and smaller in size. -// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be +// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be // reentrant or used in multiple threads. This might be a pattern you will want to use in your code, but most of the real data // you would be editing is likely going to be stored outside your functions. @@ -589,7 +589,7 @@ static void ShowDemoWindowWidgets() { for (int i = 0; i < 5; i++) { - // Use SetNextItemOpen() so set the default state of a node to be open. + // Use SetNextItemOpen() so set the default state of a node to be open. // We could also use TreeNodeEx() with the ImGuiTreeNodeFlags_DefaultOpen flag to achieve the same thing! if (i == 0) ImGui::SetNextItemOpen(true, ImGuiCond_Once); @@ -1109,7 +1109,7 @@ static void ShowDemoWindowWidgets() if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; } } - // Typically we would use ImVec2(-1.0f,0.0f) or ImVec2(-FLT_MIN,0.0f) to use all available width, + // Typically we would use ImVec2(-1.0f,0.0f) or ImVec2(-FLT_MIN,0.0f) to use all available width, // or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth. ImGui::ProgressBar(progress, ImVec2(0.0f,0.0f)); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); @@ -2259,7 +2259,7 @@ static void ShowDemoWindowLayout() ImGui::SameLine(); ImGui::SetNextItemWidth(100); ImGui::DragFloat("##csx", &contents_size_x); - ImVec2 p = ImGui::GetCursorScreenPos(); + ImVec2 p = ImGui::GetCursorScreenPos(); ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + 10, p.y + 10), IM_COL32_WHITE); ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(p.x + contents_size_x - 10, p.y), ImVec2(p.x + contents_size_x, p.y + 10), IM_COL32_WHITE); ImGui::Dummy(ImVec2(0, 10)); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3eb1067e..f3832201 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1202,7 +1202,7 @@ void ImDrawListSplitter::ClearFreeMemory() { for (int i = 0; i < _Channels.Size; i++) { - if (i == _Current) + if (i == _Current) memset(&_Channels[i], 0, sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again _Channels[i]._CmdBuffer.clear(); _Channels[i]._IdxBuffer.clear(); @@ -1307,7 +1307,7 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list) void ImDrawListSplitter::SetCurrentChannel(ImDrawList* draw_list, int idx) { IM_ASSERT(idx >= 0 && idx < _Count); - if (_Current == idx) + if (_Current == idx) return; // Overwrite ImVector (12/16 bytes), four times. This is merely a silly optimization instead of doing .swap() memcpy(&_Channels.Data[_Current]._CmdBuffer, &draw_list->CmdBuffer, sizeof(draw_list->CmdBuffer)); diff --git a/imgui_internal.h b/imgui_internal.h index 9c87d2a1..ca51e51b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -809,7 +809,7 @@ struct ImGuiNextWindowData void* SizeCallbackUserData; float BgAlphaVal; ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. - + ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } }; @@ -1710,7 +1710,7 @@ IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned ch // Debug Tools // Use 'Metrics->Tools->Item Picker' to break into the call-stack of a specific item. -#ifndef IM_DEBUG_BREAK +#ifndef IM_DEBUG_BREAK #if defined(__clang__) #define IM_DEBUG_BREAK() __builtin_debugtrap() #elif defined (_MSC_VER) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ba3bac87..f924bbd1 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -399,37 +399,37 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // See the series of events below and the corresponding state reported by dear imgui: //------------------------------------------------------------------------------------------------------------------------------------------------ // with PressedOnClickRelease: return-value IsItemHovered() IsItemActive() IsItemActivated() IsItemDeactivated() IsItemClicked() -// Frame N+0 (mouse is outside bb) - - - - - - -// Frame N+1 (mouse moves inside bb) - true - - - - +// Frame N+0 (mouse is outside bb) - - - - - - +// Frame N+1 (mouse moves inside bb) - true - - - - // Frame N+2 (mouse button is down) - true true true - true -// Frame N+3 (mouse button is down) - true true - - - +// Frame N+3 (mouse button is down) - true true - - - // Frame N+4 (mouse moves outside bb) - - true - - - // Frame N+5 (mouse moves inside bb) - true true - - - -// Frame N+6 (mouse button is released) true true - - true - -// Frame N+7 (mouse button is released) - true - - - - -// Frame N+8 (mouse moves outside bb) - - - - - - +// Frame N+6 (mouse button is released) true true - - true - +// Frame N+7 (mouse button is released) - true - - - - +// Frame N+8 (mouse moves outside bb) - - - - - - //------------------------------------------------------------------------------------------------------------------------------------------------ // with PressedOnClick: return-value IsItemHovered() IsItemActive() IsItemActivated() IsItemDeactivated() IsItemClicked() // Frame N+2 (mouse button is down) true true true true - true -// Frame N+3 (mouse button is down) - true true - - - -// Frame N+6 (mouse button is released) - true - - true - -// Frame N+7 (mouse button is released) - true - - - - +// Frame N+3 (mouse button is down) - true true - - - +// Frame N+6 (mouse button is released) - true - - true - +// Frame N+7 (mouse button is released) - true - - - - //------------------------------------------------------------------------------------------------------------------------------------------------ // with PressedOnRelease: return-value IsItemHovered() IsItemActive() IsItemActivated() IsItemDeactivated() IsItemClicked() // Frame N+2 (mouse button is down) - true - - - true -// Frame N+3 (mouse button is down) - true - - - - +// Frame N+3 (mouse button is down) - true - - - - // Frame N+6 (mouse button is released) true true - - - - -// Frame N+7 (mouse button is released) - true - - - - +// Frame N+7 (mouse button is released) - true - - - - //------------------------------------------------------------------------------------------------------------------------------------------------ // with PressedOnDoubleClick: return-value IsItemHovered() IsItemActive() IsItemActivated() IsItemDeactivated() IsItemClicked() // Frame N+0 (mouse button is down) - true - - - true -// Frame N+1 (mouse button is down) - true - - - - +// Frame N+1 (mouse button is down) - true - - - - // Frame N+2 (mouse button is released) - true - - - - -// Frame N+3 (mouse button is released) - true - - - - +// Frame N+3 (mouse button is released) - true - - - - // Frame N+4 (mouse button is down) true true true true - true -// Frame N+5 (mouse button is down) - true true - - - +// Frame N+5 (mouse button is down) - true true - - - // Frame N+6 (mouse button is released) - true - - true - -// Frame N+7 (mouse button is released) - true - - - - +// Frame N+7 (mouse button is released) - true - - - - //------------------------------------------------------------------------------------------------------------------------------------------------ // Note that some combinations are supported, // - PressedOnDragDropHold can generally be associated with any flag. @@ -439,7 +439,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // Repeat+ Repeat+ Repeat+ Repeat+ // PressedOnClickRelease PressedOnClick PressedOnRelease PressedOnDoubleClick //------------------------------------------------------------------------------------------------------------------------------------------------- -// Frame N+0 (mouse button is down) - true - true +// Frame N+0 (mouse button is down) - true - true // ... - - - - // Frame N + RepeatDelay true true - true // ... - - - - @@ -5507,7 +5507,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); - // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard + // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) { if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) @@ -7291,7 +7291,7 @@ void ImGui::PushColumnsBackground() return; window->DrawList->ChannelsSetCurrent(0); int cmd_size = window->DrawList->CmdBuffer.Size; - PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false); + PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false); IM_UNUSED(cmd_size); IM_ASSERT(cmd_size == window->DrawList->CmdBuffer.Size); // Being in channel 0 this should not have created an ImDrawCmd } From 3f986e72d955795ea0306c2b6c1007dc0ad53776 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 12:06:31 +0200 Subject: [PATCH 013/384] Internal: Offset STB_TEXTURE_K_ defines to remove that change from #2541 + sponsors update. --- docs/README.md | 4 ++-- imgui_widgets.cpp | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5a706354..a07acc79 100644 --- a/docs/README.md +++ b/docs/README.md @@ -311,10 +311,10 @@ Ongoing dear imgui development is financially supported by users and private spo - Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn. **Salty caramel supporters** -- Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, Morten Skaaning, Nikhil Deshpande, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford. +- Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. **Caramel supporters** -- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis. +- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis. And all other past and present supporters; THANK YOU! (Please contact me if you would like to be added or removed from this list) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f924bbd1..3cd0638b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3222,21 +3222,21 @@ static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const Im } // We don't use an enum so we can build even with conflicting symbols (if another user of stb_textedit.h leak their STB_TEXTEDIT_K_* symbols) -#define STB_TEXTEDIT_K_LEFT 0x10000 // keyboard input to move cursor left -#define STB_TEXTEDIT_K_RIGHT 0x10001 // keyboard input to move cursor right -#define STB_TEXTEDIT_K_UP 0x10002 // keyboard input to move cursor up -#define STB_TEXTEDIT_K_DOWN 0x10003 // keyboard input to move cursor down -#define STB_TEXTEDIT_K_LINESTART 0x10004 // keyboard input to move cursor to start of line -#define STB_TEXTEDIT_K_LINEEND 0x10005 // keyboard input to move cursor to end of line -#define STB_TEXTEDIT_K_TEXTSTART 0x10006 // keyboard input to move cursor to start of text -#define STB_TEXTEDIT_K_TEXTEND 0x10007 // keyboard input to move cursor to end of text -#define STB_TEXTEDIT_K_DELETE 0x10008 // keyboard input to delete selection or character under cursor -#define STB_TEXTEDIT_K_BACKSPACE 0x10009 // keyboard input to delete selection or character left of cursor -#define STB_TEXTEDIT_K_UNDO 0x1000A // keyboard input to perform undo -#define STB_TEXTEDIT_K_REDO 0x1000B // keyboard input to perform redo -#define STB_TEXTEDIT_K_WORDLEFT 0x1000C // keyboard input to move cursor left one word -#define STB_TEXTEDIT_K_WORDRIGHT 0x1000D // keyboard input to move cursor right one word -#define STB_TEXTEDIT_K_SHIFT 0x20000 +#define STB_TEXTEDIT_K_LEFT 0x200000 // keyboard input to move cursor left +#define STB_TEXTEDIT_K_RIGHT 0x200001 // keyboard input to move cursor right +#define STB_TEXTEDIT_K_UP 0x200002 // keyboard input to move cursor up +#define STB_TEXTEDIT_K_DOWN 0x200003 // keyboard input to move cursor down +#define STB_TEXTEDIT_K_LINESTART 0x200004 // keyboard input to move cursor to start of line +#define STB_TEXTEDIT_K_LINEEND 0x200005 // keyboard input to move cursor to end of line +#define STB_TEXTEDIT_K_TEXTSTART 0x200006 // keyboard input to move cursor to start of text +#define STB_TEXTEDIT_K_TEXTEND 0x200007 // keyboard input to move cursor to end of text +#define STB_TEXTEDIT_K_DELETE 0x200008 // keyboard input to delete selection or character under cursor +#define STB_TEXTEDIT_K_BACKSPACE 0x200009 // keyboard input to delete selection or character left of cursor +#define STB_TEXTEDIT_K_UNDO 0x20000A // keyboard input to perform undo +#define STB_TEXTEDIT_K_REDO 0x20000B // keyboard input to perform redo +#define STB_TEXTEDIT_K_WORDLEFT 0x20000C // keyboard input to move cursor left one word +#define STB_TEXTEDIT_K_WORDRIGHT 0x20000D // keyboard input to move cursor right one word +#define STB_TEXTEDIT_K_SHIFT 0x400000 #define STB_TEXTEDIT_IMPLEMENTATION #include "imstb_textedit.h" From b48dc067ae794cd9159397b338a985c0b906404d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 16:16:38 +0200 Subject: [PATCH 014/384] Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) + Fix #2775 --- docs/CHANGELOG.txt | 1 + imgui.cpp | 4 ++-- imgui.h | 2 +- imgui_demo.cpp | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 36ba83ba..0c3a28d6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,7 @@ Other Changes: - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] - DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. - DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] +- Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) - Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow diff --git a/imgui.cpp b/imgui.cpp index c4b3425d..d717fb17 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3692,7 +3692,7 @@ static void NewFrameSanityChecks() IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!"); IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!"); IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."); - IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); + IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); for (int n = 0; n < ImGuiKey_COUNT; n++) IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)"); @@ -5314,7 +5314,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl ImGuiWindowFlags flags = window->Flags; const bool has_close_button = (p_open != NULL); - const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse); + const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse) && (style.WindowMenuButtonPosition != ImGuiDir_None); // Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer) const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags; diff --git a/imgui.h b/imgui.h index 965e81a0..a3faa620 100644 --- a/imgui.h +++ b/imgui.h @@ -1289,7 +1289,7 @@ struct ImGuiStyle float WindowBorderSize; // Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). ImVec2 WindowMinSize; // Minimum window size. This is a global setting. If you want to constraint individual windows, use SetNextWindowSizeConstraints(). ImVec2 WindowTitleAlign; // Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. - ImGuiDir WindowMenuButtonPosition; // Side of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left. + ImGuiDir WindowMenuButtonPosition; // Side of the collapsing/docking button in the title bar (None/Left/Right). Defaults to ImGuiDir_Left. float ChildRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows. float ChildBorderSize; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). float PopupRounding; // Radius of popup window corners rounding. (Note that tooltip windows use WindowRounding) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e7ffdddd..13877cd5 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3195,7 +3195,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f"); ImGui::Text("Alignment"); ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f"); - ImGui::Combo("WindowMenuButtonPosition", (int*)&style.WindowMenuButtonPosition, "Left\0Right\0"); + int window_menu_button_position = style.WindowMenuButtonPosition + 1; + if (ImGui::Combo("WindowMenuButtonPosition", (int*)&window_menu_button_position, "None\0Left\0Right\0")) + style.WindowMenuButtonPosition = window_menu_button_position - 1; ImGui::Combo("ColorButtonPosition", (int*)&style.ColorButtonPosition, "Left\0Right\0"); ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Alignment applies when a button is larger than its text content."); ImGui::SliderFloat2("SelectableTextAlign", (float*)&style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Alignment applies when a selectable is larger than its text content."); @@ -3284,7 +3286,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::InputFloat("Font offset", &font->DisplayOffset.y, 1, 1, "%.0f"); ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); ImGui::Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar); - ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar); + ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar, font->EllipsisChar); const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface); ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt); for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) From 1ca6ff974ccc0359cd58925fd9635fe1d028d5c6 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 18:02:58 +0200 Subject: [PATCH 015/384] Viewport: fix to allow multiple shutdown / calls to DestroyPlatformWindows(). (#2769) --- imgui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 70914d2b..5048bc5b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11173,7 +11173,11 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) if (g.PlatformIO.Platform_DestroyWindow) g.PlatformIO.Platform_DestroyWindow(viewport); IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL); - viewport->PlatformWindowCreated = false; + + // Don't clear PlatformWindowCreated for the main viewport, as we initially set that up to true in Initialize() + // The right-er way may be to leave it to the back-end to set this flag all-together, and made the flag public. + if (viewport->ID != IMGUI_VIEWPORT_DEFAULT_ID) + viewport->PlatformWindowCreated = false; } else { From cf982908732ee4c7e3faa3db47feab2eec7da00d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 18:32:26 +0200 Subject: [PATCH 016/384] Backends: DirectX9: Workaround for windows not refreshing when main viewport has no draw call. (#2560) --- examples/imgui_impl_dx9.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 2c22885e..a9df2e8a 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -214,6 +214,11 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) global_vtx_offset += cmd_list->VtxBuffer.Size; } + // When using multi-viewports, it appears that there's an odd logic in DirectX9 which prevent subsequent windows + // from rendering until the first window submits at least one draw call, even once. That's our workaround. (see #2560) + if (global_vtx_offset == 0) + g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, 0); + // Restore the DX9 transform g_pd3dDevice->SetTransform(D3DTS_WORLD, &last_world); g_pd3dDevice->SetTransform(D3DTS_VIEW, &last_view); From 098591fe4c95dd4939d0c6e30d18f6b1ff49e49d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Sep 2019 20:27:15 +0200 Subject: [PATCH 017/384] ImDrawListSplitter: fixed an issue merging channels if the last submitted draw command used a different texture. (#2506) --- docs/CHANGELOG.txt | 1 + imgui_draw.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0c3a28d6..dcb8fab1 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -56,6 +56,7 @@ Other Changes: Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow as possible. (#2775) [@rokups] - ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740) +- ImDrawListSplitter: fixed an issue merging channels if the last submitted draw command used a different texture. (#2506) - Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory diff --git a/imgui_draw.cpp b/imgui_draw.cpp index e1a023d7..eb173b44 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1301,6 +1301,7 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list) } draw_list->_IdxWritePtr = idx_write; draw_list->UpdateClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call. + draw_list->UpdateTextureID(); _Count = 1; } From 74e01e62ceadcbc859644657cb98de9271fc266a Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Sep 2019 13:21:12 +0200 Subject: [PATCH 018/384] Fixed unused static function warning for some compilers. (#2793) --- imgui.cpp | 19 +++++++------------ imgui_internal.h | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d717fb17..8c9dc9a2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1082,6 +1082,7 @@ static void NavUpdateWindowingOverlay(); static void NavUpdateMoveResult(); static float NavUpdatePageUpPageDown(int allowed_dir_flags); static inline void NavUpdateAnyRequestFlag(); +static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand); static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, ImGuiID id); static ImVec2 NavCalcPreferredRefPos(); static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window); @@ -3344,12 +3345,6 @@ ImDrawList* ImGui::GetBackgroundDrawList() return &GImGui->BackgroundDrawList; } -static ImDrawList* GetForegroundDrawList(ImGuiWindow*) -{ - // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. - return &GImGui->ForegroundDrawList; -} - ImDrawList* ImGui::GetForegroundDrawList() { return &GImGui->ForegroundDrawList; @@ -7882,7 +7877,7 @@ static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect } // Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057 -static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) +static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -7945,22 +7940,22 @@ static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) #if IMGUI_DEBUG_NAV_SCORING char buf[128]; - if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max)) + if (IsMouseHoveringRect(cand.Min, cand.Max)) { ImFormatString(buf, IM_ARRAYSIZE(buf), "dbox (%.2f,%.2f->%.4f)\ndcen (%.2f,%.2f->%.4f)\nd (%.2f,%.2f->%.4f)\nnav %c, quadrant %c", dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]); - ImDrawList* draw_list = ImGui::GetForegroundDrawList(window); + ImDrawList* draw_list = GetForegroundDrawList(window); draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100)); draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200)); - draw_list->AddRectFilled(cand.Max-ImVec2(4,4), cand.Max+ImGui::CalcTextSize(buf)+ImVec2(4,4), IM_COL32(40,0,0,150)); + draw_list->AddRectFilled(cand.Max - ImVec2(4,4), cand.Max + CalcTextSize(buf) + ImVec2(4,4), IM_COL32(40,0,0,150)); draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Max, ~0U, buf); } else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate. { - if (ImGui::IsKeyPressedMap(ImGuiKey_C)) { g.NavMoveDirLast = (ImGuiDir)((g.NavMoveDirLast + 1) & 3); g.IO.KeysDownDuration[g.IO.KeyMap[ImGuiKey_C]] = 0.01f; } + if (IsKeyPressedMap(ImGuiKey_C)) { g.NavMoveDirLast = (ImGuiDir)((g.NavMoveDirLast + 1) & 3); g.IO.KeysDownDuration[g.IO.KeyMap[ImGuiKey_C]] = 0.01f; } if (quadrant == g.NavMoveDir) { ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center); - ImDrawList* draw_list = ImGui::GetForegroundDrawList(window); + ImDrawList* draw_list = GetForegroundDrawList(window); draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200)); draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Min, IM_COL32(255, 255, 255, 255), buf); } diff --git a/imgui_internal.h b/imgui_internal.h index 3d82869c..47da60ab 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1495,6 +1495,7 @@ namespace ImGui IMGUI_API void SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } + inline ImDrawList* GetForegroundDrawList(ImGuiWindow*) { ImGuiContext& g = *GImGui; return &g.ForegroundDrawList; } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. // Init IMGUI_API void Initialize(ImGuiContext* context); From 9d02ed51e3d10e6aff09d10871e7b55b3475dd95 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Sep 2019 17:13:41 +0200 Subject: [PATCH 019/384] TreeNode: Added ImGuiTreeNodeFlags_SpanAvailWidth and ImGuiTreeNodeFlags_SpanFullWidth flags (#2451, #2438, #1897) Added demo bits. --- docs/CHANGELOG.txt | 7 +++++++ imgui.h | 5 +++-- imgui_demo.cpp | 14 +++++++++----- imgui_widgets.cpp | 36 +++++++++++++++++++++--------------- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index dcb8fab1..80df2c16 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,13 @@ Other Changes: - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] - DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. - DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] +- TreeNode: Added ImGuiTreeNodeFlags_SpanAvailWidth flag. (#2451, #2438, #1897) [@Melix19, @PathogenDavid] + This extends the hit-box to the right-most edge, even if the node is not framed. + (Note: this is not the default in order to allow adding other items on the same line. In the future we will + aim toward refactoring the hit-system to be front-to-back, allowing more natural overlapping of items, + and then we will be able to make this the default.) +- TreeNode: Added ImGuiTreeNodeFlags_SpanFullWidth flag. This extends the hit-box to both the left-most and + right-most edge of the working area, bypassing indentation. - Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) - Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. diff --git a/imgui.h b/imgui.h index a3faa620..048ac71a 100644 --- a/imgui.h +++ b/imgui.h @@ -791,9 +791,10 @@ enum ImGuiTreeNodeFlags_ ImGuiTreeNodeFlags_Leaf = 1 << 8, // No collapsing, no arrow (use as a convenience for leaf nodes). ImGuiTreeNodeFlags_Bullet = 1 << 9, // Display a bullet instead of arrow ImGuiTreeNodeFlags_FramePadding = 1 << 10, // Use FramePadding (even for an unframed text node) to vertically align text baseline to regular widget height. Equivalent to calling AlignTextToFramePadding(). - //ImGuiTreeNodeFlags_SpanAllAvailWidth = 1 << 11, // FIXME: TODO: Extend hit box horizontally even if not framed - //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 12, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible + ImGuiTreeNodeFlags_SpanAvailWidth = 1 << 11, // Extend hit box to the right-most edge, even if not framed. This is not the default in order to allow adding other items on the same line. In the future we may refactor the hit system to be front-to-back, allowing natural overlaps and then this can become the default. + ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, // Extend hit box to the left-most and right-most edges (bypass the indented area). ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop) + //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 14, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog // Obsolete names (will be removed) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 13877cd5..1f5c66d6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -608,7 +608,12 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("Advanced, with Selectable nodes")) { HelpMarker("This is a more typical looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open."); + static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; static bool align_label_with_current_x_position = false; + ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnArrow", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnArrow); + ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnDoubleClick", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnDoubleClick); + ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanAvailWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanAvailWidth); + ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanFullWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanFullWidth); ImGui::Checkbox("Align label with current X position)", &align_label_with_current_x_position); ImGui::Text("Hello!"); if (align_label_with_current_x_position) @@ -616,12 +621,12 @@ static void ShowDemoWindowWidgets() static int selection_mask = (1 << 2); // Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit. int node_clicked = -1; // Temporary storage of what node we have clicked to process selection at the end of the loop. May be a pointer to your own node type, etc. - ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize()*3); // Increase spacing to differentiate leaves from expanded contents. for (int i = 0; i < 6; i++) { // Disable the default open on single-click behavior and pass in Selected flag according to our selection state. - ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; - if (selection_mask & (1 << i)) + ImGuiTreeNodeFlags node_flags = base_flags; + const bool is_selected = (selection_mask & (1 << i)); + if (is_selected) node_flags |= ImGuiTreeNodeFlags_Selected; if (i < 3) { @@ -631,7 +636,7 @@ static void ShowDemoWindowWidgets() node_clicked = i; if (node_open) { - ImGui::Text("Blah blah\nBlah Blah"); + ImGui::BulletText("Blah blah\nBlah Blah"); ImGui::TreePop(); } } @@ -654,7 +659,6 @@ static void ShowDemoWindowWidgets() else //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, this commented bit preserve selection when clicking on item that is part of the selection selection_mask = (1 << node_clicked); // Click to single-select } - ImGui::PopStyleVar(); if (align_label_with_current_x_position) ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing()); ImGui::TreePop(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3cd0638b..3adfc892 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5177,29 +5177,36 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const ImVec2 label_size = CalcTextSize(label, label_end, false); // We vertically grow up to current line height up the typical widget height. - const float text_base_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it const float frame_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y*2), label_size.y + padding.y*2); - ImRect frame_bb = ImRect(window->DC.CursorPos, ImVec2(window->WorkRect.Max.x, window->DC.CursorPos.y + frame_height)); + ImRect frame_bb; + frame_bb.Min.x = (flags & ImGuiTreeNodeFlags_SpanFullWidth) ? window->WorkRect.Min.x : window->DC.CursorPos.x; + frame_bb.Min.y = window->DC.CursorPos.y; + frame_bb.Max.x = window->WorkRect.Max.x; + frame_bb.Max.y = window->DC.CursorPos.y + frame_height; if (display_frame) { - // Framed header expand a little outside the default padding + // Framed header expand a little outside the default padding, to the edge of InnerClipRect + // (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f) frame_bb.Min.x -= (float)(int)(window->WindowPadding.x * 0.5f - 1.0f); frame_bb.Max.x += (float)(int)(window->WindowPadding.x * 0.5f); } - const float text_offset_x = (g.FontSize + (display_frame ? padding.x*3 : padding.x*2)); // Collapser arrow width + Spacing - const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x*2 : 0.0f); // Include collapser - ItemSize(ImVec2(text_width, frame_height), text_base_offset_y); + const float text_offset_x = g.FontSize + (display_frame ? padding.x*3 : padding.x*2); // Collapser arrow width + Spacing + const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it + const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x*2 : 0.0f); // Include collapser + const ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y); + ItemSize(ImVec2(text_width, frame_height), text_offset_y); // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing - // (Ideally we'd want to add a flag for the user to specify if we want the hit test to be done up to the right side of the content or not) - const ImRect interact_bb = display_frame ? frame_bb : ImRect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + text_width + style.ItemSpacing.x*2, frame_bb.Max.y); - bool is_open = TreeNodeBehaviorIsOpen(id, flags); - bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; - + ImRect interact_bb = frame_bb; + if (!display_frame && (flags & (ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth)) == 0) + interact_bb.Max.x = frame_bb.Min.x + text_width + style.ItemSpacing.x * 2.0f; + // Store a flag for the current depth to tell if we will allow closing this node when navigating one of its child. // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop(). // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero. + const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; + bool is_open = TreeNodeBehaviorIsOpen(id, flags); if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) window->DC.TreeStoreMayJumpToParentOnPop |= (1 << window->DC.TreeDepth); @@ -5273,7 +5280,6 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // Render const ImU32 text_col = GetColorU32(ImGuiCol_Text); - const ImVec2 text_pos = frame_bb.Min + ImVec2(text_offset_x, text_base_offset_y); ImGuiNavHighlightFlags nav_highlight_flags = ImGuiNavHighlightFlags_TypeThin; if (display_frame) { @@ -5281,7 +5287,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, true, style.FrameRounding); RenderNavHighlight(frame_bb, id, nav_highlight_flags); - RenderArrow(window->DrawList, frame_bb.Min + ImVec2(padding.x, text_base_offset_y), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f); + RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f); if (flags & ImGuiTreeNodeFlags_ClipLabelForTrailingButton) frame_bb.Max.x -= g.FontSize + style.FramePadding.x; if (g.LogEnabled) @@ -5309,9 +5315,9 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l } if (flags & ImGuiTreeNodeFlags_Bullet) - RenderBullet(window->DrawList, frame_bb.Min + ImVec2(text_offset_x * 0.5f, g.FontSize*0.50f + text_base_offset_y), text_col); + RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.5f, text_pos.y + g.FontSize*0.50f), text_col); else if (!is_leaf) - RenderArrow(window->DrawList, frame_bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f); + RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y + g.FontSize*0.15f), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f); if (g.LogEnabled) LogRenderedText(&text_pos, ">"); RenderText(text_pos, label, label_end, false); From 656c515bad460e3e1fd7c190697c6796a7567f29 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Sep 2019 17:21:04 +0200 Subject: [PATCH 020/384] Warning fix. --- imgui_demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 1f5c66d6..0c911dfb 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -625,7 +625,7 @@ static void ShowDemoWindowWidgets() { // Disable the default open on single-click behavior and pass in Selected flag according to our selection state. ImGuiTreeNodeFlags node_flags = base_flags; - const bool is_selected = (selection_mask & (1 << i)); + const bool is_selected = (selection_mask & (1 << i)) != 0; if (is_selected) node_flags |= ImGuiTreeNodeFlags_Selected; if (i < 3) From accb0261b8fd4c1bd32f58b3ecc7a0b732d6006e Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Sat, 31 Aug 2019 18:44:20 +0300 Subject: [PATCH 021/384] ColorPicker / ColorEdit: restore Hue when zeroing Saturation. (#2722, #2770) Issue is fixed by storing last active color picker color and last hue value when active color picker takes rgb as input. Then if current color picker color matches last active color - hue value will be restored. IDs are not used because ColorEdit4() and ColorWidget4() may call each other in hard-to-predict ways and they both push their own IDs on to the stack. We need hue restoration to happen in entire stack of these widgets if topmost widget used hue restoration. Since these widgets operate on exact same color value - color was chosen as a factor deciding which widgets should restore hue. --- imgui_internal.h | 2 ++ imgui_widgets.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/imgui_internal.h b/imgui_internal.h index 47da60ab..8fc03a03 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1012,6 +1012,8 @@ struct ImGuiContext ImFont InputTextPasswordFont; ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets + float ColorEditLastHue; + float ColorEditLastActiveColor[3]; ImVec4 ColorPickerRef; bool DragCurrentAccumDirty; float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3adfc892..7466acff 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4200,7 +4200,12 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if ((flags & ImGuiColorEditFlags_InputHSV) && (flags & ImGuiColorEditFlags_DisplayRGB)) ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV)) + { ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); + // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. + if (f[1] == 0 && memcmp(g.ColorEditLastActiveColor, col, sizeof(float) * 3) == 0) + f[0] = g.ColorEditLastHue; + } int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; bool value_changed = false; @@ -4327,7 +4332,11 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag for (int n = 0; n < 4; n++) f[n] = i[n] / 255.0f; if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB)) + { + g.ColorEditLastHue = f[0]; ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); + memcpy(g.ColorEditLastActiveColor, f, sizeof(float) * 3); + } if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV)) ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); @@ -4504,7 +4513,12 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl float H = col[0], S = col[1], V = col[2]; float R = col[0], G = col[1], B = col[2]; if (flags & ImGuiColorEditFlags_InputRGB) + { ColorConvertRGBtoHSV(R, G, B, H, S, V); + // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. + if (S == 0 && memcmp(g.ColorEditLastActiveColor, col, sizeof(float) * 3) == 0) + H = g.ColorEditLastHue; + } else if (flags & ImGuiColorEditFlags_InputHSV) ColorConvertHSVtoRGB(H, S, V, R, G, B); @@ -4628,6 +4642,8 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl if (flags & ImGuiColorEditFlags_InputRGB) { ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); + g.ColorEditLastHue = H; + memcpy(g.ColorEditLastActiveColor, col, sizeof(float) * 3); } else if (flags & ImGuiColorEditFlags_InputHSV) { @@ -4680,7 +4696,9 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl R = col[0]; G = col[1]; B = col[2]; + float preserve_hue = H; ColorConvertRGBtoHSV(R, G, B, H, S, V); + H = preserve_hue; // Avoids picker losing hue value for 1 frame glitch. } else if (flags & ImGuiColorEditFlags_InputHSV) { From 38d22bc47de97384c2f61619c4da7e53ca71f29b Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 20 Sep 2019 15:31:39 +0200 Subject: [PATCH 022/384] ColorPicker / ColorEdit: restore Hue when zeroing Saturation. (#2722, #2770) - changelog, fixed uninitialized variables, tweaks, renaming. --- docs/CHANGELOG.txt | 4 +++- imgui_internal.h | 4 +++- imgui_widgets.cpp | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 80df2c16..b5d0c254 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -35,10 +35,12 @@ HOW TO UPDATE? Other Changes: - Nav, Scrolling: Added support for Home/End key. (#787) +- ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around. +- ColorEdit, ColorPicker: In HSV display of a RGB stored value, attempt to locally preserve Hue + when Saturation==0, which reduces accidentally lossy interactions. (#2722, 2770) [@rokups] - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). -- ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around. - TabBar: fixed ScrollToBar request creating bouncing loop when tab is larger than available space. - TabBar: fixed single-tab not shrinking their width down. - TabBar: feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) diff --git a/imgui_internal.h b/imgui_internal.h index 8fc03a03..6dd68b56 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1013,7 +1013,7 @@ struct ImGuiContext ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets float ColorEditLastHue; - float ColorEditLastActiveColor[3]; + float ColorEditLastColor[3]; ImVec4 ColorPickerRef; bool DragCurrentAccumDirty; float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings @@ -1158,6 +1158,8 @@ struct ImGuiContext LastValidMousePos = ImVec2(0.0f, 0.0f); TempInputTextId = 0; ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; + ColorEditLastHue = 0.0f; + ColorEditLastColor[0] = ColorEditLastColor[1] = ColorEditLastColor[2] = FLT_MAX; DragCurrentAccumDirty = false; DragCurrentAccum = 0.0f; DragSpeedDefaultRatio = 1.0f / 100.0f; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 7466acff..042af866 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4201,9 +4201,9 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); else if ((flags & ImGuiColorEditFlags_InputRGB) && (flags & ImGuiColorEditFlags_DisplayHSV)) { - ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. - if (f[1] == 0 && memcmp(g.ColorEditLastActiveColor, col, sizeof(float) * 3) == 0) + ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); + if (f[1] == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) f[0] = g.ColorEditLastHue; } int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; @@ -4335,7 +4335,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag { g.ColorEditLastHue = f[0]; ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); - memcpy(g.ColorEditLastActiveColor, f, sizeof(float) * 3); + memcpy(g.ColorEditLastColor, f, sizeof(float) * 3); } if ((flags & ImGuiColorEditFlags_DisplayRGB) && (flags & ImGuiColorEditFlags_InputHSV)) ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); @@ -4514,13 +4514,15 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl float R = col[0], G = col[1], B = col[2]; if (flags & ImGuiColorEditFlags_InputRGB) { - ColorConvertRGBtoHSV(R, G, B, H, S, V); // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. - if (S == 0 && memcmp(g.ColorEditLastActiveColor, col, sizeof(float) * 3) == 0) + ColorConvertRGBtoHSV(R, G, B, H, S, V); + if (S == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) H = g.ColorEditLastHue; } else if (flags & ImGuiColorEditFlags_InputHSV) + { ColorConvertHSVtoRGB(H, S, V, R, G, B); + } bool value_changed = false, value_changed_h = false, value_changed_sv = false; @@ -4643,7 +4645,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); g.ColorEditLastHue = H; - memcpy(g.ColorEditLastActiveColor, col, sizeof(float) * 3); + memcpy(g.ColorEditLastColor, col, sizeof(float) * 3); } else if (flags & ImGuiColorEditFlags_InputHSV) { @@ -4696,9 +4698,9 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl R = col[0]; G = col[1]; B = col[2]; - float preserve_hue = H; ColorConvertRGBtoHSV(R, G, B, H, S, V); - H = preserve_hue; // Avoids picker losing hue value for 1 frame glitch. + if (S == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) // Fix local Hue as display below will use it immediately. + H = g.ColorEditLastHue; } else if (flags & ImGuiColorEditFlags_InputHSV) { From f7468d05fe46d72df175afa00478b0148347c7ff Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 20 Sep 2019 15:46:18 +0200 Subject: [PATCH 023/384] Fixed mouse event forwarding in macos example (#2710, #1961) --- docs/CHANGELOG.txt | 2 ++ examples/example_apple_opengl2/main.mm | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b5d0c254..389f0a64 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,6 +77,8 @@ Other Changes: - Backends: Vulkan: Added support for specifying multisample count. Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values to use, default is non-multisampled as before. (#2705, #2706) [@vilya] +- Examples: OSX: Fix example_apple_opengl2/main.mm not forwarding mouse clicks and drags correctly. (#1961, #2710) + [@intonarumori, @ElectricMagic] - Misc: Updated stb_rect_pack from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic, fix handling of rectangles too large to fit inside texture). (#2762) [@tido64] diff --git a/examples/example_apple_opengl2/main.mm b/examples/example_apple_opengl2/main.mm index d11b908d..72f934a3 100644 --- a/examples/example_apple_opengl2/main.mm +++ b/examples/example_apple_opengl2/main.mm @@ -133,12 +133,6 @@ return (YES); } -// Flip coordinate system upside down on Y --(BOOL)isFlipped -{ - return (YES); -} - -(void)dealloc { animationTimer = nil; @@ -150,6 +144,8 @@ -(void)flagsChanged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } -(void)mouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } -(void)mouseUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } +-(void)mouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } +-(void)mouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } -(void)scrollWheel:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); } @end @@ -179,6 +175,7 @@ _window = [[NSWindow alloc] initWithContentRect:viewRect styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:YES]; [_window setTitle:@"Dear ImGui OSX+OpenGL2 Example"]; + [_window setAcceptsMouseMovedEvents:YES]; [_window setOpaque:YES]; [_window makeKeyAndOrderFront:NSApp]; From a45e3b5bb3e4c228584bb66776d69003303ad9fa Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 20 Sep 2019 19:04:19 +0200 Subject: [PATCH 024/384] Readme, Wiki: Image loading examples. --- docs/README.md | 4 ++-- docs/TODO.txt | 4 ++++ imgui.cpp | 24 ++++-------------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/docs/README.md b/docs/README.md index a07acc79..6ca295ea 100644 --- a/docs/README.md +++ b/docs/README.md @@ -244,13 +244,13 @@ See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software usi The library started its life as "ImGui" due to the fact that I didn't give it a proper name when I released 1.0 and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce this ambiguity without affecting existing codebases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. Please try to refer to this library as "Dear ImGui". **How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?** -
**How can I display an image? What is ImTextureID, how does it works?** +
**How can I display an image? What is ImTextureID, how does it works?** ([examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples))
**Why are multiple widgets reacting when I interact with a single one? How can I have multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack...**
**How can I use my own math types instead of ImVec2/ImVec4?**
**How can I load a different font than the default?**
**How can I easily use icons in my application?**
**How can I load multiple fonts?** -
**How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?** ([example](https://github.com/ocornut/imgui/wiki/Loading-Font-Example)) +
**How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?** ([examples](https://github.com/ocornut/imgui/wiki/Loading-Font-Example))
**How can I interact with standard C++ types (such as std::string and std::vector)?**
**How can I use the drawing facilities without a Dear ImGui window? (using ImDrawList API)**
**How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)** diff --git a/docs/TODO.txt b/docs/TODO.txt index df413b7e..9c37f690 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -93,6 +93,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there. - input text: a way for the user to provide syntax coloring. - input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count. + - input text: facilitate patterns like if (InputText(..., obj.get_string_ref()) { obj.set_string(...); } relying on internally held buffer. - input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc). - input text multi-line: support for cut/paste without selection (cut/paste the current line) - input text multi-line: line numbers? status bar? (follow up on #200) @@ -111,6 +112,9 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - layout: more generic alignment state (left/right/centered) for single items? - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. - layout: vertical alignment of mixed height items (e.g. buttons) within a same line (#1284) + - layout: null layout mode were items are not rendered but user can query GetItemRectMin()/Max/Size. + - layout: (R&D) local multi-pass layout mode. + - layout: (R&D) bind authored layout data (created by an off-line tool), items fetch their pos/size at submission, self-optimize data structures to stable linear access. - group: BeginGroup() needs a border option. (~#1496) - group: IsHovered() after EndGroup() covers whole aabb rather than the intersection of individual items. Is that desirable? diff --git a/imgui.cpp b/imgui.cpp index 8c9dc9a2..af5ffc4b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -622,6 +622,7 @@ CODE Q: How can I display an image? What is ImTextureID, how does it works? A: Short explanation: + - Please read Wiki entry for examples: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples - You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures. - Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value. - Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). @@ -669,26 +670,9 @@ CODE This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. - Here's a simplified OpenGL example using stb_image.h: - - // Use stb_image.h to load a PNG from disk and turn it into raw RGBA pixel data: - #define STB_IMAGE_IMPLEMENTATION - #include - [...] - int my_image_width, my_image_height; - unsigned char* my_image_data = stbi_load("my_image.png", &my_image_width, &my_image_height, NULL, 4); - - // Turn the RGBA pixel data into an OpenGL texture: - GLuint my_opengl_texture; - glGenTextures(1, &my_opengl_texture); - glBindTexture(GL_TEXTURE_2D, my_opengl_texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); - - // Now that we have an OpenGL texture, assuming our imgui rendering function (imgui_impl_xxx.cpp file) takes GLuint as ImTextureID, we can display it: - ImGui::Image((void*)(intptr_t)my_opengl_texture, ImVec2(my_image_width, my_image_height)); + Refer to the Wiki to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11: + + https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa. Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*. From 13f00331dacbfc6ff14e41fc359c4234100fa6b9 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 21 Sep 2019 14:50:02 +0200 Subject: [PATCH 025/384] Docking: Added ImGuiDockNodeFlags_NoDocking flag. (#2109) --- imgui.cpp | 3 +++ imgui_internal.h | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cb278944..cb6c3d00 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13122,6 +13122,8 @@ static void ImGui::DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNo data->IsCenterAvailable = !is_outer_docking; if (src_is_visibly_splitted && (!host_node || !host_node->IsEmpty())) data->IsCenterAvailable = false; + if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDocking)) + data->IsCenterAvailable = false; if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode()) data->IsCenterAvailable = false; @@ -15102,6 +15104,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : ""); if (ImGui::TreeNode("flags", "LocalFlags: 0x%04X SharedFlags: 0x%04X", node->LocalFlags, node->SharedFlags)) { + ImGui::CheckboxFlags("LocalFlags: NoDocking", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoDocking); ImGui::CheckboxFlags("LocalFlags: NoSplit", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoSplit); ImGui::CheckboxFlags("LocalFlags: NoResize", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoResize); ImGui::CheckboxFlags("LocalFlags: NoTabBar", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoTabBar); diff --git a/imgui_internal.h b/imgui_internal.h index a22e2b83..86c3e0ad 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -916,10 +916,11 @@ enum ImGuiDockNodeFlagsPrivate_ ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local, Saved // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar) ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local, Saved // Disable window/docking menu (that one that appears instead of the collapse button) ImGuiDockNodeFlags_NoCloseButton = 1 << 15, // Local, Saved // + ImGuiDockNodeFlags_NoDocking = 1 << 16, // Local, Saved // Disable any form of docking in this dockspace or individual node. (On a whole dockspace, this pretty much defeat the purpose of using a dockspace at all). Note: when turned on, existing docked nodes will be preserved. ImGuiDockNodeFlags_SharedFlagsInheritMask_ = ~0, - ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton, + ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking, ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace, // When splitting those flags are moved to the inheriting child, never duplicated - ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton + ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking }; // Store the source authority (dock node vs window) of a field From eab03f446758b45f331160ec4edf3af4c17059cf Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 21 Sep 2019 17:18:24 +0200 Subject: [PATCH 026/384] Selectable: Added ImGuiSelectableFlags_AllowItemOverlap flag in public api (was previously internal only). --- docs/CHANGELOG.txt | 1 + imgui.h | 3 ++- imgui_internal.h | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 389f0a64..6ccce928 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -59,6 +59,7 @@ Other Changes: and then we will be able to make this the default.) - TreeNode: Added ImGuiTreeNodeFlags_SpanFullWidth flag. This extends the hit-box to both the left-most and right-most edge of the working area, bypassing indentation. +- Selectable: Added ImGuiSelectableFlags_AllowItemOverlap flag in public api (was previously internal only). - Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) - Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. diff --git a/imgui.h b/imgui.h index 048ac71a..0657ae04 100644 --- a/imgui.h +++ b/imgui.h @@ -810,7 +810,8 @@ enum ImGuiSelectableFlags_ ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, // Generate press events on double clicks too - ImGuiSelectableFlags_Disabled = 1 << 3 // Cannot be selected, display grayed out text + ImGuiSelectableFlags_Disabled = 1 << 3, // Cannot be selected, display grayed out text + ImGuiSelectableFlags_AllowItemOverlap = 1 << 4 // (WIP) Hit testing to allow subsequent widgets to overlap this one }; // Flags for ImGui::BeginCombo() diff --git a/imgui_internal.h b/imgui_internal.h index 6dd68b56..a27c1849 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -361,9 +361,8 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_PressedOnClick = 1 << 21, ImGuiSelectableFlags_PressedOnRelease = 1 << 22, ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus) - ImGuiSelectableFlags_AllowItemOverlap = 1 << 24, - ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 25, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. - ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26 + ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 24, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. + ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25 }; // Extend ImGuiTreeNodeFlags_ From f47a0a85ccd6c5d35e29c742f80759154a83dbc0 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 21 Sep 2019 17:04:10 +0200 Subject: [PATCH 027/384] ImVector: added find, find_erase, find_erase_unsorted helpers. --- docs/CHANGELOG.txt | 11 ++++++----- imgui.h | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6ccce928..fa5d3d16 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,11 +41,11 @@ Other Changes: - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). -- TabBar: fixed ScrollToBar request creating bouncing loop when tab is larger than available space. -- TabBar: fixed single-tab not shrinking their width down. -- TabBar: feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) +- TabBar: Fixed ScrollToBar request creating bouncing loop when tab is larger than available space. +- TabBar: Fixed single-tab not shrinking their width down. +- TabBar: Feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) (before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations). -- TabBar: improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. +- TabBar: Improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right. - Columns, Separator: Fixed a bug where non-visible separators within columns would alter the next row position differently than visible ones. @@ -65,9 +65,10 @@ Other Changes: unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow as possible. (#2775) [@rokups] -- ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740) +- ImDrawList: Clarified the name of many parameters so reading the code is a little easier. (#2740) - ImDrawListSplitter: fixed an issue merging channels if the last submitted draw command used a different texture. (#2506) - Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) +- ImVector: Added find(), find_erase(), find_erase_unsorted() helpers. - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636) diff --git a/imgui.h b/imgui.h index 0657ae04..b5a1155e 100644 --- a/imgui.h +++ b/imgui.h @@ -1273,6 +1273,10 @@ struct ImVector inline T* erase_unsorted(const T* it) { IM_ASSERT(it >= Data && it < Data+Size); const ptrdiff_t off = it - Data; if (it < Data+Size-1) memcpy(Data + off, Data + Size - 1, sizeof(T)); Size--; return Data + off; } inline T* insert(const T* it, const T& v) { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(T)); memcpy(&Data[off], &v, sizeof(v)); Size++; return Data + off; } inline bool contains(const T& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } + inline T* find(const T& v) { T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data == v) break; else ++data; return data; } + inline const T* find(const T& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data == v) break; else ++data; return data; } + inline bool find_erase(const T& v) { const T* it = find(v); if (it < Data + Size) { erase(it); return true; } return false; } + inline bool find_erase_unsorted(const T& v) { const T* it = find(v); if (it < Data + Size) { erase_unsorted(it); return true; } return false; } inline int index_from_ptr(const T* it) const { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; return (int)off; } }; From 80b3ab7d3e09185355727aa42b69652b9afc3b97 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Sep 2019 22:16:05 +0200 Subject: [PATCH 028/384] TabBar: Fixed single tab shrinking reducing the tab to 0.0f size. Broken by a856c670c17fe70d61e519bf74ccb2559915a2ff. --- imgui_widgets.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 042af866..ca84674a 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1366,7 +1366,7 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc { if (count == 1) { - items[0].Width -= width_excess; + items[0].Width = ImMax(items[0].Width - width_excess, 1.0f); return; } ImQsort(items, (size_t)count, sizeof(ImGuiShrinkWidthItem), ShrinkWidthItemComparer); @@ -6562,6 +6562,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; tab->Width = ImMin(tab->WidthContents, tab_max_width); + IM_ASSERT(tab->Width > 0.0f); } } From 44cd8e39da53f1a2ac7608ecf891e935eebd7ba9 Mon Sep 17 00:00:00 2001 From: osheriff Date: Sun, 22 Sep 2019 12:52:36 +0200 Subject: [PATCH 029/384] Automatically include the available gl loader header --- examples/imgui_impl_opengl3.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 0f7eef74..fbf2417c 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -32,7 +32,19 @@ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) -#define IMGUI_IMPL_OPENGL_LOADER_GL3W + // to avoid problem with non-clang compilers not having this macro. + #if defined(__has_include) + // check if the header exists, then automatically define the macros .. + #if __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLEW + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLAD + #else + #define IMGUI_IMPL_OPENGL_LOADER_GL3W + #endif + #else + #define IMGUI_IMPL_OPENGL_LOADER_GL3W + #endif #endif IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); From 97691643b7fb198831af32207b88d7e4889c6887 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Sep 2019 23:19:04 +0200 Subject: [PATCH 030/384] Backends: OpenGL3: Attempt to automatically detect default GL loader by using __has_include. Followup to 44cd8e3 (#2798) --- docs/CHANGELOG.txt | 1 + examples/example_glfw_opengl3/main.cpp | 7 +++-- examples/example_sdl_opengl3/main.cpp | 7 +++-- examples/imgui_impl_opengl3.cpp | 33 ++++++++++++++++++-- examples/imgui_impl_opengl3.h | 43 ++++++++++++++------------ 5 files changed, 63 insertions(+), 28 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fa5d3d16..29b993f5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,7 @@ Other Changes: usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636) - Backends: OpenGL3: Tweaked initialization code allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before ImGui_ImplOpenGL3_NewFrame() if for some reason they wanted. +- Backends: OpenGL3: Attempt to automatically detect default GL loader by using __has_include. (#2798) [@o-micron] - Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count, would generally make the debug layer complain (Added in 1.72). - Backends: Vulkan: Added support for specifying multisample count. diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 76174a1f..4833d1b0 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -7,9 +7,10 @@ #include "imgui_impl_opengl3.h" #include -// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually. -// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad. -// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. +// About Desktop OpenGL function loaders: +// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers. +// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad). +// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) #include // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index ae1ef5b3..19d34e9a 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -9,9 +9,10 @@ #include #include -// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually. -// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad. -// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. +// About Desktop OpenGL function loaders: +// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers. +// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad). +// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) #include // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 199638e8..189814f4 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -1,5 +1,5 @@ // dear imgui: Renderer for modern OpenGL with shaders / programmatic pipeline -// - Desktop GL: 3.x 4.x +// - Desktop GL: 2.x 3.x 4.x // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility. // 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call. // 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. @@ -79,12 +80,21 @@ // Auto-detect GL version #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) -#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" +#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" +#undef IMGUI_IMPL_OPENGL_LOADER_GL3W +#undef IMGUI_IMPL_OPENGL_LOADER_GLEW +#undef IMGUI_IMPL_OPENGL_LOADER_GLAD +#undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #elif defined(__EMSCRIPTEN__) -#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" +#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" +#undef IMGUI_IMPL_OPENGL_LOADER_GL3W +#undef IMGUI_IMPL_OPENGL_LOADER_GLEW +#undef IMGUI_IMPL_OPENGL_LOADER_GLAD +#undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif #endif +// GL includes #if defined(IMGUI_IMPL_OPENGL_ES2) #include #elif defined(IMGUI_IMPL_OPENGL_ES3) @@ -149,6 +159,23 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) strcpy(g_GlslVersionString, glsl_version); strcat(g_GlslVersionString, "\n"); + // Dummy construct to make it easily visible in the IDE and debugger which GL loader has been selected. + // The code actually never uses the 'gl_loader' variable! It is only here so you can read it! + // If auto-detection fails or doesn't select the same GL loader file as used by your application, + // you are likely to get a crash below. + // You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. + const char* gl_loader = "Unknown"; + IM_UNUSED(gl_loader); +#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) + gl_loader = "GL3W"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) + gl_loader = "GLEW"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) + gl_loader = "GLAD"; +#else IMGUI_IMPL_OPENGL_LOADER_CUSTOM + gl_loader = "Custom"; +#endif + // Make a dummy GL call (we don't actually need the result) // IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code. // Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above. diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index fbf2417c..1cb790b1 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -1,5 +1,5 @@ // dear imgui: Renderer for modern OpenGL with shaders / programmatic pipeline -// - Desktop GL: 3.x 4.x +// - Desktop GL: 2.x 3.x 4.x // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) @@ -23,37 +23,42 @@ #pragma once +// Backend API +IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); + +// (Optional) Called by Init/NewFrame/Shutdown +IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); +IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); +IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); + // Specific OpenGL versions //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android -// Set default OpenGL3 loader to be gl3w -#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ - && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ - && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ +// Desktop OpenGL: attempt to detect default GL loader based on available header files. +// If auto-detection fails or doesn't select the same GL loader file as used by your application, +// you are likely to get a crash in ImGui_ImplOpenGL3_Init(). +// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. +#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) - // to avoid problem with non-clang compilers not having this macro. #if defined(__has_include) - // check if the header exists, then automatically define the macros .. #if __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GLEW #elif __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GLAD - #else + #elif __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GL3W + #else + #error "Cannot detect OpenGL loader!" #endif #else - #define IMGUI_IMPL_OPENGL_LOADER_GL3W + #define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W #endif #endif -IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); -IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); -IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); -IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); - -// Called by Init/NewFrame/Shutdown -IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); -IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); -IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); -IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); From 25849234f60a4197c9cbb94b1fc249a971e74543 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Sep 2019 12:45:52 +0200 Subject: [PATCH 031/384] Internal: Tree: tweaks (initially tried to implement auto-scrolling, stashed) --- docs/CHANGELOG.txt | 19 +++++++++---------- docs/TODO.txt | 2 +- imgui.cpp | 2 +- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 9 ++++++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 29b993f5..68adbaf0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,8 +41,8 @@ Other Changes: - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). -- TabBar: Fixed ScrollToBar request creating bouncing loop when tab is larger than available space. - TabBar: Fixed single-tab not shrinking their width down. +- TabBar: Fixed clicking on a tab larger than tab-bar width creating a bouncing feedback loop. - TabBar: Feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768) (before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations). - TabBar: Improved shrinking for large number of tabs to avoid leaving extraneous space on the right side. @@ -50,8 +50,8 @@ Other Changes: - Columns, Separator: Fixed a bug where non-visible separators within columns would alter the next row position differently than visible ones. - SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton] -- DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value. -- DragScalar: Fixed dragging of unsigned values on ARM cpu. (#2780) [@dBagrat] +- DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edits to the value. +- DragScalar: Fixed dragging of unsigned values on ARM cpu (float to uint cast is undefined). (#2780) [@dBagrat] - TreeNode: Added ImGuiTreeNodeFlags_SpanAvailWidth flag. (#2451, #2438, #1897) [@Melix19, @PathogenDavid] This extends the hit-box to the right-most edge, even if the node is not framed. (Note: this is not the default in order to allow adding other items on the same line. In the future we will @@ -66,20 +66,19 @@ Other Changes: Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow as possible. (#2775) [@rokups] - ImDrawList: Clarified the name of many parameters so reading the code is a little easier. (#2740) -- ImDrawListSplitter: fixed an issue merging channels if the last submitted draw command used a different texture. (#2506) +- ImDrawListSplitter: Fixed merging channels if the last submitted draw command used a different texture. (#2506) - Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) - ImVector: Added find(), find_erase(), find_erase_unsorted() helpers. - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636) - Backends: OpenGL3: Tweaked initialization code allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() - before ImGui_ImplOpenGL3_NewFrame() if for some reason they wanted. + before ImGui_ImplOpenGL3_NewFrame(), which sometimes can be convenient. - Backends: OpenGL3: Attempt to automatically detect default GL loader by using __has_include. (#2798) [@o-micron] -- Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count, - would generally make the debug layer complain (Added in 1.72). -- Backends: Vulkan: Added support for specifying multisample count. - Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values - to use, default is non-multisampled as before. (#2705, #2706) [@vilya] +- Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count, which would + generally make the DX11 debug layer complain (bug added in 1.72). +- Backends: Vulkan: Added support for specifying multisample count. Set 'ImGui_ImplVulkan_InitInfo::MSAASamples' to + one of the VkSampleCountFlagBits values to use, default is non-multisampled as before. (#2705, #2706) [@vilya] - Examples: OSX: Fix example_apple_opengl2/main.mm not forwarding mouse clicks and drags correctly. (#1961, #2710) [@intonarumori, @ElectricMagic] - Misc: Updated stb_rect_pack from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic, diff --git a/docs/TODO.txt b/docs/TODO.txt index 9c37f690..07f6676b 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -63,7 +63,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395) - widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h. - widgets: add visuals for Disabled/ReadOnly mode and expose publicly (#211) - - widgets: add always-allow-overlap mode. This should perhaps be the default. + - widgets: add always-allow-overlap mode. This should perhaps be the default? one problem is that highlight after mouse-wheel scrolling gets deferred, makes scrolling more flickery. - widgets: start exposing PushItemFlag() and ImGuiItemFlags - widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260 - widgets: activate by identifier (trigger button, focus given id) diff --git a/imgui.cpp b/imgui.cpp index af5ffc4b..e25ca076 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5901,7 +5901,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.TextWrapPosStack.resize(0); window->DC.CurrentColumns = NULL; window->DC.TreeDepth = 0; - window->DC.TreeStoreMayJumpToParentOnPop = 0x00; + window->DC.TreeMayJumpToParentOnPopMask = 0x00; window->DC.StateStorage = &window->StateStorage; window->DC.GroupStack.resize(0); window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); diff --git a/imgui_internal.h b/imgui_internal.h index a27c1849..0a585f34 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1208,7 +1208,7 @@ struct IMGUI_API ImGuiWindowTempData float CurrLineTextBaseOffset; float PrevLineTextBaseOffset; int TreeDepth; - ImU32 TreeStoreMayJumpToParentOnPop; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. + ImU32 TreeMayJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. ImGuiID LastItemId; ImGuiItemStatusFlags LastItemStatusFlags; ImRect LastItemRect; // Interaction rect @@ -1249,7 +1249,7 @@ struct IMGUI_API ImGuiWindowTempData CurrLineSize = PrevLineSize = ImVec2(0.0f, 0.0f); CurrLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; TreeDepth = 0; - TreeStoreMayJumpToParentOnPop = 0x00; + TreeMayJumpToParentOnPopMask = 0x00; LastItemId = 0; LastItemStatusFlags = 0; LastItemRect = LastItemDisplayRect = ImRect(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ca84674a..ded5d881 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5228,7 +5228,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; bool is_open = TreeNodeBehaviorIsOpen(id, flags); if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) - window->DC.TreeStoreMayJumpToParentOnPop |= (1 << window->DC.TreeDepth); + window->DC.TreeMayJumpToParentOnPopMask |= (1 << window->DC.TreeDepth); bool item_add = ItemAdd(interact_bb, id); window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HasDisplayRect; @@ -5380,13 +5380,16 @@ void ImGui::TreePop() Unindent(); window->DC.TreeDepth--; + ImU32 tree_depth_mask = (1 << window->DC.TreeDepth); + + // Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled) if (g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet()) - if (g.NavIdIsAlive && (window->DC.TreeStoreMayJumpToParentOnPop & (1 << window->DC.TreeDepth))) + if (g.NavIdIsAlive && (window->DC.TreeMayJumpToParentOnPopMask & tree_depth_mask)) { SetNavID(window->IDStack.back(), g.NavLayer); NavMoveRequestCancel(); } - window->DC.TreeStoreMayJumpToParentOnPop &= (1 << window->DC.TreeDepth) - 1; + window->DC.TreeMayJumpToParentOnPopMask &= tree_depth_mask - 1; IM_ASSERT(window->IDStack.Size > 1); // There should always be 1 element in the IDStack (pushed during window creation). If this triggers you called TreePop/PopID too much. PopID(); From 52deb415e0ed9bc042f8eacfea5114ad3d562455 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Sep 2019 14:53:49 +0200 Subject: [PATCH 032/384] Internal: Refactored internal RenderMouseCursor so colors can be specified. (#2614) --- imgui.cpp | 2 +- imgui_draw.cpp | 6 +----- imgui_internal.h | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e25ca076..1557d595 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4274,7 +4274,7 @@ void ImGui::Render() // Draw software mouse cursor if requested if (g.IO.MouseDrawCursor) - RenderMouseCursor(&g.ForegroundDrawList, g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor); + RenderMouseCursor(&g.ForegroundDrawList, g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); if (!g.ForegroundDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.ForegroundDrawList); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index eb173b44..2cbf209b 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3038,16 +3038,12 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderRectFilledRangeH() //----------------------------------------------------------------------------- -void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor) +void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) { if (mouse_cursor == ImGuiMouseCursor_None) return; IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); - const ImU32 col_shadow = IM_COL32(0, 0, 0, 48); - const ImU32 col_border = IM_COL32(0, 0, 0, 255); // Black - const ImU32 col_fill = IM_COL32(255, 255, 255, 255); // White - ImFontAtlas* font_atlas = draw_list->_Data->Font->ContainerAtlas; ImVec2 offset, size, uv[4]; if (font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) diff --git a/imgui_internal.h b/imgui_internal.h index 0a585f34..acd2d256 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1636,7 +1636,7 @@ namespace ImGui // Render helpers (those functions don't access any ImGui state!) IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col); - IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor = ImGuiMouseCursor_Arrow); + IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); From ca858c084b5dfbb2b899a781db142408182f2efe Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Sep 2019 15:31:05 +0200 Subject: [PATCH 033/384] Demo tweaks. Comments. Compacting the rarely used AutoFitXXX fields in ImGuiWindowTempData. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 4 +-- imgui_demo.cpp | 66 ++++++++++++++++++++++++++++++++-------------- imgui_internal.h | 34 ++++++++++++------------ 4 files changed, 66 insertions(+), 39 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 68adbaf0..554ea045 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -169,6 +169,7 @@ Other Changes: - Demo: Log, Console: Using a simpler stateless pattern for auto-scrolling. - Demo: Widgets: Showing how to use the format parameter of Slider/Drag functions to display the name of an enum value instead of the underlying integer value. +- Demo: Renamed the "Help" menu to "Tools" (more accurate). - Backends: DX10/DX11: Backup, clear and restore Geometry Shader is any is bound when calling renderer. - Backends: DX11: Clear Hull Shader, Domain Shader, Compute Shader before rendering. Not backing/restoring them. - Backends: OSX: Disabled default native Mac clipboard copy/paste implementation in core library (added in 1.71), diff --git a/imgui.cpp b/imgui.cpp index 1557d595..f276b5f4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2704,8 +2704,8 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) BeginOrderWithinContext = -1; PopupId = 0; AutoFitFramesX = AutoFitFramesY = -1; - AutoFitOnlyGrows = false; AutoFitChildAxises = 0x00; + AutoFitOnlyGrows = false; AutoPosLastDirection = ImGuiDir_None; HiddenFramesCanSkipItems = HiddenFramesCannotSkipItems = 0; SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; @@ -4729,7 +4729,7 @@ static bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size ImGuiWindow* child_window = g.CurrentWindow; child_window->ChildId = id; - child_window->AutoFitChildAxises = auto_fit_axises; + child_window->AutoFitChildAxises = (ImS8)auto_fit_axises; // Set the cursor to handle case where the user called SetNextWindowPos()+BeginChild() manually. // While this is not really documented/defined, it seems that the expected thing to do. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 0c911dfb..09f3dae0 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -106,8 +106,6 @@ Index of this file: #define IM_NEWLINE "\n" #endif -#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B)) - //----------------------------------------------------------------------------- // [SECTION] Forward Declarations, Helpers //----------------------------------------------------------------------------- @@ -153,8 +151,11 @@ void ImGui::ShowUserGuide() { ImGuiIO& io = ImGui::GetIO(); ImGui::BulletText("Double-click on title bar to collapse window."); - ImGui::BulletText("Click and drag on lower right corner to resize window\n(double-click to auto fit window to its contents)."); - ImGui::BulletText("Click and drag on any empty space to move window."); + ImGui::BulletText("Click and drag on lower corner to resize window\n(double-click to auto fit window to its contents)."); + if (io.ConfigWindowsMoveFromTitleBarOnly) + ImGui::BulletText("Click and drag on title bar to move window."); + else + ImGui::BulletText("Click and drag on any empty space to move window."); ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text."); if (io.FontAllowUserScaling) @@ -175,6 +176,12 @@ void ImGui::ShowUserGuide() //----------------------------------------------------------------------------- // [SECTION] Demo Window / ShowDemoWindow() //----------------------------------------------------------------------------- +// - ShowDemoWindowWidgets() +// - ShowDemoWindowLayout() +// - ShowDemoWindowPopups() +// - ShowDemoWindowColumns() +// - ShowDemoWindowMisc() +//----------------------------------------------------------------------------- // We split the contents of the big ShowDemoWindow() function into smaller functions (because the link time of very large functions grow non-linearly) static void ShowDemoWindowWidgets(); @@ -216,7 +223,7 @@ void ImGui::ShowDemoWindow(bool* p_open) if (show_app_window_titles) ShowExampleAppWindowTitles(&show_app_window_titles); if (show_app_custom_rendering) ShowExampleAppCustomRendering(&show_app_custom_rendering); - // Dear ImGui Apps (accessible from the "Help" menu) + // Dear ImGui Apps (accessible from the "Tools" menu) static bool show_app_metrics = false; static bool show_app_style_editor = false; static bool show_app_about = false; @@ -289,7 +296,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::MenuItem("Documents", NULL, &show_app_documents); ImGui::EndMenu(); } - if (ImGui::BeginMenu("Help")) + if (ImGui::BeginMenu("Tools")) { ImGui::MenuItem("Metrics", NULL, &show_app_metrics); ImGui::MenuItem("Style Editor", NULL, &show_app_style_editor); @@ -307,7 +314,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::Text("PROGRAMMER GUIDE:"); ImGui::BulletText("Please see the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!"); ImGui::BulletText("Please see the comments in imgui.cpp."); - ImGui::BulletText("Please see the examples/ in application."); + ImGui::BulletText("Please see the examples/ application."); ImGui::BulletText("Enable 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls."); ImGui::BulletText("Enable 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls."); ImGui::Separator(); @@ -1495,6 +1502,8 @@ static void ShowDemoWindowWidgets() // They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets // to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo. ImGui::BulletText("Drag and drop in standard widgets"); + ImGui::SameLine(); + HelpMarker("You can drag from the colored squares."); ImGui::Indent(); static float col1[3] = { 1.0f,0.0f,0.2f }; static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; @@ -1527,8 +1536,8 @@ static void ShowDemoWindowWidgets() // Our buttons are both drag sources and drag targets here! if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) { - ImGui::SetDragDropPayload("DND_DEMO_CELL", &n, sizeof(int)); // Set payload to carry the index of our item (could be anything) - if (mode == Mode_Copy) { ImGui::Text("Copy %s", names[n]); } // Display preview (could be anything, e.g. when dragging an image we could decide to display the filename and a small preview of the image, etc.) + ImGui::SetDragDropPayload("DND_DEMO_CELL", &n, sizeof(int)); // Set payload to carry the index of our item (could be anything) + if (mode == Mode_Copy) { ImGui::Text("Copy %s", names[n]); } // Display preview (could be anything, e.g. when dragging an image we could decide to display the filename and a small preview of the image, etc.) if (mode == Mode_Move) { ImGui::Text("Move %s", names[n]); } if (mode == Mode_Swap) { ImGui::Text("Swap %s", names[n]); } ImGui::EndDragDropSource(); @@ -1567,19 +1576,18 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("Querying Status (Active/Focused/Hovered etc.)")) { - // Display the value of IsItemHovered() and other common item state functions. Note that the flags can be combined. - // (because BulletText is an item itself and that would affect the output of IsItemHovered() we pass all state in a single call to simplify the code). + // Submit an item (various types available) so we can query their status in the following block. static int item_type = 1; - static bool b = false; - static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f }; - static char str[16] = {}; ImGui::Combo("Item Type", &item_type, "Text\0Button\0Button (w/ repeat)\0Checkbox\0SliderFloat\0InputText\0InputFloat\0InputFloat3\0ColorEdit4\0MenuItem\0TreeNode (w/ double-click)\0ListBox\0"); ImGui::SameLine(); HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions."); bool ret = false; + static bool b = false; + static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f }; + static char str[16] = {}; if (item_type == 0) { ImGui::Text("ITEM: Text"); } // Testing text items with no identifier/interaction if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); } // Testing button - if (item_type == 2) { ImGui::PushButtonRepeat(true); ret = ImGui::Button("ITEM: Button"); ImGui::PopButtonRepeat(); } // Testing button (with repeater) + if (item_type == 2) { ImGui::PushButtonRepeat(true); ret = ImGui::Button("ITEM: Button"); ImGui::PopButtonRepeat(); } // Testing button (with repeater) if (item_type == 3) { ret = ImGui::Checkbox("ITEM: Checkbox", &b); } // Testing checkbox if (item_type == 4) { ret = ImGui::SliderFloat("ITEM: SliderFloat", &col4f[0], 0.0f, 1.0f); } // Testing basic item if (item_type == 5) { ret = ImGui::InputText("ITEM: InputText", &str[0], IM_ARRAYSIZE(str)); } // Testing input text (which handles tabbing) @@ -1589,6 +1597,11 @@ static void ShowDemoWindowWidgets() if (item_type == 9) { ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy) if (item_type == 10){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy. if (item_type == 11){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); } + + // Display the value of IsItemHovered() and other common item state functions. + // Note that the ImGuiHoveredFlags_XXX flags can be combined. + // Because BulletText is an item itself and that would affect the output of IsItemXXX functions, + // we query every state in a single call to avoid storing them and to simplify the code ImGui::BulletText( "Return value = %d\n" "IsItemFocused() = %d\n" @@ -1631,7 +1644,8 @@ static void ShowDemoWindowWidgets() if (embed_all_inside_a_child_window) ImGui::BeginChild("outer_child", ImVec2(0, ImGui::GetFontSize() * 20), true); - // Testing IsWindowFocused() function with its various flags. Note that the flags can be combined. + // Testing IsWindowFocused() function with its various flags. + // Note that the ImGuiFocusedFlags_XXX flags can be combined. ImGui::BulletText( "IsWindowFocused() = %d\n" "IsWindowFocused(_ChildWindows) = %d\n" @@ -1644,7 +1658,8 @@ static void ShowDemoWindowWidgets() ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow), ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow)); - // Testing IsWindowHovered() function with its various flags. Note that the flags can be combined. + // Testing IsWindowHovered() function with its various flags. + // Note that the ImGuiHoveredFlags_XXX flags can be combined. ImGui::BulletText( "IsWindowHovered() = %d\n" "IsWindowHovered(_AllowWhenBlockedByPopup) = %d\n" @@ -2798,6 +2813,8 @@ static void ShowDemoWindowMisc() { if (ImGui::CollapsingHeader("Filtering")) { + // Helper class to easy setup a text filter. + // You may want to implement a more feature-full filtering scheme in your own application. static ImGuiTextFilter filter; ImGui::Text("Filter usage:\n" " \"\" display all lines\n" @@ -2815,12 +2832,14 @@ static void ShowDemoWindowMisc() { ImGuiIO& io = ImGui::GetIO(); + // Display ImGuiIO output flags ImGui::Text("WantCaptureMouse: %d", io.WantCaptureMouse); ImGui::Text("WantCaptureKeyboard: %d", io.WantCaptureKeyboard); ImGui::Text("WantTextInput: %d", io.WantTextInput); ImGui::Text("WantSetMousePos: %d", io.WantSetMousePos); ImGui::Text("NavActive: %d, NavVisible: %d", io.NavActive, io.NavVisible); + // Display Keyboard/Mouse state if (ImGui::TreeNode("Keyboard, Mouse & Navigation State")) { if (ImGui::IsMousePosValid()) @@ -2953,7 +2972,7 @@ static void ShowDemoWindowMisc() //----------------------------------------------------------------------------- // [SECTION] About Window / ShowAboutWindow() -// Access from Dear ImGui Demo -> Help -> About +// Access from Dear ImGui Demo -> Tools -> About //----------------------------------------------------------------------------- void ImGui::ShowAboutWindow(bool* p_open) @@ -2965,7 +2984,7 @@ void ImGui::ShowAboutWindow(bool* p_open) } ImGui::Text("Dear ImGui %s", ImGui::GetVersion()); ImGui::Separator(); - ImGui::Text("By Omar Cornut and all dear imgui contributors."); + ImGui::Text("By Omar Cornut and all Dear ImGui contributors."); ImGui::Text("Dear ImGui is licensed under the MIT License, see LICENSE for more information."); static bool show_config_info = false; @@ -3085,6 +3104,10 @@ void ImGui::ShowAboutWindow(bool* p_open) //----------------------------------------------------------------------------- // [SECTION] Style Editor / ShowStyleEditor() //----------------------------------------------------------------------------- +// - ShowStyleSelector() +// - ShowFontSelector() +// - ShowStyleEditor() +//----------------------------------------------------------------------------- // Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options. // Here we use the simplified Combo() api that packs items into a single literal string. Useful for quick combo boxes where the choices are known locally. @@ -3379,6 +3402,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) //----------------------------------------------------------------------------- // [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar() //----------------------------------------------------------------------------- +// - ShowExampleAppMainMenuBar() +// - ShowExampleMenuFile() +//----------------------------------------------------------------------------- // Demonstrate creating a "main" fullscreen menu bar and populating it. // Note the difference between BeginMainMenuBar() and BeginMenuBar(): @@ -4174,7 +4200,7 @@ static void ShowExampleAppConstrainedResize(bool* p_open) { struct CustomConstraints // Helper functions to demonstrate programmatic constraints { - static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize = ImVec2(IM_MAX(data->DesiredSize.x, data->DesiredSize.y), IM_MAX(data->DesiredSize.x, data->DesiredSize.y)); } + static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = (data->DesiredSize.x > data->DesiredSize.y ? data->DesiredSize.x : data->DesiredSize.y); } static void Step(ImGuiSizeCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); } }; diff --git a/imgui_internal.h b/imgui_internal.h index acd2d256..edc0fb06 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1199,20 +1199,20 @@ struct ImGuiContext // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered. struct IMGUI_API ImGuiWindowTempData { - ImVec2 CursorPos; + ImVec2 CursorPos; // Current emitting position, in absolute coordinates. ImVec2 CursorPosPrevLine; - ImVec2 CursorStartPos; // Initial position in client area with padding + ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding. ImVec2 CursorMaxPos; // Used to implicitly calculate the size of our contents, always growing during the frame. Used to calculate window->ContentSize at the beginning of next frame ImVec2 CurrLineSize; ImVec2 PrevLineSize; - float CurrLineTextBaseOffset; + float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added). float PrevLineTextBaseOffset; - int TreeDepth; - ImU32 TreeMayJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. - ImGuiID LastItemId; - ImGuiItemStatusFlags LastItemStatusFlags; - ImRect LastItemRect; // Interaction rect - ImRect LastItemDisplayRect; // End-user display rect (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) + int TreeDepth; // Current tree depth. + ImU32 TreeMayJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. + ImGuiID LastItemId; // ID for last item + ImGuiItemStatusFlags LastItemStatusFlags; // Status flags for last item (see ImGuiItemStatusFlags_) + ImRect LastItemRect; // Interaction rect for last item + ImRect LastItemDisplayRect; // End-user display rect for last item (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping. int NavLayerActiveMask; // Which layer have been written to (result from previous frame) @@ -1222,7 +1222,7 @@ struct IMGUI_API ImGuiWindowTempData bool MenuBarAppending; // FIXME: Remove this ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs. ImVector ChildWindows; - ImGuiStorage* StateStorage; + ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state) ImGuiLayoutType LayoutType; ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() int FocusCounterAll; // Counter for focus/tabbing system. Start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) @@ -1287,9 +1287,9 @@ struct IMGUI_API ImGuiWindow ImVec2 SizeFull; // Size when non collapsed ImVec2 ContentSize; // Size of contents/scrollable client area (calculated from the extents reach of the cursor) from previous frame. Does not include window decoration or window padding. ImVec2 ContentSizeExplicit; // Size of contents/scrollable client area explicitly request by the user via SetNextWindowContentSize(). - ImVec2 WindowPadding; // Window padding at the time of begin. - float WindowRounding; // Window rounding at the time of begin. - float WindowBorderSize; // Window border size at the time of begin. + ImVec2 WindowPadding; // Window padding at the time of Begin(). + float WindowRounding; // Window rounding at the time of Begin(). + float WindowBorderSize; // Window border size at the time of Begin(). int NameBufLen; // Size of buffer storing Name. May be larger than strlen(Name)! ImGuiID MoveId; // == window->GetID("#MOVE") ImGuiID ChildId; // ID of corresponding item in parent window (for navigation to return from child window to parent window) @@ -1298,7 +1298,7 @@ struct IMGUI_API ImGuiWindow ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change) ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered ImVec2 ScrollbarSizes; // Size taken by scrollbars on each axis - bool ScrollbarX, ScrollbarY; + bool ScrollbarX, ScrollbarY; // Are scrollbars visible? bool Active; // Set to true on Begin(), unless Collapsed bool WasActive; bool WriteAccessed; // Set to true when any widget access the current window @@ -1313,9 +1313,9 @@ struct IMGUI_API ImGuiWindow short BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0. short BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues. ImGuiID PopupId; // ID in the popup stack when this window is used as a popup/menu (because we use generic Name/ID for recycling) - int AutoFitFramesX, AutoFitFramesY; + ImS8 AutoFitFramesX, AutoFitFramesY; + ImS8 AutoFitChildAxises; bool AutoFitOnlyGrows; - int AutoFitChildAxises; ImGuiDir AutoPosLastDirection; int HiddenFramesCanSkipItems; // Hide the window for N frames int HiddenFramesCannotSkipItems; // Hide the window for N frames while allowing items to be submitted so we can measure their size @@ -1338,7 +1338,7 @@ struct IMGUI_API ImGuiWindow ImRect ContentsRegionRect; // FIXME: This is currently confusing/misleading. It is essentially WorkRect but not handling of scrolling. We currently rely on it as right/bottom aligned sizing operation need some size to rely on. int LastFrameActive; // Last frame number the window was Active. - float LastTimeActive; + float LastTimeActive; // Last timestamp the window was Active (using float as we don't need high precision there) float ItemWidthDefault; ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items ImGuiStorage StateStorage; From e100523917e00c7a7ee1c71309e0cd80a8ba3b27 Mon Sep 17 00:00:00 2001 From: goran-w <44604769+goran-w@users.noreply.github.com> Date: Tue, 30 Oct 2018 15:52:27 +0100 Subject: [PATCH 034/384] CollapsingHeader: Added support for ImGuiTreeNodeFlags_Bullet and ImGuiTreeNodeFlags_Leaf on framed nodes. (#2159, #2160) The Bullet and Leaf ImGuiTreeNodeFlags are now taken into account for Framed/CollapsingHeader tree nodes as well. TreeNodeEx() can be used to specify these flags. A choice was made to left-adjust the Framed text when no Bullet/Arrow is rendered, since this was deemed to look better in the Framed context (especially when considering that CollapsingHeader is drawn using NoTreePushOnOpen, so child/sibling Text items etc will often be non-indented). --- docs/CHANGELOG.txt | 2 ++ imgui_demo.cpp | 11 ++++++++++- imgui_widgets.cpp | 14 +++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 554ea045..63e96fe0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -59,6 +59,8 @@ Other Changes: and then we will be able to make this the default.) - TreeNode: Added ImGuiTreeNodeFlags_SpanFullWidth flag. This extends the hit-box to both the left-most and right-most edge of the working area, bypassing indentation. +- CollapsingHeader: Added support for ImGuiTreeNodeFlags_Bullet and ImGuiTreeNodeFlags_Leaf on framed nodes, + mostly for consistency. (#2159, #2160) [@goran-w] - Selectable: Added ImGuiSelectableFlags_AllowItemOverlap flag in public api (was previously internal only). - Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) - Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 09f3dae0..492158d1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -677,7 +677,7 @@ static void ShowDemoWindowWidgets() { static bool closable_group = true; ImGui::Checkbox("Show 2nd header", &closable_group); - if (ImGui::CollapsingHeader("Header")) + if (ImGui::CollapsingHeader("Header", ImGuiTreeNodeFlags_None)) { ImGui::Text("IsItemHovered: %d", ImGui::IsItemHovered()); for (int i = 0; i < 5; i++) @@ -689,6 +689,10 @@ static void ShowDemoWindowWidgets() for (int i = 0; i < 5; i++) ImGui::Text("More content %d", i); } + /* + if (ImGui::CollapsingHeader("Header with a bullet", ImGuiTreeNodeFlags_Bullet)) + ImGui::Text("IsItemHovered: %d", ImGui::IsItemHovered()); + */ ImGui::TreePop(); } @@ -696,6 +700,11 @@ static void ShowDemoWindowWidgets() { ImGui::BulletText("Bullet point 1"); ImGui::BulletText("Bullet point 2\nOn multiple lines"); + if (ImGui::TreeNode("Tree node")) + { + ImGui::BulletText("Another bullet point"); + ImGui::TreePop(); + } ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)"); ImGui::Bullet(); ImGui::SmallButton("Button"); ImGui::TreePop(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ded5d881..d9dc4ec6 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5214,7 +5214,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const float text_offset_x = g.FontSize + (display_frame ? padding.x*3 : padding.x*2); // Collapser arrow width + Spacing const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x*2 : 0.0f); // Include collapser - const ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y); + ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y); ItemSize(ImVec2(text_width, frame_height), text_offset_y); // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing @@ -5307,7 +5307,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, true, style.FrameRounding); RenderNavHighlight(frame_bb, id, nav_highlight_flags); - RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f); + if (flags & ImGuiTreeNodeFlags_Bullet) + RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.60f, text_pos.y + g.FontSize * 0.5f), text_col); + else if (!is_leaf) + RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f); + else // Leaf without bullet, left-adjusted text + text_pos.x -= text_offset_x; if (flags & ImGuiTreeNodeFlags_ClipLabelForTrailingButton) frame_bb.Max.x -= g.FontSize + style.FramePadding.x; if (g.LogEnabled) @@ -5333,11 +5338,10 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, false); RenderNavHighlight(frame_bb, id, nav_highlight_flags); } - if (flags & ImGuiTreeNodeFlags_Bullet) - RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.5f, text_pos.y + g.FontSize*0.50f), text_col); + RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.5f, text_pos.y + g.FontSize * 0.5f), text_col); else if (!is_leaf) - RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y + g.FontSize*0.15f), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f); + RenderArrow(window->DrawList, ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y + g.FontSize * 0.15f), text_col, is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f); if (g.LogEnabled) LogRenderedText(&text_pos, ">"); RenderText(text_pos, label, label_end, false); From 664f9e76b919226fb4854698e5d535cf68ff6a02 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Sep 2019 15:46:08 +0200 Subject: [PATCH 035/384] Documentation: Various tweaks and improvements to the README page. [@ker0chan] --- docs/CHANGELOG.txt | 1 + docs/README.md | 90 ++++++++++++++++++++++------------------------ 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 63e96fe0..851dd561 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,7 @@ Other Changes: - Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636) +- Documentation: Various tweaks and improvements to the README page. [@ker0chan] - Backends: OpenGL3: Tweaked initialization code allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before ImGui_ImplOpenGL3_NewFrame(), which sometimes can be convenient. - Backends: OpenGL3: Attempt to automatically detect default GL loader by using __has_include. (#2798) [@o-micron] diff --git a/docs/README.md b/docs/README.md index 6ca295ea..36ca6d6f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,9 +3,9 @@ dear imgui [![Build Status](https://api.travis-ci.com/ocornut/imgui.svg?branch=master)](https://travis-ci.com/ocornut/imgui) [![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) -_(This library is available under a free and permissive licence, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.)_ +(This library is available under a free and permissive licence, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) -Businesses: support continued development via invoiced technical support & maintenance contracts: +Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: omarcornut at gmail dot com_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: @@ -14,14 +14,23 @@ Individuals/hobbyists: support continued maintenance and development via the mon Individuals/hobbyists: support continued maintenance and development via PayPal:
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) -Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies). +---- -Dear ImGui is designed to enable fast iterations and to empower programmers to create content creation tools and visualization / debug tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries. +Dear ImGui is a **bloat-free graphical user interface library for C++**. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies). + +Dear ImGui is designed to **enable fast iterations** and to **empower programmers** to create **content creation tools and visualization / debug tools** (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries. Dear ImGui is particularly suited to integration in games engine (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on consoles platforms where operating system features are non-standard. See [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui), [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Gallery](https://github.com/ocornut/imgui/issues/2529) pages to get an idea of its use cases. +| [Usage](#usage) - [How it works](#how-it-works) - [Demo](#demo) - [Integration](#integration) | +:----------------------------------------------------------: | +| [Upcoming changes](#upcoming-changes) - [Gallery](#gallery) - [Support, FAQ](#support-frequently-asked-questions-faq) - [How to help](#how-to-help) - [Sponsors](#sponsors) - [Credits](#credits) - [License](#license) | +| [Wiki](https://github.com/ocornut/imgui/wiki) - [Language & frameworks bindings](https://github.com/ocornut/imgui/wiki/Bindings) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) | + +### Usage + Dear ImGui is self-contained within a few files that you can easily copy and compile into your application/engine: - imgui.cpp - imgui.h @@ -36,12 +45,12 @@ Dear ImGui is self-contained within a few files that you can easily copy and com No specific build process is required. You can add the .cpp files to your project or #include them from an existing file. -### Usage +Backends for a variety of graphics api and rendering platforms are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. -Your code passes mouse/keyboard/gamepad inputs and settings to Dear ImGui (see example applications for more details). After Dear ImGui is setup, you can use it from \_anywhere\_ in your program loop: +The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices (see example applications for more details). After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: Code: -```cpp +```cp ImGui::Text("Hello, world %d", 123); if (ImGui::Button("Save")) { @@ -88,6 +97,8 @@ ImGui::End(); Result:
![sample code output](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/code_sample_03_color.gif) +Dear ImGui allows you **create elaborate tools** as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. + ### How it works Check out the References section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. @@ -96,18 +107,18 @@ Dear ImGui outputs vertex buffers and command lists that you can easily render i _A common misunderstanding is to mistake immediate mode gui for immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes as the gui functions are called. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._ -Dear ImGui allows you create elaborate tools as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. +### Demo -Demo Binaries -------------- +Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of Dear ImGui features and examples. + +![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: - [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, Dear ImGui 1.72 WIP built 2019/07/15, master branch, 5 executables) The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`. -Bindings --------- +### Integration Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you about an hour to integrate Dear ImGui in your custom engine. Make sure to spend time reading the FAQ, the comments and other documentation! @@ -158,8 +169,8 @@ Frameworks: For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/). Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. -Roadmap -------- +### Upcoming Changes + Some of the goals for 2019 are: - Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public `docking` branch looking for feedback) - Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public `docking` branch looking for feedback) @@ -168,18 +179,9 @@ Some of the goals for 2019 are: - Make Columns better. (they are currently pretty terrible!) - Make the examples look better, improve styles, improve font support, make the examples hi-DPI aware. -Gallery -------- -User screenshots: -
[Gallery Part 1](https://github.com/ocornut/imgui/issues/123) (Feb 2015 to Feb 2016) -
[Gallery Part 2](https://github.com/ocornut/imgui/issues/539) (Feb 2016 to Aug 2016) -
[Gallery Part 3](https://github.com/ocornut/imgui/issues/772) (Aug 2016 to Jan 2017) -
[Gallery Part 4](https://github.com/ocornut/imgui/issues/973) (Jan 2017 to Aug 2017) -
[Gallery Part 5](https://github.com/ocornut/imgui/issues/1269) (Aug 2017 to Feb 2018) -
[Gallery Part 6](https://github.com/ocornut/imgui/issues/1607) (Feb 2018 to June 2018) -
[Gallery Part 7](https://github.com/ocornut/imgui/issues/1902) (June 2018 to January 2019) -
[Gallery Part 8](https://github.com/ocornut/imgui/issues/2265) (January 2019 to May 2019) -
[Gallery Part 9](https://github.com/ocornut/imgui/issues/2529) (May 2019 onward) +### Gallery + +For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/2529)! Custom engine [![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) @@ -187,14 +189,10 @@ Custom engine Custom engine [![screenshot tool](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white_preview.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) -Demo window -![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) - [Tracy Profiler](https://bitbucket.org/wolfpld/tracy) ![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/tracy_profiler.png) -References ----------- +### References The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works. - [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html). @@ -206,18 +204,14 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This See the [Wiki](https://github.com/ocornut/imgui/wiki) for more references and [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for third-party bindings to different languages and frameworks. -Support -------- +### Support, Frequently Asked Questions (FAQ) -If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: please post on the Discourse forums: https://discourse.dearimgui.org. +If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forums](https://discourse.dearimgui.org). Otherwise for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. Private support is available for paying customers. -Frequently Asked Question (FAQ) -------------------------------- - **Where is the documentation?** This library is poorly documented at the moment and expects of the user to be acquainted with C/C++. @@ -278,12 +272,12 @@ Dear ImGui takes advantage of a few C++ languages features for convenience but n There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. -Support dear imgui ------------------- +How to help +----------- **How can I help?** -- You may participate in the [Discourse forums](https://discourse.dearimgui.org) and the GitHub [issues tracker](https://github.com/ocornut/imgui/issues). +- You may participate in the [Discord server](https://discord.gg/NgJ4SEP), [Discourse forums](https://discourse.dearimgui.org), GitHub [issues tracker](https://github.com/ocornut/imgui/issues). - You may help with development and submit pull requests! Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance forever. PR should be crafted both in the interest in the end-users and also to ease the maintainer into understanding and accepting it. - See [Help wanted](https://github.com/ocornut/imgui/wiki/Help-Wanted) on the [Wiki](https://github.com/ocornut/imgui/wiki/) for some more ideas. - Have your company financially support this project. @@ -292,7 +286,7 @@ Support dear imgui Your contributions are keeping this project alive. The library is available under a free and permissive licence, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you! -Businesses: support continued development via invoiced technical support & maintenance contracts: +Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: omarcornut at gmail dot com_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: @@ -301,20 +295,22 @@ Individuals/hobbyists: support continued maintenance and development via the mon Individuals/hobbyists: support continued maintenance and development via PayPal:
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) -Ongoing dear imgui development is financially supported by users and private sponsors, recently: +### Sponsors + +Ongoing Dear ImGui development is financially supported by users and private sponsors, recently: -**Platinum-chocolate sponsors** +*Platinum-chocolate sponsors* - Blizzard Entertainment - Google -**Double-chocolate sponsors** +*Double-chocolate sponsors* - Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn. -**Salty caramel supporters** +*Salty caramel supporters* - Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. -**Caramel supporters** -- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis. +*Caramel supporters* +- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis, Matt Reyer. And all other past and present supporters; THANK YOU! (Please contact me if you would like to be added or removed from this list) From 293f74e9964630eb35cf41b4bbd839f5136bae36 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Sep 2019 16:00:53 +0200 Subject: [PATCH 036/384] Update README.md --- docs/README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/README.md b/docs/README.md index 36ca6d6f..c8c80cb3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,7 +9,7 @@ Businesses: support continued development via invoiced technical support, mainte
  _E-mail: omarcornut at gmail dot com_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: -
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_01.png)](http://www.patreon.com/imgui) +
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) Individuals/hobbyists: support continued maintenance and development via PayPal:
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) @@ -22,12 +22,10 @@ Dear ImGui is designed to **enable fast iterations** and to **empower programmer Dear ImGui is particularly suited to integration in games engine (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on consoles platforms where operating system features are non-standard. -See [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui), [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Gallery](https://github.com/ocornut/imgui/issues/2529) pages to get an idea of its use cases. - | [Usage](#usage) - [How it works](#how-it-works) - [Demo](#demo) - [Integration](#integration) | :----------------------------------------------------------: | | [Upcoming changes](#upcoming-changes) - [Gallery](#gallery) - [Support, FAQ](#support-frequently-asked-questions-faq) - [How to help](#how-to-help) - [Sponsors](#sponsors) - [Credits](#credits) - [License](#license) | -| [Wiki](https://github.com/ocornut/imgui/wiki) - [Language & frameworks bindings](https://github.com/ocornut/imgui/wiki/Bindings) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) | +| [Wiki](https://github.com/ocornut/imgui/wiki) - [Language & frameworks bindings](https://github.com/ocornut/imgui/wiki/Bindings) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [User quotes](https://github.com/ocornut/imgui/wiki/Quotes) | ### Usage @@ -45,9 +43,9 @@ Dear ImGui is self-contained within a few files that you can easily copy and com No specific build process is required. You can add the .cpp files to your project or #include them from an existing file. -Backends for a variety of graphics api and rendering platforms are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. +Backends for a variety of graphics api and rendering platforms along with example applications are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. -The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices (see example applications for more details). After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: +The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: Code: ```cp @@ -109,12 +107,12 @@ _A common misunderstanding is to mistake immediate mode gui for immediate mode r ### Demo -Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of Dear ImGui features and examples. +Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of features and examples. ![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, Dear ImGui 1.72 WIP built 2019/07/15, master branch, 5 executables) +- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, 1.72 WIP built 2019/07/15, master branch, 5 executables) The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`. @@ -172,12 +170,12 @@ For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Binding ### Upcoming Changes Some of the goals for 2019 are: -- Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public `docking` branch looking for feedback) -- Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public `docking` branch looking for feedback) +- Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) +- Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787)) - Add an automation and testing system, both to test the library and end-user apps. (see [#435](https://github.com/ocornut/imgui/issues/435)) -- Make Columns better. (they are currently pretty terrible!) -- Make the examples look better, improve styles, improve font support, make the examples hi-DPI aware. +- Make Columns better. They are currently pretty terrible! New Tables API coming Q4 2019! +- Make the examples look better, improve styles, improve font support, make the examples hi-DPI and multi-DPI aware. ### Gallery @@ -290,7 +288,7 @@ Businesses: support continued development via invoiced technical support, mainte
  _E-mail: omarcornut at gmail dot com_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: -
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_01.png)](http://www.patreon.com/imgui) +
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) Individuals/hobbyists: support continued maintenance and development via PayPal:
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) From d5efe161572c894baed5865dee4db943a54fa0c3 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Sep 2019 16:33:47 +0200 Subject: [PATCH 037/384] Version 1.73 --- docs/CHANGELOG.txt | 7 ++++--- examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- misc/fonts/README.txt | 10 ++++++---- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 851dd561..219e9fce 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,10 +30,11 @@ HOW TO UPDATE? ----------------------------------------------------------------------- - VERSION 1.73 WIP (In Progress) + VERSION 1.73 (Released 2019-09-24) ----------------------------------------------------------------------- Other Changes: + - Nav, Scrolling: Added support for Home/End key. (#787) - ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around. - ColorEdit, ColorPicker: In HSV display of a RGB stored value, attempt to locally preserve Hue @@ -63,7 +64,7 @@ Other Changes: mostly for consistency. (#2159, #2160) [@goran-w] - Selectable: Added ImGuiSelectableFlags_AllowItemOverlap flag in public api (was previously internal only). - Style: Allow style.WindowMenuButtonPosition to be set to ImGuiDir_None to hide the collapse button. (#2634, #2639) -- Font: Better ellipsis drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly +- Font: Better ellipsis ("...") drawing implementation. Instead of drawing three pixel-ey dots (which was glaringly unfitting with many types of fonts) we first attempt to find a standard ellipsis glyphs within the loaded set. Otherwise we render ellipsis using '.' from the font from where we trim excessive spacing to make it as narrow as possible. (#2775) [@rokups] @@ -84,7 +85,7 @@ Other Changes: one of the VkSampleCountFlagBits values to use, default is non-multisampled as before. (#2705, #2706) [@vilya] - Examples: OSX: Fix example_apple_opengl2/main.mm not forwarding mouse clicks and drags correctly. (#1961, #2710) [@intonarumori, @ElectricMagic] -- Misc: Updated stb_rect_pack from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic, +- Misc: Updated stb_rect_pack.h from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic, fix handling of rectangles too large to fit inside texture). (#2762) [@tido64] diff --git a/examples/README.txt b/examples/README.txt index 7e46c843..031a53b9 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.73 WIP + dear imgui, v1.73 ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index f276b5f4..93b15ddb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (main code and documentation) // Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. diff --git a/imgui.h b/imgui.h index b5a1155e..9697c80d 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (headers) // See imgui.cpp file for documentation. @@ -46,8 +46,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.73 WIP" -#define IMGUI_VERSION_NUM 17203 +#define IMGUI_VERSION "1.73" +#define IMGUI_VERSION_NUM 17300 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 492158d1..ec1ada82 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (demo code) // Message to the person tempted to delete this file when integrating Dear ImGui into their code base: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 2cbf209b..845cd04e 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index edc0fb06..6d393103 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d9dc4ec6..bcd051e5 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 WIP +// dear imgui, v1.73 // (widgets code) /* diff --git a/misc/fonts/README.txt b/misc/fonts/README.txt index b8790af6..51a97f93 100644 --- a/misc/fonts/README.txt +++ b/misc/fonts/README.txt @@ -1,7 +1,9 @@ -dear imgui, v1.73 WIP -(Font Readme) - ---------------------------------------- +---------------------------------------------------------------------- + dear imgui, v1.73 +---------------------------------------------------------------------- + misc/fonts/README.txt + This is the Readme dedicated to fonts. +---------------------------------------------------------------------- The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' (by Tristan Grimmer), a 13 pixels high, pixel-perfect font used by default. From f0f5301612dbaa2caeede3091df6aee1c872dbdf Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Wed, 25 Sep 2019 01:06:14 +0300 Subject: [PATCH 038/384] Backends: OpenGL3: Commented out extra tokens at end of #else directive (#2804) --- examples/imgui_impl_opengl3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 189814f4..e1eee236 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -172,7 +172,7 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) gl_loader = "GLEW"; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) gl_loader = "GLAD"; -#else IMGUI_IMPL_OPENGL_LOADER_CUSTOM +#else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM gl_loader = "Custom"; #endif From c262276988da6ae4b16911d9c56fc8d9226e7319 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 30 Sep 2019 14:27:56 +0200 Subject: [PATCH 039/384] Version 1.74 WIP --- docs/CHANGELOG.txt | 11 +++++++++++ examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- misc/fonts/README.txt | 2 +- 9 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 219e9fce..8ef15ad7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -29,6 +29,17 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.74 WIP (In Progress) +----------------------------------------------------------------------- + +Breaking Changes: +- + +Other Changes: +- + + ----------------------------------------------------------------------- VERSION 1.73 (Released 2019-09-24) ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index 031a53b9..23c6bdb9 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.73 + dear imgui, v1.74 WIP ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index 93b15ddb..cee65ff8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (main code and documentation) // Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. diff --git a/imgui.h b/imgui.h index 9697c80d..8696ef4d 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (headers) // See imgui.cpp file for documentation. @@ -46,8 +46,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.73" -#define IMGUI_VERSION_NUM 17300 +#define IMGUI_VERSION "1.74 WIP" +#define IMGUI_VERSION_NUM 17301 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index ec1ada82..41c26546 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (demo code) // Message to the person tempted to delete this file when integrating Dear ImGui into their code base: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 845cd04e..4a6dce6d 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index 6d393103..19f2bfef 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index bcd051e5..838f9367 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.73 +// dear imgui, v1.74 WIP // (widgets code) /* diff --git a/misc/fonts/README.txt b/misc/fonts/README.txt index 51a97f93..39e0dd48 100644 --- a/misc/fonts/README.txt +++ b/misc/fonts/README.txt @@ -1,5 +1,5 @@ ---------------------------------------------------------------------- - dear imgui, v1.73 + dear imgui, v1.74 WIP ---------------------------------------------------------------------- misc/fonts/README.txt This is the Readme dedicated to fonts. From 0dad3f436b2ae06267ee9c8e2df39bc6cd9d9e18 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 30 Sep 2019 15:16:30 +0200 Subject: [PATCH 040/384] Fix harmless float calculation overflow. (#2813) --- imgui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index cee65ff8..77eeb4c4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2711,6 +2711,8 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX); + InnerRect = ImRect(0.0f, 0.0f, 0.0f, 0.0f); // Clear so the InnerRect.GetSize() code in Begin() doesn't lead to overflow even if the result isn't used. + LastFrameActive = -1; LastTimeActive = -1.0f; ItemWidthDefault = 0.0f; From eb5223276c8d4169f40ab063bd2fd9e66b2e8716 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 30 Sep 2019 20:54:37 +0200 Subject: [PATCH 041/384] Update README.md --- docs/README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/README.md b/docs/README.md index c8c80cb3..de68bdab 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,7 +6,7 @@ dear imgui (This library is available under a free and permissive licence, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts: -
  _E-mail: omarcornut at gmail dot com_ +
  _E-mail: contact @ dearimgui dot org_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon:
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) @@ -51,9 +51,7 @@ Code: ```cp ImGui::Text("Hello, world %d", 123); if (ImGui::Button("Save")) -{ - // do stuff -} + MySaveFunction(); ImGui::InputText("string", buf, IM_ARRAYSIZE(buf)); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ``` @@ -99,7 +97,7 @@ Dear ImGui allows you **create elaborate tools** as well as very short-lived one ### How it works -Check out the References section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. +Check out the [References](#references) section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. Dear ImGui outputs vertex buffers and command lists that you can easily render in your application. The number of draw calls and state changes required to render them is fairly small. Because Dear ImGui doesn't know or touch graphics state directly, you can call its functions anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate dear imgui with your existing codebase. @@ -107,23 +105,25 @@ _A common misunderstanding is to mistake immediate mode gui for immediate mode r ### Demo -Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of features and examples. +Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcasing variety of features and examples. The code is always available for reference in `imgui_demo.cpp`. ![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, 1.72 WIP built 2019/07/15, master branch, 5 executables) +- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, 1.72 WIP, built 2019/07/15, master branch, 5 executables) -The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`. +The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your style with `style.ScaleAllSizes()`. ### Integration -Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you about an hour to integrate Dear ImGui in your custom engine. Make sure to spend time reading the FAQ, the comments and other documentation! +On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/examples) files without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more of the imgui_impl_xxxx files instead of rewriting them: this will be less work for you and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom binding using your custom engine functions if you wish so. + +Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the FAQ, comments, and one of the examples/ application!** -_NB: those third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ +_NB: those third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users!). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ -Languages: (third-party bindings) -- C: [cimgui](https://github.com/cimgui/cimgui) (2018: now auto-generated! you can use its json output to generate bindings for other languages) +Languages: +- C: [cimgui](https://github.com/cimgui/cimgui) (auto-generated! **you can use its json output to generate bindings for other languages**) - C#/.Net: [ImGui.NET](https://github.com/mellinoe/ImGui.NET) - ChaiScript: [imgui-chaiscript](https://github.com/JuJuBoSc/imgui-chaiscript) - D: [DerelictImgui](https://github.com/Extrawurst/DerelictImgui) @@ -139,7 +139,7 @@ Languages: (third-party bindings) - Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy) or [ogre-imgui](https://github.com/OGRECave/ogre-imgui) - Ruby: [ruby-imgui](https://github.com/vaiorabbit/ruby-imgui) - Rust: [imgui-rs](https://github.com/Gekkio/imgui-rs) or [imgui-rust](https://github.com/nsf/imgui-rust) -- Swift [swift-imgui](https://github.com/mnmly/Swift-imgui) +- Swift: [swift-imgui](https://github.com/mnmly/Swift-imgui) Frameworks: - Renderers: DirectX 9/10/11/12, Metal, OpenGL2, OpenGL3+/ES2/ES3, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) @@ -266,7 +266,7 @@ You can alter the look of the interface to some degree: changing colors, sizes, **Why using C++ (as opposed to C)?** -Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost-insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. +Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. @@ -285,7 +285,7 @@ How to help Your contributions are keeping this project alive. The library is available under a free and permissive licence, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you! Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts: -
  _E-mail: omarcornut at gmail dot com_ +
  _E-mail: contact @ dearimgui dot org_ Individuals/hobbyists: support continued maintenance and development via the monthly Patreon:
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) @@ -316,13 +316,13 @@ And all other past and present supporters; THANK YOU! Credits ------- -Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). +Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com) (Vita). I first discovered the IMGUI paradigm at [Q-Games](http://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it. Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license). -Embeds [stb_textedit.h, stb_truetype.h, stb_rectpack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). +Embeds [stb_textedit.h, stb_truetype.h, stb_rect_pack.h](https://github.com/nothings/stb/) by Sean Barrett (public domain). Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. And everybody posting feedback, questions and patches on the GitHub. From 893056a2094a254f0ceab74edc4aa9f1d73df3de Mon Sep 17 00:00:00 2001 From: Denys Nahurnyi Date: Tue, 1 Oct 2019 22:49:44 +0300 Subject: [PATCH 042/384] Fix syntax typos in README (#2819) --- docs/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index de68bdab..b4540c17 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,7 @@ dear imgui [![Build Status](https://api.travis-ci.com/ocornut/imgui.svg?branch=master)](https://travis-ci.com/ocornut/imgui) [![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) -(This library is available under a free and permissive licence, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) +(This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ @@ -206,7 +206,7 @@ See the [Wiki](https://github.com/ocornut/imgui/wiki) for more references and [B If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forums](https://discourse.dearimgui.org). -Otherwise for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. +Otherwise, for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. Private support is available for paying customers. @@ -218,8 +218,8 @@ Private support is available for paying customers. - The demo covers most features of Dear ImGui, so you can read the code and see its output. - See documentation and comments at the top of imgui.cpp + effectively imgui.h. - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder to explain how to integrate Dear ImGui with your own engine/application. - - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. - - We obviously needs better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort. + - Your programming IDE is your friend, find the type or function declaration to find comments associated with it. + - We obviously need better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort. **Which version should I get?** @@ -233,7 +233,7 @@ See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software usi **Why the odd dual naming, "Dear ImGui" vs "ImGui"?** -The library started its life as "ImGui" due to the fact that I didn't give it a proper name when I released 1.0 and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce this ambiguity without affecting existing codebases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. Please try to refer to this library as "Dear ImGui". +The library started its life as "ImGui" due to the fact that I didn't give it a proper name when I released 1.0 and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses its own implementation of the IMGUI paradigm). To reduce this ambiguity without affecting existing codebases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. Please try to refer to this library as "Dear ImGui". **How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?**
**How can I display an image? What is ImTextureID, how does it works?** ([examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples)) @@ -256,7 +256,7 @@ See the FAQ in [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cp Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. -Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might requires you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. +Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. **Can you reskin the look of Dear ImGui?** @@ -282,7 +282,7 @@ How to help **How can I help financing further development of Dear ImGui?** -Your contributions are keeping this project alive. The library is available under a free and permissive licence, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you! +Your contributions are keeping this project alive. The library is available under a free and permissive license, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you! Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ From a2f3dcfc9755ae5b4d4110c31e4101437f7554be Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 2 Oct 2019 11:38:30 +0200 Subject: [PATCH 043/384] Added comment about SDL and SDL_INIT_GAMECONTROLLER. (#2809) --- docs/TODO.txt | 5 +++-- examples/example_sdl_directx11/main.cpp | 2 ++ examples/example_sdl_opengl2/main.cpp | 2 ++ examples/example_sdl_opengl3/main.cpp | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 07f6676b..7ca24ca8 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -262,16 +262,17 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - drag and drop: fix/support/options for overlapping drag sources. - drag and drop: releasing a drop shows the "..." tooltip for one frame - since e13e598 (#1725) - drag and drop: drag source on a group object (would need e.g. an invisible button covering group in EndGroup) https://twitter.com/paniq/status/1121446364909535233 - - drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov. + - drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov. (see 2018/01/11 post in #143) - drag and drop: allow preview tooltip to be submitted from a different place than the drag source. (#1725) - drag and drop: allow using with other mouse buttons (where activeid won't be set). (#1637) - drag and drop: make it easier and provide a demo to have tooltip both are source and target site, with a more detailed one on target site (tooltip ordering problem) - drag and drop: demo with reordering nodes (in a list, or a tree node). (#143) - drag and drop: test integrating with os drag and drop (make it easy to do a naive WM_DROPFILE integration) - drag and drop: allow for multiple payload types. (#143) - - drag and drop: make payload optional? (#143) + - drag and drop: make payload optional? payload promise? (see 2018/01/11 post in #143) - drag and drop: (#143) "both an in-process pointer and a promise to generate a serialized version, for whether the drag ends inside or outside the same process" - drag and drop: feedback when hovering a region blocked by modal (mouse cursor "NO"?) + - node/graph editor (#306) - pie menus patterns (#434) - markup: simple markup language for color change? (#902) diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index ae523fe9..680f179e 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -26,6 +26,8 @@ void CleanupRenderTarget(); int main(int, char**) { // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 1222c250..9bc88d90 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -17,6 +17,8 @@ int main(int, char**) { // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 19d34e9a..16415465 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -27,6 +27,8 @@ int main(int, char**) { // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); From 892dfb1dea65644b1c6f9882b9c883a837b18369 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 2 Oct 2019 11:38:30 +0200 Subject: [PATCH 044/384] InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) Small refactor of ActiveIdUsingXXX inputs flags toward a little more consistent system. (#2637) --- docs/CHANGELOG.txt | 4 ++-- imgui.cpp | 43 +++++++++++++++++++++++++------------------ imgui.h | 1 - imgui_internal.h | 18 ++++++++++++------ imgui_widgets.cpp | 20 ++++++++++++-------- 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8ef15ad7..a46b3af8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,10 +34,10 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Breaking Changes: -- +- Other Changes: -- +- InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 77eeb4c4..3e3cb4e4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1064,7 +1064,7 @@ static void NavUpdate(); static void NavUpdateWindowing(); static void NavUpdateWindowingOverlay(); static void NavUpdateMoveResult(); -static float NavUpdatePageUpPageDown(int allowed_dir_flags); +static float NavUpdatePageUpPageDown(); static inline void NavUpdateAnyRequestFlag(); static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand); static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, ImGuiID id); @@ -2867,8 +2867,6 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) } } g.ActiveId = id; - g.ActiveIdAllowNavDirFlags = 0; - g.ActiveIdBlockNavInputFlags = 0; g.ActiveIdAllowOverlap = false; g.ActiveIdWindow = window; g.ActiveIdHasBeenEditedThisFrame = false; @@ -2877,6 +2875,12 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) g.ActiveIdIsAlive = id; g.ActiveIdSource = (g.NavActivateId == id || g.NavInputId == id || g.NavJustTabbedId == id || g.NavJustMovedToId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse; } + + // Clear declaration of inputs claimed by the widget + // (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet) + g.ActiveIdUsingNavDirMask = 0x00; + g.ActiveIdUsingNavInputMask = 0x00; + g.ActiveIdUsingKeyInputMask = 0x00; } // FIXME-NAV: The existence of SetNavID/SetNavIDWithRectRel/SetFocusID is incredibly messy and confusing and needs some explanation or refactoring. @@ -3157,7 +3161,7 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id) // Process TAB/Shift-TAB to tab *OUT* of the currently focused item. // (Note that we can always TAB out of a widget that doesn't allow tabbing in) - if (g.ActiveId == id && g.FocusTabPressed && !(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_KeyTab_)) && g.FocusRequestNextWindow == NULL) + if (g.ActiveId == id && g.FocusTabPressed && !IsActiveIdUsingKey(ImGuiKey_Tab) && g.FocusRequestNextWindow == NULL) { g.FocusRequestNextWindow = window; g.FocusRequestNextCounterTab = window->DC.FocusCounterTab + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items. @@ -3782,6 +3786,11 @@ void ImGui::NewFrame() g.ActiveIdIsJustActivated = false; if (g.TempInputTextId != 0 && g.ActiveId != g.TempInputTextId) g.TempInputTextId = 0; + if (g.ActiveId == 0) + { + g.ActiveIdUsingNavDirMask = g.ActiveIdUsingNavInputMask = 0; + g.ActiveIdUsingKeyInputMask = 0; + } // Drag and drop g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr; @@ -8271,7 +8280,6 @@ static void ImGui::NavUpdate() NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_); NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ ); NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ ); - NAV_MAP_KEY(ImGuiKey_Tab, ImGuiNavInput_KeyTab_ ); if (g.IO.KeyCtrl) g.IO.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f; if (g.IO.KeyShift) @@ -8349,7 +8357,7 @@ static void ImGui::NavUpdate() { if (g.ActiveId != 0) { - if (!(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_Cancel))) + if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel)) ClearActiveID(); } else if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow) && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow) @@ -8411,17 +8419,16 @@ static void ImGui::NavUpdate() g.NavNextActivateId = 0; // Initiate directional inputs request - const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags; if (g.NavMoveRequestForward == ImGuiNavForward_None) { g.NavMoveDir = ImGuiDir_None; g.NavMoveRequestFlags = ImGuiNavMoveFlags_None; - if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) + if (g.NavWindow && !g.NavWindowingTarget && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { - if ((allowed_dir_flags & (1 << ImGuiDir_Left)) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadLeft, ImGuiNavInput_KeyLeft_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Left; } - if ((allowed_dir_flags & (1 << ImGuiDir_Right)) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadRight,ImGuiNavInput_KeyRight_,ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Right; } - if ((allowed_dir_flags & (1 << ImGuiDir_Up)) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadUp, ImGuiNavInput_KeyUp_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Up; } - if ((allowed_dir_flags & (1 << ImGuiDir_Down)) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadDown, ImGuiNavInput_KeyDown_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Down; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadLeft, ImGuiNavInput_KeyLeft_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Left; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadRight,ImGuiNavInput_KeyRight_,ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Right; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadUp, ImGuiNavInput_KeyUp_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Up; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadDown, ImGuiNavInput_KeyDown_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Down; } } g.NavMoveClipDir = g.NavMoveDir; } @@ -8438,7 +8445,7 @@ static void ImGui::NavUpdate() // FIXME-NAV: Consider enabling those keys even without the master ImGuiConfigFlags_NavEnableKeyboard flag? float nav_scoring_rect_offset_y = 0.0f; if (nav_keyboard_active) - nav_scoring_rect_offset_y = NavUpdatePageUpPageDown(allowed_dir_flags); + nav_scoring_rect_offset_y = NavUpdatePageUpPageDown(); // If we initiate a movement request and have no current NavId, we initiate a InitDefautRequest that will be used as a fallback if the direction fails to find a match if (g.NavMoveDir != ImGuiDir_None) @@ -8585,7 +8592,7 @@ static void ImGui::NavUpdateMoveResult() } // Handle PageUp/PageDown/Home/End keys -static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags) +static float ImGui::NavUpdatePageUpPageDown() { ImGuiContext& g = *GImGui; if (g.NavMoveDir != ImGuiDir_None || g.NavWindow == NULL) @@ -8594,10 +8601,10 @@ static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags) return 0.0f; ImGuiWindow* window = g.NavWindow; - const bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && (allowed_dir_flags & (1 << ImGuiDir_Up)); - const bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && (allowed_dir_flags & (1 << ImGuiDir_Down)); - const bool home_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_Home]) && (allowed_dir_flags & (1 << ImGuiDir_Up)); - const bool end_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_End]) && (allowed_dir_flags & (1 << ImGuiDir_Down)); + const bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && !IsActiveIdUsingKey(ImGuiKey_PageUp); + const bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && !IsActiveIdUsingKey(ImGuiKey_PageDown); + const bool home_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_Home]) && !IsActiveIdUsingKey(ImGuiKey_Home); + const bool end_pressed = IsKeyPressed(g.IO.KeyMap[ImGuiKey_End]) && !IsActiveIdUsingKey(ImGuiKey_End); if (page_up_held != page_down_held || home_pressed != end_pressed) // If either (not both) are pressed { if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll) diff --git a/imgui.h b/imgui.h index 8696ef4d..a7e5fd7e 100644 --- a/imgui.h +++ b/imgui.h @@ -986,7 +986,6 @@ enum ImGuiNavInput_ // [Internal] Don't use directly! This is used internally to differentiate keyboard from gamepad inputs for behaviors that require to differentiate them. // Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from io.KeysDown[] instead of io.NavInputs[]. ImGuiNavInput_KeyMenu_, // toggle menu // = io.KeyAlt - ImGuiNavInput_KeyTab_, // tab // = Tab key ImGuiNavInput_KeyLeft_, // move left // = Arrow keys ImGuiNavInput_KeyRight_, // move right ImGuiNavInput_KeyUp_, // move up diff --git a/imgui_internal.h b/imgui_internal.h index 19f2bfef..dcb8f4f5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -900,8 +900,9 @@ struct ImGuiContext bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch. bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state. bool ActiveIdHasBeenEditedThisFrame; - int ActiveIdAllowNavDirFlags; // Active widget allows using directional navigation (e.g. can activate a button and move away from it) - int ActiveIdBlockNavInputFlags; + ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those directional navigation requests (e.g. can activate a button and move away from it) + ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs. + ImU64 ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) @@ -1092,8 +1093,9 @@ struct ImGuiContext ActiveIdHasBeenPressedBefore = false; ActiveIdHasBeenEditedBefore = false; ActiveIdHasBeenEditedThisFrame = false; - ActiveIdAllowNavDirFlags = 0x00; - ActiveIdBlockNavInputFlags = 0x00; + ActiveIdUsingNavDirMask = 0x00; + ActiveIdUsingNavInputMask = 0x00; + ActiveIdUsingKeyInputMask = 0x00; ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = NULL; ActiveIdSource = ImGuiInputSource_None; @@ -1584,9 +1586,13 @@ namespace ImGui IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel); // Inputs + // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. + inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } + inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; } + inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; IM_ASSERT(key < 64); return (g.ActiveIdUsingKeyInputMask & ((ImU64)1 << key)) != 0; } IMGUI_API bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); - inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { const int key_index = GImGui->IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } - inline bool IsNavInputDown(ImGuiNavInput n) { return GImGui->IO.NavInputs[n] > 0.0f; } + inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } + inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } inline bool IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode) { return GetNavInputAmount(n, mode) > 0.0f; } inline bool IsNavInputPressedAnyOfTwo(ImGuiNavInput n1, ImGuiNavInput n2, ImGuiInputReadMode mode) { return (GetNavInputAmount(n1, mode) + GetNavInputAmount(n2, mode)) > 0.0f; } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 838f9367..3f5a24f7 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -557,7 +557,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool SetActiveID(id, window); if ((nav_activated_by_code || nav_activated_by_inputs) && !(flags & ImGuiButtonFlags_NoNavFocus)) SetFocusID(id, window); - g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right) | (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); } } @@ -2093,7 +2092,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); - g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); + g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); if (focus_requested || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavInputId == id) { temp_input_start = true; @@ -2542,7 +2541,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); - g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); + g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); if (focus_requested || (clicked && g.IO.KeyCtrl) || g.NavInputId == id) { temp_input_start = true; @@ -2696,7 +2695,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); - g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); + g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); } // Draw frame @@ -3505,12 +3504,17 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); + + // Declare our inputs IM_ASSERT(ImGuiNavInput_COUNT < 32); - g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel); + if (is_multiline || (flags & ImGuiInputTextFlags_CallbackHistory)) + g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); + g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); + g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_Home) | ((ImU64)1 << ImGuiKey_End); + if (is_multiline) + g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_PageUp) | ((ImU64)1 << ImGuiKey_PageDown); // FIXME-NAV: Page up/down actually not supported yet by widget, but claim them ahead. if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out as we will use the \t character. - g.ActiveIdBlockNavInputFlags |= (1 << ImGuiNavInput_KeyTab_); - if (!is_multiline && !(flags & ImGuiInputTextFlags_CallbackHistory)) - g.ActiveIdAllowNavDirFlags = ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down)); + g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_Tab); } // We have an edge case if ActiveId was set through another widget (e.g. widget being swapped), clear id immediately (don't wait until the end of the function) From a6c3be4bda0a18a189a2e75de96290671ddadb18 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 3 Oct 2019 15:59:36 +0200 Subject: [PATCH 045/384] Internals: Tweaks to ItemSize() should be harmless. Added DebugDrawItemRect() helper. --- imgui.cpp | 16 ++++++++-------- imgui_internal.h | 8 +++++--- imgui_widgets.cpp | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3e3cb4e4..4e95e011 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2969,7 +2969,7 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla } // Advance cursor given item size for layout. -void ImGui::ItemSize(const ImVec2& size, float text_offset_y) +void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -2978,28 +2978,28 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y) // Always align ourselves on pixel boundaries const float line_height = ImMax(window->DC.CurrLineSize.y, size.y); - const float text_base_offset = ImMax(window->DC.CurrLineTextBaseOffset, text_offset_y); //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); - window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); + window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line + window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] window->DC.PrevLineSize.y = line_height; - window->DC.PrevLineTextBaseOffset = text_base_offset; - window->DC.CurrLineSize.y = window->DC.CurrLineTextBaseOffset = 0.0f; + window->DC.CurrLineSize.y = 0.0f; + window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y); + window->DC.CurrLineTextBaseOffset = 0.0f; // Horizontal layout mode if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) SameLine(); } -void ImGui::ItemSize(const ImRect& bb, float text_offset_y) +void ImGui::ItemSize(const ImRect& bb, float text_baseline_y) { - ItemSize(bb.GetSize(), text_offset_y); + ItemSize(bb.GetSize(), text_baseline_y); } // Declare item bounding box for clipping and interaction. diff --git a/imgui_internal.h b/imgui_internal.h index dcb8f4f5..df96fd8b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -383,6 +383,7 @@ enum ImGuiSeparatorFlags_ // This is going to be exposed in imgui.h when stabilized enough. enum ImGuiItemFlags_ { + ImGuiItemFlags_None = 0, ImGuiItemFlags_NoTabStop = 1 << 0, // false ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. ImGuiItemFlags_Disabled = 1 << 2, // false // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211 @@ -1541,8 +1542,8 @@ namespace ImGui IMGUI_API void PushOverrideID(ImGuiID id); // Basic Helpers for widget code - IMGUI_API void ItemSize(const ImVec2& size, float text_offset_y = 0.0f); - IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); + IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = 0.0f); + IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = 0.0f); IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL); IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); @@ -1704,7 +1705,8 @@ namespace ImGui IMGUI_API void ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp); // Debug Tools - inline void DebugStartItemPicker() { GImGui->DebugItemPickerActive = true; } + inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max, col); } + inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; } } // namespace ImGui diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3f5a24f7..a16cff3c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -112,6 +112,7 @@ static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const //------------------------------------------------------------------------- // [SECTION] Widgets: Text, etc. //------------------------------------------------------------------------- +// - TextEx() [Internal] // - TextUnformatted() // - Text() // - TextV() From 1425bec7a450e378db20930c1e9f47601dc1f45b Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 3 Oct 2019 16:57:14 +0200 Subject: [PATCH 046/384] Demo: Text baseline demo tweaks. --- imgui_demo.cpp | 136 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 46 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 41c26546..036d9068 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2047,55 +2047,99 @@ static void ShowDemoWindowLayout() if (ImGui::TreeNode("Text Baseline Alignment")) { - HelpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets."); - - ImGui::Text("One\nTwo\nThree"); ImGui::SameLine(); - ImGui::Text("Hello\nWorld"); ImGui::SameLine(); - ImGui::Text("Banana"); - - ImGui::Text("Banana"); ImGui::SameLine(); - ImGui::Text("Hello\nWorld"); ImGui::SameLine(); - ImGui::Text("One\nTwo\nThree"); - - ImGui::Button("HOP##1"); ImGui::SameLine(); - ImGui::Text("Banana"); ImGui::SameLine(); - ImGui::Text("Hello\nWorld"); ImGui::SameLine(); - ImGui::Text("Banana"); - - ImGui::Button("HOP##2"); ImGui::SameLine(); - ImGui::Text("Hello\nWorld"); ImGui::SameLine(); - ImGui::Text("Banana"); - - ImGui::Button("TEST##1"); ImGui::SameLine(); - ImGui::Text("TEST"); ImGui::SameLine(); - ImGui::SmallButton("TEST##2"); - - ImGui::AlignTextToFramePadding(); // If your line starts with text, call this to align it to upcoming widgets. - ImGui::Text("Text aligned to Widget"); ImGui::SameLine(); - ImGui::Button("Widget##1"); ImGui::SameLine(); - ImGui::Text("Widget"); ImGui::SameLine(); - ImGui::SmallButton("Widget##2"); ImGui::SameLine(); - ImGui::Button("Widget##3"); - - // Tree - const float spacing = ImGui::GetStyle().ItemInnerSpacing.x; - ImGui::Button("Button##1"); - ImGui::SameLine(0.0f, spacing); - if (ImGui::TreeNode("Node##1")) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + { + ImGui::BulletText("Text baseline:"); + ImGui::SameLine(); + HelpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets."); + ImGui::Indent(); - ImGui::AlignTextToFramePadding(); // Vertically align text node a bit lower so it'll be vertically centered with upcoming widget. Otherwise you can use SmallButton (smaller fit). - bool node_open = ImGui::TreeNode("Node##2"); // Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content. - ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2"); - if (node_open) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + ImGui::Text("KO Blahblah"); ImGui::SameLine(); + ImGui::Button("Some framed item"); ImGui::SameLine(); + HelpMarker("Baseline of button will look misaligned with text.."); - // Bullet - ImGui::Button("Button##3"); - ImGui::SameLine(0.0f, spacing); - ImGui::BulletText("Bullet text"); + // If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets. + // Because we don't know what's coming after the Text() statement, we need to move the text baseline down by FramePadding.y + ImGui::AlignTextToFramePadding(); + ImGui::Text("OK Blahblah"); ImGui::SameLine(); + ImGui::Button("Some framed item"); ImGui::SameLine(); + HelpMarker("We call AlignTextToFramePadding() to vertically align the text baseline by +FramePadding.y"); - ImGui::AlignTextToFramePadding(); - ImGui::BulletText("Node"); - ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##4"); + // SmallButton() uses the same vertical padding as Text + ImGui::Button("TEST##1"); ImGui::SameLine(); + ImGui::Text("TEST"); ImGui::SameLine(); + ImGui::SmallButton("TEST##2"); + + // If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets. + ImGui::AlignTextToFramePadding(); + ImGui::Text("Text aligned to framed item"); ImGui::SameLine(); + ImGui::Button("Item##1"); ImGui::SameLine(); + ImGui::Text("Item"); ImGui::SameLine(); + ImGui::SmallButton("Item##2"); ImGui::SameLine(); + ImGui::Button("Item##3"); + + ImGui::Unindent(); + } + + ImGui::Spacing(); + + { + ImGui::BulletText("Multi-line text:"); + ImGui::Indent(); + ImGui::Text("One\nTwo\nThree"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("One\nTwo\nThree"); + + ImGui::Button("HOP##1"); ImGui::SameLine(); + ImGui::Text("Banana"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + + ImGui::Button("HOP##2"); ImGui::SameLine(); + ImGui::Text("Hello\nWorld"); ImGui::SameLine(); + ImGui::Text("Banana"); + ImGui::Unindent(); + } + + ImGui::Spacing(); + + { + ImGui::BulletText("Misc items:"); + ImGui::Indent(); + + // SmallButton() sets FramePadding to zero. Text baseline is aligned to match baseline of previous Button + ImGui::Button("80x80", ImVec2(80, 80)); + ImGui::SameLine(); + ImGui::Button("50x50", ImVec2(50, 50)); + ImGui::SameLine(); + ImGui::Button("Button()"); + ImGui::SameLine(); + ImGui::SmallButton("SmallButton()"); + + // Tree + const float spacing = ImGui::GetStyle().ItemInnerSpacing.x; + ImGui::Button("Button##1"); + ImGui::SameLine(0.0f, spacing); + if (ImGui::TreeNode("Node##1")) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + + ImGui::AlignTextToFramePadding(); // Vertically align text node a bit lower so it'll be vertically centered with upcoming widget. Otherwise you can use SmallButton (smaller fit). + bool node_open = ImGui::TreeNode("Node##2");// Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content. + ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2"); + if (node_open) { for (int i = 0; i < 6; i++) ImGui::BulletText("Item %d..", i); ImGui::TreePop(); } // Dummy tree data + + // Bullet + ImGui::Button("Button##3"); + ImGui::SameLine(0.0f, spacing); + ImGui::BulletText("Bullet text"); + + ImGui::AlignTextToFramePadding(); + ImGui::BulletText("Node"); + ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##4"); + ImGui::Unindent(); + } ImGui::TreePop(); } From ccb2a947a27d9fe5c711a7d7bc5ab18c6fa0b78b Mon Sep 17 00:00:00 2001 From: domgho Date: Fri, 4 Oct 2019 11:57:20 +0200 Subject: [PATCH 047/384] Internal: SliderBehaviorT: Condition '!is_decimal' is always true (#2828) --- imgui_widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a16cff3c..26e1d648 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2430,7 +2430,7 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ FLOATTYPE v_new_off_f = (v_max - v_min) * clicked_t; TYPE v_new_off_floor = (TYPE)(v_new_off_f); TYPE v_new_off_round = (TYPE)(v_new_off_f + (FLOATTYPE)0.5); - if (!is_decimal && v_new_off_floor < v_new_off_round) + if (v_new_off_floor < v_new_off_round) v_new = v_min + v_new_off_round; else v_new = v_min + v_new_off_floor; From ee3373d067ed253ee70087818a16b0b1210e1b8c Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 4 Oct 2019 19:21:29 +0200 Subject: [PATCH 048/384] TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a46b3af8..e1cd2ad9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,6 +38,8 @@ Breaking Changes: Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) +- TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow + incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) ----------------------------------------------------------------------- diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 26e1d648..d6631a17 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5270,9 +5270,11 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l { if (pressed) { + const float arrow_x1 = text_pos.x - text_offset_x; + const float arrow_x2 = arrow_x1 + g.FontSize + padding.x * 2.0f; toggled = !(flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) || (g.NavActivateId == id); if (flags & ImGuiTreeNodeFlags_OpenOnArrow) - toggled |= IsMouseHoveringRect(interact_bb.Min, ImVec2(interact_bb.Min.x + text_offset_x, interact_bb.Max.y)) && (!g.NavDisableMouseHover); + toggled |= IsMouseHoveringRect(ImVec2(arrow_x1, interact_bb.Min.y), ImVec2(arrow_x2, interact_bb.Max.y)) && (!g.NavDisableMouseHover); if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) toggled |= g.IO.MouseDoubleClicked[0]; if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. From f1f321d3f6d585df3d6320a23e5b69885d392405 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 5 Oct 2019 16:07:00 +0200 Subject: [PATCH 049/384] Update README.md --- docs/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index b4540c17..7d29ace9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -120,9 +120,14 @@ On most platforms and when using C++, **you should be able to use a combination Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the FAQ, comments, and one of the examples/ application!** -_NB: those third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users!). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ +_NB: third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users!). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ -Languages: +Officially maintained bindings in repository: +- Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. +- Platforms: GLFW, SDL2, Win32, Glut, OSX. +- Others: Allegro5, Marmalade. + +Third-party - Languages bindings: - C: [cimgui](https://github.com/cimgui/cimgui) (auto-generated! **you can use its json output to generate bindings for other languages**) - C#/.Net: [ImGui.NET](https://github.com/mellinoe/ImGui.NET) - ChaiScript: [imgui-chaiscript](https://github.com/JuJuBoSc/imgui-chaiscript) @@ -141,11 +146,7 @@ Languages: - Rust: [imgui-rs](https://github.com/Gekkio/imgui-rs) or [imgui-rust](https://github.com/nsf/imgui-rust) - Swift: [swift-imgui](https://github.com/mnmly/Swift-imgui) -Frameworks: -- Renderers: DirectX 9/10/11/12, Metal, OpenGL2, OpenGL3+/ES2/ES3, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) -- Platform: GLFW, SDL, Win32, OSX, GLUT: [examples/](https://github.com/ocornut/imgui/tree/master/examples) -- Framework: Allegro 5, Emscripten, Marmalade: [examples/](https://github.com/ocornut/imgui/tree/master/examples) -- Unmerged PR: Android: [#421](https://github.com/ocornut/imgui/pull/421) +Third-party - Engines/Frameworks bindings: - bsf: [bsfimgui](https://github.com/pgruenbacher/bsfImgui) - Cinder: [Cinder-ImGui](https://github.com/simongeilfus/Cinder-ImGui) - Cocos2d-x: [imguix](https://github.com/c0i/imguix), [#551](https://github.com/ocornut/imgui/issues/551) @@ -164,6 +165,7 @@ Frameworks: - SFML: [imgui-sfml](https://github.com/eliasdaler/imgui-sfml) - Software renderer: [imgui_software_renderer](https://github.com/emilk/imgui_software_renderer) - Unreal Engine 4: [segross/UnrealImGui](https://github.com/segross/UnrealImGui) or [sronsse/UnrealEngine_ImGui](https://github.com/sronsse/UnrealEngine_ImGui) +- Unmerged PR: Android: [#421](https://github.com/ocornut/imgui/pull/421) For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/). Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. From 73fa6509a516c2b43478947e6cc713c538ce2ec2 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 5 Oct 2019 16:53:28 +0200 Subject: [PATCH 050/384] Internal: InputTextEx: tweaked a bit of code (should be a no-op) --- imgui.cpp | 2 +- imgui_widgets.cpp | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4e95e011..7bf2bf59 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4303,7 +4303,7 @@ void ImGui::Render() } // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. -// CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize) +// CalcTextSize("") should return ImVec2(0.0f, g.FontSize) ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) { ImGuiContext& g = *GImGui; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d6631a17..1561c157 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3404,11 +3404,14 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ BeginGroup(); const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); - ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line - const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size); - const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); + const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line + const ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y); + + const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); + const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size); ImGuiWindow* draw_window = window; + ImVec2 inner_size = frame_size; if (is_multiline) { if (!ItemAdd(total_bb, id, &frame_bb)) @@ -3423,9 +3426,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ EndGroup(); return false; } - draw_window = GetCurrentWindow(); + draw_window = g.CurrentWindow; // Child window draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight - size.x -= draw_window->ScrollbarSizes.x; + inner_size.x -= draw_window->ScrollbarSizes.x; } else { @@ -3914,7 +3917,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); } - const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size + const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + inner_size.x, frame_bb.Min.y + inner_size.y); // Not using frame_bb.Max because we have adjusted size ImVec2 draw_pos = is_multiline ? draw_window->DC.CursorPos : frame_bb.Min + style.FramePadding; ImVec2 text_size(0.0f, 0.0f); @@ -3995,7 +3998,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Store text height (note that we haven't calculated text width at all, see GitHub issues #383, #1224) if (is_multiline) - text_size = ImVec2(size.x, line_count * g.FontSize); + text_size = ImVec2(inner_size.x, line_count * g.FontSize); } // Scroll @@ -4004,11 +4007,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Horizontal scroll in chunks of quarter width if (!(flags & ImGuiInputTextFlags_NoHorizontalScroll)) { - const float scroll_increment_x = size.x * 0.25f; + const float scroll_increment_x = inner_size.x * 0.25f; if (cursor_offset.x < state->ScrollX) state->ScrollX = (float)(int)ImMax(0.0f, cursor_offset.x - scroll_increment_x); - else if (cursor_offset.x - size.x >= state->ScrollX) - state->ScrollX = (float)(int)(cursor_offset.x - size.x + scroll_increment_x); + else if (cursor_offset.x - inner_size.x >= state->ScrollX) + state->ScrollX = (float)(int)(cursor_offset.x - inner_size.x + scroll_increment_x); } else { @@ -4021,8 +4024,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ float scroll_y = draw_window->Scroll.y; if (cursor_offset.y - g.FontSize < scroll_y) scroll_y = ImMax(0.0f, cursor_offset.y - g.FontSize); - else if (cursor_offset.y - size.y >= scroll_y) - scroll_y = cursor_offset.y - size.y; + else if (cursor_offset.y - inner_size.y >= scroll_y) + scroll_y = cursor_offset.y - inner_size.y; draw_pos.y += (draw_window->Scroll.y - scroll_y); // Manipulate cursor pos immediately avoid a frame of lag draw_window->Scroll.y = scroll_y; } @@ -4093,7 +4096,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { // Render text only (no selection, no cursor) if (is_multiline) - text_size = ImVec2(size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_display_end) * g.FontSize); // We don't need width + text_size = ImVec2(inner_size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_display_end) * g.FontSize); // We don't need width else if (!is_displaying_hint && g.ActiveId == id) buf_display_end = buf_display + state->CurLenA; else if (!is_displaying_hint) From 323412dd23bb414c8885ee545a5ca0aaa3a40e84 Mon Sep 17 00:00:00 2001 From: Harris Brakmic Date: Sun, 6 Oct 2019 13:02:01 +0200 Subject: [PATCH 051/384] Examples: Allegro5: updated build instructions for macOS --- examples/example_allegro5/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/example_allegro5/README.md b/examples/example_allegro5/README.md index 5ef45557..10d9d6e9 100644 --- a/examples/example_allegro5/README.md +++ b/examples/example_allegro5/README.md @@ -9,12 +9,14 @@ Note that the back-end supports _BOTH_ 16-bit and 32-bit indices, but 32-bit ind # How to Build -### On Ubuntu 14.04+ +### On Ubuntu 14.04+ and macOS ```bash -g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ../imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_primitives -o allegro5_example +g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ../imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_main -lallegro_primitives -o allegro5_example ``` +On macOS, install Allegro with homebrew: `brew install allegro`. + ### On Windows with Visual Studio's CLI You may install Allegro using vcpkg: From 8aad3482a412af966082c297d5c7f05e070b7d98 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 7 Oct 2019 17:22:55 +0200 Subject: [PATCH 052/384] ImVector: Fixed index_from_ptr() not asserting when passed end() element. --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index a7e5fd7e..1db78b4a 100644 --- a/imgui.h +++ b/imgui.h @@ -1276,7 +1276,7 @@ struct ImVector inline const T* find(const T& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data == v) break; else ++data; return data; } inline bool find_erase(const T& v) { const T* it = find(v); if (it < Data + Size) { erase(it); return true; } return false; } inline bool find_erase_unsorted(const T& v) { const T* it = find(v); if (it < Data + Size) { erase_unsorted(it); return true; } return false; } - inline int index_from_ptr(const T* it) const { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; return (int)off; } + inline int index_from_ptr(const T* it) const { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; return (int)off; } }; //----------------------------------------------------------------------------- From 3b271b1847f0cf159cfd0dfeaa171034fcab2507 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 7 Oct 2019 17:52:31 +0200 Subject: [PATCH 053/384] Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] --- docs/CHANGELOG.txt | 1 + imgui_demo.cpp | 47 +++++++++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e1cd2ad9..64bbe6bd 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,7 @@ Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) +- Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] ----------------------------------------------------------------------- diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 036d9068..0eeec980 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1506,24 +1506,21 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("Drag and Drop")) { + if (ImGui::TreeNode("Drag and drop in standard widgets")) { // ColorEdit widgets automatically act as drag source and drag target. // They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets // to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo. - ImGui::BulletText("Drag and drop in standard widgets"); - ImGui::SameLine(); HelpMarker("You can drag from the colored squares."); - ImGui::Indent(); - static float col1[3] = { 1.0f,0.0f,0.2f }; - static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; + static float col1[3] = { 1.0f, 0.0f, 0.2f }; + static float col2[4] = { 0.4f, 0.7f, 0.0f, 0.5f }; ImGui::ColorEdit3("color 1", col1); ImGui::ColorEdit4("color 2", col2); - ImGui::Unindent(); + ImGui::TreePop(); } + if (ImGui::TreeNode("Drag and drop to copy/swap items")) { - ImGui::BulletText("Drag and drop to copy/swap items"); - ImGui::Indent(); enum Mode { Mode_Copy, @@ -1577,7 +1574,31 @@ static void ShowDemoWindowWidgets() } ImGui::PopID(); } - ImGui::Unindent(); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Drag to reorder items (simple)")) + { + // Simple reordering + HelpMarker("We don't use the drag and drop api at all here! Instead we query when the item is held but not hovered, and order items accordingly."); + static const char* item_names[] = { "Item One", "Item Two", "Item Three", "Item Four", "Item Five" }; + for (int n = 0; n < IM_ARRAYSIZE(item_names); n++) + { + const char* item = item_names[n]; + ImGui::Selectable(item); + + if (ImGui::IsItemActive() && !ImGui::IsItemHovered()) + { + int n_next = n + (ImGui::GetMouseDragDelta(0).y < 0.f ? -1 : 1); + if (n_next >= 0 && n_next < IM_ARRAYSIZE(item_names)) + { + item_names[n] = item_names[n_next]; + item_names[n_next] = item; + ImGui::ResetMouseDragDelta(); + } + } + } + ImGui::TreePop(); } ImGui::TreePop(); @@ -1607,10 +1628,10 @@ static void ShowDemoWindowWidgets() if (item_type == 10){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy. if (item_type == 11){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); } - // Display the value of IsItemHovered() and other common item state functions. + // Display the value of IsItemHovered() and other common item state functions. // Note that the ImGuiHoveredFlags_XXX flags can be combined. - // Because BulletText is an item itself and that would affect the output of IsItemXXX functions, - // we query every state in a single call to avoid storing them and to simplify the code + // Because BulletText is an item itself and that would affect the output of IsItemXXX functions, + // we query every state in a single call to avoid storing them and to simplify the code ImGui::BulletText( "Return value = %d\n" "IsItemFocused() = %d\n" @@ -1653,7 +1674,7 @@ static void ShowDemoWindowWidgets() if (embed_all_inside_a_child_window) ImGui::BeginChild("outer_child", ImVec2(0, ImGui::GetFontSize() * 20), true); - // Testing IsWindowFocused() function with its various flags. + // Testing IsWindowFocused() function with its various flags. // Note that the ImGuiFocusedFlags_XXX flags can be combined. ImGui::BulletText( "IsWindowFocused() = %d\n" From 927472f5ff978bcc9f67708316481a3fcae4c04d Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 7 Oct 2019 19:14:08 +0200 Subject: [PATCH 054/384] Combo: Added _NoMove flag to prevent window from docking, which has an effect in Docking branch (in Master was not noticeable as the Combo code kept repositioning the window). (#2835) --- imgui_widgets.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1561c157..0da7353e 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1505,8 +1505,10 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF SetNextWindowPos(pos); } + // We don't use BeginPopupEx() solely because we have a custom name string, which we could make an argument to BeginPopupEx() + ImGuiWindowFlags window_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove; + // Horizontally align ourselves with the framed text - ImGuiWindowFlags window_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(style.FramePadding.x, style.WindowPadding.y)); bool ret = Begin(name, NULL, window_flags); PopStyleVar(); From bf746c4215b92b764a7101b8673d24beb3e0c996 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 11 Oct 2019 12:03:43 +0200 Subject: [PATCH 055/384] DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the datato clarify how they are used, and more comments redirecting to the demo code. (#2844) --- docs/CHANGELOG.txt | 2 + imgui.h | 14 ++-- imgui_internal.h | 10 +-- imgui_widgets.cpp | 158 +++++++++++++++++++++++---------------------- 4 files changed, 96 insertions(+), 88 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 64bbe6bd..1d8e7e79 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,8 @@ Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) +- DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data + to clarify how they are used, and more comments redirecting to the demo code. (#2844) - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] diff --git a/imgui.h b/imgui.h index 1db78b4a..1675fc6c 100644 --- a/imgui.h +++ b/imgui.h @@ -438,8 +438,8 @@ namespace ImGui IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d"); IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d"); IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d", const char* format_max = NULL); - IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* v, float v_speed, const void* v_min = NULL, const void* v_max = NULL, const char* format = NULL, float power = 1.0f); - IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* v, int components, float v_speed, const void* v_min = NULL, const void* v_max = NULL, const char* format = NULL, float power = 1.0f); + IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min = NULL, const void* p_max = NULL, const char* format = NULL, float power = 1.0f); + IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min = NULL, const void* p_max = NULL, const char* format = NULL, float power = 1.0f); // Widgets: Sliders // - CTRL+Click on any slider to turn them into an input box. Manually input values aren't clamped and can go off-bounds. @@ -453,11 +453,11 @@ namespace ImGui IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* format = "%d"); IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* format = "%d"); IMGUI_API bool SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* format = "%d"); - IMGUI_API bool SliderScalar(const char* label, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format = NULL, float power = 1.0f); - IMGUI_API bool SliderScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* v_min, const void* v_max, const char* format = NULL, float power = 1.0f); + IMGUI_API bool SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format = NULL, float power = 1.0f); + IMGUI_API bool SliderScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_min, const void* p_max, const char* format = NULL, float power = 1.0f); IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); IMGUI_API bool VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* format = "%d"); - IMGUI_API bool VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format = NULL, float power = 1.0f); + IMGUI_API bool VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format = NULL, float power = 1.0f); // Widgets: Input with Keyboard // - If you want to use InputText() with a dynamic string type such as std::string or your own, see misc/cpp/imgui_stdlib.h @@ -474,8 +474,8 @@ namespace ImGui IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags flags = 0); IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags flags = 0); IMGUI_API bool InputDouble(const char* label, double* v, double step = 0.0, double step_fast = 0.0, const char* format = "%.6f", ImGuiInputTextFlags flags = 0); - IMGUI_API bool InputScalar(const char* label, ImGuiDataType data_type, void* v, const void* step = NULL, const void* step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags flags = 0); - IMGUI_API bool InputScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* step = NULL, const void* step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags flags = 0); + IMGUI_API bool InputScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_step = NULL, const void* p_step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags flags = 0); + IMGUI_API bool InputScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_step = NULL, const void* p_step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags flags = 0); // Widgets: Color Editor/Picker (tip: the ColorEdit* functions have a little colored preview square that can be left-clicked to open a picker, and right-clicked to open an option menu.) // - Note that in C++ a 'float v[X]' function argument is the _same_ as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. diff --git a/imgui_internal.h b/imgui_internal.h index df96fd8b..201a071c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1666,8 +1666,8 @@ namespace ImGui // Widgets low-level behaviors IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0); - IMGUI_API bool DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format, float power, ImGuiDragFlags flags); - IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb); + IMGUI_API bool DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v_speed, const void* p_min, const void* p_max, const char* format, float power, ImGuiDragFlags flags); + IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb); IMGUI_API bool SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f); IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextItemOpen() data, if any. May return true when logging @@ -1683,13 +1683,13 @@ namespace ImGui // Data type helpers IMGUI_API const ImGuiDataTypeInfo* DataTypeGetInfo(ImGuiDataType data_type); - IMGUI_API int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format); + IMGUI_API int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* p_data, const char* format); IMGUI_API void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg_1, const void* arg_2); - IMGUI_API bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* format); + IMGUI_API bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format); // InputText IMGUI_API bool InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); - IMGUI_API bool TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format); + IMGUI_API bool TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format); inline bool TempInputTextIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputTextId == id); } // Color diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0da7353e..a92eb5a9 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1680,25 +1680,25 @@ const ImGuiDataTypeInfo* ImGui::DataTypeGetInfo(ImGuiDataType data_type) return &GDataTypeInfo[data_type]; } -int ImGui::DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format) +int ImGui::DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* p_data, const char* format) { // Signedness doesn't matter when pushing integer arguments if (data_type == ImGuiDataType_S32 || data_type == ImGuiDataType_U32) - return ImFormatString(buf, buf_size, format, *(const ImU32*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImU32*)p_data); if (data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64) - return ImFormatString(buf, buf_size, format, *(const ImU64*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImU64*)p_data); if (data_type == ImGuiDataType_Float) - return ImFormatString(buf, buf_size, format, *(const float*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const float*)p_data); if (data_type == ImGuiDataType_Double) - return ImFormatString(buf, buf_size, format, *(const double*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const double*)p_data); if (data_type == ImGuiDataType_S8) - return ImFormatString(buf, buf_size, format, *(const ImS8*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImS8*)p_data); if (data_type == ImGuiDataType_U8) - return ImFormatString(buf, buf_size, format, *(const ImU8*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImU8*)p_data); if (data_type == ImGuiDataType_S16) - return ImFormatString(buf, buf_size, format, *(const ImS16*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImS16*)p_data); if (data_type == ImGuiDataType_U16) - return ImFormatString(buf, buf_size, format, *(const ImU16*)data_ptr); + return ImFormatString(buf, buf_size, format, *(const ImU16*)p_data); IM_ASSERT(0); return 0; } @@ -1755,7 +1755,7 @@ void ImGui::DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* // User can input math operators (e.g. +100) to edit a numerical values. // NB: This is _not_ a full expression evaluator. We should probably add one and replace this dumb mess.. -bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* format) +bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format) { while (ImCharIsBlankA(*buf)) buf++; @@ -1781,7 +1781,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b int data_backup[2]; const ImGuiDataTypeInfo* type_info = ImGui::DataTypeGetInfo(data_type); IM_ASSERT(type_info->Size <= sizeof(data_backup)); - memcpy(data_backup, data_ptr, type_info->Size); + memcpy(data_backup, p_data, type_info->Size); if (format == NULL) format = type_info->ScanFmt; @@ -1790,7 +1790,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b int arg1i = 0; if (data_type == ImGuiDataType_S32) { - int* v = (int*)data_ptr; + int* v = (int*)p_data; int arg0i = *v; float arg1f = 0.0f; if (op && sscanf(initial_value_buf, format, &arg0i) < 1) @@ -1805,7 +1805,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b { // For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in format = "%f"; - float* v = (float*)data_ptr; + float* v = (float*)p_data; float arg0f = *v, arg1f = 0.0f; if (op && sscanf(initial_value_buf, format, &arg0f) < 1) return false; @@ -1819,7 +1819,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b else if (data_type == ImGuiDataType_Double) { format = "%lf"; // scanf differentiate float/double unlike printf which forces everything to double because of ellipsis - double* v = (double*)data_ptr; + double* v = (double*)p_data; double arg0f = *v, arg1f = 0.0; if (op && sscanf(initial_value_buf, format, &arg0f) < 1) return false; @@ -1834,7 +1834,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b { // All other types assign constant // We don't bother handling support for legacy operators since they are a little too crappy. Instead we will later implement a proper expression evaluator in the future. - sscanf(buf, format, data_ptr); + sscanf(buf, format, p_data); } else { @@ -1842,18 +1842,18 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b int v32; sscanf(buf, format, &v32); if (data_type == ImGuiDataType_S8) - *(ImS8*)data_ptr = (ImS8)ImClamp(v32, (int)IM_S8_MIN, (int)IM_S8_MAX); + *(ImS8*)p_data = (ImS8)ImClamp(v32, (int)IM_S8_MIN, (int)IM_S8_MAX); else if (data_type == ImGuiDataType_U8) - *(ImU8*)data_ptr = (ImU8)ImClamp(v32, (int)IM_U8_MIN, (int)IM_U8_MAX); + *(ImU8*)p_data = (ImU8)ImClamp(v32, (int)IM_U8_MIN, (int)IM_U8_MAX); else if (data_type == ImGuiDataType_S16) - *(ImS16*)data_ptr = (ImS16)ImClamp(v32, (int)IM_S16_MIN, (int)IM_S16_MAX); + *(ImS16*)p_data = (ImS16)ImClamp(v32, (int)IM_S16_MIN, (int)IM_S16_MAX); else if (data_type == ImGuiDataType_U16) - *(ImU16*)data_ptr = (ImU16)ImClamp(v32, (int)IM_U16_MIN, (int)IM_U16_MAX); + *(ImU16*)p_data = (ImU16)ImClamp(v32, (int)IM_U16_MIN, (int)IM_U16_MAX); else IM_ASSERT(0); } - return memcmp(data_backup, data_ptr, type_info->Size) != 0; + return memcmp(data_backup, p_data, type_info->Size) != 0; } static float GetMinimumStepAtDecimalPrecision(int decimal_precision) @@ -2023,7 +2023,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const return true; } -bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format, float power, ImGuiDragFlags flags) +bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v_speed, const void* p_min, const void* p_max, const char* format, float power, ImGuiDragFlags flags) { ImGuiContext& g = *GImGui; if (g.ActiveId == id) @@ -2038,30 +2038,32 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_s switch (data_type) { - case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)v; bool r = DragBehaviorT(ImGuiDataType_S32, &v32, v_speed, v_min ? *(const ImS8*) v_min : IM_S8_MIN, v_max ? *(const ImS8*)v_max : IM_S8_MAX, format, power, flags); if (r) *(ImS8*)v = (ImS8)v32; return r; } - case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)v; bool r = DragBehaviorT(ImGuiDataType_U32, &v32, v_speed, v_min ? *(const ImU8*) v_min : IM_U8_MIN, v_max ? *(const ImU8*)v_max : IM_U8_MAX, format, power, flags); if (r) *(ImU8*)v = (ImU8)v32; return r; } - case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)v; bool r = DragBehaviorT(ImGuiDataType_S32, &v32, v_speed, v_min ? *(const ImS16*)v_min : IM_S16_MIN, v_max ? *(const ImS16*)v_max : IM_S16_MAX, format, power, flags); if (r) *(ImS16*)v = (ImS16)v32; return r; } - case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)v; bool r = DragBehaviorT(ImGuiDataType_U32, &v32, v_speed, v_min ? *(const ImU16*)v_min : IM_U16_MIN, v_max ? *(const ImU16*)v_max : IM_U16_MAX, format, power, flags); if (r) *(ImU16*)v = (ImU16)v32; return r; } - case ImGuiDataType_S32: return DragBehaviorT(data_type, (ImS32*)v, v_speed, v_min ? *(const ImS32* )v_min : IM_S32_MIN, v_max ? *(const ImS32* )v_max : IM_S32_MAX, format, power, flags); - case ImGuiDataType_U32: return DragBehaviorT(data_type, (ImU32*)v, v_speed, v_min ? *(const ImU32* )v_min : IM_U32_MIN, v_max ? *(const ImU32* )v_max : IM_U32_MAX, format, power, flags); - case ImGuiDataType_S64: return DragBehaviorT(data_type, (ImS64*)v, v_speed, v_min ? *(const ImS64* )v_min : IM_S64_MIN, v_max ? *(const ImS64* )v_max : IM_S64_MAX, format, power, flags); - case ImGuiDataType_U64: return DragBehaviorT(data_type, (ImU64*)v, v_speed, v_min ? *(const ImU64* )v_min : IM_U64_MIN, v_max ? *(const ImU64* )v_max : IM_U64_MAX, format, power, flags); - case ImGuiDataType_Float: return DragBehaviorT(data_type, (float*)v, v_speed, v_min ? *(const float* )v_min : -FLT_MAX, v_max ? *(const float* )v_max : FLT_MAX, format, power, flags); - case ImGuiDataType_Double: return DragBehaviorT(data_type, (double*)v, v_speed, v_min ? *(const double*)v_min : -DBL_MAX, v_max ? *(const double*)v_max : DBL_MAX, format, power, flags); + case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)p_v; bool r = DragBehaviorT(ImGuiDataType_S32, &v32, v_speed, p_min ? *(const ImS8*) p_min : IM_S8_MIN, p_max ? *(const ImS8*)p_max : IM_S8_MAX, format, power, flags); if (r) *(ImS8*)p_v = (ImS8)v32; return r; } + case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)p_v; bool r = DragBehaviorT(ImGuiDataType_U32, &v32, v_speed, p_min ? *(const ImU8*) p_min : IM_U8_MIN, p_max ? *(const ImU8*)p_max : IM_U8_MAX, format, power, flags); if (r) *(ImU8*)p_v = (ImU8)v32; return r; } + case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)p_v; bool r = DragBehaviorT(ImGuiDataType_S32, &v32, v_speed, p_min ? *(const ImS16*)p_min : IM_S16_MIN, p_max ? *(const ImS16*)p_max : IM_S16_MAX, format, power, flags); if (r) *(ImS16*)p_v = (ImS16)v32; return r; } + case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)p_v; bool r = DragBehaviorT(ImGuiDataType_U32, &v32, v_speed, p_min ? *(const ImU16*)p_min : IM_U16_MIN, p_max ? *(const ImU16*)p_max : IM_U16_MAX, format, power, flags); if (r) *(ImU16*)p_v = (ImU16)v32; return r; } + case ImGuiDataType_S32: return DragBehaviorT(data_type, (ImS32*)p_v, v_speed, p_min ? *(const ImS32* )p_min : IM_S32_MIN, p_max ? *(const ImS32* )p_max : IM_S32_MAX, format, power, flags); + case ImGuiDataType_U32: return DragBehaviorT(data_type, (ImU32*)p_v, v_speed, p_min ? *(const ImU32* )p_min : IM_U32_MIN, p_max ? *(const ImU32* )p_max : IM_U32_MAX, format, power, flags); + case ImGuiDataType_S64: return DragBehaviorT(data_type, (ImS64*)p_v, v_speed, p_min ? *(const ImS64* )p_min : IM_S64_MIN, p_max ? *(const ImS64* )p_max : IM_S64_MAX, format, power, flags); + case ImGuiDataType_U64: return DragBehaviorT(data_type, (ImU64*)p_v, v_speed, p_min ? *(const ImU64* )p_min : IM_U64_MIN, p_max ? *(const ImU64* )p_max : IM_U64_MAX, format, power, flags); + case ImGuiDataType_Float: return DragBehaviorT(data_type, (float*)p_v, v_speed, p_min ? *(const float* )p_min : -FLT_MAX, p_max ? *(const float* )p_max : FLT_MAX, format, power, flags); + case ImGuiDataType_Double: return DragBehaviorT(data_type, (double*)p_v, v_speed, p_min ? *(const double*)p_min : -DBL_MAX, p_max ? *(const double*)p_max : DBL_MAX, format, power, flags); case ImGuiDataType_COUNT: break; } IM_ASSERT(0); return false; } -bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format, float power) +// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget, p_min and p_max are optional. +// Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly. +bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, float power) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; if (power != 1.0f) - IM_ASSERT(v_min != NULL && v_max != NULL); // When using a power curve the drag needs to have known bounds + IM_ASSERT(p_min != NULL && p_max != NULL); // When using a power curve the drag needs to have known bounds ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; @@ -2104,7 +2106,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa } } if (temp_input_is_active || temp_input_start) - return TempInputTextScalar(frame_bb, id, label, data_type, v, format); + return TempInputTextScalar(frame_bb, id, label, data_type, p_data, format); // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); @@ -2112,13 +2114,13 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding); // Drag behavior - const bool value_changed = DragBehavior(id, data_type, v, v_speed, v_min, v_max, format, power, ImGuiDragFlags_None); + const bool value_changed = DragBehavior(id, data_type, p_data, v_speed, p_min, p_max, format, power, ImGuiDragFlags_None); if (value_changed) MarkItemEdited(id); // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; - const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, v, format); + const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format); RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); if (label_size.x > 0.0f) @@ -2128,7 +2130,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa return value_changed; } -bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int components, float v_speed, const void* v_min, const void* v_max, const char* format, float power) +bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, float power) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -2145,10 +2147,10 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int PushID(i); if (i > 0) SameLine(0, g.Style.ItemInnerSpacing.x); - value_changed |= DragScalar("", data_type, v, v_speed, v_min, v_max, format, power); + value_changed |= DragScalar("", data_type, p_data, v_speed, p_min, p_max, format, power); PopID(); PopItemWidth(); - v = (void*)((char*)v + type_size); + p_data = (void*)((char*)p_data + type_size); } PopID(); @@ -2474,39 +2476,41 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ // For 32-bits and larger types, slider bounds are limited to half the natural type range. // So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2 will be ok. // It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders. -bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb) +bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb) { switch (data_type) { - case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_S32, &v32, *(const ImS8*)v_min, *(const ImS8*)v_max, format, power, flags, out_grab_bb); if (r) *(ImS8*)v = (ImS8)v32; return r; } - case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_U32, &v32, *(const ImU8*)v_min, *(const ImU8*)v_max, format, power, flags, out_grab_bb); if (r) *(ImU8*)v = (ImU8)v32; return r; } - case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_S32, &v32, *(const ImS16*)v_min, *(const ImS16*)v_max, format, power, flags, out_grab_bb); if (r) *(ImS16*)v = (ImS16)v32; return r; } - case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_U32, &v32, *(const ImU16*)v_min, *(const ImU16*)v_max, format, power, flags, out_grab_bb); if (r) *(ImU16*)v = (ImU16)v32; return r; } + case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)p_v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_S32, &v32, *(const ImS8*)p_min, *(const ImS8*)p_max, format, power, flags, out_grab_bb); if (r) *(ImS8*)p_v = (ImS8)v32; return r; } + case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)p_v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_U32, &v32, *(const ImU8*)p_min, *(const ImU8*)p_max, format, power, flags, out_grab_bb); if (r) *(ImU8*)p_v = (ImU8)v32; return r; } + case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)p_v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_S32, &v32, *(const ImS16*)p_min, *(const ImS16*)p_max, format, power, flags, out_grab_bb); if (r) *(ImS16*)p_v = (ImS16)v32; return r; } + case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)p_v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_U32, &v32, *(const ImU16*)p_min, *(const ImU16*)p_max, format, power, flags, out_grab_bb); if (r) *(ImU16*)p_v = (ImU16)v32; return r; } case ImGuiDataType_S32: - IM_ASSERT(*(const ImS32*)v_min >= IM_S32_MIN/2 && *(const ImS32*)v_max <= IM_S32_MAX/2); - return SliderBehaviorT(bb, id, data_type, (ImS32*)v, *(const ImS32*)v_min, *(const ImS32*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const ImS32*)p_min >= IM_S32_MIN/2 && *(const ImS32*)p_max <= IM_S32_MAX/2); + return SliderBehaviorT(bb, id, data_type, (ImS32*)p_v, *(const ImS32*)p_min, *(const ImS32*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_U32: - IM_ASSERT(*(const ImU32*)v_max <= IM_U32_MAX/2); - return SliderBehaviorT(bb, id, data_type, (ImU32*)v, *(const ImU32*)v_min, *(const ImU32*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const ImU32*)p_max <= IM_U32_MAX/2); + return SliderBehaviorT(bb, id, data_type, (ImU32*)p_v, *(const ImU32*)p_min, *(const ImU32*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_S64: - IM_ASSERT(*(const ImS64*)v_min >= IM_S64_MIN/2 && *(const ImS64*)v_max <= IM_S64_MAX/2); - return SliderBehaviorT(bb, id, data_type, (ImS64*)v, *(const ImS64*)v_min, *(const ImS64*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const ImS64*)p_min >= IM_S64_MIN/2 && *(const ImS64*)p_max <= IM_S64_MAX/2); + return SliderBehaviorT(bb, id, data_type, (ImS64*)p_v, *(const ImS64*)p_min, *(const ImS64*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_U64: - IM_ASSERT(*(const ImU64*)v_max <= IM_U64_MAX/2); - return SliderBehaviorT(bb, id, data_type, (ImU64*)v, *(const ImU64*)v_min, *(const ImU64*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const ImU64*)p_max <= IM_U64_MAX/2); + return SliderBehaviorT(bb, id, data_type, (ImU64*)p_v, *(const ImU64*)p_min, *(const ImU64*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_Float: - IM_ASSERT(*(const float*)v_min >= -FLT_MAX/2.0f && *(const float*)v_max <= FLT_MAX/2.0f); - return SliderBehaviorT(bb, id, data_type, (float*)v, *(const float*)v_min, *(const float*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const float*)p_min >= -FLT_MAX/2.0f && *(const float*)p_max <= FLT_MAX/2.0f); + return SliderBehaviorT(bb, id, data_type, (float*)p_v, *(const float*)p_min, *(const float*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_Double: - IM_ASSERT(*(const double*)v_min >= -DBL_MAX/2.0f && *(const double*)v_max <= DBL_MAX/2.0f); - return SliderBehaviorT(bb, id, data_type, (double*)v, *(const double*)v_min, *(const double*)v_max, format, power, flags, out_grab_bb); + IM_ASSERT(*(const double*)p_min >= -DBL_MAX/2.0f && *(const double*)p_max <= DBL_MAX/2.0f); + return SliderBehaviorT(bb, id, data_type, (double*)p_v, *(const double*)p_min, *(const double*)p_max, format, power, flags, out_grab_bb); case ImGuiDataType_COUNT: break; } IM_ASSERT(0); return false; } -bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power) +// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a slider, they are all required. +// Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly. +bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, float power) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -2553,7 +2557,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co } } if (temp_input_is_active || temp_input_start) - return TempInputTextScalar(frame_bb, id, label, data_type, v, format); + return TempInputTextScalar(frame_bb, id, label, data_type, p_data, format); // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); @@ -2562,7 +2566,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co // Slider behavior ImRect grab_bb; - const bool value_changed = SliderBehavior(frame_bb, id, data_type, v, v_min, v_max, format, power, ImGuiSliderFlags_None, &grab_bb); + const bool value_changed = SliderBehavior(frame_bb, id, data_type, p_data, p_min, p_max, format, power, ImGuiSliderFlags_None, &grab_bb); if (value_changed) MarkItemEdited(id); @@ -2572,7 +2576,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; - const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, v, format); + const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format); RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.5f)); if (label_size.x > 0.0f) @@ -2668,7 +2672,7 @@ bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const return SliderScalarN(label, ImGuiDataType_S32, v, 4, &v_min, &v_max, format); } -bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power) +bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, float power) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -2708,7 +2712,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d // Slider behavior ImRect grab_bb; - const bool value_changed = SliderBehavior(frame_bb, id, data_type, v, v_min, v_max, format, power, ImGuiSliderFlags_Vertical, &grab_bb); + const bool value_changed = SliderBehavior(frame_bb, id, data_type, p_data, p_min, p_max, format, power, ImGuiSliderFlags_Vertical, &grab_bb); if (value_changed) MarkItemEdited(id); @@ -2719,7 +2723,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. // For the vertical slider we allow centered text to overlap the frame padding char value_buf[64]; - const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, v, format); + const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format); RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.0f)); if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); @@ -2832,7 +2836,7 @@ int ImParseFormatPrecision(const char* fmt, int default_precision) // Create text input in place of another active widget (e.g. used when doing a CTRL+Click on drag/slider widgets) // FIXME: Facilitate using this in variety of other situations. -bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* data_ptr, const char* format) +bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format) { ImGuiContext& g = *GImGui; @@ -2845,7 +2849,7 @@ bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, char fmt_buf[32]; char data_buf[32]; format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf)); - DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, data_ptr, format); + DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format); ImStrTrimBlanks(data_buf); g.CurrentWindow->DC.CursorPos = bb.Min; @@ -2860,14 +2864,16 @@ bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, } if (value_changed) { - value_changed = DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, data_ptr, NULL); + value_changed = DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL); if (value_changed) MarkItemEdited(id); } return value_changed; } -bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_ptr, const void* step, const void* step_fast, const char* format, ImGuiInputTextFlags flags) +// Note: p_data, p_step, p_step_fast are _pointers_ to a memory address holding the data. For an Input widget, p_step and p_step_fast are optional. +// Read code of e.g. InputFloat(), InputInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly. +bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -2880,7 +2886,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p format = DataTypeGetInfo(data_type)->PrintFmt; char buf[64]; - DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, data_ptr, format); + DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format); bool value_changed = false; if ((flags & (ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0) @@ -2888,7 +2894,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p flags |= ImGuiInputTextFlags_AutoSelectAll; flags |= ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselve by comparing the actual data rather than the string. - if (step != NULL) + if (p_step != NULL) { const float button_size = GetFrameHeight(); @@ -2896,7 +2902,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p PushID(label); SetNextItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2)); if (InputText("", buf, IM_ARRAYSIZE(buf), flags)) // PushId(label) + "" gives us the expected ID from outside point of view - value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, data_ptr, format); + value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, p_data, format); // Step buttons const ImVec2 backup_frame_padding = style.FramePadding; @@ -2907,13 +2913,13 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p SameLine(0, style.ItemInnerSpacing.x); if (ButtonEx("-", ImVec2(button_size, button_size), button_flags)) { - DataTypeApplyOp(data_type, '-', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast ? step_fast : step); + DataTypeApplyOp(data_type, '-', p_data, p_data, g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step); value_changed = true; } SameLine(0, style.ItemInnerSpacing.x); if (ButtonEx("+", ImVec2(button_size, button_size), button_flags)) { - DataTypeApplyOp(data_type, '+', data_ptr, data_ptr, g.IO.KeyCtrl && step_fast ? step_fast : step); + DataTypeApplyOp(data_type, '+', p_data, p_data, g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step); value_changed = true; } @@ -2931,7 +2937,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p else { if (InputText(label, buf, IM_ARRAYSIZE(buf), flags)) - value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, data_ptr, format); + value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, p_data, format); } if (value_changed) MarkItemEdited(window->DC.LastItemId); @@ -2939,7 +2945,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p return value_changed; } -bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* step, const void* step_fast, const char* format, ImGuiInputTextFlags flags) +bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -2956,10 +2962,10 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, in PushID(i); if (i > 0) SameLine(0, g.Style.ItemInnerSpacing.x); - value_changed |= InputScalar("", data_type, v, step, step_fast, format, flags); + value_changed |= InputScalar("", data_type, p_data, p_step, p_step_fast, format, flags); PopID(); PopItemWidth(); - v = (void*)((char*)v + type_size); + p_data = (void*)((char*)p_data + type_size); } PopID(); From 378035c6ff4a0cbd92140a4b39e41dbd0ba915be Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 30 Sep 2019 21:16:30 -0700 Subject: [PATCH 056/384] Fixed backspace handling on MacOS (fixed https://github.com/ocornut/imgui/issues/2817). Allow null view passing as parameter to ImGui_ImplOSX_NewFrame --- examples/imgui_impl_osx.h | 2 +- examples/imgui_impl_osx.mm | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/imgui_impl_osx.h b/examples/imgui_impl_osx.h index 66df2527..fe066eec 100644 --- a/examples/imgui_impl_osx.h +++ b/examples/imgui_impl_osx.h @@ -13,5 +13,5 @@ IMGUI_API bool ImGui_ImplOSX_Init(); IMGUI_API void ImGui_ImplOSX_Shutdown(); -IMGUI_API void ImGui_ImplOSX_NewFrame(NSView *_Nonnull view); +IMGUI_API void ImGui_ImplOSX_NewFrame(NSView *_Nullable view); IMGUI_API bool ImGui_ImplOSX_HandleEvent(NSEvent *_Nonnull event, NSView *_Nullable view); diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index 9042e15f..fd548bf6 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -150,9 +150,12 @@ void ImGui_ImplOSX_NewFrame(NSView* view) { // Setup display size ImGuiIO& io = ImGui::GetIO(); - const float dpi = [view.window backingScaleFactor]; - io.DisplaySize = ImVec2((float)view.bounds.size.width, (float)view.bounds.size.height); - io.DisplayFramebufferScale = ImVec2(dpi, dpi); + if (view) + { + const float dpi = [view.window backingScaleFactor]; + io.DisplaySize = ImVec2((float)view.bounds.size.width, (float)view.bounds.size.height); + io.DisplayFramebufferScale = ImVec2(dpi, dpi); + } // Setup time step if (g_Time == 0.0) @@ -250,7 +253,7 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) for (int i = 0; i < len; i++) { int c = [str characterAtIndex:i]; - if (!io.KeyCtrl && !(c >= 0xF700 && c <= 0xFFFF)) + if (!io.KeyCtrl && !((c >= 0xF700 && c <= 0xFFFF) || c == 127)) io.AddInputCharacter((unsigned int)c); // We must reset in case we're pressing a sequence of special keys while keeping the command pressed From fc10ba8d24ddc8b43d46d6c75b586ed75cdfb6b4 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 11 Oct 2019 14:20:04 +0200 Subject: [PATCH 057/384] Amend f0238ece9cba67ecabef438008fea53682bd6bc7 (#2817, #2818) --- docs/CHANGELOG.txt | 1 + examples/imgui_impl_osx.mm | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1d8e7e79..73492038 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,6 +43,7 @@ Other Changes: - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] +- Backends: OSX: Fix using Backspace key. (#2817, #2818) [@DiligentGraphics] ----------------------------------------------------------------------- diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index fd548bf6..a491616a 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -14,7 +14,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2019-07-21: Readded clipboard handlers as they are not enabled by default in core imgui.cpp (reverted 2019-05-18 change). +// 2019-10-11: Inputs: Fix using Backspace key. +// 2019-07-21: Re-added clipboard handlers as they are not enabled by default in core imgui.cpp (reverted 2019-05-18 change). // 2019-05-28: Inputs: Added mouse cursor shape and visibility support. // 2019-05-18: Misc: Removed clipboard handlers as they are now supported by core imgui.cpp. // 2019-05-11: Inputs: Don't filter character values before calling AddInputCharacter() apart from 0xF700..0xFFFF range. @@ -40,13 +41,13 @@ bool ImGui_ImplOSX_Init() ImGuiIO& io = ImGui::GetIO(); // Setup back-end capabilities flags - io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) + io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) //io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) //io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) //io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can set io.MouseHoveredViewport correctly (optional, not easy) io.BackendPlatformName = "imgui_impl_osx"; - // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + // Keyboard mapping. Dear ImGui will use those indices to peek into the io.KeyDown[] array. const int offset_for_function_keys = 256 - 0xF700; io.KeyMap[ImGuiKey_Tab] = '\t'; io.KeyMap[ImGuiKey_LeftArrow] = NSLeftArrowFunctionKey + offset_for_function_keys; @@ -232,7 +233,7 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) } } else - #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ + #endif // MAC_OS_X_VERSION_MAX_ALLOWED { wheel_dx = [event deltaX]; wheel_dy = [event deltaY]; @@ -253,7 +254,7 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view) for (int i = 0; i < len; i++) { int c = [str characterAtIndex:i]; - if (!io.KeyCtrl && !((c >= 0xF700 && c <= 0xFFFF) || c == 127)) + if (!io.KeyCtrl && !(c >= 0xF700 && c <= 0xFFFF) && c != 127) io.AddInputCharacter((unsigned int)c); // We must reset in case we're pressing a sequence of special keys while keeping the command pressed From aeb64814995d624f6b3c2122d9e8312474e168f6 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 14:25:18 +0200 Subject: [PATCH 058/384] InputText: Filter out Ascii 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) --- docs/CHANGELOG.txt | 3 ++- imgui_widgets.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 73492038..1ec907e8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,12 +38,13 @@ Breaking Changes: Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) +- InputText: Filter out Ascii 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] -- Backends: OSX: Fix using Backspace key. (#2817, #2818) [@DiligentGraphics] +- Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] ----------------------------------------------------------------------- diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a92eb5a9..a1560a2c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3331,6 +3331,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f return false; } + // We ignore Ascii representation of delete (emitted from Backspace on OSX, see #2578, #2817) + if (c == 127) + return false; + // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME) if (c >= 0xE000 && c <= 0xF8FF) return false; From cba84df7b59b0e181d53ca18721184391fa208f9 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 17:05:08 +0200 Subject: [PATCH 059/384] Update README.md --- docs/README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/docs/README.md b/docs/README.md index 7d29ace9..373f498f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -97,7 +97,7 @@ Dear ImGui allows you **create elaborate tools** as well as very short-lived one ### How it works -Check out the [References](#references) section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. +Check out the Wiki's [About the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#About-the-IMGUI-paradigm) section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. Dear ImGui outputs vertex buffers and command lists that you can easily render in your application. The number of draw calls and state changes required to render them is fairly small. Because Dear ImGui doesn't know or touch graphics state directly, you can call its functions anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate dear imgui with your existing codebase. @@ -192,17 +192,11 @@ Custom engine [Tracy Profiler](https://bitbucket.org/wolfpld/tracy) ![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/tracy_profiler.png) -### References +### Wiki -The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works. -- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html). -- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf). -- [Jari Komppa's tutorial on building an IMGUI library](http://iki.fi/sol/imgui/). -- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861). -- [Nicolas Guillemot's CppCon'16 flash-talk about Dear ImGui](https://www.youtube.com/watch?v=LSRJ1jZq90k). -- [Thierry Excoffier's Zero Memory Widget](http://perso.univ-lyon1.fr/thierry.excoffier/ZMW/). +See [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, articles. -See the [Wiki](https://github.com/ocornut/imgui/wiki) for more references and [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for third-party bindings to different languages and frameworks. +See [Articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#Articles-about-the-IMGUI-paradigm) to read/watch about the Immediate Mode GUI paradigm. ### Support, Frequently Asked Questions (FAQ) @@ -210,7 +204,7 @@ If you are new to Dear ImGui and have issues with: compiling, linking, adding fo Otherwise, for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. -Private support is available for paying customers. +Paid private support is available for business customers (E-mail: _contact @ dearimgui dot org_). **Where is the documentation?** From 1c73a0c17e02d44d3a814c477b9badf00c9913dd Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 17:18:44 +0200 Subject: [PATCH 060/384] Bindings --- docs/README.md | 51 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/docs/README.md b/docs/README.md index 373f498f..4a0d75de 100644 --- a/docs/README.md +++ b/docs/README.md @@ -122,52 +122,19 @@ Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/ _NB: third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users!). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ -Officially maintained bindings in repository: +Officially maintained bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. - Platforms: GLFW, SDL2, Win32, Glut, OSX. - Others: Allegro5, Marmalade. -Third-party - Languages bindings: -- C: [cimgui](https://github.com/cimgui/cimgui) (auto-generated! **you can use its json output to generate bindings for other languages**) -- C#/.Net: [ImGui.NET](https://github.com/mellinoe/ImGui.NET) -- ChaiScript: [imgui-chaiscript](https://github.com/JuJuBoSc/imgui-chaiscript) -- D: [DerelictImgui](https://github.com/Extrawurst/DerelictImgui) -- Go: [imgui-go](https://github.com/inkyblackness/imgui-go) or [go-imgui](https://github.com/Armored-Dragon/go-imgui) -- Haxe/hxcpp: [linc_imgui](https://github.com/Aidan63/linc_imgui) -- Java: [jimgui](https://github.com/ice1000/jimgui) -- JavaScript: [imgui-js](https://github.com/flyover/imgui-js) -- Julia: [CImGui.jl](https://github.com/Gnimuc/CImGui.jl) -- Lua: [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui), [imgui_lua_bindings](https://github.com/patrickriordan/imgui_lua_bindings) or [lua-ffi-bindings](https://github.com/thenumbernine/lua-ffi-bindings) -- Odin: [odin-dear_imgui](https://github.com/ThisDrunkDane/odin-dear_imgui) -- Pascal: [imgui-pas](https://github.com/dpethes/imgui-pas) -- PureBasic: [pb-cimgui](https://github.com/hippyau/pb-cimgui) -- Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy) or [ogre-imgui](https://github.com/OGRECave/ogre-imgui) -- Ruby: [ruby-imgui](https://github.com/vaiorabbit/ruby-imgui) -- Rust: [imgui-rs](https://github.com/Gekkio/imgui-rs) or [imgui-rust](https://github.com/nsf/imgui-rust) -- Swift: [swift-imgui](https://github.com/mnmly/Swift-imgui) - -Third-party - Engines/Frameworks bindings: -- bsf: [bsfimgui](https://github.com/pgruenbacher/bsfImgui) -- Cinder: [Cinder-ImGui](https://github.com/simongeilfus/Cinder-ImGui) -- Cocos2d-x: [imguix](https://github.com/c0i/imguix), [#551](https://github.com/ocornut/imgui/issues/551) -- Flexium: [FlexGUI](https://github.com/DXsmiley/FlexGUI) -- GML/GameMakerStudio2: [ImGuiGML](https://marketplace.yoyogames.com/assets/6221/imguigml) -- Irrlicht: [IrrIMGUI](https://github.com/ZahlGraf/IrrIMGUI) -- Ogre: [ogre-imgui](https://github.com/OGRECave/ogre-imgui) -- OpenFrameworks: [ofxImGui](https://github.com/jvcleave/ofxImGui) -- OpenSceneGraph/OSG: [gist](https://gist.github.com/fulezi/d2442ca7626bf270226014501357042c) -- ORX: [ImGuiOrx](https://github.com/thegwydd/ImGuiOrx), [#1843](https://github.com/ocornut/imgui/pull/1843) -- px_render: [px_render_imgui.h](https://github.com/pplux/px/blob/master/px_render_imgui.h), [#1935](https://github.com/ocornut/imgui/pull/1935) -- LÖVE+Lua: [love-imgui](https://github.com/slages/love-imgui) -- Magnum: [ImGuiIntegration](https://doc.magnum.graphics/magnum/namespaceMagnum_1_1ImGuiIntegration.html) ([example](https://doc.magnum.graphics/magnum/examples-imgui.html)) -- NanoRT: [syoyo/imgui](https://github.com/syoyo/imgui/tree/nanort) -- Qt: [imgui-qt3d](https://github.com/alpqr/imgui-qt3d) / [QOpenGLWindow (qtimgui)](https://github.com/ocornut/imgui/issues/1910) / [QtDirect3D](https://github.com/giladreich/QtDirect3D) / [qt6](https://github.com/alpqr/qvk6/tree/imgui/examples/rhi/imguidemo) -- SFML: [imgui-sfml](https://github.com/eliasdaler/imgui-sfml) -- Software renderer: [imgui_software_renderer](https://github.com/emilk/imgui_software_renderer) -- Unreal Engine 4: [segross/UnrealImGui](https://github.com/segross/UnrealImGui) or [sronsse/UnrealEngine_ImGui](https://github.com/sronsse/UnrealEngine_ImGui) -- Unmerged PR: Android: [#421](https://github.com/ocornut/imgui/pull/421) - -For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/). Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. +Third-party Languages bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): +- C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... +- The C ([cimgui](https://github.com/cimgui/cimgui)) bindings are auto-generated, **you can use its json output to generate bindings for other languages**. + +Third-party Engines/Frameworks bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): +- bsf, Cinder, Cocos2d-x, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... + +Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. ### Upcoming Changes From 58411033e262dde5be104f617495389f0cb01f67 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 17:21:11 +0200 Subject: [PATCH 061/384] Bindings --- docs/README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index 4a0d75de..cb7a50be 100644 --- a/docs/README.md +++ b/docs/README.md @@ -120,19 +120,15 @@ On most platforms and when using C++, **you should be able to use a combination Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the FAQ, comments, and one of the examples/ application!** -_NB: third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users!). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ - Officially maintained bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. - Platforms: GLFW, SDL2, Win32, Glut, OSX. -- Others: Allegro5, Marmalade. - -Third-party Languages bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): -- C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- The C ([cimgui](https://github.com/cimgui/cimgui)) bindings are auto-generated, **you can use its json output to generate bindings for other languages**. +- Frameworks: Allegro5, Marmalade. -Third-party Engines/Frameworks bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): -- bsf, Cinder, Cocos2d-x, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): +- Languages: C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... +- Frameworks: bsf, Cinder, Cocos2d-x, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +- Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. From 23eabd5991a23eee18de35d73ee6017a9a9d1a2f Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 17:41:56 +0200 Subject: [PATCH 062/384] Emscripten --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index cb7a50be..98972a8d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -123,7 +123,7 @@ Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/ Officially maintained bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. - Platforms: GLFW, SDL2, Win32, Glut, OSX. -- Frameworks: Allegro5, Marmalade. +- Frameworks: Emscripten, Allegro5, Marmalade. Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): - Languages: C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... From 8c4dcbfa45cd3669d0bdf56c517ef2b875528172 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 12 Oct 2019 17:56:32 +0200 Subject: [PATCH 063/384] Diligent Engine --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 98972a8d..c2d42591 100644 --- a/docs/README.md +++ b/docs/README.md @@ -127,7 +127,7 @@ Officially maintained bindings (in repository): Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): - Languages: C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- Frameworks: bsf, Cinder, Cocos2d-x, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +- Frameworks: bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. From 67e4cd5cc6ce1432ddf574b25008fce16ea1f5ed Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 14 Oct 2019 14:08:56 +0200 Subject: [PATCH 064/384] Comments, some logging for NavInitRequest debugging Moved OpenPopupOnItemClick() next to BeginPopupContextItem() --- docs/README.md | 2 +- imgui.cpp | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/README.md b/docs/README.md index c2d42591..2cb47404 100644 --- a/docs/README.md +++ b/docs/README.md @@ -127,7 +127,7 @@ Officially maintained bindings (in repository): Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): - Languages: C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- Frameworks: bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +- Frameworks: Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. diff --git a/imgui.cpp b/imgui.cpp index 7bf2bf59..59f6fa82 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -955,9 +955,6 @@ CODE - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window. this is also useful to set yourself in the context of another window (to get/set other settings) - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug". - - tip: the ImGuiOnceUponAFrame helper will allow run the block of code only once a frame. You can use it to quickly add custom UI in the middle - of a deep nested inner loop in your code. - - tip: you can call Render() multiple times (e.g for VR renders). - tip: call and read the ShowDemoWindow() code in imgui_demo.cpp for more example of how to use ImGui! */ @@ -7511,19 +7508,6 @@ void ImGui::OpenPopupEx(ImGuiID id) } } -bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) -{ - ImGuiWindow* window = GImGui->CurrentWindow; - if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) - { - ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict! - IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item) - OpenPopupEx(id); - return true; - } - return false; -} - void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup) { ImGuiContext& g = *GImGui; @@ -7693,6 +7677,19 @@ void ImGui::EndPopup() End(); } +bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) +{ + ImGuiWindow* window = GImGui->CurrentWindow; + if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + { + ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict! + IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item) + OpenPopupEx(id); + return true; + } + return false; +} + // This is a helper to handle the simplest case of associating one named popup to one given widget. // You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters). // You can pass a NULL str_id to use the identifier of the last item. @@ -8181,6 +8178,7 @@ void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) if (!(window->Flags & ImGuiWindowFlags_NoNavInputs)) if (!(window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_Popup) || (window->NavLastIds[0] == 0) || force_reinit) init_for_nav = true; + //IMGUI_DEBUG_LOG("[Nav] NavInitWindow() init_for_nav=%d, window=\"%s\", layer=%d\n", init_for_nav, window->Name, g.NavLayer); if (init_for_nav) { SetNavID(0, g.NavLayer); @@ -8297,6 +8295,7 @@ static void ImGui::NavUpdate() if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove) && g.NavWindow) { // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called) + //IMGUI_DEBUG_LOG("[Nav] Apply NavInitRequest result: 0x%08X Layer %d in \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name); if (g.NavInitRequestFromMove) SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel); else @@ -8455,6 +8454,7 @@ static void ImGui::NavUpdate() } if (g.NavMoveRequest && g.NavId == 0) { + //IMGUI_DEBUG_LOG("[Nav] NavInitRequest from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer); g.NavInitRequest = g.NavInitRequestFromMove = true; g.NavInitResultId = 0; g.NavDisableHighlight = false; From c7bdec7e18801efe300ab46ccacc44f10f8bb3f7 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 14 Oct 2019 22:43:04 +0200 Subject: [PATCH 065/384] InputText, Nav: Fixed Left!Right keys broken when activating Keyboard Navigation. (#787) Amend 892dfb1 --- imgui_internal.h | 2 +- imgui_widgets.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index 201a071c..83b66955 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1648,7 +1648,7 @@ namespace ImGui IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - // 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while. + // [1.71: 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while] inline void RenderArrow(ImVec2 pos, ImGuiDir dir, float scale=1.0f) { ImGuiWindow* window = GetCurrentWindow(); RenderArrow(window->DrawList, pos, GetColorU32(ImGuiCol_Text), dir, scale); } inline void RenderBullet(ImVec2 pos) { ImGuiWindow* window = GetCurrentWindow(); RenderBullet(window->DrawList, pos, GetColorU32(ImGuiCol_Text)); } #endif diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a1560a2c..a955daad 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3523,6 +3523,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Declare our inputs IM_ASSERT(ImGuiNavInput_COUNT < 32); + g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); if (is_multiline || (flags & ImGuiInputTextFlags_CallbackHistory)) g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); From a41f0b2df47193c3c755f0703dfba85c4baec253 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 14 Oct 2019 23:07:06 +0200 Subject: [PATCH 066/384] Inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. IMPORTANT: Renamed internal CalcTypematicPressedRepeatAmount to CalcTypematicRepeatAmount and reordered the t1, t0 arguments to t0, t1 !! If you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. --- docs/CHANGELOG.txt | 11 +++++++++-- imgui.cpp | 34 +++++++++++++++++++++++----------- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1ec907e8..16d53e02 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,11 +34,18 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Breaking Changes: -- +- Inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used + by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. + If you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can + add +io.KeyRepeatDelay to it to compensate for the fix. + The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). + Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). + Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. + If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) -- InputText: Filter out Ascii 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) +- InputText: Filter out ASCII 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data diff --git a/imgui.cpp b/imgui.cpp index 59f6fa82..03ad95fd 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -369,6 +369,10 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. + if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. + The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). + If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. - 2019/07/15 (1.72) - removed TreeAdvanceToLabelPos() which is rarely used and only does SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()). Kept redirection function (will obsolete). - 2019/07/12 (1.72) - renamed ImFontAtlas::CustomRect to ImFontAtlasCustomRect. Kept redirection typedef (will obsolete). - 2019/06/14 (1.72) - removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): ImGuiCol_Column*, ImGuiSetCond_*, IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow(), IMGUI_ONCE_UPON_A_FRAME. Grep this log for details and new names. @@ -1206,7 +1210,7 @@ ImGuiIO::ImGuiIO() MouseDoubleClickMaxDist = 6.0f; for (int i = 0; i < ImGuiKey_COUNT; i++) KeyMap[i] = -1; - KeyRepeatDelay = 0.250f; + KeyRepeatDelay = 0.275f; KeyRepeatRate = 0.050f; UserData = NULL; @@ -4402,14 +4406,22 @@ bool ImGui::IsKeyDown(int user_key_index) return g.IO.KeysDown[user_key_index]; } -int ImGui::CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate) +// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime) +// t1 = current time (e.g.: g.Time) +// An event is triggered at: +// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N +int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate) { - if (t == 0.0f) + if (t1 == 0.0f) return 1; - if (t <= repeat_delay || repeat_rate <= 0.0f) + if (t0 >= t1) return 0; - const int count = (int)((t - repeat_delay) / repeat_rate) - (int)((t_prev - repeat_delay) / repeat_rate); - return (count > 0) ? count : 0; + if (repeat_rate <= 0.0f) + return (t0 < repeat_delay) && (t1 >= repeat_delay); + const int count_t0 = (t0 < repeat_delay) ? -1 : (int)((t0 - repeat_delay) / repeat_rate); + const int count_t1 = (t1 < repeat_delay) ? -1 : (int)((t1 - repeat_delay) / repeat_rate); + const int count = count_t1 - count_t0; + return count; } int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate) @@ -4419,7 +4431,7 @@ int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_r return 0; IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); const float t = g.IO.KeysDownDuration[key_index]; - return CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, repeat_delay, repeat_rate); + return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate); } bool ImGui::IsKeyPressed(int user_key_index, bool repeat) @@ -4471,7 +4483,7 @@ bool ImGui::IsMouseClicked(int button, bool repeat) if (repeat && t > g.IO.KeyRepeatDelay) { // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold. - int amount = CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.5f); + int amount = CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.50f); if (amount > 0) return true; } @@ -8228,11 +8240,11 @@ float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode) if (mode == ImGuiInputReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input. return (t == 0.0f) ? 1.0f : 0.0f; if (mode == ImGuiInputReadMode_Repeat) - return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f); + return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.80f); if (mode == ImGuiInputReadMode_RepeatSlow) - return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 1.00f, g.IO.KeyRepeatRate * 2.00f); + return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 1.25f, g.IO.KeyRepeatRate * 2.00f); if (mode == ImGuiInputReadMode_RepeatFast) - return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.30f); + return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.30f); return 0.0f; } diff --git a/imgui_internal.h b/imgui_internal.h index 83b66955..e7868613 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1581,7 +1581,7 @@ namespace ImGui IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags); IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode); IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); - IMGUI_API int CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate); + IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. IMGUI_API void SetNavID(ImGuiID id, int nav_layer); IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a955daad..b2398a00 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -487,7 +487,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool { hovered = true; SetHoveredID(id); - if (CalcTypematicPressedRepeatAmount(g.HoveredIdTimer + 0.0001f, g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, 0.01f, 0.70f)) // FIXME: Our formula for CalcTypematicPressedRepeatAmount() is fishy + if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, 0.70f, 0.00f)) { pressed = true; FocusWindow(window); From c21fdabb438f611f263d264f14fcd021df531bb4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 15 Oct 2019 13:00:04 +0200 Subject: [PATCH 067/384] Doc: Readme: moving contents to FAQ. --- docs/README.md | 97 ++++++++---------- imgui.cpp | 265 ++++++++----------------------------------------- 2 files changed, 82 insertions(+), 280 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2cb47404..1991b954 100644 --- a/docs/README.md +++ b/docs/README.md @@ -118,7 +118,7 @@ The demo applications are not DPI aware so expect some blurriness on a 4K screen On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/examples) files without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more of the imgui_impl_xxxx files instead of rewriting them: this will be less work for you and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom binding using your custom engine functions if you wish so. -Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the FAQ, comments, and one of the examples/ application!** +Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the [FAQ](https://github.com/ocornut/imgui/wiki/FAQ), comments, and one of the examples/ application!** Officially maintained bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. @@ -144,7 +144,7 @@ Some of the goals for 2019 are: ### Gallery -For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/2529)! +For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! Custom engine [![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) @@ -155,79 +155,62 @@ Custom engine [Tracy Profiler](https://bitbucket.org/wolfpld/tracy) ![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/tracy_profiler.png) -### Wiki - -See [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, articles. - -See [Articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#Articles-about-the-IMGUI-paradigm) to read/watch about the Immediate Mode GUI paradigm. - ### Support, Frequently Asked Questions (FAQ) -If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forums](https://discourse.dearimgui.org). - -Otherwise, for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. - -Paid private support is available for business customers (E-mail: _contact @ dearimgui dot org_). +Most common questions will be answered by the [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/wiki/FAQ) page, e.g.: -**Where is the documentation?** +**Basics** +- "Where is the documentation?" +- "Which version should I get?" +- "Why the names "Dear ImGui" vs "ImGui"?" - This library is poorly documented at the moment and expects of the user to be acquainted with C/C++. - - Run the examples/ applications and explore them. - - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. - - The demo covers most features of Dear ImGui, so you can read the code and see its output. - - See documentation and comments at the top of imgui.cpp + effectively imgui.h. - - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder to explain how to integrate Dear ImGui with your own engine/application. - - Your programming IDE is your friend, find the type or function declaration to find comments associated with it. - - We obviously need better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort. +**Community** +- "How can I help?" -**Which version should I get?** +**Concerns** +- "Who uses Dear ImGui?" +- "Can you create elaborate/serious tools with Dear ImGui?" +- "Can you reskin the look of Dear ImGui?" +- "Why using C++ (as opposed to C)?" -I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. +**Integration** +- "How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?" +- "How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)" +- "I integrated Dear ImGui in my engine and the text or lines are blurry.." +- "I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.." -You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) features in the `docking` branch. Many projects are using this branch and it is kept in sync with master regularly. +**Usage** +- "Why are multiple widgets reacting when I interact with a single one? How can I have multiple widgets with the same label or with an empty label?" +- "How can I display an image? What is ImTextureID, how does it work?" +- "How can I use my own math types instead of ImVec2/ImVec4?" +- "How can I interact with standard C++ types (such as std::string and std::vector)?" +- "How can I use low-level drawing facilities? (using ImDrawList API)" -**Who uses Dear ImGui?** +**Fonts, Text** +- "How can I load a different font than the default?" +- "How can I easily use icons in my application?" +- "How can I load multiple fonts?" +- "How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?" -See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for a list of games/software which are publicly known to use dear imgui. Please add yours if you can! +See: [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, articles. -**Why the odd dual naming, "Dear ImGui" vs "ImGui"?** +See: [Articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#Articles-about-the-IMGUI-paradigm) to read/learn about the Immediate Mode GUI paradigm. -The library started its life as "ImGui" due to the fact that I didn't give it a proper name when I released 1.0 and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses its own implementation of the IMGUI paradigm). To reduce this ambiguity without affecting existing codebases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. Please try to refer to this library as "Dear ImGui". - -**How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?** -
**How can I display an image? What is ImTextureID, how does it works?** ([examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples)) -
**Why are multiple widgets reacting when I interact with a single one? How can I have multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack...** -
**How can I use my own math types instead of ImVec2/ImVec4?** -
**How can I load a different font than the default?** -
**How can I easily use icons in my application?** -
**How can I load multiple fonts?** -
**How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?** ([examples](https://github.com/ocornut/imgui/wiki/Loading-Font-Example)) -
**How can I interact with standard C++ types (such as std::string and std::vector)?** -
**How can I use the drawing facilities without a Dear ImGui window? (using ImDrawList API)** -
**How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)** -
**I integrated Dear ImGui in my engine and the text or lines are blurry..** -
**I integrated Dear ImGui in my engine and some elements are disappearing when I move windows around..** -
**How can I help?** - -See the FAQ in [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) for answers. - -**Can you create elaborate/serious tools with Dear ImGui?** - -Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. +If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forums](https://discourse.dearimgui.org). -Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. +Otherwise, for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. -**Can you reskin the look of Dear ImGui?** +Paid private support is available for business customers (E-mail: _contact @ dearimgui dot org_). -You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Below is a screenshot from [LumixEngine](https://github.com/nem0/LumixEngine) with custom colors + a docking/tabs extension (both of which you can find in the Issues section and will eventually be merged): +**Which version should I get?** -![LumixEngine](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v151/lumix-201710-rearranged.png) +I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. -**Why using C++ (as opposed to C)?** +You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) features in the `docking` branch. Many projects are using this branch and it is kept in sync with master regularly. -Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. +**Who uses Dear ImGui?** -There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. +See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for a list of games/software which are publicly known to use dear imgui. Please add yours if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! How to help ----------- diff --git a/imgui.cpp b/imgui.cpp index 03ad95fd..390f555f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6,7 +6,7 @@ // Get latest version at https://github.com/ocornut/imgui // Releases change-log at https://github.com/ocornut/imgui/releases // Technical Support for Getting Started https://discourse.dearimgui.org/c/getting-started -// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2529 +// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2847 // Developed by Omar Cornut and every direct or indirect contributors to the GitHub. // See LICENSE.txt for copyright and licensing details (standard MIT License). @@ -36,7 +36,8 @@ DOCUMENTATION - This is how a simple rendering function may look like. - Using gamepad/keyboard navigation controls. - API BREAKING CHANGES (read me when you update!) -- FREQUENTLY ASKED QUESTIONS (FAQ), TIPS +- FREQUENTLY ASKED QUESTIONS (FAQ) + - All answers in https://github.com/ocornut/imgui/wiki/FAQ - Where is the documentation? - Which version should I get? - Who uses Dear ImGui? @@ -576,6 +577,13 @@ CODE FREQUENTLY ASKED QUESTIONS (FAQ), TIPS ====================================== + All answers in: https://github.com/ocornut/imgui/wiki/FAQ + Some answers are copied down here to facilitate searching in code or because they are most likely to + be varying depending on your version of the code. + + Q&A: Basics + =========== + Q: Where is the documentation? A: This library is poorly documented at the moment and expects of the user to be acquainted with C/C++. - Run the examples/ and explore them. @@ -588,26 +596,20 @@ CODE associated to it. Q: Which version should I get? - A: I occasionally tag Releases (https://github.com/ocornut/imgui/releases) but it is generally safe - and recommended to sync to master/latest. The library is fairly stable and regressions tend to be - fixed fast when reported. You may also peak at the 'docking' branch which includes: - - Docking/Merging features (https://github.com/ocornut/imgui/issues/2109) - - Multi-viewport features (https://github.com/ocornut/imgui/issues/1542) - Many projects are using this branch and it is kept in sync with master regularly. + Q: Why the names "Dear ImGui" vs "ImGui"? + A: See https://github.com/ocornut/imgui/wiki/FAQ + + Q&A: Concerns + ============= Q: Who uses Dear ImGui? - A: See "Quotes" (https://github.com/ocornut/imgui/wiki/Quotes) and - "Software using Dear ImGui" (https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages - for a list of games/software which are publicly known to use dear imgui. Please add yours if you can! - - Q: Why the odd dual naming, "Dear ImGui" vs "ImGui"? - A: The library started its life as "ImGui" due to the fact that I didn't give it a proper name when - when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI - (immediate-mode graphical user interface) was coined before and is being used in variety of other - situations (e.g. Unity uses it own implementation of the IMGUI paradigm). - To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, - longer name "Dear ImGui" that people can use to refer to this specific library. - Please try to refer to this library as "Dear ImGui". + Q: Can you create elaborate/serious tools with Dear ImGui? + Q: Can you reskin the look of Dear ImGui? + Q: Why using C++ (as opposed to C)? + A: See https://github.com/ocornut/imgui/wiki/FAQ + + Q&A: Integration + ================ Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application? A: You can read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags from the ImGuiIO structure (e.g. if (ImGui::GetIO().WantCaptureMouse) { ... } ) @@ -623,76 +625,14 @@ CODE Note: Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) + + Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) + Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. + Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. + A: See https://github.com/ocornut/imgui/wiki/FAQ - Q: How can I display an image? What is ImTextureID, how does it works? - A: Short explanation: - - Please read Wiki entry for examples: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples - - You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures. - - Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value. - - Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). - Please read documentations or tutorials on your graphics API to understand how to display textures on the screen before moving onward. - - Long explanation: - - Dear ImGui's job is to create "meshes", defined in a renderer-agnostic format made of draw commands and vertices. - At the end of the frame those meshes (ImDrawList) will be displayed by your rendering function. They are made up of textured polygons and the code - to render them is generally fairly short (a few dozen lines). In the examples/ folder we provide functions for popular graphics API (OpenGL, DirectX, etc.). - - Each rendering function decides on a data type to represent "textures". The concept of what is a "texture" is entirely tied to your underlying engine/graphics API. - We carry the information to identify a "texture" in the ImTextureID type. - ImTextureID is nothing more that a void*, aka 4/8 bytes worth of data: just enough to store 1 pointer or 1 integer of your choice. - Dear ImGui doesn't know or understand what you are storing in ImTextureID, it merely pass ImTextureID values until they reach your rendering function. - - In the examples/ bindings, for each graphics API binding we decided on a type that is likely to be a good representation for specifying - an image from the end-user perspective. This is what the _examples_ rendering functions are using: - - OpenGL: ImTextureID = GLuint (see ImGui_ImplOpenGL3_RenderDrawData() function in imgui_impl_opengl3.cpp) - DirectX9: ImTextureID = LPDIRECT3DTEXTURE9 (see ImGui_ImplDX9_RenderDrawData() function in imgui_impl_dx9.cpp) - DirectX11: ImTextureID = ID3D11ShaderResourceView* (see ImGui_ImplDX11_RenderDrawData() function in imgui_impl_dx11.cpp) - DirectX12: ImTextureID = D3D12_GPU_DESCRIPTOR_HANDLE (see ImGui_ImplDX12_RenderDrawData() function in imgui_impl_dx12.cpp) - - For example, in the OpenGL example binding we store raw OpenGL texture identifier (GLuint) inside ImTextureID. - Whereas in the DirectX11 example binding we store a pointer to ID3D11ShaderResourceView inside ImTextureID, which is a higher-level structure - tying together both the texture and information about its format and how to read it. - - If you have a custom engine built over e.g. OpenGL, instead of passing GLuint around you may decide to use a high-level data type to carry information about - the texture as well as how to display it (shaders, etc.). The decision of what to use as ImTextureID can always be made better knowing how your codebase - is designed. If your engine has high-level data types for "textures" and "material" then you may want to use them. - If you are starting with OpenGL or DirectX or Vulkan and haven't built much of a rendering engine over them, keeping the default ImTextureID - representation suggested by the example bindings is probably the best choice. - (Advanced users may also decide to keep a low-level type in ImTextureID, and use ImDrawList callback and pass information to their renderer) - - User code may do: - - // Cast our texture type to ImTextureID / void* - MyTexture* texture = g_CoffeeTableTexture; - ImGui::Image((void*)texture, ImVec2(texture->Width, texture->Height)); - - The renderer function called after ImGui::Render() will receive that same value that the user code passed: - - // Cast ImTextureID / void* stored in the draw command as our texture type - MyTexture* texture = (MyTexture*)pcmd->TextureId; - MyEngineBindTexture2D(texture); - - Once you understand this design you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. - This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. - If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. - - Refer to the Wiki to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11: - - https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples - - C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa. - Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*. - Examples: - - GLuint my_tex = XXX; - void* my_void_ptr; - my_void_ptr = (void*)(intptr_t)my_tex; // cast a GLuint into a void* (we don't take its address! we literally store the value inside the pointer) - my_tex = (GLuint)(intptr_t)my_void_ptr; // cast a void* into a GLuint - - ID3D11ShaderResourceView* my_dx11_srv = XXX; - void* my_void_ptr; - my_void_ptr = (void*)my_dx11_srv; // cast a ID3D11ShaderResourceView* into an opaque void* - my_dx11_srv = (ID3D11ShaderResourceView*)my_void_ptr; // cast a void* into a ID3D11ShaderResourceView* - - Finally, you may call ImGui::ShowMetricsWindow() to explore/visualize/understand how the ImDrawList are generated. + Q&A: Usage + ---------- Q: Why are multiple widgets reacting when I interact with a single one? Q: How can I have multiple widgets with the same label or with an empty label? @@ -810,141 +750,25 @@ CODE e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. See what makes more sense in your situation! + Q: How can I display an image? What is ImTextureID, how does it works? + A: See https://github.com/ocornut/imgui/wiki/FAQ and https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples + Q: How can I use my own math types instead of ImVec2/ImVec4? - A: You can edit imconfig.h and setup the IM_VEC2_CLASS_EXTRA/IM_VEC4_CLASS_EXTRA macros to add implicit type conversions. - This way you'll be able to use your own types everywhere, e.g. passing glm::vec2 to ImGui functions instead of ImVec2. + Q: How can I interact with standard C++ types (such as std::string and std::vector)? + Q: How can I use low-level drawing facilities? (using ImDrawList API) + A: See https://github.com/ocornut/imgui/wiki/FAQ - Q: How can I load a different font than the default? - A: Use the font atlas to load the TTF/OTF file you want: - ImGuiIO& io = ImGui::GetIO(); - io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); - io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() - Default is ProggyClean.ttf, monospace, rendered at size 13, embedded in dear imgui's source code. - (Tip: monospace fonts are convenient because they allow to facilitate horizontal alignment directly at the string level.) - (Read the 'misc/fonts/README.txt' file for more details about font loading.) - - New programmers: remember that in C/C++ and most programming languages if you want to use a - backslash \ within a string literal, you need to write it double backslash "\\": - io.Fonts->AddFontFromFileTTF("MyDataFolder\MyFontFile.ttf", size_in_pixels); // WRONG (you are escape the M here!) - io.Fonts->AddFontFromFileTTF("MyDataFolder\\MyFontFile.ttf", size_in_pixels); // CORRECT - io.Fonts->AddFontFromFileTTF("MyDataFolder/MyFontFile.ttf", size_in_pixels); // ALSO CORRECT + Q&A: Fonts, Text + ================ + Q: How can I load a different font than the default? Q: How can I easily use icons in my application? - A: The most convenient and practical way is to merge an icon font such as FontAwesome inside you - main font. Then you can refer to icons within your strings. - You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment. - (Read the 'misc/fonts/README.txt' file for more details about icons font loading.) - With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, - and copying your own graphics data into it. See misc/fonts/README.txt about using the AddCustomRectFontGlyph API. - Q: How can I load multiple fonts? - A: Use the font atlas to pack them into a single texture: - (Read the 'misc/fonts/README.txt' file and the code in ImFontAtlas for more details.) - - ImGuiIO& io = ImGui::GetIO(); - ImFont* font0 = io.Fonts->AddFontDefault(); - ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); - ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels); - io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() - // the first loaded font gets used by default - // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime - - // Options - ImFontConfig config; - config.OversampleH = 2; - config.OversampleV = 1; - config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixels up - config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters - io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config); - - // Combine multiple fonts into one (e.g. for icon fonts) - static ImWchar ranges[] = { 0xf000, 0xf3ff, 0 }; - ImFontConfig config; - config.MergeMode = true; - io.Fonts->AddFontDefault(); - io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); // Merge icon font - io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs - Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? - A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. - - // Add default Japanese ranges - io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); - - // Or create your own custom ranges (e.g. for a game you can feed your entire game script and only build the characters the game need) - ImVector ranges; - ImFontGlyphRangesBuilder builder; - builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters) - builder.AddChar(0x7262); // Add a specific character - builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges - builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) - io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, ranges.Data); - - All your strings needs to use UTF-8 encoding. In C++11 you can encode a string literal in UTF-8 - by using the u8"hello" syntax. Specifying literal in your source code using a local code page - (such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! - Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. - - Text input: it is up to your application to pass the right character code by calling io.AddInputCharacter(). - The applications in examples/ are doing that. - Windows: you can use the WM_CHAR or WM_UNICHAR or WM_IME_CHAR message (depending if your app is built using Unicode or MultiByte mode). - You may also use MultiByteToWideChar() or ToUnicode() to retrieve Unicode codepoints from MultiByte characters or keyboard state. - Windows: if your language is relying on an Input Method Editor (IME), you copy the HWND of your window to io.ImeWindowHandle in order for - the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft IME position correctly. + A: See https://github.com/ocornut/imgui/wiki/FAQ and misc/fonts/README.txt - Q: How can I interact with standard C++ types (such as std::string and std::vector)? - A: - Being highly portable (bindings for several languages, frameworks, programming style, obscure or older platforms/compilers), - and aiming for compatibility & performance suitable for every modern real-time game engines, dear imgui does not use - any of std C++ types. We use raw types (e.g. char* instead of std::string) because they adapt to more use cases. - - To use ImGui::InputText() with a std::string or any resizable string class, see misc/cpp/imgui_stdlib.h. - - To use combo boxes and list boxes with std::vector or any other data structure: the BeginCombo()/EndCombo() API - lets you iterate and submit items yourself, so does the ListBoxHeader()/ListBoxFooter() API. - Prefer using them over the old and awkward Combo()/ListBox() api. - - Generally for most high-level types you should be able to access the underlying data type. - You may write your own one-liner wrappers to facilitate user code (tip: add new functions in ImGui:: namespace from your code). - - Dear ImGui applications often need to make intensive use of strings. It is expected that many of the strings you will pass - to the API are raw literals (free in C/C++) or allocated in a manner that won't incur a large cost on your application. - Please bear in mind that using std::string on applications with large amount of UI may incur unsatisfactory performances. - Modern implementations of std::string often include small-string optimization (which is often a local buffer) but those - are not configurable and not the same across implementations. - - If you are finding your UI traversal cost to be too large, make sure your string usage is not leading to excessive amount - of heap allocations. Consider using literals, statically sized buffers and your own helper functions. A common pattern - is that you will need to build lots of strings on the fly, and their maximum length can be easily be scoped ahead. - One possible implementation of a helper to facilitate printf-style building of strings: https://github.com/ocornut/Str - This is a small helper where you can instance strings with configurable local buffers length. Many game engines will - provide similar or better string helpers. - - Q: How can I use the drawing facilities without an ImGui window? (using ImDrawList API) - A: - You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags. - (The ImGuiWindowFlags_NoDecoration flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse) - Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. - - You can call ImGui::GetBackgroundDrawList() or ImGui::GetForegroundDrawList() and use those draw list to display - contents behind or over every other imgui windows (one bg/fg drawlist per viewport). - - You can create your own ImDrawList instance. You'll need to initialize them ImGui::GetDrawListSharedData(), or create - your own ImDrawListSharedData, and then call your rendered code with your own ImDrawList or ImDrawData data. - - Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) - A: - You can control Dear ImGui with a gamepad. Read about navigation in "Using gamepad/keyboard navigation controls". - (short version: map gamepad inputs into the io.NavInputs[] array + set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad) - - You can share your computer mouse seamlessly with your console/tablet/phone using Synergy (https://symless.com/synergy) - This is the preferred solution for developer productivity. - In particular, the "micro-synergy-client" repository (https://github.com/symless/micro-synergy-client) has simple - and portable source code (uSynergy.c/.h) for a small embeddable client that you can use on any platform to connect - to your host computer, based on the Synergy 1.x protocol. Make sure you download the Synergy 1 server on your computer. - Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-like protocols. - - You may also use a third party solution such as Remote ImGui (https://github.com/JordiRos/remoteimgui) which sends - the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. - - For touch inputs, you can increase the hit box of widgets (via the style.TouchPadding setting) to accommodate - for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing - for screen real-estate and precision. - - Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. - A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). - Also make sure your orthographic projection matrix and io.DisplaySize matches your actual framebuffer dimension. - - Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. - A: You are probably mishandling the clipping rectangles in your render function. - Rectangles provided by ImGui are defined as (x1=left,y1=top,x2=right,y2=bottom) and NOT as (x1,y1,width,height). + Q&A: Community + ============== Q: How can I help? A: - If you are experienced with Dear ImGui and C++, look at the github issues, look at the Wiki, read docs/TODO.txt @@ -952,15 +776,10 @@ CODE - Businesses: convince your company to fund development via support contracts/sponsoring! This is among the most useful thing you can do for dear imgui. - Individuals: you can also become a Patron (http://www.patreon.com/imgui) or donate on PayPal! See README. - Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. - You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/1902). Visuals are ideal as they inspire other programmers. + You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues (on github or privately). - - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window. - this is also useful to set yourself in the context of another window (to get/set other settings) - - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug". - - tip: call and read the ShowDemoWindow() code in imgui_demo.cpp for more example of how to use ImGui! - */ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) From 6892b8157825e69a3c426b4d49842a0a96ef82c8 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 15 Oct 2019 16:20:27 +0300 Subject: [PATCH 068/384] Remove trailing spaces from bunch of files. (cherry picked from commit 50e0f8d4ddf4c426f62f346c8260a927f6b7c779) --- examples/example_glfw_opengl2/main.cpp | 4 ++-- examples/example_glfw_vulkan/main.cpp | 4 ++-- examples/example_sdl_directx11/main.cpp | 2 +- examples/example_sdl_opengl2/main.cpp | 2 +- examples/example_sdl_opengl3/main.cpp | 2 +- examples/example_sdl_vulkan/main.cpp | 4 ++-- examples/imgui_impl_opengl3.cpp | 4 ++-- examples/imgui_impl_opengl3.h | 4 ++-- examples/imgui_impl_vulkan.cpp | 2 +- examples/imgui_impl_vulkan.h | 8 ++++---- imgui.cpp | 4 ++-- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 0a7aa3c3..4b4a5fe3 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -134,9 +134,9 @@ int main(int, char**) glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); - // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), + // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), // you may need to backup/reset/restore current shader using the commented lines below. - //GLint last_program; + //GLint last_program; //glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); //glUseProgram(0); ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index fc3c1efb..fb92bad8 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -4,7 +4,7 @@ // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. // You will use those if you want to use this rendering back-end in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by +// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by // the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. // Read comments in imgui_impl_vulkan.h. @@ -194,7 +194,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) } } -// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo. +// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo. // Your real engine/app may not use them. static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) { diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 680f179e..b6345bd1 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -26,7 +26,7 @@ void CleanupRenderTarget(); int main(int, char**) { // Setup SDL - // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 9bc88d90..9a0f07c6 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -17,7 +17,7 @@ int main(int, char**) { // Setup SDL - // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 16415465..03cd3a7b 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -27,7 +27,7 @@ int main(int, char**) { // Setup SDL - // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index 12c262e9..1969b452 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -4,7 +4,7 @@ // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. // You will use those if you want to use this rendering back-end in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by +// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by // the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. // Read comments in imgui_impl_vulkan.h. @@ -186,7 +186,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) } } -// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo. +// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo. // Your real engine/app may not use them. static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) { diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index e1eee236..d7b108ef 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -159,9 +159,9 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) strcpy(g_GlslVersionString, glsl_version); strcat(g_GlslVersionString, "\n"); - // Dummy construct to make it easily visible in the IDE and debugger which GL loader has been selected. + // Dummy construct to make it easily visible in the IDE and debugger which GL loader has been selected. // The code actually never uses the 'gl_loader' variable! It is only here so you can read it! - // If auto-detection fails or doesn't select the same GL loader file as used by your application, + // If auto-detection fails or doesn't select the same GL loader file as used by your application, // you are likely to get a crash below. // You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. const char* gl_loader = "Unknown"; diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 1cb790b1..75f8f8c8 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -40,8 +40,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android // Desktop OpenGL: attempt to detect default GL loader based on available header files. -// If auto-detection fails or doesn't select the same GL loader file as used by your application, -// you are likely to get a crash in ImGui_ImplOpenGL3_Init(). +// If auto-detection fails or doesn't select the same GL loader file as used by your application, +// you are likely to get a crash in ImGui_ImplOpenGL3_Init(). // You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 9d977f00..2b8a3702 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -16,7 +16,7 @@ // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. // You will use those if you want to use this rendering back-end in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by +// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by // the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. // Read comments in imgui_impl_vulkan.h. diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h index f2bf9293..5b0bd7b3 100644 --- a/examples/imgui_impl_vulkan.h +++ b/examples/imgui_impl_vulkan.h @@ -16,7 +16,7 @@ // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. // You will use those if you want to use this rendering back-end in your engine/app. -// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by +// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by // the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. // Read comments in imgui_impl_vulkan.h. @@ -116,9 +116,9 @@ struct ImGui_ImplVulkanH_Window ImGui_ImplVulkanH_Frame* Frames; ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores; - ImGui_ImplVulkanH_Window() - { - memset(this, 0, sizeof(*this)); + ImGui_ImplVulkanH_Window() + { + memset(this, 0, sizeof(*this)); PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR; ClearEnable = true; } diff --git a/imgui.cpp b/imgui.cpp index 390f555f..fc155333 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2327,7 +2327,7 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con float ellipsis_glyph_width = glyph->X1; // Width of the glyph with no padding on either side float ellipsis_total_width = ellipsis_glyph_width; // Full width of entire ellipsis - + if (ellipsis_char_count > 1) { // Full ellipsis size without free spacing after it. @@ -2335,7 +2335,7 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con ellipsis_glyph_width = glyph->X1 - glyph->X0 + spacing_between_dots; ellipsis_total_width = ellipsis_glyph_width * (float)ellipsis_char_count - spacing_between_dots; } - + // We can now claim the space between pos_max.x and ellipsis_max.x const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f); float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x; From 9d6b2b096b20fa654c84fd8bb4d9631c250b33d6 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 15 Oct 2019 15:48:46 +0300 Subject: [PATCH 069/384] Ignore directories created by JetBrains IDEs. (cherry picked from commit c470de572c2f63e7ba5eeb7d97bc1f4bc114b375) --- examples/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/.gitignore b/examples/.gitignore index d56b94f0..2b5671a8 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -40,3 +40,7 @@ example_sdl_opengl3/example_sdl_opengl3 ## Dear ImGui Ini files imgui.ini + +## JetBrains IDEs +.idea +cmake-build-* From 5fc427a49e1f2935b26e211ddcd5b9c32e3eee61 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 16 Oct 2019 11:03:41 +0200 Subject: [PATCH 070/384] Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. (#2848) --- docs/CHANGELOG.txt | 2 + docs/FAQ.md | 510 +++++++++++++++++++++++++++++++++++++++++++++ imgui.cpp | 52 ++--- 3 files changed, 528 insertions(+), 36 deletions(-) create mode 100644 docs/FAQ.md diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 16d53e02..ee9fcdd2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,8 @@ Other Changes: incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) +- Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] +- Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] diff --git a/docs/FAQ.md b/docs/FAQ.md new file mode 100644 index 00000000..9fc36234 --- /dev/null +++ b/docs/FAQ.md @@ -0,0 +1,510 @@ +# FAQ (Frequenty Asked Questions) + +You may browse this document at: + https://github.com/ocornut/imgui/blob/master/docs/FAQ.md +or use any Markdown viewer. + + +## Index + +| **Q&A: Basics** | +:---------------------------------------------------------- | +| [Where is the documentation?](#q-where-is-the-documentation) | +| [Which version should I get?](#q-which-version-should-i-get) | +| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-names-dear-imgui-vs-imgui) | +| **Q&A: Concerns** | +| [Who uses Dear ImGui?](#q-who-uses-dear-imgui) | +| [Can you create elaborate/serious tools with Dear ImGui?](#q-can-you-create-elaborateserious-tools-with-dear-imgui) | +| [Can you reskin the look of Dear ImGui?](#q-can-you-reskin-the-look-of-dear-imgui) | +| [Why using C++ (as opposed to C)?](#q-why-using-c-as-opposed-to-c) | +| **Q&A: Integration** | +| [How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?](#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application) | +| [How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)](#q-how-can-i-use-this-without-a-mouse-without-a-keyboard-or-without-a-screen-gamepad-input-share-remote-display) | +| [I integrated Dear ImGui in my engine and the text or lines are blurry..](#q-i-integrated-dear-imgui-in-my-engine-and-the-text-or-lines-are-blurry) | +| [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) | +| **Q&A: Usage** | +| [Why are multiple widgets reacting when I interact with a single one?
How can I have multiple widgets with the same label or with an empty label?](#q-why-are-multiple-widgets-reacting-when-i-interact-with-a-single-one-q-how-can-i-have-multiple-widgets-with-the-same-label-or-with-an-empty-label) | +| [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| +| [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | +| [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | +| [How can I use low-level drawing facilities? (using ImDrawList API)](#q-how-can-i-use-low-level-drawing-facilities-using-imdrawlist-api) | +| **Q&A: Fonts, Text** | +| [How can I load a different font than the default?](#q-how-can-i-load-a-different-font-than-the-default) | +| [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | +| [How can I load multiple fonts?](#q-how-can-i-load-multiple-fonts) | +| [How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?](#q-how-can-i-display-and-input-non-latin-characters-such-as-chinese-japanese-korean-cyrillic) | +| **Q&A: Community** | +| [How can I help?](#q-how-can-i-help) | + + +# Q&A: Basics + +### Q: Where is the documentation? + +**This library is poorly documented at the moment and expects of the user to be acquainted with C/C++.** +- Run the examples/ and explore them. +- See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. +- The demo covers most features of Dear ImGui, so you can read the code and see its output. +- See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h). +- Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. +- Your programming IDE is your friend, find the type or function declaration to find comments associated to it. + +--- + +### Q: Which version should I get? +I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. + +You may also peak at the [docking](https://github.com/ocornut/imgui/tree/docking) branch which includes: +- [Docking/Merging features](https://github.com/ocornut/imgui/issues/2109) +- [Multi-viewport features](https://github.com/ocornut/imgui/issues/1542) + +Many projects are using this branch and it is kept in sync with master regularly. + +--- + +### Q: Why the names "Dear ImGui" vs "ImGui"? + +**TL;DR: Please try to refer to this library as "Dear ImGui".** + +The library started its life as "ImGui" due to the fact that I didn't give it a proper name when when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. + +##### [Return to Index](#index) + + +# Q&A: Concerns + +### Q: Who uses Dear ImGui? + +You may take a look at: + +- [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) +- [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) +- [Gallery](https://github.com/ocornut/imgui/issues/2847) + +### Q: Can you create elaborate/serious tools with Dear ImGui? + +Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. + +Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. + +Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. + +### Q: Can you reskin the look of Dear ImGui? + +Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. + +A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) +![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) + +### Q: Why using C++ (as opposed to C)? + +Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. + +There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. + +##### [Return to Index](#index) + + +# Q&A: Integration + +### Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application? + +You can read the `io.WantCaptureMouse`, `io.WantCaptureKeyboard` and `io.WantTextInput` flags from the ImGuiIO structure. + +e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` + +- When `io.WantCaptureMouse` is set, imgui wants to use your mouse state, and you may want to discard/hide the inputs from the rest of your application. +- When `io.WantCaptureKeyboard` is set, imgui wants to use your keyboard state, and you may want to discard/hide the inputs from the rest of your application. +- When `io.WantTextInput` is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console OS). + +**Note:** You should always pass your mouse/keyboard inputs to Dear ImGui, even when the io.WantCaptureXXX flag are set false. + This is because imgui needs to detect that you clicked in the void to unfocus its own windows. + +**Note:** The `io.WantCaptureMouse` is more accurate that any manual attempt to "check if the mouse is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs. Those flags are updated by `ImGui::NewFrame()`. Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you might find use for an early call to `UpdateHoveredWindowAndCaptureFlags()`. + +**Note:** Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have `io.WantCaptureKeyboard == false`. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) + +--- + +### Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) +- You can control Dear ImGui with a gamepad. Read about navigation in "Using gamepad/keyboard navigation controls". +(short version: map gamepad inputs into the io.NavInputs[] array + set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad`). +- You can share your computer mouse seamlessly with your console/tablet/phone using [Synergy](https://symless.com/synergy) +This is the preferred solution for developer productivity. +In particular, the [micro-synergy-client repository](https://github.com/symless/micro-synergy-client) has simple +and portable source code (uSynergy.c/.h) for a small embeddable client that you can use on any platform to connect +to your host computer, based on the Synergy 1.x protocol. Make sure you download the Synergy 1 server on your computer. +Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-like protocols. +- You may also use a third party solution such as [Remote ImGui](https://github.com/JordiRos/remoteimgui) or [imgui-ws](https://github.com/ggerganov/imgui-ws) which sends the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. See Wiki index for most details. +- For touch inputs, you can increase the hit box of widgets (via the `style.TouchPadding` setting) to accommodate +for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing +for screen real-estate and precision. + +--- + +### Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. +In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). +Also make sure your orthographic projection matrix and io.DisplaySize matches your actual framebuffer dimension. + +--- + +### Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. +You are probably mishandling the clipping rectangles in your render function. +Rectangles provided by ImGui are defined as +`(x1=left,y1=top,x2=right,y2=bottom)` +and **NOT** as +`(x1,y1,width,height)` + +##### [Return to Index](#index) + + +# Q&A: Usage + +### Q: Why are multiple widgets reacting when I interact with a single one?
Q: How can I have multiple widgets with the same label or with an empty label? + +A primer on labels and the ID Stack... + +Dear ImGui internally need to uniquely identify UI elements. +Elements that are typically not clickable (such as calls to the Text functions) don't need an ID. +Interactive widgets (such as calls to Button buttons) need a unique ID. +Unique ID are used internally to track active widgets and occasionally associate state to widgets. +Unique ID are implicitly built from the hash of multiple elements that identify the "path" to the UI element. + +- Unique ID are often derived from a string label: +```c +Button("OK"); // Label = "OK", ID = hash of (..., "OK") +Button("Cancel"); // Label = "Cancel", ID = hash of (..., "Cancel") +``` +- ID are uniquely scoped within windows, tree nodes, etc. which all pushes to the ID stack. Having +two buttons labeled "OK" in different windows or different tree locations is fine. +We used "..." above to signify whatever was already pushed to the ID stack previously: +```c +Begin("MyWindow"); +Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "OK") +End(); +Begin("MyOtherWindow"); +Button("OK"); // Label = "OK", ID = hash of ("MyOtherWindow", "OK") +End(); +``` +- If you have a same ID twice in the same location, you'll have a conflict: +```c +Button("OK"); +Button("OK"); // ID collision! Interacting with either button will trigger the first one. +``` +Fear not! this is easy to solve and there are many ways to solve it! + +- Solving ID conflict in a simple/local context: +When passing a label you can optionally specify extra ID information within string itself. +Use "##" to pass a complement to the ID that won't be visible to the end-user. +This helps solving the simple collision cases when you know e.g. at compilation time which items +are going to be created: +```c +Begin("MyWindow"); +Button("Play"); // Label = "Play", ID = hash of ("MyWindow", "Play") +Button("Play##foo1"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo1") // Different from above +Button("Play##foo2"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo2") // Different from above +End(); +``` +- If you want to completely hide the label, but still need an ID: +```c +Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox! +``` +- Occasionally/rarely you might want change a label while preserving a constant ID. This allows +you to animate labels. For example you may want to include varying information in a window title bar, +but windows are uniquely identified by their ID. Use "###" to pass a label that isn't part of ID: +```c +Button("Hello###ID"); // Label = "Hello", ID = hash of (..., "###ID") +Button("World###ID"); // Label = "World", ID = hash of (..., "###ID") // Same as above, even if the label looks different + +sprintf(buf, "My game (%f FPS)###MyGame", fps); +Begin(buf); // Variable title, ID = hash of "MyGame" +``` +- Solving ID conflict in a more general manner: +Use PushID() / PopID() to create scopes and manipulate the ID stack, as to avoid ID conflicts +within the same window. This is the most convenient way of distinguishing ID when iterating and +creating many UI elements programmatically. +You can push a pointer, a string or an integer value into the ID stack. +Remember that ID are formed from the concatenation of _everything_ pushed into the ID stack. +At each level of the stack we store the seed used for items at this level of the ID stack. +```c +Begin("Window"); +for (int i = 0; i < 100; i++) +{ + PushID(i); // Push i to the id tack + Button("Click"); // Label = "Click", ID = hash of ("Window", i, "Click") + PopID(); +} +for (int i = 0; i < 100; i++) +{ + MyObject* obj = Objects[i]; + PushID(obj); + Button("Click"); // Label = "Click", ID = hash of ("Window", obj pointer, "Click") + PopID(); +} +for (int i = 0; i < 100; i++) +{ + MyObject* obj = Objects[i]; + PushID(obj->Name); + Button("Click"); // Label = "Click", ID = hash of ("Window", obj->Name, "Click") + PopID(); +} +End(); +``` +- You can stack multiple prefixes into the ID stack: +```c +Button("Click"); // Label = "Click", ID = hash of (..., "Click") +PushID("node"); + Button("Click"); // Label = "Click", ID = hash of (..., "node", "Click") + PushID(my_ptr); + Button("Click"); // Label = "Click", ID = hash of (..., "node", my_ptr, "Click") + PopID(); +PopID(); +``` +- Tree nodes implicitly creates a scope for you by calling PushID(). +```c +Button("Click"); // Label = "Click", ID = hash of (..., "Click") +if (TreeNode("node")) // <-- this function call will do a PushID() for you (unless instructed not to, with a special flag) +{ + Button("Click"); // Label = "Click", ID = hash of (..., "node", "Click") + TreePop(); +} +``` +- When working with trees, ID are used to preserve the open/close state of each tree node. +Depending on your use cases you may want to use strings, indices or pointers as ID. +e.g. when following a single pointer that may change over time, using a static string as ID +will preserve your node open/closed state when the targeted object change. +e.g. when displaying a list of objects, using indices or pointers as ID will preserve the +node open/closed state differently. See what makes more sense in your situation! + +--- + +### Q: How can I display an image? What is ImTextureID, how does it work? + +Short explanation: +- Please read Wiki entry for examples: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples +- You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures. +- Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value. +- Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). + +**Please read documentations or tutorials on your graphics API to understand how to display textures on the screen before moving onward.** + +Long explanation: +- Dear ImGui's job is to create "meshes", defined in a renderer-agnostic format made of draw commands and vertices. At the end of the frame those meshes (ImDrawList) will be displayed by your rendering function. They are made up of textured polygons and the code to render them is generally fairly short (a few dozen lines). In the examples/ folder we provide functions for popular graphics API (OpenGL, DirectX, etc.). +- Each rendering function decides on a data type to represent "textures". The concept of what is a "texture" is entirely tied to your underlying engine/graphics API. + We carry the information to identify a "texture" in the ImTextureID type. +ImTextureID is nothing more that a void*, aka 4/8 bytes worth of data: just enough to store 1 pointer or 1 integer of your choice. +Dear ImGui doesn't know or understand what you are storing in ImTextureID, it merely pass ImTextureID values until they reach your rendering function. +- In the examples/ bindings, for each graphics API binding we decided on a type that is likely to be a good representation for specifying an image from the end-user perspective. This is what the _examples_ rendering functions are using: +``` +OpenGL: +- ImTextureID = GLuint +- See ImGui_ImplOpenGL3_RenderDrawData() function in imgui_impl_opengl3.cpp + +DirectX9: +- ImTextureID = LPDIRECT3DTEXTURE9 +- See ImGui_ImplDX9_RenderDrawData() function in imgui_impl_dx9.cpp + +DirectX11: +- ImTextureID = ID3D11ShaderResourceView* +- See ImGui_ImplDX11_RenderDrawData() function in imgui_impl_dx11.cpp + +DirectX12: +- ImTextureID = D3D12_GPU_DESCRIPTOR_HANDLE +- See ImGui_ImplDX12_RenderDrawData() function in imgui_impl_dx12.cpp +``` +For example, in the OpenGL example binding we store raw OpenGL texture identifier (GLuint) inside ImTextureID. +Whereas in the DirectX11 example binding we store a pointer to ID3D11ShaderResourceView inside ImTextureID, which is a higher-level structure tying together both the texture and information about its format and how to read it. + +- If you have a custom engine built over e.g. OpenGL, instead of passing GLuint around you may decide to use a high-level data type to carry information about the texture as well as how to display it (shaders, etc.). The decision of what to use as ImTextureID can always be made better knowing how your codebase is designed. If your engine has high-level data types for "textures" and "material" then you may want to use them. +If you are starting with OpenGL or DirectX or Vulkan and haven't built much of a rendering engine over them, keeping the default ImTextureID representation suggested by the example bindings is probably the best choice. +(Advanced users may also decide to keep a low-level type in ImTextureID, and use ImDrawList callback and pass information to their renderer) + +User code may do: +```cpp +// Cast our texture type to ImTextureID / void* +MyTexture* texture = g_CoffeeTableTexture; +ImGui::Image((void*)texture, ImVec2(texture->Width, texture->Height)); +``` +The renderer function called after ImGui::Render() will receive that same value that the user code passed: +```cpp +// Cast ImTextureID / void* stored in the draw command as our texture type +MyTexture* texture = (MyTexture*)pcmd->TextureId; +MyEngineBindTexture2D(texture); +``` +Once you understand this design you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. +This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. +If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. + +Refer to the Wiki to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples + +C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa. +Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*. +Examples: +```cpp +GLuint my_tex = XXX; +void* my_void_ptr; +my_void_ptr = (void*)(intptr_t)my_tex; // cast a GLuint into a void* (we don't take its address! we literally store the value inside the pointer) +my_tex = (GLuint)(intptr_t)my_void_ptr; // cast a void* into a GLuint + +ID3D11ShaderResourceView* my_dx11_srv = XXX; +void* my_void_ptr; +my_void_ptr = (void*)my_dx11_srv; // cast a ID3D11ShaderResourceView* into an opaque void* +my_dx11_srv = (ID3D11ShaderResourceView*)my_void_ptr; // cast a void* into a ID3D11ShaderResourceView* +``` +Finally, you may call ImGui::ShowMetricsWindow() to explore/visualize/understand how the ImDrawList are generated. + +--- + +### Q: How can I use my own math types instead of ImVec2/ImVec4? + +You can edit [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) and setup the IM_VEC2_CLASS_EXTRA/IM_VEC4_CLASS_EXTRA macros to add implicit type conversions. +This way you'll be able to use your own types everywhere, e.g. passing MyVector2 or glm::vec2 to ImGui functions instead of ImVec2. + +--- + +### Q: How can I interact with standard C++ types (such as std::string and std::vector)? +- Being highly portable (bindings for several languages, frameworks, programming style, obscure or older platforms/compilers), and aiming for compatibility & performance suitable for every modern real-time game engines, dear imgui does not use any of std C++ types. We use raw types (e.g. char* instead of std::string) because they adapt to more use cases. +- To use ImGui::InputText() with a std::string or any resizable string class, see [misc/cpp/imgui_stdlib.h](https://github.com/ocornut/imgui/blob/master/misc/cpp/imgui_stdlib.h). +- To use combo boxes and list boxes with std::vector or any other data structure: the BeginCombo()/EndCombo() API +lets you iterate and submit items yourself, so does the ListBoxHeader()/ListBoxFooter() API. +Prefer using them over the old and awkward Combo()/ListBox() api. +- Generally for most high-level types you should be able to access the underlying data type. +You may write your own one-liner wrappers to facilitate user code (tip: add new functions in ImGui:: namespace from your code). +- Dear ImGui applications often need to make intensive use of strings. It is expected that many of the strings you will pass +to the API are raw literals (free in C/C++) or allocated in a manner that won't incur a large cost on your application. +Please bear in mind that using std::string on applications with large amount of UI may incur unsatisfactory performances. +Modern implementations of std::string often include small-string optimization (which is often a local buffer) but those +are not configurable and not the same across implementations. +- If you are finding your UI traversal cost to be too large, make sure your string usage is not leading to excessive amount +of heap allocations. Consider using literals, statically sized buffers and your own helper functions. A common pattern +is that you will need to build lots of strings on the fly, and their maximum length can be easily be scoped ahead. +One possible implementation of a helper to facilitate printf-style building of strings: https://github.com/ocornut/Str +This is a small helper where you can instance strings with configurable local buffers length. Many game engines will +provide similar or better string helpers. + +--- + +### Q: How can I use low-level drawing facilities? (using ImDrawList API) +- You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags. +(The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse) +Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. +- You can call `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` and use those draw list to display +contents behind or over every other imgui windows (one bg/fg drawlist per viewport). +- You can create your own ImDrawList instance. You'll need to initialize them with ImGui::GetDrawListSharedData(), or create your own instancing ImDrawListSharedData, and then call your rendered code with your own ImDrawList or ImDrawData data. + +##### [Return to Index](#index) + + +# Q&A: Fonts, Text + +### Q: How can I load a different font than the default? +Use the font atlas to load the TTF/OTF file you want: + +```c +ImGuiIO& io = ImGui::GetIO(); +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); +io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() +``` + +Default is ProggyClean.ttf, monospace, rendered at size 13, embedded in dear imgui's source code. + +(Tip: monospace fonts are convenient because they allow to facilitate horizontal alignment directly at the string level.) + +(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file for more details about font loading.) + +New programmers: remember that in C/C++ and most programming languages if you want to use a +backslash \ within a string literal, you need to write it double backslash "\\": + +```c +io.Fonts->AddFontFromFileTTF("MyFolder\MyFont.ttf", size); // WRONG (you are escape the M here!) +io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size; // CORRECT +io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT +``` + +--- + +### Q: How can I easily use icons in my application? +The most convenient and practical way is to merge an icon font such as FontAwesome inside you +main font. Then you can refer to icons within your strings. +You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment. +(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file for more details about icons font loading.) +With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, +and copying your own graphics data into it. See misc/fonts/README.txt about using the AddCustomRectFontGlyph API. + +--- + +### Q: How can I load multiple fonts? +Use the font atlas to pack them into a single texture: +(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file and the code in ImFontAtlas for more details.) + +```cpp +ImGuiIO& io = ImGui::GetIO(); +ImFont* font0 = io.Fonts->AddFontDefault(); +ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); +ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels); +io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() +// the first loaded font gets used by default +// use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime + +// Options +ImFontConfig config; +config.OversampleH = 2; +config.OversampleV = 1; +config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixels up +config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config); + +// Combine multiple fonts into one (e.g. for icon fonts) +static ImWchar ranges[] = { 0xf000, 0xf3ff, 0 }; +ImFontConfig config; +config.MergeMode = true; +io.Fonts->AddFontDefault(); +io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); // Merge icon font +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs +``` + +--- + +### Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? +When loading a font, pass custom Unicode ranges to specify the glyphs to load. + +```cpp +// Add default Japanese ranges +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); + +// Or create your own custom ranges (e.g. for a game you can feed your entire game script and only build the characters the game need) +ImVector ranges; +ImFontGlyphRangesBuilder builder; +builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters) +builder.AddChar(0x7262); // Add a specific character +builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges +builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted) +io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 16.0f, NULL, ranges.Data); +``` + +All your strings needs to use UTF-8 encoding. In C++11 you can encode a string literal in UTF-8 +by using the u8"hello" syntax. Specifying literal in your source code using a local code page +(such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! +Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. + +Text input: it is up to your application to pass the right character code by calling io.AddInputCharacter(). +The applications in examples/ are doing that. +Windows: you can use the WM_CHAR or WM_UNICHAR or WM_IME_CHAR message (depending if your app is built using Unicode or MultiByte mode). +You may also use MultiByteToWideChar() or ToUnicode() to retrieve Unicode codepoints from MultiByte characters or keyboard state. +Windows: if your language is relying on an Input Method Editor (IME), you copy the HWND of your window to io.ImeWindowHandle in order for +the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft IME position correctly. + +##### [Return to Index](#index) + +# Q&A: Community + +### Q: How can I help? +- If you are experienced with Dear ImGui and C++, look at the [GitHub Issues](https://github.com/ocornut/imgui/issues), look at the [Wiki](https://github.com/ocornut/imgui/wiki), read [docs/TODO.txt](https://github.com/ocornut/imgui/blob/master/docs/TODO.txt) and see how you want to help and can help! +- Businesses: convince your company to fund development via support contracts/sponsoring! This is among the most useful thing you can do for Dear ImGui. With increased funding we will be able to hire more people working on this project. +- Individuals: you can also become a [Patron](http://www.patreon.com/imgui) or donate on PayPal! See README. +- Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. +You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. +But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. +- If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete pR. + +##### [Return to Index](#index) diff --git a/imgui.cpp b/imgui.cpp index fc155333..597e681c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -28,7 +28,7 @@ DOCUMENTATION - MISSION STATEMENT - END-USER GUIDE -- PROGRAMMER GUIDE (read me!) +- PROGRAMMER GUIDE - Read first. - How to update to a newer version of Dear ImGui. - Getting started with integrating Dear ImGui in your code/engine. @@ -37,26 +37,7 @@ DOCUMENTATION - Using gamepad/keyboard navigation controls. - API BREAKING CHANGES (read me when you update!) - FREQUENTLY ASKED QUESTIONS (FAQ) - - All answers in https://github.com/ocornut/imgui/wiki/FAQ - - Where is the documentation? - - Which version should I get? - - Who uses Dear ImGui? - - Why the odd dual naming, "Dear ImGui" vs "ImGui"? - - How can I tell whether to dispatch mouse/keyboard to imgui or to my application? - - How can I display an image? What is ImTextureID, how does it works? - - Why are multiple widgets reacting when I interact with a single one? How can I have - multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack... - - How can I use my own math types instead of ImVec2/ImVec4? - - How can I load a different font than the default? - - How can I easily use icons in my application? - - How can I load multiple fonts? - - How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic? - - How can I interact with standard C++ types (such as std::string and std::vector)? - - How can I use the drawing facilities without a Dear ImGui window? (using ImDrawList API) - - How can I use Dear ImGui on a platform that doesn't have a mouse or a keyboard? (input share, remoting, gamepad) - - I integrated Dear ImGui in my engine and the text or lines are blurry.. - - I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. - - How can I help? + - Read all answers online: https://www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer) CODE (search for "[SECTION]" in the code to find them) @@ -138,7 +119,7 @@ CODE READ FIRST: - - Read the FAQ below this section! + - Remember to read the FAQ (https://www.dearimgui.org/faq) - Your code creates the UI, if your code doesn't run the UI is gone! The UI can be highly dynamic, there are no construction or destruction steps, less superfluous data retention on your side, less state duplication, less state synchronization, less bugs. - Call and read ImGui::ShowDemoWindow() for demo code demonstrating most features. @@ -235,7 +216,7 @@ CODE // At this point you've got the texture data and you need to upload that your your graphic system: // After we have created the texture, store its pointer/identifier (_in whichever format your engine uses_) in 'io.Fonts->TexID'. - // This will be passed back to your via the renderer. Basically ImTextureID == void*. Read FAQ below for details about ImTextureID. + // This will be passed back to your via the renderer. Basically ImTextureID == void*. Read FAQ for details about ImTextureID. MyTexture* texture = MyEngine::CreateTextureFromMemoryPixels(pixels, width, height, TEXTURE_TYPE_RGBA32) io.Fonts->TexID = (void*)texture; @@ -321,8 +302,8 @@ CODE - The examples/ folders contains many actual implementation of the pseudo-codes above. - When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated. They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs from the - rest of your application. In every cases you need to pass on the inputs to Dear ImGui. Refer to the FAQ for more information. - - Please read the FAQ below!. Amusingly, it is called a FAQ because people frequently run into the same issues! + rest of your application. In every cases you need to pass on the inputs to Dear ImGui. + - Refer to the FAQ for more information. Amusingly, it is called a FAQ because people frequently run into the same issues! USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS @@ -574,12 +555,11 @@ CODE - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS - ====================================== + FREQUENTLY ASKED QUESTIONS (FAQ) + ================================ - All answers in: https://github.com/ocornut/imgui/wiki/FAQ - Some answers are copied down here to facilitate searching in code or because they are most likely to - be varying depending on your version of the code. + Read all answers online: https://www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer) + Some answers are copied down here to facilitate searching in code. Q&A: Basics =========== @@ -597,7 +577,7 @@ CODE Q: Which version should I get? Q: Why the names "Dear ImGui" vs "ImGui"? - A: See https://github.com/ocornut/imgui/wiki/FAQ + >> See https://www.dearimgui.org/faq Q&A: Concerns ============= @@ -606,7 +586,7 @@ CODE Q: Can you create elaborate/serious tools with Dear ImGui? Q: Can you reskin the look of Dear ImGui? Q: Why using C++ (as opposed to C)? - A: See https://github.com/ocornut/imgui/wiki/FAQ + >> See https://www.dearimgui.org/faq Q&A: Integration ================ @@ -629,7 +609,7 @@ CODE Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. - A: See https://github.com/ocornut/imgui/wiki/FAQ + >> See https://www.dearimgui.org/faq Q&A: Usage ---------- @@ -751,12 +731,12 @@ CODE node open/closed state differently. See what makes more sense in your situation! Q: How can I display an image? What is ImTextureID, how does it works? - A: See https://github.com/ocornut/imgui/wiki/FAQ and https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples + >> See https://www.dearimgui.org/faq and https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples Q: How can I use my own math types instead of ImVec2/ImVec4? Q: How can I interact with standard C++ types (such as std::string and std::vector)? Q: How can I use low-level drawing facilities? (using ImDrawList API) - A: See https://github.com/ocornut/imgui/wiki/FAQ + >> See https://www.dearimgui.org/faq Q&A: Fonts, Text ================ @@ -765,7 +745,7 @@ CODE Q: How can I easily use icons in my application? Q: How can I load multiple fonts? Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? - A: See https://github.com/ocornut/imgui/wiki/FAQ and misc/fonts/README.txt + >> See https://www.dearimgui.org/faq and misc/fonts/README.txt Q&A: Community ============== From 3bbc27ebd98771edad15f5be200510c2ef8445c2 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 16 Oct 2019 11:23:15 +0200 Subject: [PATCH 071/384] Fixed more FAQ links. (#2848) --- docs/FAQ.md | 36 ++++++++++++++++--------------- docs/README.md | 2 +- docs/issue_template.md | 12 +++++------ examples/imgui_impl_allegro5.cpp | 2 +- examples/imgui_impl_allegro5.h | 2 +- examples/imgui_impl_dx10.cpp | 2 +- examples/imgui_impl_dx10.h | 2 +- examples/imgui_impl_dx11.cpp | 2 +- examples/imgui_impl_dx11.h | 2 +- examples/imgui_impl_dx12.cpp | 2 +- examples/imgui_impl_dx12.h | 2 +- examples/imgui_impl_dx9.cpp | 2 +- examples/imgui_impl_dx9.h | 2 +- examples/imgui_impl_marmalade.cpp | 2 +- examples/imgui_impl_marmalade.h | 2 +- examples/imgui_impl_metal.h | 2 +- examples/imgui_impl_metal.mm | 2 +- examples/imgui_impl_opengl2.cpp | 2 +- examples/imgui_impl_opengl2.h | 2 +- examples/imgui_impl_opengl3.cpp | 2 +- examples/imgui_impl_opengl3.h | 2 +- misc/fonts/README.txt | 2 +- 22 files changed, 45 insertions(+), 43 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 9fc36234..6dfdb436 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1,8 +1,10 @@ # FAQ (Frequenty Asked Questions) -You may browse this document at: +You may link to this document using short form: + https://www.dearimgui.org/faq +or its real address: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md -or use any Markdown viewer. +or view this file with any Markdown viewer. ## Index @@ -24,13 +26,13 @@ or use any Markdown viewer. | [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) | | **Q&A: Usage** | | [Why are multiple widgets reacting when I interact with a single one?
How can I have multiple widgets with the same label or with an empty label?](#q-why-are-multiple-widgets-reacting-when-i-interact-with-a-single-one-q-how-can-i-have-multiple-widgets-with-the-same-label-or-with-an-empty-label) | -| [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| +| [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| | [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | | [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | | [How can I use low-level drawing facilities? (using ImDrawList API)](#q-how-can-i-use-low-level-drawing-facilities-using-imdrawlist-api) | | **Q&A: Fonts, Text** | | [How can I load a different font than the default?](#q-how-can-i-load-a-different-font-than-the-default) | -| [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | +| [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | | [How can I load multiple fonts?](#q-how-can-i-load-multiple-fonts) | | [How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?](#q-how-can-i-display-and-input-non-latin-characters-such-as-chinese-japanese-korean-cyrillic) | | **Q&A: Community** | @@ -52,7 +54,7 @@ or use any Markdown viewer. --- ### Q: Which version should I get? -I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. +I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. You may also peak at the [docking](https://github.com/ocornut/imgui/tree/docking) branch which includes: - [Docking/Merging features](https://github.com/ocornut/imgui/issues/2109) @@ -87,11 +89,11 @@ Yes. People have written game editors, data browsers, debuggers, profilers and a Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. -Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. +Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. ### Q: Can you reskin the look of Dear ImGui? -Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. +Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) ![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) @@ -110,7 +112,7 @@ There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/ci ### Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application? You can read the `io.WantCaptureMouse`, `io.WantCaptureKeyboard` and `io.WantTextInput` flags from the ImGuiIO structure. - + e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` - When `io.WantCaptureMouse` is set, imgui wants to use your mouse state, and you may want to discard/hide the inputs from the rest of your application. @@ -150,9 +152,9 @@ Also make sure your orthographic projection matrix and io.DisplaySize matches yo ### Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. You are probably mishandling the clipping rectangles in your render function. -Rectangles provided by ImGui are defined as -`(x1=left,y1=top,x2=right,y2=bottom)` -and **NOT** as +Rectangles provided by ImGui are defined as +`(x1=left,y1=top,x2=right,y2=bottom)` +and **NOT** as `(x1,y1,width,height)` ##### [Return to Index](#index) @@ -282,7 +284,7 @@ node open/closed state differently. See what makes more sense in your situation! Short explanation: - Please read Wiki entry for examples: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples -- You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures. +- You may use functions such as `ImGui::Image()`, `ImGui::ImageButton()` or lower-level `ImDrawList::AddImage()` to emit draw calls that will use your own textures. - Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value. - Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). @@ -294,21 +296,21 @@ Long explanation: We carry the information to identify a "texture" in the ImTextureID type. ImTextureID is nothing more that a void*, aka 4/8 bytes worth of data: just enough to store 1 pointer or 1 integer of your choice. Dear ImGui doesn't know or understand what you are storing in ImTextureID, it merely pass ImTextureID values until they reach your rendering function. -- In the examples/ bindings, for each graphics API binding we decided on a type that is likely to be a good representation for specifying an image from the end-user perspective. This is what the _examples_ rendering functions are using: +- In the [examples/](https://github.com/ocornut/imgui/tree/master/examples) bindings, for each graphics API binding we decided on a type that is likely to be a good representation for specifying an image from the end-user perspective. This is what the _examples_ rendering functions are using: ``` OpenGL: - ImTextureID = GLuint - See ImGui_ImplOpenGL3_RenderDrawData() function in imgui_impl_opengl3.cpp -DirectX9: +DirectX9: - ImTextureID = LPDIRECT3DTEXTURE9 - See ImGui_ImplDX9_RenderDrawData() function in imgui_impl_dx9.cpp -DirectX11: +DirectX11: - ImTextureID = ID3D11ShaderResourceView* - See ImGui_ImplDX11_RenderDrawData() function in imgui_impl_dx11.cpp -DirectX12: +DirectX12: - ImTextureID = D3D12_GPU_DESCRIPTOR_HANDLE - See ImGui_ImplDX12_RenderDrawData() function in imgui_impl_dx12.cpp ``` @@ -331,7 +333,7 @@ The renderer function called after ImGui::Render() will receive that same value MyTexture* texture = (MyTexture*)pcmd->TextureId; MyEngineBindTexture2D(texture); ``` -Once you understand this design you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. +Once you understand this design you will understand that loading image files and turning them into displayable textures is not within the scope of Dear ImGui. This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. diff --git a/docs/README.md b/docs/README.md index 1991b954..50a50c9d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -157,7 +157,7 @@ Custom engine ### Support, Frequently Asked Questions (FAQ) -Most common questions will be answered by the [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/wiki/FAQ) page, e.g.: +Most common questions will be answered by the [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) page, e.g.: **Basics** - "Where is the documentation?" diff --git a/docs/issue_template.md b/docs/issue_template.md index 21f0c1a9..bd05f0a5 100644 --- a/docs/issue_template.md +++ b/docs/issue_template.md @@ -1,16 +1,16 @@ (Click "Preview" to turn any http URL into a clickable link) -1. PLEASE CAREFULLY READ: -https://github.com/ocornut/imgui/issues/2261 +1. PLEASE CAREFULLY READ: [FAQ](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) -2. IF YOU ARE HAVING AN ISSUE COMPILING/LINKING/RUNNING/LOADING FONTS, please post on the "Getting Started" Discourse forum: -https://discourse.dearimgui.org +2. PLEASE CAREFULLY READ: https://github.com/ocornut/imgui/issues/2261 -3. PLEASE MAKE SURE that you have: read the FAQ in imgui.cpp; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1). +2. FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING/LOADING FONTS, please use the [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forum](https://discourse.dearimgui.org/c/getting-started). + +3. PLEASE MAKE SURE that you have: read the FAQ; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1) (2). 4. Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users. -5. Delete points 1-5 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue. +5. Delete points 1-6 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue. Thank you! diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp index 525ad5c9..8cee95f0 100644 --- a/examples/imgui_impl_allegro5.cpp +++ b/examples/imgui_impl_allegro5.cpp @@ -2,7 +2,7 @@ // (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.) // Implemented features: -// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Platform: Clipboard support (from Allegro 5.1.12) // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // Issues: diff --git a/examples/imgui_impl_allegro5.h b/examples/imgui_impl_allegro5.h index bc995a5a..8b9a47d1 100644 --- a/examples/imgui_impl_allegro5.h +++ b/examples/imgui_impl_allegro5.h @@ -2,7 +2,7 @@ // (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.) // Implemented features: -// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Platform: Clipboard support (from Allegro 5.1.12) // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // Issues: diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 6dec6147..362756db 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h index db156e17..94e6db80 100644 --- a/examples/imgui_impl_dx10.h +++ b/examples/imgui_impl_dx10.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index 197bbe02..2b80f766 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h index 1741a5d3..5eee80d5 100644 --- a/examples/imgui_impl_dx11.h +++ b/examples/imgui_impl_dx11.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 3161d183..6d6161a1 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // Issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 8ae75e53..274c1c92 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // Issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 2ee76ca6..82b96475 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h index 1eaea87d..a0413e00 100644 --- a/examples/imgui_impl_dx9.h +++ b/examples/imgui_impl_dx9.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: -// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_marmalade.cpp b/examples/imgui_impl_marmalade.cpp index 497a5705..0675c6b4 100644 --- a/examples/imgui_impl_marmalade.cpp +++ b/examples/imgui_impl_marmalade.cpp @@ -2,7 +2,7 @@ // Marmalade code: Copyright (C) 2015 by Giovanni Zito (this file is part of Dear ImGui) // Implemented features: -// [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID! // Missing features: // [ ] Renderer: Clipping rectangles are not honored. diff --git a/examples/imgui_impl_marmalade.h b/examples/imgui_impl_marmalade.h index 8a767f9d..01fbd0d2 100644 --- a/examples/imgui_impl_marmalade.h +++ b/examples/imgui_impl_marmalade.h @@ -2,7 +2,7 @@ // Marmalade code: Copyright (C) 2015 by Giovanni Zito (this file is part of Dear ImGui) // Implemented features: -// [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID! // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_metal.h b/examples/imgui_impl_metal.h index 869c3e52..7fa558fa 100644 --- a/examples/imgui_impl_metal.h +++ b/examples/imgui_impl_metal.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. OSX) // Implemented features: -// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm index f3f1b126..9d1045f1 100644 --- a/examples/imgui_impl_metal.mm +++ b/examples/imgui_impl_metal.mm @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. OSX) // Implemented features: -// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index fbe278c7..a3496225 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_opengl2.h b/examples/imgui_impl_opengl2.h index 2e3271dc..009052d7 100644 --- a/examples/imgui_impl_opengl2.h +++ b/examples/imgui_impl_opengl2.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index d7b108ef..3824647a 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -4,7 +4,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! // [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices. // 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/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 75f8f8c8..2d10ea30 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -4,7 +4,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. +// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! // [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. diff --git a/misc/fonts/README.txt b/misc/fonts/README.txt index 39e0dd48..4ddafe62 100644 --- a/misc/fonts/README.txt +++ b/misc/fonts/README.txt @@ -13,7 +13,7 @@ You may also load external .TTF/.OTF files. The files in this folder are suggested fonts, provided as a convenience. Fonts are rasterized in a single texture at the time of calling either of io.Fonts->GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). -Also read dear imgui FAQ in imgui.cpp! +Also read the FAQ: https://www.dearimgui.org/faq If you have other loading/merging/adding fonts, you can post on the Dear ImGui "Getting Started" forum: https://discourse.dearimgui.org/c/getting-started From 9994f5bcbed2649907ecc52be0010f8f3c9a697e Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 16 Oct 2019 11:28:45 +0200 Subject: [PATCH 072/384] Fixed more FAQ links, oops.. (#2848) --- docs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 50a50c9d..aaca0316 100644 --- a/docs/README.md +++ b/docs/README.md @@ -118,7 +118,7 @@ The demo applications are not DPI aware so expect some blurriness on a 4K screen On most platforms and when using C++, **you should be able to use a combination of the [imgui_impl_xxxx](https://github.com/ocornut/imgui/tree/master/examples) files without modification** (e.g. `imgui_impl_win32.cpp` + `imgui_impl_dx11.cpp`). If your engine supports multiple platforms, consider using more of the imgui_impl_xxxx files instead of rewriting them: this will be less work for you and you can get Dear ImGui running immediately. You can _later_ decide to rewrite a custom binding using your custom engine functions if you wish so. -Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the [FAQ](https://github.com/ocornut/imgui/wiki/FAQ), comments, and one of the examples/ application!** +Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you less than two hours to integrate Dear ImGui in your custom engine. **Make sure to spend time reading the [FAQ](https://www.dearimgui.org/faq), comments, and some of the examples/ application!** Officially maintained bindings (in repository): - Renderers: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal. @@ -134,7 +134,7 @@ Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. ### Upcoming Changes -Some of the goals for 2019 are: +Some of the goals for 2019+ are: - Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787)) From 53278be61f9ff67e43024032e1a3e155179b8c6a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 18 Oct 2019 12:54:30 +0200 Subject: [PATCH 073/384] FAQ, Readme. Use = {} instead of = { 0 }, wasn't problematic because they were all static variables or one stack array not read. But hey. --- docs/FAQ.md | 42 ++++++++++++++++++++++++++++-------- docs/README.md | 4 ++-- docs/TODO.txt | 1 + examples/imgui_impl_glfw.cpp | 2 +- examples/imgui_impl_osx.mm | 2 +- examples/imgui_impl_sdl.cpp | 2 +- imgui.cpp | 4 ++-- imgui_demo.cpp | 6 +++--- 8 files changed, 44 insertions(+), 19 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 6dfdb436..6430f678 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -13,7 +13,7 @@ or view this file with any Markdown viewer. :---------------------------------------------------------- | | [Where is the documentation?](#q-where-is-the-documentation) | | [Which version should I get?](#q-which-version-should-i-get) | -| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-names-dear-imgui-vs-imgui) | +| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-the-names-dear-imgui-vs-imgui) | | **Q&A: Concerns** | | [Who uses Dear ImGui?](#q-who-uses-dear-imgui) | | [Can you create elaborate/serious tools with Dear ImGui?](#q-can-you-create-elaborateserious-tools-with-dear-imgui) | @@ -29,7 +29,7 @@ or view this file with any Markdown viewer. | [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| | [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | | [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | -| [How can I use low-level drawing facilities? (using ImDrawList API)](#q-how-can-i-use-low-level-drawing-facilities-using-imdrawlist-api) | +| [How can I display custom shapes? (using low-level ImDrawList API)](#q-how-can-i-display-custom-shapes-using-low-level-imdrawlist-api) | | **Q&A: Fonts, Text** | | [How can I load a different font than the default?](#q-how-can-i-load-a-different-font-than-the-default) | | [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | @@ -386,13 +386,37 @@ provide similar or better string helpers. --- -### Q: How can I use low-level drawing facilities? (using ImDrawList API) -- You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags. -(The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse) -Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. -- You can call `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` and use those draw list to display -contents behind or over every other imgui windows (one bg/fg drawlist per viewport). -- You can create your own ImDrawList instance. You'll need to initialize them with ImGui::GetDrawListSharedData(), or create your own instancing ImDrawListSharedData, and then call your rendered code with your own ImDrawList or ImDrawData data. +### Q: How can I display custom shapes? (using low-level ImDrawList API) + +- You can use the low-level `ImDrawList` api to render shapes within a window. + +``` +ImGui::Begin("My shapes"); + +ImDrawList* draw_list = ImGui::GetWindowDrawList(); + +// Get the current ImGui cursor position +ImVec2 p = ImGui::GetCursorScreenPos(); + +// Draw a red circle +draw_list->AddCircleFilled(ImVec2(p.x + 50, p.y + 50), 30.0f, IM_COL32(255, 0, 0, 255), 16); + +// Draw a 3 pixel thick yellow line +draw_list->AddLine(ImVec2(p.x, p.y), ImVec2(p.x + 100.0f, p.y + 100.0f), IM_COL32(255, 255, 0, 255), 3.0f); + +// Advance the ImGui cursor to claim space in the window (otherwise the window will appears small and needs to be resized) +ImGui::Dummy(ImVec2(200, 200)); + +ImGui::End(); +``` +![ImDrawList usage](https://raw.githubusercontent.com/wiki/ocornut/imgui/tutorials/CustomRendering01.png) + +- Refer to "Demo > Examples > Custom Rendering" in the demo window and read the code of `ShowExampleAppCustomRendering()` in `imgui_demo.cpp` from more examples. +- To generate colors: you can use the macro `IM_COL32(255,255,255,255)` to generate them at compile time, or use `ImGui::GetColorU32(IM_COL32(255,255,255,255))` or `ImGui::GetColorU32(ImVec4(1.0f,1.0f,1.0f,1.0f))` to generate a color that is multiplied by the current value of `style.Alpha`. +- Math operators: if you have setup `IM_VEC2_CLASS_EXTRA` in `imconfig.h` to bind your own math types, you can use your own math types and their natural operators instead of ImVec2. ImVec2 by default doesn't export any math operators in the public API. You may use `#define IMGUI_DEFINE_MATH_OPERATORS` `#include "imgui_internal.h"` to use the internally defined math operators, but instead prefer using your own math library and set it up in `imconfig.h`. +- You can use `ImGui::GetBackgroundDrawList()` or `ImGui::GetForegroundDrawList()` to access draw lists which will be displayed behind and over every other dear imgui windows (one bg/fg drawlist per viewport). This is very convenient if you need to quickly display something on the screen that is not associated to a dear imgui window. +- You can also create your own dummy window and draw inside it. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags (The `ImGuiWindowFlags_NoDecoration` flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse). Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. +- You can create your own ImDrawList instance. You'll need to initialize them with `ImGui::GetDrawListSharedData()`, or create your own instancing ImDrawListSharedData, and then call your renderer function with your own ImDrawList or ImDrawData data. ##### [Return to Index](#index) diff --git a/docs/README.md b/docs/README.md index aaca0316..a99ffe67 100644 --- a/docs/README.md +++ b/docs/README.md @@ -184,7 +184,7 @@ Most common questions will be answered by the [Frequently Asked Questions (FAQ)] - "How can I display an image? What is ImTextureID, how does it work?" - "How can I use my own math types instead of ImVec2/ImVec4?" - "How can I interact with standard C++ types (such as std::string and std::vector)?" -- "How can I use low-level drawing facilities? (using ImDrawList API)" +- "How can I display custom shapes? (using low-level ImDrawList API)" **Fonts, Text** - "How can I load a different font than the default?" @@ -247,7 +247,7 @@ Ongoing Dear ImGui development is financially supported by users and private spo - Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn. *Salty caramel supporters* -- Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. +- Remedy Entertainment, Next Level Games, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. *Caramel supporters* - Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis, Matt Reyer. diff --git a/docs/TODO.txt b/docs/TODO.txt index 7ca24ca8..b9fcecee 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -363,6 +363,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - demo: add vertical separator demo - demo: add virtual scrolling example? - demo: demonstrate Plot offset + - demo: window size constraint: square demo is broken when resizing from edges (#1975), would need to rework the callback system to solve this - examples: window minimize, maximize (#583) - examples: provide a zero frame-rate/idle example. - examples: apple: example_apple should be using modern GL3. diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index a9e72c6c..dbf1188d 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -61,7 +61,7 @@ static GLFWwindow* g_Window = NULL; // Main window static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown; static double g_Time = 0.0; static bool g_MouseJustPressed[5] = { false, false, false, false, false }; -static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL; diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index a491616a..4f4e9753 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -24,7 +24,7 @@ // Data static CFAbsoluteTime g_Time = 0.0; -static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static bool g_MouseCursorHidden = false; // Undocumented methods for creating cursors. diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 42677581..06d27b21 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -57,7 +57,7 @@ static SDL_Window* g_Window = NULL; static Uint64 g_Time = 0; static bool g_MousePressed[3] = { false, false, false }; -static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; +static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; static const char* ImGui_ImplSDL2_GetClipboardText(void*) diff --git a/imgui.cpp b/imgui.cpp index 597e681c..700138f4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -735,7 +735,7 @@ CODE Q: How can I use my own math types instead of ImVec2/ImVec4? Q: How can I interact with standard C++ types (such as std::string and std::vector)? - Q: How can I use low-level drawing facilities? (using ImDrawList API) + Q: How can I display custom shapes? (using low-level ImDrawList API) >> See https://www.dearimgui.org/faq Q&A: Fonts, Text @@ -5522,7 +5522,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Handle manual resize: Resize Grips, Borders, Gamepad int border_held = -1; - ImU32 resize_grip_col[4] = { 0 }; + ImU32 resize_grip_col[4] = {}; const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4 const float resize_grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f); if (!window->Collapsed) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 0eeec980..8e765863 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -923,7 +923,7 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("In columns")) { ImGui::Columns(3, NULL, false); - static bool selected[16] = { 0 }; + static bool selected[16] = {}; for (int i = 0; i < 16; i++) { char label[32]; sprintf(label, "Item %d", i); @@ -1075,7 +1075,7 @@ static void ShowDemoWindowWidgets() // Create a dummy array of contiguous float values to plot // Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter. - static float values[90] = { 0 }; + static float values[90] = {}; static int values_offset = 0; static double refresh_time = 0.0; if (!animate || refresh_time == 0.0) @@ -1176,7 +1176,7 @@ static void ShowDemoWindowWidgets() // Generate a dummy default palette. The palette will persist and can be edited. static bool saved_palette_init = true; - static ImVec4 saved_palette[32] = { }; + static ImVec4 saved_palette[32] = {}; if (saved_palette_init) { for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++) From 714fe29d1a93a9d5b62dce1859aa195ef1fb096c Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 17 Oct 2019 12:36:26 +0300 Subject: [PATCH 074/384] Replace manual flooring with IM_FLOOR() macro. (#2850) Macro is used to ensure that flooring operation is always inlined even in debug builds. __forceinline does not force inlining in /Od builds with MSVC. (cherry picked from commit bc165df6fd7969605bbc07b8a6d3d28f9109e8f3) --- imgui.cpp | 36 +++++++------- imgui_draw.cpp | 14 +++--- imgui_internal.h | 3 +- imgui_widgets.cpp | 80 ++++++++++++++++---------------- misc/freetype/imgui_freetype.cpp | 4 +- 5 files changed, 69 insertions(+), 68 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 700138f4..50dd9647 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -302,7 +302,7 @@ CODE - The examples/ folders contains many actual implementation of the pseudo-codes above. - When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated. They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs from the - rest of your application. In every cases you need to pass on the inputs to Dear ImGui. + rest of your application. In every cases you need to pass on the inputs to Dear ImGui. - Refer to the FAQ for more information. Amusingly, it is called a FAQ because people frequently run into the same issues! USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS @@ -605,7 +605,7 @@ CODE Note: Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) - + Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. @@ -2781,8 +2781,8 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line - window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line + window->DC.CursorPos.y = IM_FLOOR(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] @@ -4121,7 +4121,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL); // Round - text_size.x = (float)(int)(text_size.x + 0.95f); + text_size.x = IM_FLOOR(text_size.x + 0.95f); return text_size; } @@ -4763,8 +4763,8 @@ static ImVec2 CalcWindowContentSize(ImGuiWindow* window) return window->ContentSize; ImVec2 sz; - sz.x = (float)(int)((window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x); - sz.y = (float)(int)((window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y); + sz.x = IM_FLOOR((window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x); + sz.y = IM_FLOOR((window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y); return sz; } @@ -4875,8 +4875,8 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au bool ret_auto_fit = false; const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0; - const float grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f); - const float grip_hover_inner_size = (float)(int)(grip_draw_size * 0.75f); + const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); + const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f); const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS : 0.0f; ImVec2 pos_target(FLT_MAX, FLT_MAX); @@ -5184,7 +5184,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl if (flags & ImGuiWindowFlags_UnsavedDocument) { ImVec2 marker_pos = ImVec2(ImMax(layout_r.Min.x, layout_r.Min.x + (layout_r.GetWidth() - text_size.x) * style.WindowTitleAlign.x) + text_size.x, layout_r.Min.y) + ImVec2(2 - marker_size_x, 0.0f); - ImVec2 off = ImVec2(0.0f, (float)(int)(-g.FontSize * 0.25f)); + ImVec2 off = ImVec2(0.0f, IM_FLOOR(-g.FontSize * 0.25f)); RenderTextClipped(marker_pos + off, layout_r.Max + off, UNSAVED_DOCUMENT_MARKER, NULL, NULL, ImVec2(0, style.WindowTitleAlign.y), &clip_r); } } @@ -5524,7 +5524,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) int border_held = -1; ImU32 resize_grip_col[4] = {}; const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4 - const float resize_grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f); + const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); if (!window->Collapsed) if (UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0])) use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true; @@ -5592,9 +5592,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Default item width. Make it proportional to window size if window manually resizes if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize)) - window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); + window->ItemWidthDefault = ImFloor(window->Size.x * 0.65f); else - window->ItemWidthDefault = (float)(int)(g.FontSize * 16.0f); + window->ItemWidthDefault = ImFloor(g.FontSize * 16.0f); // SCROLLING @@ -5988,8 +5988,8 @@ void ImGui::PushMultiItemsWidths(int components, float w_full) ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; const ImGuiStyle& style = g.Style; - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); + const float w_item_one = ImMax(1.0f, IM_FLOOR((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, IM_FLOOR(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); window->DC.ItemWidthStack.push_back(w_item_last); for (int i = 0; i < components-1; i++) window->DC.ItemWidthStack.push_back(w_item_one); @@ -6020,7 +6020,7 @@ float ImGui::CalcItemWidth() float region_max_x = GetContentRegionMaxAbs().x; w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w); } - w = (float)(int)w; + w = IM_FLOOR(w); return w; } @@ -7125,7 +7125,7 @@ void ImGui::SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x { // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size IM_ASSERT(center_x_ratio >= 0.0f && center_x_ratio <= 1.0f); - window->ScrollTarget.x = (float)(int)(local_x + window->Scroll.x); + window->ScrollTarget.x = IM_FLOOR(local_x + window->Scroll.x); window->ScrollTargetCenterRatio.x = center_x_ratio; } @@ -7135,7 +7135,7 @@ void ImGui::SetScrollFromPosY(ImGuiWindow* window, float local_y, float center_y IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f); const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight(); local_y -= decoration_up_height; - window->ScrollTarget.y = (float)(int)(local_y + window->Scroll.y); + window->ScrollTarget.y = IM_FLOOR(local_y + window->Scroll.y); window->ScrollTargetCenterRatio.y = center_y_ratio; } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 4a6dce6d..e2b5ee86 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2069,7 +2069,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float descent = ImFloor(unscaled_descent * font_scale + ((unscaled_descent > 0.0f) ? +1 : -1)); ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); const float font_off_x = cfg.GlyphOffset.x; - const float font_off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); + const float font_off_y = cfg.GlyphOffset.y + ImFloor(dst_font->Ascent + 0.5f); for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++) { @@ -2080,7 +2080,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float char_advance_x_mod = ImClamp(char_advance_x_org, cfg.GlyphMinAdvanceX, cfg.GlyphMaxAdvanceX); float char_off_x = font_off_x; if (char_advance_x_org != char_advance_x_mod) - char_off_x += cfg.PixelSnapH ? (float)(int)((char_advance_x_mod - char_advance_x_org) * 0.5f) : (char_advance_x_mod - char_advance_x_org) * 0.5f; + char_off_x += cfg.PixelSnapH ? ImFloor((char_advance_x_mod - char_advance_x_org) * 0.5f) : (char_advance_x_mod - char_advance_x_org) * 0.5f; // Register glyph stbtt_aligned_quad q; @@ -2591,7 +2591,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, glyph.AdvanceX = advance_x + ConfigData->GlyphExtraSpacing.x; // Bake spacing into AdvanceX if (ConfigData->PixelSnapH) - glyph.AdvanceX = (float)(int)(glyph.AdvanceX + 0.5f); + glyph.AdvanceX = IM_FLOOR(glyph.AdvanceX + 0.5f); // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round) DirtyLookupTables = true; @@ -2833,8 +2833,8 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col if (const ImFontGlyph* glyph = FindGlyph(c)) { float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f; - pos.x = (float)(int)pos.x + DisplayOffset.x; - pos.y = (float)(int)pos.y + DisplayOffset.y; + pos.x = IM_FLOOR(pos.x + DisplayOffset.x); + pos.y = IM_FLOOR(pos.y + DisplayOffset.y); draw_list->PrimReserve(6, 4); draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); } @@ -2846,8 +2846,8 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls. // Align to be pixel perfect - pos.x = (float)(int)pos.x + DisplayOffset.x; - pos.y = (float)(int)pos.y + DisplayOffset.y; + pos.x = IM_FLOOR(pos.x + DisplayOffset.x); + pos.y = IM_FLOOR(pos.y + DisplayOffset.y); float x = pos.x; float y = pos.y; if (y > clip_rect.w) diff --git a/imgui_internal.h b/imgui_internal.h index e7868613..feee1036 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -144,6 +144,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 +#define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds // Debug Logging #ifndef IMGUI_DEBUG_LOG @@ -569,7 +570,7 @@ struct IMGUI_API ImRect void TranslateY(float dy) { Min.y += dy; Max.y += dy; } void ClipWith(const ImRect& r) { Min = ImMax(Min, r.Min); Max = ImMin(Max, r.Max); } // Simple version, may lead to an inverted rectangle, which is fine for Contains/Overlaps test but not for display. void ClipWithFull(const ImRect& r) { Min = ImClamp(Min, r.Min, r.Max); Max = ImClamp(Max, r.Min, r.Max); } // Full version, ensure both points are fully clipped. - void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } + void Floor() { Min.x = IM_FLOOR(Min.x); Min.y = IM_FLOOR(Min.y); Max.x = IM_FLOOR(Max.x); Max.y = IM_FLOOR(Max.y); } bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; } }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b2398a00..d223f147 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -808,7 +808,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa const bool horizontal = (axis == ImGuiAxis_X); ImRect bb = bb_frame; - bb.Expand(ImVec2(-ImClamp((float)(int)((bb_frame_width - 2.0f) * 0.5f), 0.0f, 3.0f), -ImClamp((float)(int)((bb_frame_height - 2.0f) * 0.5f), 0.0f, 3.0f))); + bb.Expand(ImVec2(-ImClamp(IM_FLOOR((bb_frame_width - 2.0f) * 0.5f), 0.0f, 3.0f), -ImClamp(IM_FLOOR((bb_frame_height - 2.0f) * 0.5f), 0.0f, 3.0f))); // V denote the main, longer axis of the scrollbar (= height for a vertical scrollbar) const float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight(); @@ -851,7 +851,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa // Apply scroll // It is ok to modify Scroll here because we are being called in Begin() after the calculation of ContentSize and before setting up our starting position const float scroll_v_norm = ImSaturate((clicked_v_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm * 0.5f) / (1.0f - grab_h_norm)); - *p_scroll_v = (float)(int)(0.5f + scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); + *p_scroll_v = IM_FLOOR(0.5f + scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); // Update values for rendering scroll_ratio = ImSaturate(*p_scroll_v / scroll_max); @@ -1004,12 +1004,12 @@ bool ImGui::Checkbox(const char* label, bool* v) if (window->DC.ItemFlags & ImGuiItemFlags_MixedValue) { // Undocumented tristate/mixed/indeterminate checkbox (#2644) - ImVec2 pad(ImMax(1.0f, (float)(int)(square_sz / 3.6f)), ImMax(1.0f, (float)(int)(square_sz / 3.6f))); + ImVec2 pad(ImMax(1.0f, IM_FLOOR(square_sz / 3.6f)), ImMax(1.0f, IM_FLOOR(square_sz / 3.6f))); window->DrawList->AddRectFilled(check_bb.Min + pad, check_bb.Max - pad, check_col, style.FrameRounding); } else if (*v) { - const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f)); + const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); RenderCheckMark(check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad*2.0f); } @@ -1057,8 +1057,8 @@ bool ImGui::RadioButton(const char* label, bool active) return false; ImVec2 center = check_bb.GetCenter(); - center.x = (float)(int)center.x + 0.5f; - center.y = (float)(int)center.y + 0.5f; + center.x = IM_FLOOR(center.x + 0.5f); + center.y = IM_FLOOR(center.y + 0.5f); const float radius = (square_sz - 1.0f) * 0.5f; bool hovered, held; @@ -1070,7 +1070,7 @@ bool ImGui::RadioButton(const char* label, bool active) window->DrawList->AddCircleFilled(center, radius, GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16); if (active) { - const float pad = ImMax(1.0f, (float)(int)(square_sz / 6.0f)); + const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); window->DrawList->AddCircleFilled(center, radius - pad, GetColorU32(ImGuiCol_CheckMark), 16); } @@ -4022,9 +4022,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { const float scroll_increment_x = inner_size.x * 0.25f; if (cursor_offset.x < state->ScrollX) - state->ScrollX = (float)(int)ImMax(0.0f, cursor_offset.x - scroll_increment_x); + state->ScrollX = IM_FLOOR(ImMax(0.0f, cursor_offset.x - scroll_increment_x)); else if (cursor_offset.x - inner_size.x >= state->ScrollX) - state->ScrollX = (float)(int)(cursor_offset.x - inner_size.x + scroll_increment_x); + state->ScrollX = IM_FLOOR(cursor_offset.x - inner_size.x + scroll_increment_x); } else { @@ -4072,7 +4072,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ else { ImVec2 rect_size = InputTextCalcTextSizeW(p, text_selected_end, &p, NULL, true); - if (rect_size.x <= 0.0f) rect_size.x = (float)(int)(g.Font->GetCharAdvance((ImWchar)' ') * 0.50f); // So we can see selected empty lines + if (rect_size.x <= 0.0f) rect_size.x = IM_FLOOR(g.Font->GetCharAdvance((ImWchar)' ') * 0.50f); // So we can see selected empty lines ImRect rect(rect_pos + ImVec2(0.0f, bg_offy_up - g.FontSize), rect_pos +ImVec2(rect_size.x, bg_offy_dn)); rect.ClipWith(clip_rect); if (rect.Overlaps(clip_rect)) @@ -4239,8 +4239,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if ((flags & (ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV)) != 0 && (flags & ImGuiColorEditFlags_NoInputs) == 0) { // RGB/HSV 0..255 Sliders - const float w_item_one = ImMax(1.0f, (float)(int)((w_inputs - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_inputs - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); + const float w_item_one = ImMax(1.0f, IM_FLOOR((w_inputs - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, IM_FLOOR(w_inputs - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); const bool hide_prefix = (w_item_one <= CalcTextSize((flags & ImGuiColorEditFlags_Float) ? "M:0.000" : "M:000").x); static const char* ids[4] = { "##X", "##Y", "##Z", "##W" }; @@ -4515,7 +4515,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl float sv_picker_size = ImMax(bars_width * 1, width - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x; float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; - float bars_triangles_half_sz = (float)(int)(bars_width * 0.20f); + float bars_triangles_half_sz = IM_FLOOR(bars_width * 0.20f); float backup_initial_col[4]; memcpy(backup_initial_col, col, components * sizeof(float)); @@ -4795,13 +4795,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), col_white, hue_color32, hue_color32, col_white); draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), 0, 0, col_black, col_black); RenderFrameBorder(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), 0.0f); - sv_cursor_pos.x = ImClamp((float)(int)(picker_pos.x + ImSaturate(S) * sv_picker_size + 0.5f), picker_pos.x + 2, picker_pos.x + sv_picker_size - 2); // Sneakily prevent the circle to stick out too much - sv_cursor_pos.y = ImClamp((float)(int)(picker_pos.y + ImSaturate(1 - V) * sv_picker_size + 0.5f), picker_pos.y + 2, picker_pos.y + sv_picker_size - 2); + sv_cursor_pos.x = ImClamp(IM_FLOOR(picker_pos.x + ImSaturate(S) * sv_picker_size + 0.5f), picker_pos.x + 2, picker_pos.x + sv_picker_size - 2); // Sneakily prevent the circle to stick out too much + sv_cursor_pos.y = ImClamp(IM_FLOOR(picker_pos.y + ImSaturate(1 - V) * sv_picker_size + 0.5f), picker_pos.y + 2, picker_pos.y + sv_picker_size - 2); // Render Hue Bar for (int i = 0; i < 6; ++i) draw_list->AddRectFilledMultiColor(ImVec2(bar0_pos_x, picker_pos.y + i * (sv_picker_size / 6)), ImVec2(bar0_pos_x + bars_width, picker_pos.y + (i + 1) * (sv_picker_size / 6)), col_hues[i], col_hues[i], col_hues[i + 1], col_hues[i + 1]); - float bar0_line_y = (float)(int)(picker_pos.y + H * sv_picker_size + 0.5f); + float bar0_line_y = IM_FLOOR(picker_pos.y + H * sv_picker_size + 0.5f); RenderFrameBorder(ImVec2(bar0_pos_x, picker_pos.y), ImVec2(bar0_pos_x + bars_width, picker_pos.y + sv_picker_size), 0.0f); RenderArrowsForVerticalBar(draw_list, ImVec2(bar0_pos_x - 1, bar0_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f, style.Alpha); } @@ -4819,7 +4819,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl ImRect bar1_bb(bar1_pos_x, picker_pos.y, bar1_pos_x + bars_width, picker_pos.y + sv_picker_size); RenderColorRectWithAlphaCheckerboard(bar1_bb.Min, bar1_bb.Max, 0, bar1_bb.GetWidth() / 2.0f, ImVec2(0.0f, 0.0f)); draw_list->AddRectFilledMultiColor(bar1_bb.Min, bar1_bb.Max, user_col32_striped_of_alpha, user_col32_striped_of_alpha, user_col32_striped_of_alpha & ~IM_COL32_A_MASK, user_col32_striped_of_alpha & ~IM_COL32_A_MASK); - float bar1_line_y = (float)(int)(picker_pos.y + (1.0f - alpha) * sv_picker_size + 0.5f); + float bar1_line_y = IM_FLOOR(picker_pos.y + (1.0f - alpha) * sv_picker_size + 0.5f); RenderFrameBorder(bar1_bb.Min, bar1_bb.Max, 0.0f); RenderArrowsForVerticalBar(draw_list, ImVec2(bar1_pos_x - 1, bar1_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f, style.Alpha); } @@ -4876,7 +4876,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl bb_inner.Expand(off); if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col_rgb.w < 1.0f) { - float mid_x = (float)(int)((bb_inner.Min.x + bb_inner.Max.x) * 0.5f + 0.5f); + float mid_x = IM_FLOOR((bb_inner.Min.x + bb_inner.Max.x) * 0.5f + 0.5f); RenderColorRectWithAlphaCheckerboard(ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col_rgb), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight| ImDrawCornerFlags_BotRight); window->DrawList->AddRectFilled(bb_inner.Min, ImVec2(mid_x, bb_inner.Max.y), GetColorU32(col_rgb_without_alpha), rounding, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotLeft); } @@ -5228,8 +5228,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l { // Framed header expand a little outside the default padding, to the edge of InnerClipRect // (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f) - frame_bb.Min.x -= (float)(int)(window->WindowPadding.x * 0.5f - 1.0f); - frame_bb.Max.x += (float)(int)(window->WindowPadding.x * 0.5f); + frame_bb.Min.x -= IM_FLOOR(window->WindowPadding.x * 0.5f - 1.0f); + frame_bb.Max.x += IM_FLOOR(window->WindowPadding.x * 0.5f); } const float text_offset_x = g.FontSize + (display_frame ? padding.x*3 : padding.x*2); // Collapser arrow width + Spacing @@ -5242,7 +5242,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l ImRect interact_bb = frame_bb; if (!display_frame && (flags & (ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth)) == 0) interact_bb.Max.x = frame_bb.Min.x + text_width + style.ItemSpacing.x * 2.0f; - + // Store a flag for the current depth to tell if we will allow closing this node when navigating one of its child. // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop(). // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero. @@ -5521,8 +5521,8 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // Selectables are tightly packed together so we extend the box to cover spacing between selectable. const float spacing_x = style.ItemSpacing.x; const float spacing_y = style.ItemSpacing.y; - const float spacing_L = (float)(int)(spacing_x * 0.50f); - const float spacing_U = (float)(int)(spacing_y * 0.50f); + const float spacing_L = IM_FLOOR(spacing_x * 0.50f); + const float spacing_U = IM_FLOOR(spacing_y * 0.50f); bb.Min.x -= spacing_L; bb.Min.y -= spacing_U; bb.Max.x += (spacing_x - spacing_L); @@ -5972,7 +5972,7 @@ void ImGuiMenuColumns::Update(int count, float spacing, bool clear) { if (i > 0 && NextWidths[i] > 0.0f) Width += Spacing; - Pos[i] = (float)(int)Width; + Pos[i] = IM_FLOOR(Width); Width += NextWidths[i]; NextWidths[i] = 0.0f; } @@ -6129,19 +6129,19 @@ bool ImGui::BeginMenu(const char* label, bool enabled) // Menu inside an horizontal menu bar // Selectable extend their highlight by half ItemSpacing in each direction. // For ChildMenu, the popup position will be overwritten by the call to FindBestWindowPosForPopup() in Begin() - popup_pos = ImVec2(pos.x - 1.0f - (float)(int)(style.ItemSpacing.x * 0.5f), pos.y - style.FramePadding.y + window->MenuBarHeight()); - window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); + popup_pos = ImVec2(pos.x - 1.0f - IM_FLOOR(style.ItemSpacing.x * 0.5f), pos.y - style.FramePadding.y + window->MenuBarHeight()); + window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * 0.5f); PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); float w = label_size.x; pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); PopStyleVar(); - window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). + window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). } else { // Menu inside a menu popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); - float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, (float)(int)(g.FontSize * 1.20f)); // Feedback to next frame + float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled); @@ -6280,16 +6280,16 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo // Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful // Note that in this situation we render neither the shortcut neither the selected tick mark float w = label_size.x; - window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); + window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * 0.5f); PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); pressed = Selectable(label, false, flags, ImVec2(w, 0.0f)); PopStyleVar(); - window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). + window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). } else { ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); - float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame + float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f)); if (shortcut_size.x > 0.0f) @@ -6583,7 +6583,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // If we don't have enough room, resize down the largest tabs first ShrinkWidths(g.ShrinkWidthBuffer.Data, g.ShrinkWidthBuffer.Size, width_excess); for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) - tab_bar->Tabs[g.ShrinkWidthBuffer[tab_n].Index].Width = (float)(int)g.ShrinkWidthBuffer[tab_n].Width; + tab_bar->Tabs[g.ShrinkWidthBuffer[tab_n].Index].Width = IM_FLOOR(g.ShrinkWidthBuffer[tab_n].Width); } else { @@ -6984,7 +6984,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // Layout size.x = tab->Width; - window->DC.CursorPos = tab_bar->BarRect.Min + ImVec2((float)(int)tab->Offset - tab_bar->ScrollingAnim, 0.0f); + window->DC.CursorPos = tab_bar->BarRect.Min + ImVec2(IM_FLOOR(tab->Offset - tab_bar->ScrollingAnim), 0.0f); ImVec2 pos = window->DC.CursorPos; ImRect bb(pos, pos + size); @@ -7042,7 +7042,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, if (hovered && g.HoveredIdNotActiveTimer > 0.50f && bb.GetWidth() < tab->WidthContents) { // Enlarge tab display when hovering - bb.Max.x = bb.Min.x + (float)(int)ImLerp(bb.GetWidth(), tab->WidthContents, ImSaturate((g.HoveredIdNotActiveTimer - 0.40f) * 6.0f)); + bb.Max.x = bb.Min.x + IM_FLOOR(ImLerp(bb.GetWidth(), tab->WidthContents, ImSaturate((g.HoveredIdNotActiveTimer - 0.40f) * 6.0f))); display_draw_list = GetForegroundDrawList(window); TabItemBackground(display_draw_list, bb, flags, GetColorU32(ImGuiCol_TitleBgActive)); } @@ -7152,7 +7152,7 @@ bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, if (flags & ImGuiTabItemFlags_UnsavedDocument) { text_pixel_clip_bb.Max.x -= CalcTextSize(TAB_UNSAVED_MARKER, NULL, false).x; - ImVec2 unsaved_marker_pos(ImMin(bb.Min.x + frame_padding.x + label_size.x + 2, text_pixel_clip_bb.Max.x), bb.Min.y + frame_padding.y + (float)(int)(-g.FontSize * 0.25f)); + ImVec2 unsaved_marker_pos(ImMin(bb.Min.x + frame_padding.x + label_size.x + 2, text_pixel_clip_bb.Max.x), bb.Min.y + frame_padding.y + IM_FLOOR(-g.FontSize * 0.25f)); RenderTextClippedEx(draw_list, unsaved_marker_pos, bb.Max - frame_padding, TAB_UNSAVED_MARKER, NULL, NULL); } ImRect text_ellipsis_clip_bb = text_pixel_clip_bb; @@ -7461,7 +7461,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag float width = offset_1 - offset_0; PushItemWidth(width * 0.65f); window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding; } @@ -7476,7 +7476,7 @@ void ImGui::NextColumn() if (columns->Count == 1) { - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); IM_ASSERT(columns->Current == 0); return; } @@ -7501,7 +7501,7 @@ void ImGui::NextColumn() columns->Current = 0; columns->LineMinY = columns->LineMaxY; } - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); window->DC.CursorPos.y = columns->LineMinY; window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); window->DC.CurrLineTextBaseOffset = 0.0f; @@ -7568,7 +7568,7 @@ void ImGui::EndColumns() // Draw column const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); - const float xi = (float)(int)x; + const float xi = IM_FLOOR(x); window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col); } @@ -7588,7 +7588,7 @@ void ImGui::EndColumns() window->WorkRect = columns->HostWorkRect; window->DC.CurrentColumns = NULL; window->DC.ColumnsOffset.x = 0.0f; - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); } // [2018-03: This is currently the only public API, while we are working on making BeginColumns/EndColumns user-facing] diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index d3f2bf54..3a89df59 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -545,7 +545,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns const float descent = src_tmp.Font.Info.Descender; ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); const float font_off_x = cfg.GlyphOffset.x; - const float font_off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); + const float font_off_y = cfg.GlyphOffset.y + IM_FLOOR(dst_font->Ascent + 0.5f); const int padding = atlas->TexGlyphPadding; for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++) @@ -572,7 +572,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns float char_advance_x_mod = ImClamp(char_advance_x_org, cfg.GlyphMinAdvanceX, cfg.GlyphMaxAdvanceX); float char_off_x = font_off_x; if (char_advance_x_org != char_advance_x_mod) - char_off_x += cfg.PixelSnapH ? (float)(int)((char_advance_x_mod - char_advance_x_org) * 0.5f) : (char_advance_x_mod - char_advance_x_org) * 0.5f; + char_off_x += cfg.PixelSnapH ? IM_FLOOR((char_advance_x_mod - char_advance_x_org) * 0.5f) : (char_advance_x_mod - char_advance_x_org) * 0.5f; // Register glyph float x0 = info.OffsetX + char_off_x; From 4de32cc87ec6e446fb08998ec1933b3913216592 Mon Sep 17 00:00:00 2001 From: malte-v <34393802+malte-v@users.noreply.github.com> Date: Fri, 18 Oct 2019 16:25:18 +0200 Subject: [PATCH 075/384] Backends: GLFW: Restore previously installed user callbacks in ImplGlfw when ImGui shuts down (#2836) --- docs/CHANGELOG.txt | 1 + examples/imgui_impl_glfw.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ee9fcdd2..bed35ef3 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,7 @@ Other Changes: - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] +- Backends: GLFW: Previously installed user callbacks are now restored on shutdown. (#2836) [@malte-v] ----------------------------------------------------------------------- diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index dbf1188d..a28634e2 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -15,6 +15,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter(). // 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized. @@ -62,6 +63,7 @@ static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown; static double g_Time = 0.0; static bool g_MouseJustPressed[5] = { false, false, false, false, false }; static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; +static bool g_InstalledCallbacks = false; // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL; @@ -183,6 +185,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_PrevUserCallbackChar = NULL; if (install_callbacks) { + g_InstalledCallbacks = true; g_PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); g_PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); g_PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); @@ -205,6 +208,15 @@ bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks) void ImGui_ImplGlfw_Shutdown() { + if (g_InstalledCallbacks) + { + glfwSetMouseButtonCallback(g_Window, g_PrevUserCallbackMousebutton); + glfwSetScrollCallback(g_Window, g_PrevUserCallbackScroll); + glfwSetKeyCallback(g_Window, g_PrevUserCallbackKey); + glfwSetCharCallback(g_Window, g_PrevUserCallbackChar); + g_InstalledCallbacks = false; + } + for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) { glfwDestroyCursor(g_MouseCursors[cursor_n]); From eedc8f993f9b69db3e3d5540be55c5774b836342 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 18 Oct 2019 18:20:53 +0200 Subject: [PATCH 076/384] Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. --- docs/CHANGELOG.txt | 1 + examples/example_win32_directx12/main.cpp | 29 ++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bed35ef3..c941f2cd 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -53,6 +53,7 @@ Other Changes: - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] +- Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] - Backends: GLFW: Previously installed user callbacks are now restored on shutdown. (#2836) [@malte-v] diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 90631e85..e555051c 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -9,7 +9,12 @@ #include #include -#define DX12_ENABLE_DEBUG_LAYER 0 +//#define DX12_ENABLE_DEBUG_LAYER + +#ifdef DX12_ENABLE_DEBUG_LAYER +#include +#pragma comment(lib, "dxguid.lib") +#endif struct FrameContext { @@ -233,15 +238,14 @@ bool CreateDeviceD3D(HWND hWnd) sd.Stereo = FALSE; } - if (DX12_ENABLE_DEBUG_LAYER) +#ifdef DX12_ENABLE_DEBUG_LAYER + ID3D12Debug* pdx12Debug = NULL; + if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pdx12Debug)))) { - ID3D12Debug* dx12Debug = NULL; - if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&dx12Debug)))) - { - dx12Debug->EnableDebugLayer(); - dx12Debug->Release(); - } + pdx12Debug->EnableDebugLayer(); + pdx12Debug->Release(); } +#endif D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0; if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK) @@ -329,6 +333,15 @@ void CleanupDeviceD3D() if (g_fence) { g_fence->Release(); g_fence = NULL; } if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; } if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } + +#ifdef DX12_ENABLE_DEBUG_LAYER + IDXGIDebug1* pDebug = NULL; + if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)))) + { + pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_SUMMARY); + pDebug->Release(); + } +#endif } void CreateRenderTarget() From 05c1f2795a077681f836dd783f92442c39c79d52 Mon Sep 17 00:00:00 2001 From: "Ilya.Sevrikov" Date: Thu, 17 Oct 2019 16:53:43 +0300 Subject: [PATCH 077/384] Add multi-viewports for DX12. (#2851) (cherry picked from commit 899e48565d1ecefde06063f99c75e702adcef175) --- examples/example_win32_directx12/main.cpp | 4 +- examples/imgui_impl_dx12.cpp | 358 ++++++++++++++++------ examples/imgui_impl_dx12.h | 5 +- 3 files changed, 265 insertions(+), 102 deletions(-) diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 26a16f0f..0f519c16 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -73,7 +73,7 @@ int main(int, char**) io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking - //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows (FIXME: Currently broken in DX12 back-end, need some work!) + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows //io.ConfigViewportsNoAutoMerge = true; //io.ConfigViewportsNoTaskBarIcon = true; @@ -92,7 +92,7 @@ int main(int, char**) // Setup Platform/Renderer bindings ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT, - DXGI_FORMAT_R8G8B8A8_UNORM, + DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap, g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index d8a46221..7f645d3b 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -4,8 +4,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Multi-viewport. // Missing features, issues: -// [ ] Renderer: Missing multi-viewport support. // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. @@ -46,6 +46,8 @@ static ID3D12Resource* g_pFontTextureResource = NULL; static D3D12_CPU_DESCRIPTOR_HANDLE g_hFontSrvCpuDescHandle = {}; static D3D12_GPU_DESCRIPTOR_HANDLE g_hFontSrvGpuDescHandle = {}; +static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = NULL; + struct FrameResources { ID3D12Resource* IndexBuffer; @@ -53,9 +55,80 @@ struct FrameResources int IndexBufferSize; int VertexBufferSize; }; -static FrameResources* g_pFrameResources = NULL; + static UINT g_numFramesInFlight = 0; -static UINT g_frameIndex = UINT_MAX; + +struct FrameContext +{ + ID3D12CommandAllocator* CommandAllocator; + UINT64 FenceValue; + ID3D12Resource* RenderTarget; + D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetCpuDescriptors; +}; + +struct ImGuiViewportDataDx12 +{ + ID3D12CommandQueue* CommandQueue; + ID3D12GraphicsCommandList* CommandList; + + ID3D12DescriptorHeap* RtvDescHeap; + IDXGISwapChain3* SwapChain; + + ID3D12Fence* Fence; + UINT64 FenceSignaledValue; + HANDLE FenceEvent; + + FrameContext* FrameCtx; + FrameResources* Resources; + + UINT FrameIndex; + + ImGuiViewportDataDx12() + { + CommandQueue = NULL; + CommandList = NULL; + + RtvDescHeap = NULL; + SwapChain = NULL; + FenceSignaledValue = 0; + Fence = NULL; + FenceEvent = NULL; + FrameIndex = UINT_MAX; + + FrameCtx = new FrameContext[g_numFramesInFlight]; + Resources = new FrameResources[g_numFramesInFlight]; + + for (UINT i = 0; i < g_numFramesInFlight; ++i) + { + FrameCtx[i].CommandAllocator = NULL; + FrameCtx[i].RenderTarget = NULL; + + // Create buffers with a default size (they will later be grown as needed) + Resources[i].IndexBuffer = NULL; + Resources[i].VertexBuffer = NULL; + Resources[i].VertexBufferSize = 5000; + Resources[i].IndexBufferSize = 10000; + } + + } + ~ImGuiViewportDataDx12() + { + IM_ASSERT(CommandQueue == NULL && CommandList == NULL); + IM_ASSERT(RtvDescHeap == NULL); + IM_ASSERT(SwapChain == NULL); + IM_ASSERT(Fence == NULL); + IM_ASSERT(FenceEvent == NULL); + + for (UINT i = 0; i < g_numFramesInFlight; ++i) + { + IM_ASSERT(FrameCtx[i].CommandAllocator == NULL && FrameCtx[i].RenderTarget == NULL); + IM_ASSERT(Resources[i].IndexBuffer == NULL && Resources[i].VertexBuffer == NULL); + } + + delete[] FrameCtx; FrameCtx = NULL; + delete[] Resources; Resources = NULL; + } +}; struct VERTEX_CONSTANT_BUFFER { @@ -129,10 +202,9 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f) return; - // FIXME: I'm assuming that this only gets called once per frame! - // If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator. - g_frameIndex = g_frameIndex + 1; - FrameResources* fr = &g_pFrameResources[g_frameIndex % g_numFramesInFlight]; + ImGuiViewportDataDx12* render_data = (ImGuiViewportDataDx12*)draw_data->OwnerViewport->RendererUserData; + render_data->FrameIndex++; + FrameResources* fr = &render_data->Resources[render_data->FrameIndex % g_numFramesInFlight]; // Create and grow vertex/index buffers if needed if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount) @@ -599,15 +671,9 @@ void ImGui_ImplDX12_InvalidateDeviceObjects() if (g_pRootSignature) { g_pRootSignature->Release(); g_pRootSignature = NULL; } if (g_pPipelineState) { g_pPipelineState->Release(); g_pPipelineState = NULL; } if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; io.Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. - for (UINT i = 0; i < g_numFramesInFlight; i++) - { - FrameResources* fr = &g_pFrameResources[i]; - if (fr->IndexBuffer) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; } - if (fr->VertexBuffer) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; } - } } -bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, +bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle) { // Setup back-end capabilities flags @@ -620,20 +686,14 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO g_RTVFormat = rtv_format; g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle; g_hFontSrvGpuDescHandle = font_srv_gpu_desc_handle; - g_pFrameResources = new FrameResources[num_frames_in_flight]; g_numFramesInFlight = num_frames_in_flight; - g_frameIndex = UINT_MAX; + g_pd3dSrvDescHeap = cbv_srv_heap; - // Create buffers with a default size (they will later be grown as needed) - for (int i = 0; i < num_frames_in_flight; i++) - { - FrameResources* fr = &g_pFrameResources[i]; - fr->IndexBuffer = NULL; - fr->VertexBuffer = NULL; - fr->IndexBufferSize = 10000; - fr->VertexBufferSize = 5000; - } + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataDx12); + // Setup back-end capabilities flags + io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) ImGui_ImplDX12_InitPlatformInterface(); @@ -644,13 +704,17 @@ void ImGui_ImplDX12_Shutdown() { ImGui_ImplDX12_ShutdownPlatformInterface(); ImGui_ImplDX12_InvalidateDeviceObjects(); - delete[] g_pFrameResources; - g_pFrameResources = NULL; + g_pd3dDevice = NULL; g_hFontSrvCpuDescHandle.ptr = 0; g_hFontSrvGpuDescHandle.ptr = 0; g_numFramesInFlight = 0; - g_frameIndex = UINT_MAX; + g_pd3dSrvDescHeap = NULL; + + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)main_viewport->RendererUserData) + IM_DELETE(data); + main_viewport->RendererUserData = NULL; } void ImGui_ImplDX12_NewFrame() @@ -665,54 +729,118 @@ void ImGui_ImplDX12_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- -struct ImGuiViewportDataDx12 -{ - IDXGISwapChain3* SwapChain; - - ImGuiViewportDataDx12() { SwapChain = NULL; } - ~ImGuiViewportDataDx12() { IM_ASSERT(SwapChain == NULL); } -}; - static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) { ImGuiViewportDataDx12* data = IM_NEW(ImGuiViewportDataDx12)(); viewport->RendererUserData = data; - IM_ASSERT(0); - /* - // FIXME-PLATFORM // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). // Some back-ends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); + data->FrameIndex = UINT_MAX; + + // Create command queue. + D3D12_COMMAND_QUEUE_DESC queue_desc = {}; + queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; + queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + + HRESULT res = S_OK; + res = g_pd3dDevice->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&data->CommandQueue)); + IM_ASSERT(res == S_OK); + + // Create command allocator. + for (UINT i = 0; i < g_numFramesInFlight; ++i) + { + res = g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&data->FrameCtx[i].CommandAllocator)); + IM_ASSERT(res == S_OK); + } + + // Create command list. + res = g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, data->FrameCtx[0].CommandAllocator, NULL, IID_PPV_ARGS(&data->CommandList)); + IM_ASSERT(res == S_OK); + data->CommandList->Close(); + + // Create fence. + res = g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&data->Fence)); + IM_ASSERT(res == S_OK); + + data->FenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + IM_ASSERT(data->FenceEvent != NULL); + // Create swap chain - DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory(&sd, sizeof(sd)); - sd.BufferDesc.Width = (UINT)viewport->Size.x; - sd.BufferDesc.Height = (UINT)viewport->Size.y; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.BufferCount = 1; - sd.OutputWindow = hwnd; - sd.Windowed = TRUE; - sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; - sd.Flags = 0; - - IM_ASSERT(data->SwapChain == NULL && data->RTView == NULL); - g_pFactory->CreateSwapChain(g_pd3dDevice, &sd, &data->SwapChain); - - // Create the render target + DXGI_SWAP_CHAIN_DESC1 sd1; + ZeroMemory(&sd1, sizeof(sd1)); + sd1.BufferCount = g_numFramesInFlight; + sd1.Width = (UINT)viewport->Size.x; + sd1.Height = (UINT)viewport->Size.y; + sd1.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd1.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd1.SampleDesc.Count = 1; + sd1.SampleDesc.Quality = 0; + sd1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; + sd1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; + sd1.Scaling = DXGI_SCALING_STRETCH; + sd1.Stereo = FALSE; + + IM_ASSERT(data->SwapChain == NULL); + IM_ASSERT(data->FrameCtx[0].RenderTarget == NULL && data->FrameCtx[1].RenderTarget == NULL && data->FrameCtx[2].RenderTarget == NULL); + + IDXGIFactory4* dxgi_factory = nullptr; + res = CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)); + IM_ASSERT(res == S_OK); + + IDXGISwapChain1* swap_chain = nullptr; + res = dxgi_factory->CreateSwapChainForHwnd(data->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain); + IM_ASSERT(res == S_OK); + + dxgi_factory->Release(); + + // Or swapChain.As(&mSwapChain) + swap_chain->QueryInterface(IID_PPV_ARGS(&data->SwapChain)); + + // Create the render targets if (data->SwapChain) { - ID3D11Texture2D* pBackBuffer; - data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); - pBackBuffer->Release(); + D3D12_DESCRIPTOR_HEAP_DESC desc = {}; + desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; + desc.NumDescriptors = g_numFramesInFlight; + desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; + desc.NodeMask = 1; + + IM_ASSERT(g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap)) == S_OK); + + SIZE_T rtv_descriptor_size = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); + D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = data->RtvDescHeap->GetCPUDescriptorHandleForHeapStart(); + for (UINT i = 0; i < g_numFramesInFlight; i++) + { + data->FrameCtx[i].RenderTargetCpuDescriptors = rtv_handle; + rtv_handle.ptr += rtv_descriptor_size; + } + + ID3D12Resource* back_buffer; + for (UINT i = 0; i < g_numFramesInFlight; i++) + { + data->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer)); + g_pd3dDevice->CreateRenderTargetView(back_buffer, NULL, data->FrameCtx[i].RenderTargetCpuDescriptors); + data->FrameCtx[i].RenderTarget = back_buffer; + } + } + + for (UINT i = 0; i < g_numFramesInFlight; i++) + { + if (data->Resources[i].IndexBuffer) { data->Resources[i].VertexBuffer->Release(); data->Resources[i].IndexBuffer = NULL; } + if (data->Resources[i].VertexBuffer) { data->Resources[i].VertexBuffer->Release(); data->Resources[i].VertexBuffer = NULL; } } - */ +} + +template +void SafeRelease(D12Resource*& res) +{ + if (res) + res->Release(); + res = NULL; } static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) @@ -720,16 +848,22 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData) { - IM_ASSERT(0); - /* - if (data->SwapChain) - data->SwapChain->Release(); - data->SwapChain = NULL; - if (data->RTView) - data->RTView->Release(); - data->RTView = NULL; + SafeRelease(data->CommandQueue); + SafeRelease(data->CommandList); + SafeRelease(data->SwapChain); + SafeRelease(data->RtvDescHeap); + SafeRelease(data->Fence); + CloseHandle(data->FenceEvent); data->FenceEvent = NULL; + + for (UINT i = 0; i < g_numFramesInFlight; i++) + { + SafeRelease(data->FrameCtx[i].RenderTarget); + SafeRelease(data->FrameCtx[i].CommandAllocator); + SafeRelease(data->Resources[i].IndexBuffer); + SafeRelease(data->Resources[i].VertexBuffer); + } + IM_DELETE(data); - */ } viewport->RendererUserData = NULL; } @@ -737,51 +871,79 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; - IM_ASSERT(0); - (void)data; (void)size; - /* - if (data->RTView) + + for (UINT i = 0; i < g_numFramesInFlight; i++) { - data->RTView->Release(); - data->RTView = NULL; + SafeRelease(data->FrameCtx[i].RenderTarget); } + if (data->SwapChain) { - ID3D11Texture2D* pBackBuffer = NULL; + ID3D12Resource* back_buffer = NULL; data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); - data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); - g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); - pBackBuffer->Release(); + for (UINT i = 0; i < g_numFramesInFlight; i++) + { + data->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer)); + g_pd3dDevice->CreateRenderTargetView(back_buffer, NULL, data->FrameCtx[i].RenderTargetCpuDescriptors); + data->FrameCtx[i].RenderTarget = back_buffer; + } } - */ } -// arg = ID3D12GraphicsCommandList* -static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void* renderer_arg) +static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; - IM_ASSERT(0); - (void)data; - - ID3D12GraphicsCommandList* command_list = (ID3D12GraphicsCommandList*)renderer_arg; - /* ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - g_pd3dDeviceContext->OMSetRenderTargets(1, &data->RTView, NULL); + + //-- + FrameContext* frame_context = &data->FrameCtx[data->FrameIndex % g_numFramesInFlight]; + + UINT back_buffer_idx = data->SwapChain->GetCurrentBackBufferIndex(); + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barrier.Transition.pResource = data->FrameCtx[back_buffer_idx].RenderTarget; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; + + //-- draw + ID3D12GraphicsCommandList* cmd_list = data->CommandList; + + frame_context->CommandAllocator->Reset(); + cmd_list->Reset(frame_context->CommandAllocator, NULL); + cmd_list->ResourceBarrier(1, &barrier); + cmd_list->OMSetRenderTargets(1, &data->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, FALSE, NULL); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) - g_pd3dDeviceContext->ClearRenderTargetView(data->RTView, (float*)&clear_color); - */ - ImGui_ImplDX12_RenderDrawData(viewport->DrawData, command_list); + cmd_list->ClearRenderTargetView(data->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, (float*)&clear_color, 0, NULL); + cmd_list->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap); + + ImGui_ImplDX12_RenderDrawData(viewport->DrawData, cmd_list); + + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; + cmd_list->ResourceBarrier(1, &barrier); + cmd_list->Close(); + + //-- + data->CommandQueue->Wait(data->Fence, data->FenceSignaledValue); + //-- + data->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list); + //-- + data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue); } static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; - IM_ASSERT(0); - (void)data; - /* - data->SwapChain->Present(0, 0); // Present without vsync - */ + + data->SwapChain->Present(0, 0); + + while (data->Fence->GetCompletedValue() < data->FenceSignaledValue) + { + SwitchToThread(); + } } void ImGui_ImplDX12_InitPlatformInterface() diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 80c3bfa1..2d3b1fe6 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -4,8 +4,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Multi-viewport. // Missing features, issues: -// [ ] Renderer: Missing multi-viewport support. // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. @@ -16,6 +16,7 @@ enum DXGI_FORMAT; struct ID3D12Device; +struct ID3D12DescriptorHeap; struct ID3D12GraphicsCommandList; struct D3D12_CPU_DESCRIPTOR_HANDLE; struct D3D12_GPU_DESCRIPTOR_HANDLE; @@ -24,7 +25,7 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE; // Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate // render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. // font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. -IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, +IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); From 6faad0c34f05e9a4e51919197d35497a82fb8880 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 18 Oct 2019 18:03:56 +0200 Subject: [PATCH 078/384] Backend: DX12: Amend 899e485. Fix memory leaks. Remove unused variable. (#2851) (cherry picked from commit 39e2db6d94c295e7468c6a5fb39d247c641fb123) --- examples/imgui_impl_dx12.cpp | 82 +++++++++++++++--------------------- examples/imgui_impl_dx12.h | 2 +- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 7f645d3b..91a902ea 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -3,8 +3,9 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. +// FIXME: The transition from removing a viewport and moving the window in an existing hosted viewport tends to flicker. // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. -// [X] Renderer: Multi-viewport. // Missing features, issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 @@ -45,8 +46,8 @@ static DXGI_FORMAT g_RTVFormat = DXGI_FORMAT_UNKNOWN; static ID3D12Resource* g_pFontTextureResource = NULL; static D3D12_CPU_DESCRIPTOR_HANDLE g_hFontSrvCpuDescHandle = {}; static D3D12_GPU_DESCRIPTOR_HANDLE g_hFontSrvGpuDescHandle = {}; - static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = NULL; +static UINT g_numFramesInFlight = 0; struct FrameResources { @@ -56,12 +57,9 @@ struct FrameResources int VertexBufferSize; }; -static UINT g_numFramesInFlight = 0; - struct FrameContext { ID3D12CommandAllocator* CommandAllocator; - UINT64 FenceValue; ID3D12Resource* RenderTarget; D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetCpuDescriptors; }; @@ -70,7 +68,6 @@ struct ImGuiViewportDataDx12 { ID3D12CommandQueue* CommandQueue; ID3D12GraphicsCommandList* CommandList; - ID3D12DescriptorHeap* RtvDescHeap; IDXGISwapChain3* SwapChain; @@ -78,23 +75,21 @@ struct ImGuiViewportDataDx12 UINT64 FenceSignaledValue; HANDLE FenceEvent; + UINT FrameIndex; FrameContext* FrameCtx; FrameResources* Resources; - UINT FrameIndex; - ImGuiViewportDataDx12() { CommandQueue = NULL; CommandList = NULL; - RtvDescHeap = NULL; SwapChain = NULL; - FenceSignaledValue = 0; + Fence = NULL; + FenceSignaledValue = 0; FenceEvent = NULL; FrameIndex = UINT_MAX; - FrameCtx = new FrameContext[g_numFramesInFlight]; Resources = new FrameResources[g_numFramesInFlight]; @@ -109,7 +104,6 @@ struct ImGuiViewportDataDx12 Resources[i].VertexBufferSize = 5000; Resources[i].IndexBufferSize = 10000; } - } ~ImGuiViewportDataDx12() { @@ -130,6 +124,14 @@ struct ImGuiViewportDataDx12 } }; +template +static void SafeRelease(T*& res) +{ + if (res) + res->Release(); + res = NULL; +} + struct VERTEX_CONSTANT_BUFFER { float mvp[4][4]; @@ -209,7 +211,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL // Create and grow vertex/index buffers if needed if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount) { - if (fr->VertexBuffer != NULL) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; } + SafeRelease(fr->VertexBuffer); fr->VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D12_HEAP_PROPERTIES props; memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES)); @@ -232,7 +234,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL } if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount) { - if (fr->IndexBuffer != NULL) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; } + SafeRelease(fr->IndexBuffer); fr->IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D12_HEAP_PROPERTIES props; memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES)); @@ -452,8 +454,7 @@ static void ImGui_ImplDX12_CreateFontsTexture() srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, g_hFontSrvCpuDescHandle); - if (g_pFontTextureResource != NULL) - g_pFontTextureResource->Release(); + SafeRelease(g_pFontTextureResource); g_pFontTextureResource = pTexture; } @@ -665,12 +666,14 @@ void ImGui_ImplDX12_InvalidateDeviceObjects() if (!g_pd3dDevice) return; + SafeRelease(g_pVertexShaderBlob); + SafeRelease(g_pPixelShaderBlob); + SafeRelease(g_pRootSignature); + SafeRelease(g_pPipelineState); + SafeRelease(g_pFontTextureResource); + ImGuiIO& io = ImGui::GetIO(); - if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } - if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; } - if (g_pRootSignature) { g_pRootSignature->Release(); g_pRootSignature = NULL; } - if (g_pPipelineState) { g_pPipelineState->Release(); g_pPipelineState = NULL; } - if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; io.Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + io.Fonts->TexID = NULL; // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. } bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, @@ -690,7 +693,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO g_pd3dSrvDescHeap = cbv_srv_heap; ImGuiViewport* main_viewport = ImGui::GetMainViewport(); - main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataDx12); + main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataDx12)(); // Setup back-end capabilities flags io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) @@ -770,6 +773,7 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) IM_ASSERT(data->FenceEvent != NULL); // Create swap chain + // FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application. DXGI_SWAP_CHAIN_DESC1 sd1; ZeroMemory(&sd1, sizeof(sd1)); sd1.BufferCount = g_numFramesInFlight; @@ -799,6 +803,7 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) // Or swapChain.As(&mSwapChain) swap_chain->QueryInterface(IID_PPV_ARGS(&data->SwapChain)); + swap_chain->Release(); // Create the render targets if (data->SwapChain) @@ -830,19 +835,11 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) for (UINT i = 0; i < g_numFramesInFlight; i++) { - if (data->Resources[i].IndexBuffer) { data->Resources[i].VertexBuffer->Release(); data->Resources[i].IndexBuffer = NULL; } - if (data->Resources[i].VertexBuffer) { data->Resources[i].VertexBuffer->Release(); data->Resources[i].VertexBuffer = NULL; } + SafeRelease(data->Resources[i].IndexBuffer); + SafeRelease(data->Resources[i].VertexBuffer); } } -template -void SafeRelease(D12Resource*& res) -{ - if (res) - res->Release(); - res = NULL; -} - static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) { // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. @@ -853,7 +850,8 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) SafeRelease(data->SwapChain); SafeRelease(data->RtvDescHeap); SafeRelease(data->Fence); - CloseHandle(data->FenceEvent); data->FenceEvent = NULL; + ::CloseHandle(data->FenceEvent); + data->FenceEvent = NULL; for (UINT i = 0; i < g_numFramesInFlight; i++) { @@ -873,9 +871,7 @@ static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; for (UINT i = 0; i < g_numFramesInFlight; i++) - { SafeRelease(data->FrameCtx[i].RenderTarget); - } if (data->SwapChain) { @@ -894,12 +890,10 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; - ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); - - //-- FrameContext* frame_context = &data->FrameCtx[data->FrameIndex % g_numFramesInFlight]; - UINT back_buffer_idx = data->SwapChain->GetCurrentBackBufferIndex(); + + const ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); D3D12_RESOURCE_BARRIER barrier = {}; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; @@ -908,7 +902,7 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; - //-- draw + // Draw ID3D12GraphicsCommandList* cmd_list = data->CommandList; frame_context->CommandAllocator->Reset(); @@ -926,11 +920,8 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*) cmd_list->ResourceBarrier(1, &barrier); cmd_list->Close(); - //-- data->CommandQueue->Wait(data->Fence, data->FenceSignaledValue); - //-- data->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list); - //-- data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue); } @@ -939,11 +930,8 @@ static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*) ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData; data->SwapChain->Present(0, 0); - while (data->Fence->GetCompletedValue() < data->FenceSignaledValue) - { - SwitchToThread(); - } + ::SwitchToThread(); } void ImGui_ImplDX12_InitPlatformInterface() diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 2d3b1fe6..6cbd1ace 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -3,8 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! +// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. -// [X] Renderer: Multi-viewport. // Missing features, issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 From 6ffee0e75e8f677c5fd8280dfe544c3fcb325f45 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 18 Oct 2019 18:32:48 +0200 Subject: [PATCH 079/384] Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport features (docking branch). (#2851) + Using SafeRelease() in master. --- docs/CHANGELOG.txt | 2 ++ examples/example_win32_directx12/main.cpp | 2 +- examples/imgui_impl_dx12.cpp | 36 +++++++++++++++-------- examples/imgui_impl_dx12.h | 3 +- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c941f2cd..d41923ba 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,8 @@ Breaking Changes: Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. +- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. + The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] Other Changes: - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index e555051c..968ef7d9 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -85,7 +85,7 @@ int main(int, char**) // Setup Platform/Renderer bindings ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT, - DXGI_FORMAT_R8G8B8A8_UNORM, + DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap, g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 6d6161a1..83d68527 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-10-18: DirectX12: *BREAKING CHANGE* Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. // 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. // 2019-03-29: Misc: Various minor tidying up. @@ -56,6 +57,14 @@ static FrameResources* g_pFrameResources = NULL; static UINT g_numFramesInFlight = 0; static UINT g_frameIndex = UINT_MAX; +template +static void SafeRelease(T*& res) +{ + if (res) + res->Release(); + res = NULL; +} + struct VERTEX_CONSTANT_BUFFER { float mvp[4][4]; @@ -132,7 +141,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL // Create and grow vertex/index buffers if needed if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount) { - if (fr->VertexBuffer != NULL) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; } + SafeRelease(fr->VertexBuffer); fr->VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D12_HEAP_PROPERTIES props; memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES)); @@ -155,7 +164,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL } if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount) { - if (fr->IndexBuffer != NULL) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; } + SafeRelease(fr->IndexBuffer); fr->IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D12_HEAP_PROPERTIES props; memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES)); @@ -375,8 +384,7 @@ static void ImGui_ImplDX12_CreateFontsTexture() srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, g_hFontSrvCpuDescHandle); - if (g_pFontTextureResource != NULL) - g_pFontTextureResource->Release(); + SafeRelease(g_pFontTextureResource); g_pFontTextureResource = pTexture; } @@ -588,21 +596,24 @@ void ImGui_ImplDX12_InvalidateDeviceObjects() if (!g_pd3dDevice) return; + SafeRelease(g_pVertexShaderBlob); + SafeRelease(g_pPixelShaderBlob); + SafeRelease(g_pRootSignature); + SafeRelease(g_pPipelineState); + SafeRelease(g_pFontTextureResource); + ImGuiIO& io = ImGui::GetIO(); - if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } - if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; } - if (g_pRootSignature) { g_pRootSignature->Release(); g_pRootSignature = NULL; } - if (g_pPipelineState) { g_pPipelineState->Release(); g_pPipelineState = NULL; } - if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; io.Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + io.Fonts->TexID = NULL; // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. + for (UINT i = 0; i < g_numFramesInFlight; i++) { FrameResources* fr = &g_pFrameResources[i]; - if (fr->IndexBuffer) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; } - if (fr->VertexBuffer) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; } + SafeRelease(fr->IndexBuffer); + SafeRelease(fr->VertexBuffer); } } -bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, +bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle) { // Setup back-end capabilities flags @@ -617,6 +628,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO g_pFrameResources = new FrameResources[num_frames_in_flight]; g_numFramesInFlight = num_frames_in_flight; g_frameIndex = UINT_MAX; + IM_UNUSED(cbv_srv_heap); // Unused in master branch (will be used by multi-viewports) // Create buffers with a default size (they will later be grown as needed) for (int i = 0; i < num_frames_in_flight; i++) diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 274c1c92..6c05805b 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -15,6 +15,7 @@ enum DXGI_FORMAT; struct ID3D12Device; +struct ID3D12DescriptorHeap; struct ID3D12GraphicsCommandList; struct D3D12_CPU_DESCRIPTOR_HANDLE; struct D3D12_GPU_DESCRIPTOR_HANDLE; @@ -23,7 +24,7 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE; // Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate // render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. // font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. -IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, +IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); From 7dbae8a1988b5175389c0064d208b3f7ef96106f Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 Oct 2019 13:26:47 +0200 Subject: [PATCH 080/384] Doc: Simplified Readme, removed FAQ index --- docs/README.md | 57 +++++++------------------------------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/docs/README.md b/docs/README.md index a99ffe67..e91db64c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,23 +29,15 @@ Dear ImGui is particularly suited to integration in games engine (for tooling), ### Usage -Dear ImGui is self-contained within a few files that you can easily copy and compile into your application/engine: -- imgui.cpp -- imgui.h -- imgui_demo.cpp -- imgui_draw.cpp -- imgui_widgets.cpp -- imgui_internal.h -- imconfig.h (empty by default, user-editable) -- imstb_rectpack.h -- imstb_textedit.h -- imstb_truetype.h +**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily copy and compile into your application/engine. They are all the files in the root folder of the repository (imgui.cpp, imgui.h, imgui_demo.cpp, imgui_draw.cpp etc.). -No specific build process is required. You can add the .cpp files to your project or #include them from an existing file. +**No specific build process is required**. You can add the .cpp files to your existing project. -Backends for a variety of graphics api and rendering platforms along with example applications are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder. +You will need a backend to integrate Dear ImGui in your app. The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. -The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: +**Backends for a variety of graphics api and rendering platforms** are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder, along with example applications. See the [Integration](#integration) section of this document for details. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui. + +After Dear ImGui is setup in your application, you can use it from \_anywhere\_ in your program loop: Code: ```cp @@ -153,44 +145,11 @@ Custom engine [![screenshot tool](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white_preview.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) [Tracy Profiler](https://bitbucket.org/wolfpld/tracy) -![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/tracy_profiler.png) +![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v173/tracy_profiler.jpg) ### Support, Frequently Asked Questions (FAQ) -Most common questions will be answered by the [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) page, e.g.: - -**Basics** -- "Where is the documentation?" -- "Which version should I get?" -- "Why the names "Dear ImGui" vs "ImGui"?" - -**Community** -- "How can I help?" - -**Concerns** -- "Who uses Dear ImGui?" -- "Can you create elaborate/serious tools with Dear ImGui?" -- "Can you reskin the look of Dear ImGui?" -- "Why using C++ (as opposed to C)?" - -**Integration** -- "How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?" -- "How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)" -- "I integrated Dear ImGui in my engine and the text or lines are blurry.." -- "I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.." - -**Usage** -- "Why are multiple widgets reacting when I interact with a single one? How can I have multiple widgets with the same label or with an empty label?" -- "How can I display an image? What is ImTextureID, how does it work?" -- "How can I use my own math types instead of ImVec2/ImVec4?" -- "How can I interact with standard C++ types (such as std::string and std::vector)?" -- "How can I display custom shapes? (using low-level ImDrawList API)" - -**Fonts, Text** -- "How can I load a different font than the default?" -- "How can I easily use icons in my application?" -- "How can I load multiple fonts?" -- "How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?" +Most common questions will be answered by the [Frequently Asked Questions (FAQ)](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) page. See: [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, articles. From 7b77cb3bb8712dff11c3420fc980abe2191dd395 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 Oct 2019 13:38:33 +0200 Subject: [PATCH 081/384] Backend: DX12: Fixed incorrect assert (#2851) --- examples/imgui_impl_dx12.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 91a902ea..b7ca6138 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -788,20 +788,18 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) sd1.Scaling = DXGI_SCALING_STRETCH; sd1.Stereo = FALSE; - IM_ASSERT(data->SwapChain == NULL); - IM_ASSERT(data->FrameCtx[0].RenderTarget == NULL && data->FrameCtx[1].RenderTarget == NULL && data->FrameCtx[2].RenderTarget == NULL); - - IDXGIFactory4* dxgi_factory = nullptr; - res = CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)); + IDXGIFactory4* dxgi_factory = NULL; + res = ::CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)); IM_ASSERT(res == S_OK); - IDXGISwapChain1* swap_chain = nullptr; + IDXGISwapChain1* swap_chain = NULL; res = dxgi_factory->CreateSwapChainForHwnd(data->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain); IM_ASSERT(res == S_OK); dxgi_factory->Release(); // Or swapChain.As(&mSwapChain) + IM_ASSERT(data->SwapChain == NULL); swap_chain->QueryInterface(IID_PPV_ARGS(&data->SwapChain)); swap_chain->Release(); @@ -827,6 +825,7 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) ID3D12Resource* back_buffer; for (UINT i = 0; i < g_numFramesInFlight; i++) { + IM_ASSERT(data->FrameCtx[i].RenderTarget == NULL); data->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer)); g_pd3dDevice->CreateRenderTargetView(back_buffer, NULL, data->FrameCtx[i].RenderTargetCpuDescriptors); data->FrameCtx[i].RenderTarget = back_buffer; @@ -860,7 +859,6 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) SafeRelease(data->Resources[i].IndexBuffer); SafeRelease(data->Resources[i].VertexBuffer); } - IM_DELETE(data); } viewport->RendererUserData = NULL; From 048b73dfaa0e9cbaea250305c5a4810d67722c8f Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 Oct 2019 16:12:46 +0200 Subject: [PATCH 082/384] Various comments + Doc: Examples readme. Moved main menu bar code below menu bar code. --- examples/README.txt | 32 +++++++++++++++----- imgui.h | 61 +++++++++++++++++++++----------------- imgui_demo.cpp | 4 +-- imgui_widgets.cpp | 72 ++++++++++++++++++++++----------------------- 4 files changed, 96 insertions(+), 73 deletions(-) diff --git a/examples/README.txt b/examples/README.txt index 23c6bdb9..2c73c89d 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -62,10 +62,10 @@ You can find binaries of some of those example applications at: Most the example bindings are split in 2 parts: - The "Platform" bindings, in charge of: mouse/keyboard/gamepad inputs, cursor shape, timing, windowing. - Examples: Windows (imgui_impl_win32.cpp), GLFW (imgui_impl_glfw.cpp), SDL2 (imgui_impl_sdl.cpp) + Examples: Windows (imgui_impl_win32.cpp), GLFW (imgui_impl_glfw.cpp), SDL2 (imgui_impl_sdl.cpp), etc. - The "Renderer" bindings, in charge of: creating the main font texture, rendering imgui draw data. - Examples: DirectX11 (imgui_impl_dx11.cpp), GL3 (imgui_impl_opengl3.cpp), Vulkan (imgui_impl_vulkan.cpp) + Examples: DirectX11 (imgui_impl_dx11.cpp), GL3 (imgui_impl_opengl3.cpp), Vulkan (imgui_impl_vulkan.cpp), etc. - The example _applications_ usually combine 1 platform + 1 renderer binding to create a working program. Examples: the example_win32_directx11/ application combines imgui_impl_win32.cpp + imgui_impl_dx11.cpp. @@ -122,16 +122,32 @@ List of high-level Frameworks Bindings in this repository: (combine Platform + R imgui_impl_allegro5.cpp imgui_impl_marmalade.cpp -Note that Dear ImGui works with Emscripten. -The examples_emscripten/ app uses sdl.cpp + opengl3.cpp but other combinations are possible. +Note that Dear ImGui works with Emscripten. The examples_emscripten/ app uses imgui_impl_sdl.cpp and +imgui_impl_opengl3.cpp, but other combinations are possible. + Third-party framework, graphics API and languages bindings are listed at: https://github.com/ocornut/imgui/wiki/Bindings - Languages: C, C#, ChaiScript, D, Go, Haxe, Java, Lua, Odin, Pascal, PureBasic, Python, Rust, Swift... - Frameworks: Cinder, Cocoa (OSX), Cocos2d-x, SFML, GML/GameMaker Studio, Irrlicht, Ogre, OpenSceneGraph, - openFrameworks, LOVE, NanoRT, Nim Game Lib, Qt3d, SFML, Unreal Engine 4... - Miscellaneous: Software Renderer, RemoteImgui, etc. + Languages: + C, C#, ChaiScript, CovScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Nim, + Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... + + Frameworks: + Amethyst, bsf, Cinder, Cocoa2d-x, Diligent Engine, Flexium, GML/GameMaker Studio, + GTK3 + OpenGL, Irrlicht, Ogre, OpenSceneGraph/OSG, openFrameworks, Orx, LÖVE+LUA, + Magnum, NanoRT, Nim Game Lib, px_render, Qt, Qt3d, SFML, Sokol, Unreal Engine 4, vtk... + + Miscellaneous: Software Renderer, RemoteImgui, imgui-ws, etc. + +Not sure which to use? +Recommended platform/frameworks: + + GLFW https://github.com/glfw/glfw Use imgui_impl_glfw.cpp + SDL2 https://www.libsdl.org Use imgui_impl_sdl.cp + Sokol https://github.com/floooh/sokol Use util/sokol_imgui.h in Sokol repository. + +Those will allow you to create portable applications and will solve and abstract away many issues. --------------------------------------- diff --git a/imgui.h b/imgui.h index 1675fc6c..ba7d6370 100644 --- a/imgui.h +++ b/imgui.h @@ -27,7 +27,7 @@ Index of this file: #pragma once -// Configuration file with compile-time options (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename) +// Configuration file with compile-time options (edit imconfig.h or #define IMGUI_USER_CONFIG to your own filename) #ifdef IMGUI_USER_CONFIG #include IMGUI_USER_CONFIG #endif @@ -39,8 +39,9 @@ Index of this file: // Header mess //----------------------------------------------------------------------------- -#include // FLT_MAX -#include // va_list +// Includes +#include // FLT_MIN, FLT_MAX +#include // va_list, va_start, va_end #include // ptrdiff_t, NULL #include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp @@ -66,13 +67,13 @@ Index of this file: #define IM_ASSERT(_EXPR) assert(_EXPR) // You can override the default assert handler by editing imconfig.h #endif #if defined(__clang__) || defined(__GNUC__) -#define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) // Apply printf-style warnings to user functions. +#define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) // To apply printf-style warnings to our functions. #define IM_FMTLIST(FMT) __attribute__((format(printf, FMT, 0))) #else #define IM_FMTARGS(FMT) #define IM_FMTLIST(FMT) #endif -#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) // Size of a static C-style array. Don't use on pointers! +#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*_ARR))) // Size of a static C-style array. Don't use on pointers! #define IM_UNUSED(_VAR) ((void)_VAR) // Used to silence "unused variable warnings". Often useful as asserts may be stripped out from final builds. #if (__cplusplus >= 201100) #define IM_OFFSETOF(_TYPE,_MEMBER) offsetof(_TYPE, _MEMBER) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in C++11 @@ -123,7 +124,7 @@ struct ImGuiTextBuffer; // Helper to hold and append into a text buf struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]") // Typedefs and Enums/Flags (declared as int for compatibility with old C++, to allow using as flags and to not pollute the top of this file) -// Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. +// Use your programming IDE "Go to definition" facility on the names in the central column below to find the actual flags/enum lists. #ifndef ImTextureID typedef void* ImTextureID; // User data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp) #endif @@ -157,7 +158,7 @@ typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data); typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); // Scalar data types -typedef signed char ImS8; // 8-bit signed integer == char +typedef signed char ImS8; // 8-bit signed integer typedef unsigned char ImU8; // 8-bit unsigned integer typedef signed short ImS16; // 16-bit signed integer typedef unsigned short ImU16; // 16-bit unsigned integer @@ -201,14 +202,14 @@ struct ImVec4 //----------------------------------------------------------------------------- // ImGui: Dear ImGui end-user API -// (Inside a namespace so you can add extra functions in your own separate file. Please don't modify imgui.cpp/.h!) +// (Inside a namespace so you can add extra functions in your own separate file. Please don't modify imgui source files!) //----------------------------------------------------------------------------- namespace ImGui { // Context creation and access // Each context create its own ImFontAtlas by default. You may instance one yourself and pass it to CreateContext() to share a font atlas between imgui contexts. - // All those functions are not reliant on the current context. + // None of those functions is reliant on the current context. IMGUI_API ImGuiContext* CreateContext(ImFontAtlas* shared_font_atlas = NULL); IMGUI_API void DestroyContext(ImGuiContext* ctx = NULL); // NULL = destroy current context IMGUI_API ImGuiContext* GetCurrentContext(); @@ -245,8 +246,9 @@ namespace ImGui // which clicking will set the boolean to false when clicked. // - Begin() return false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting // anything to the window. Always call a matching End() for each Begin() call, regardless of its return value! - // [this is due to legacy reason and is inconsistent with most other functions such as BeginMenu/EndMenu, BeginPopup/EndPopup, etc. - // where the EndXXX call should only be called if the corresponding BeginXXX function returned true.] + // [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu/EndMenu, + // BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function + // returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.] // - Note that the bottom of window stack always contains a window called "Debug". IMGUI_API bool Begin(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0); IMGUI_API void End(); @@ -255,13 +257,13 @@ namespace ImGui // - Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child. // - For each independent axis of 'size': ==0.0f: use remaining host window size / >0.0f: fixed size / <0.0f: use remaining window size minus abs(size) / Each axis can use a different mode, e.g. ImVec2(0,400). // - BeginChild() returns false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window. - // Always call a matching EndChild() for each BeginChild() call, regardless of its return value [this is due to legacy reason and is inconsistent with most other functions such as BeginMenu/EndMenu, BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function returned true.] + // Always call a matching EndChild() for each BeginChild() call, regardless of its return value [as with Begin: this is due to legacy reason and inconsistent with most BeginXXX functions apart from the regular Begin() which behaves like BeginChild().] IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0); IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags flags = 0); IMGUI_API void EndChild(); // Windows Utilities - // - "current window" = the window we are appending into while inside a Begin()/End() block. "next window" = next window we will Begin() into. + // - 'current window' = the window we are appending into while inside a Begin()/End() block. 'next window' = next window we will Begin() into. IMGUI_API bool IsWindowAppearing(); IMGUI_API bool IsWindowCollapsed(); IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags=0); // is current window focused? or its root/child, depending on flags. see flags for options. @@ -342,6 +344,7 @@ namespace ImGui // Cursor / Layout // - By "cursor" we mean the current output position. // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down. + // - You can call SameLine() between widgets to undo the last carriage return and output at the right of the preceeding widget. IMGUI_API void Separator(); // separator, generally horizontal. inside a menu bar or in horizontal layout mode, this becomes a vertical separator. IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f); // call between widgets or groups to layout them horizontally. X position given in window coordinates. IMGUI_API void NewLine(); // undo a SameLine() or force a new line when in an horizontal-layout context. @@ -383,8 +386,8 @@ namespace ImGui IMGUI_API ImGuiID GetID(const void* ptr_id); // Widgets: Text - IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // raw text without formatting. Roughly equivalent to Text("%s", text) but: A) doesn't require null terminated string if 'text_end' is specified, B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text. - IMGUI_API void Text(const char* fmt, ...) IM_FMTARGS(1); // simple formatted text + IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // raw text without formatting. Roughly equivalent to Text("%s", text) but: A) doesn't require null terminated string if 'text_end' is specified, B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text. + IMGUI_API void Text(const char* fmt, ...) IM_FMTARGS(1); // formatted text IMGUI_API void TextV(const char* fmt, va_list args) IM_FMTLIST(1); IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...) IM_FMTARGS(2); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor(); IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args) IM_FMTLIST(2); @@ -399,6 +402,7 @@ namespace ImGui // Widgets: Main // - Most widgets return true when the value has been changed or when pressed/selected + // - You may also use one of the many IsItemXXX functions (e.g. IsItemActive, IsItemHovered, etc.) to query widget state. IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); // button IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.) @@ -413,7 +417,7 @@ namespace ImGui IMGUI_API void Bullet(); // draw a small circle and keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses // Widgets: Combo Box - // - The new BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items. + // - The BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items. // - The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. IMGUI_API bool BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags = 0); IMGUI_API void EndCombo(); // only call EndCombo() if BeginCombo() returns true! @@ -509,7 +513,7 @@ namespace ImGui // Widgets: Selectables // - A selectable highlights when hovered, and can display another color when selected. - // - Neighbors selectable extend their highlight bounds in order to leave no gap between them. + // - Neighbors selectable extend their highlight bounds in order to leave no gap between them. This is so a series of selected Selectable appear contiguous. IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // "bool selected" carry the selection state (read-only). Selectable() is clicked is returns true so you can modify your selection state. size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // "bool* p_selected" point to the selection state (read-write), as a convenient helper. @@ -535,16 +539,19 @@ namespace ImGui IMGUI_API void Value(const char* prefix, float v, const char* float_format = NULL); // Widgets: Menus - IMGUI_API bool BeginMainMenuBar(); // create and append to a full screen menu-bar. - IMGUI_API void EndMainMenuBar(); // only call EndMainMenuBar() if BeginMainMenuBar() returns true! + // - Use BeginMenuBar() on a window ImGuiWindowFlags_MenuBar to append to its menu bar. + // - Use BeginMainMenuBar() to create a menu bar at the top of the screen. IMGUI_API bool BeginMenuBar(); // append to menu-bar of current window (requires ImGuiWindowFlags_MenuBar flag set on parent window). IMGUI_API void EndMenuBar(); // only call EndMenuBar() if BeginMenuBar() returns true! + IMGUI_API bool BeginMainMenuBar(); // create and append to a full screen menu-bar. + IMGUI_API void EndMainMenuBar(); // only call EndMainMenuBar() if BeginMainMenuBar() returns true! IMGUI_API bool BeginMenu(const char* label, bool enabled = true); // create a sub-menu entry. only call EndMenu() if this returns true! IMGUI_API void EndMenu(); // only call EndMenu() if BeginMenu() returns true! IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL // Tooltips + // - Tooltip are windows following the mouse which do not take focus away. IMGUI_API void BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items). IMGUI_API void EndTooltip(); IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). override any previous call to SetTooltip(). @@ -556,7 +563,7 @@ namespace ImGui // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. // - Their visibility state (~bool) is held internally by imgui instead of being held by the programmer as we are used to with regular Begin() calls. // User can manipulate the visibility state by calling OpenPopup(). - // (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup. + // (*) You can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup. // Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time. IMGUI_API void OpenPopup(const char* str_id); // call to mark popup as open (don't call every frame!). popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. By default, Selectable()/MenuItem() are calling CloseCurrentPopup(). Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). IMGUI_API bool BeginPopup(const char* str_id, ImGuiWindowFlags flags = 0); // return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returns true! @@ -572,6 +579,7 @@ namespace ImGui // Columns // - You can also use SameLine(pos_x) to mimic simplified columns. // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) + // - By end of the 2019 we will expose a new 'Table' api which will replace columns. IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished IMGUI_API int GetColumnIndex(); // get current column index @@ -582,7 +590,6 @@ namespace ImGui IMGUI_API int GetColumnsCount(); // Tab Bars, Tabs - // [BETA API] API may evolve! IMGUI_API bool BeginTabBar(const char* str_id, ImGuiTabBarFlags flags = 0); // create and append into a TabBar IMGUI_API void EndTabBar(); // only call EndTabBar() if BeginTabBar() returns true! IMGUI_API bool BeginTabItem(const char* label, bool* p_open = NULL, ImGuiTabItemFlags flags = 0);// create a Tab. Returns true if the Tab is selected. @@ -950,12 +957,12 @@ enum ImGuiKey_ ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_KeyPadEnter, - ImGuiKey_A, // for text edit CTRL+A: select all - ImGuiKey_C, // for text edit CTRL+C: copy - ImGuiKey_V, // for text edit CTRL+V: paste - ImGuiKey_X, // for text edit CTRL+X: cut - ImGuiKey_Y, // for text edit CTRL+Y: redo - ImGuiKey_Z, // for text edit CTRL+Z: undo + ImGuiKey_A, // for text edit CTRL+A: select all + ImGuiKey_C, // for text edit CTRL+C: copy + ImGuiKey_V, // for text edit CTRL+V: paste + ImGuiKey_X, // for text edit CTRL+X: cut + ImGuiKey_Y, // for text edit CTRL+Y: redo + ImGuiKey_Z, // for text edit CTRL+Z: undo ImGuiKey_COUNT }; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8e765863..c9ee0f43 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3263,7 +3263,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) if (ImGui::Button("Revert Ref")) style = *ref; ImGui::SameLine(); - HelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export Colors\" below to save them somewhere."); + HelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export\" below to save them somewhere."); ImGui::Separator(); @@ -3311,7 +3311,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) { static int output_dest = 0; static bool output_only_modified = true; - if (ImGui::Button("Export Unsaved")) + if (ImGui::Button("Export")) { if (output_dest == 0) ImGui::LogToClipboard(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d223f147..f9415b3a 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5943,10 +5943,10 @@ void ImGui::Value(const char* prefix, float v, const char* float_format) // [SECTION] MenuItem, BeginMenu, EndMenu, etc. //------------------------------------------------------------------------- // - ImGuiMenuColumns [Internal] -// - BeginMainMenuBar() -// - EndMainMenuBar() // - BeginMenuBar() // - EndMenuBar() +// - BeginMainMenuBar() +// - EndMainMenuBar() // - BeginMenu() // - EndMenu() // - MenuItem() @@ -5994,40 +5994,6 @@ float ImGuiMenuColumns::CalcExtraSpace(float avail_w) return ImMax(0.0f, avail_w - Width); } -// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. -bool ImGui::BeginMainMenuBar() -{ - ImGuiContext& g = *GImGui; - g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f)); - SetNextWindowPos(ImVec2(0.0f, 0.0f)); - SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y)); - PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0)); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar; - bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar(); - PopStyleVar(2); - g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); - if (!is_open) - { - End(); - return false; - } - return true; //-V1020 -} - -void ImGui::EndMainMenuBar() -{ - EndMenuBar(); - - // When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window - // FIXME: With this strategy we won't be able to restore a NULL focus. - ImGuiContext& g = *GImGui; - if (g.CurrentWindow == g.NavWindow && g.NavLayer == 0 && !g.NavAnyRequest) - FocusTopMostWindowUnderOne(g.NavWindow, NULL); - - End(); -} - // FIXME: Provided a rectangle perhaps e.g. a BeginMenuBarEx() could be used anywhere.. // Currently the main responsibility of this function being to setup clip-rect + horizontal layout + menu navigation layer. // Ideally we also want this to be responsible for claiming space out of the main window scrolling rectangle, in which case ImGuiWindowFlags_MenuBar will become unnecessary. @@ -6101,6 +6067,40 @@ void ImGui::EndMenuBar() window->DC.MenuBarAppending = false; } +// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. +bool ImGui::BeginMainMenuBar() +{ + ImGuiContext& g = *GImGui; + g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f)); + SetNextWindowPos(ImVec2(0.0f, 0.0f)); + SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y)); + PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar; + bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar(); + PopStyleVar(2); + g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); + if (!is_open) + { + End(); + return false; + } + return true; //-V1020 +} + +void ImGui::EndMainMenuBar() +{ + EndMenuBar(); + + // When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window + // FIXME: With this strategy we won't be able to restore a NULL focus. + ImGuiContext& g = *GImGui; + if (g.CurrentWindow == g.NavWindow && g.NavLayer == 0 && !g.NavAnyRequest) + FocusTopMostWindowUnderOne(g.NavWindow, NULL); + + End(); +} + bool ImGui::BeginMenu(const char* label, bool enabled) { ImGuiWindow* window = GetCurrentWindow(); From 23c1ff490744ca76c8e8581ea1605b786fb2720d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 22 Oct 2019 14:43:04 +0200 Subject: [PATCH 083/384] Removed redirecting functions/enums names that were marked obsolete in 1.52 (October 2017). - Begin() [old 5 args version] -> use Begin() [3 args], use SetNextWindowSize() SetNextWindowBgAlpha() if needed - IsRootWindowOrAnyChildHovered() -> use IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) - AlignFirstTextHeightToWidgets() -> use AlignTextToFramePadding(); - SetNextWindowPosCenter() -> use SetNextWindowPos() with a pivot of (0.5f, 0.5f) - ImFont::Glyph -> use ImFontGlyph If you were still using the old names, read "API Breaking Changes" section of imgui.cpp to find out the new names or equivalent features, or see how they were implemented until 1.73. --- docs/CHANGELOG.txt | 10 +++++++++- imgui.cpp | 19 ++----------------- imgui.h | 13 ++----------- imstb_textedit.h | 2 +- imstb_truetype.h | 2 +- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d41923ba..762a788a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,6 +34,14 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Breaking Changes: +- Removed redirecting functions/enums names that were marked obsolete in 1.52 (October 2017): + - Begin() [old 5 args version] -> use Begin() [3 args], use SetNextWindowSize() SetNextWindowBgAlpha() if needed + - IsRootWindowOrAnyChildHovered() -> use IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) + - AlignFirstTextHeightToWidgets() -> use AlignTextToFramePadding() + - SetNextWindowPosCenter() -> use SetNextWindowPos() with a pivot of (0.5f, 0.5f) + - ImFont::Glyph -> use ImFontGlyph + If you were still using the old names, read "API Breaking Changes" section of imgui.cpp to find out + the new names or equivalent features, or see how they were implemented until 1.73. - Inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. If you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can @@ -42,7 +50,7 @@ Breaking Changes: Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. -- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. +- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] Other Changes: diff --git a/imgui.cpp b/imgui.cpp index 50dd9647..6ee83835 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -351,13 +351,14 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. Grep this log for details and new names, or see how they were implemented until 1.73. - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. - 2019/07/15 (1.72) - removed TreeAdvanceToLabelPos() which is rarely used and only does SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()). Kept redirection function (will obsolete). - 2019/07/12 (1.72) - renamed ImFontAtlas::CustomRect to ImFontAtlasCustomRect. Kept redirection typedef (will obsolete). - - 2019/06/14 (1.72) - removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): ImGuiCol_Column*, ImGuiSetCond_*, IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow(), IMGUI_ONCE_UPON_A_FRAME. Grep this log for details and new names. + - 2019/06/14 (1.72) - removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): ImGuiCol_Column*, ImGuiSetCond_*, IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow(), IMGUI_ONCE_UPON_A_FRAME. Grep this log for details and new names, or see how they were implemented until 1.71. - 2019/06/07 (1.71) - rendering of child window outer decorations (bg color, border, scrollbars) is now performed as part of the parent window. If you have overlapping child windows in a same parent, and relied on their relative z-order to be mapped to their submission order, this will affect your rendering. This optimization is disabled if the parent window has no visual output, because it appears to be the most common situation leading to the creation of overlapping child windows. @@ -5814,22 +5815,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) return !skip_items; } -// Old Begin() API with 5 parameters, avoid calling this version directly! Use SetNextWindowSize()/SetNextWindowBgAlpha() + Begin() instead. -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS -bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_first_use, float bg_alpha_override, ImGuiWindowFlags flags) -{ - // Old API feature: we could pass the initial window size as a parameter. This was misleading because it only had an effect if the window didn't have data in the .ini file. - if (size_first_use.x != 0.0f || size_first_use.y != 0.0f) - SetNextWindowSize(size_first_use, ImGuiCond_FirstUseEver); - - // Old API feature: override the window background alpha with a parameter. - if (bg_alpha_override >= 0.0f) - SetNextWindowBgAlpha(bg_alpha_override); - - return Begin(name, p_open, flags); -} -#endif // IMGUI_DISABLE_OBSOLETE_FUNCTIONS - void ImGui::End() { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index ba7d6370..9662670a 100644 --- a/imgui.h +++ b/imgui.h @@ -246,8 +246,8 @@ namespace ImGui // which clicking will set the boolean to false when clicked. // - Begin() return false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting // anything to the window. Always call a matching End() for each Begin() call, regardless of its return value! - // [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu/EndMenu, - // BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function + // [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu/EndMenu, + // BeginPopup/EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function // returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.] // - Note that the bottom of window stack always contains a window called "Debug". IMGUI_API bool Begin(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0); @@ -1578,11 +1578,6 @@ namespace ImGui static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); } static inline float GetItemsLineHeightWithSpacing() { return GetFrameHeightWithSpacing(); } - // OBSOLETED in 1.52 (between Aug 2017 and Oct 2017) - IMGUI_API bool Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // Use SetNextWindowSize(size, ImGuiCond_FirstUseEver) + SetNextWindowBgAlpha() instead. - static inline bool IsRootWindowOrAnyChildHovered() { return IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); } - static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); } - static inline void SetNextWindowPosCenter(ImGuiCond c=0) { ImGuiIO& io = GetIO(); SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), c, ImVec2(0.5f, 0.5f)); } } typedef ImGuiInputTextCallback ImGuiTextEditCallback; // OBSOLETED in 1.63 (from Aug 2018): made the names consistent typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData; @@ -2230,10 +2225,6 @@ struct ImFont IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x); IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built. IMGUI_API void SetFallbackChar(ImWchar c); - -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - typedef ImFontGlyph Glyph; // OBSOLETED in 1.52+ -#endif }; #if defined(__clang__) diff --git a/imstb_textedit.h b/imstb_textedit.h index d7fcbd62..2077d02a 100644 --- a/imstb_textedit.h +++ b/imstb_textedit.h @@ -1,4 +1,4 @@ -// [DEAR IMGUI] +// [DEAR IMGUI] // This is a slightly modified version of stb_textedit.h 1.13. // Those changes would need to be pushed into nothings/stb: // - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321) diff --git a/imstb_truetype.h b/imstb_truetype.h index c1cdb180..193338af 100644 --- a/imstb_truetype.h +++ b/imstb_truetype.h @@ -1,4 +1,4 @@ -// [DEAR IMGUI] +// [DEAR IMGUI] // This is a slightly modified version of stb_truetype.h 1.20. // Mostly fixing for compiler and static analyzer warnings. // Grep for [DEAR IMGUI] to find the changes. From be9f1e8f007be79e9c1b38ada231c9be2a416e6e Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 23 Oct 2019 00:45:59 +0300 Subject: [PATCH 084/384] ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 762a788a..7b2a16a0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,7 @@ Breaking Changes: The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] Other Changes: +- ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) - InputText: Filter out ASCII 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f9415b3a..0f984deb 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4784,7 +4784,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl draw_list->PrimVtx(trb, uv_white, hue_color32); draw_list->PrimVtx(trc, uv_white, col_white); draw_list->PrimVtx(tra, uv_white, 0); - draw_list->PrimVtx(trb, uv_white, col_white); + draw_list->PrimVtx(trb, uv_white, col_black); draw_list->PrimVtx(trc, uv_white, 0); draw_list->AddTriangle(tra, trb, trc, col_midgrey, 1.5f); sv_cursor_pos = ImLerp(ImLerp(trc, tra, ImSaturate(S)), trb, ImSaturate(1 - V)); From 75d540d33699fc04d1ea31deb5f8adb726aaf915 Mon Sep 17 00:00:00 2001 From: Funto Date: Wed, 23 Oct 2019 16:55:26 +0200 Subject: [PATCH 085/384] Example: Emscripten: Fix for compilation (filesystem module is required) (#2734) --- examples/example_emscripten/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/example_emscripten/Makefile b/examples/example_emscripten/Makefile index 9edfafd0..c9f2c054 100644 --- a/examples/example_emscripten/Makefile +++ b/examples/example_emscripten/Makefile @@ -24,7 +24,8 @@ UNAME_S := $(shell uname -s) EMS = -s USE_SDL=2 -s WASM=1 EMS += -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE=clamp EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0 -EMS += -s ASSERTIONS=1 -s NO_FILESYSTEM=1 +EMS += -s ASSERTIONS=1 +#EMS += -s NO_FILESYSTEM=1 ## Getting "error: undefined symbol: $FS" if filesystem is removed #EMS += -s SAFE_HEAP=1 ## Adds overhead CPPFLAGS = -I../ -I../../ From ec0e953ccac876a6c850fde2cbbe9bc138b99a55 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 6 Oct 2019 23:17:36 +0200 Subject: [PATCH 086/384] Fixed a couple of subtle bounding box vertical positioning issues relating to text baseline alignment. The issue would generally manifest when laying out multiple items on a same line, with varying heights and text baseline offsets. (#2833) Some specific examples, e.g. a button with regular frame padding followed by another item with a multi-line label and no frame padding, such as: multi-line text, small button, tree node item, etc. The second item was correctly offset to match text baseline, and would interact/display correctly,but it wouldn't push the contents area boundary low enough. Note: previously the second parameter to ItemSize() was 0.0f was default, now -1.0f to signify "no text baseline offset request". If you have code using ItemSize() with an hardcoded zero you may need to change it. (+1 squashed commits) --- docs/CHANGELOG.txt | 10 +++++++++- imgui.cpp | 9 +++++++-- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 27 ++++++++++++++------------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7b2a16a0..46948ecc 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,9 +54,16 @@ Breaking Changes: The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] Other Changes: -- ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) - InputText: Filter out ASCII 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) +- Layout: Fixed a couple of subtle bounding box vertical positioning issues relating to the handling of text + baseline alignment. The issue would generally manifest when laying out multiple items on a same line, + with varying heights and text baseline offsets. + Some specific examples, e.g. a button with regular frame padding followed by another item with a + multi-line label and no frame padding, such as: multi-line text, small button, tree node item, etc. + The second item was correctly offset to match text baseline, and would interact/display correctly, + but it wouldn't push the contents area boundary low enough. +- ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data @@ -65,6 +72,7 @@ Other Changes: - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. +- Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] - Backends: GLFW: Previously installed user callbacks are now restored on shutdown. (#2836) [@malte-v] diff --git a/imgui.cpp b/imgui.cpp index 6ee83835..cb4ff913 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2777,8 +2777,13 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) if (window->SkipItems) return; + // We increase the height in this function to accommodate for baseline offset. + // In theory we should be offsetting the starting position (window->DC.CursorPos), that will be the topic of a larger refactor, + // but since ItemSize() is not yet an API that moves the cursor (to handle e.g. wrapping) enlarging the height has the same effect. + const float offset_to_match_baseline_y = (text_baseline_y >= 0) ? ImMax(0.0f, window->DC.CurrLineTextBaseOffset - text_baseline_y) : 0.0f; + const float line_height = ImMax(window->DC.CurrLineSize.y, size.y + offset_to_match_baseline_y); + // Always align ourselves on pixel boundaries - const float line_height = ImMax(window->DC.CurrLineSize.y, size.y); //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; @@ -6913,7 +6918,7 @@ void ImGui::EndGroup() } window->DC.CurrLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now. - ItemSize(group_bb.GetSize(), 0.0f); + ItemSize(group_bb.GetSize()); ItemAdd(group_bb, 0); // If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive(), IsItemDeactivated() etc. will be functional on the entire group. diff --git a/imgui_internal.h b/imgui_internal.h index feee1036..f669b18e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1543,8 +1543,8 @@ namespace ImGui IMGUI_API void PushOverrideID(ImGuiID id); // Basic Helpers for widget code - IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = 0.0f); - IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = 0.0f); + IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = -1.0f); + IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = -1.0f); IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL); IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0f984deb..ca98f3ce 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -213,7 +213,7 @@ void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags) text_size.y = (pos - text_pos).y; ImRect bb(text_pos, text_pos + text_size); - ItemSize(text_size); + ItemSize(text_size, 0.0f); ItemAdd(bb, 0); } else @@ -222,7 +222,7 @@ void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags) const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width); ImRect bb(text_pos, text_pos + text_size); - ItemSize(text_size); + ItemSize(text_size, 0.0f); if (!ItemAdd(bb, 0)) return; @@ -359,17 +359,18 @@ void ImGui::BulletTextV(const char* fmt, va_list args) const char* text_begin = g.TempBuffer; const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); const ImVec2 label_size = CalcTextSize(text_begin, text_end, false); - const float text_base_offset_y = ImMax(0.0f, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it - const float line_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + g.Style.FramePadding.y*2), g.FontSize); - const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x*2) : 0.0f), ImMax(line_height, label_size.y))); // Empty text doesn't add padding - ItemSize(bb); + const ImVec2 total_size = ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x * 2) : 0.0f), label_size.y); // Empty text doesn't add padding + ImVec2 pos = window->DC.CursorPos; + pos.y += window->DC.CurrLineTextBaseOffset; + ItemSize(total_size, 0.0f); + const ImRect bb(pos, pos + total_size); if (!ItemAdd(bb, 0)) return; // Render ImU32 text_col = GetColorU32(ImGuiCol_Text); - RenderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, line_height*0.5f), text_col); - RenderText(bb.Min+ImVec2(g.FontSize + style.FramePadding.x*2, text_base_offset_y), text_begin, text_end, false); + RenderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize*0.5f, g.FontSize*0.5f), text_col); + RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f), text_begin, text_end, false); } //------------------------------------------------------------------------- @@ -691,7 +692,7 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu const ImGuiID id = window->GetID(str_id); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); const float default_size = GetFrameHeight(); - ItemSize(size, (size.y >= default_size) ? g.Style.FramePadding.y : 0.0f); + ItemSize(size, (size.y >= default_size) ? g.Style.FramePadding.y : -1.0f); if (!ItemAdd(bb, id)) return false; @@ -5211,7 +5212,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const bool display_frame = (flags & ImGuiTreeNodeFlags_Framed) != 0; - const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, 0.0f); + const ImVec2 padding = (display_frame || (flags & ImGuiTreeNodeFlags_FramePadding)) ? style.FramePadding : ImVec2(style.FramePadding.x, ImMin(window->DC.CurrLineTextBaseOffset, style.FramePadding.y)); if (!label_end) label_end = FindRenderedTextEnd(label); @@ -5236,7 +5237,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const float text_offset_y = ImMax(padding.y, window->DC.CurrLineTextBaseOffset); // Latch before ItemSize changes it const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x*2 : 0.0f); // Include collapser ImVec2 text_pos(window->DC.CursorPos.x + text_offset_x, window->DC.CursorPos.y + text_offset_y); - ItemSize(ImVec2(text_width, frame_height), text_offset_y); + ItemSize(ImVec2(text_width, frame_height), padding.y); // For regular tree nodes, we arbitrary allow to click past 2 worth of ItemSpacing ImRect interact_bb = frame_bb; @@ -5507,7 +5508,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl ImVec2 pos = window->DC.CursorPos; pos.y += window->DC.CurrLineTextBaseOffset; ImRect bb_inner(pos, pos + size); - ItemSize(size); + ItemSize(size, 0.0f); // Fill horizontal space. ImVec2 window_padding = window->WindowPadding; @@ -6438,7 +6439,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG tab_bar->FramePadding = g.Style.FramePadding; // Layout - ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight())); + ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight()), tab_bar->FramePadding.y); window->DC.CursorPos.x = tab_bar->BarRect.Min.x; // Draw separator From 24e9a6e92cca227c471ab5b81eb24299f9f84b35 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 23 Oct 2019 15:39:14 +0300 Subject: [PATCH 087/384] Remove .travis.yml due to switching to github actions. --- .travis.yml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7a554baf..00000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: cpp -sudo: required -dist: trusty - -os: - - linux - - osx - -compiler: - - gcc - - clang - -before_install: - - if [ $TRAVIS_OS_NAME == linux ]; then - sudo apt-get update -qq; - sudo apt-get install -y --no-install-recommends libxrandr-dev libxi-dev libxxf86vm-dev libsdl2-dev; - wget https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip; - unzip glfw-3.2.1.zip && cd glfw-3.2.1; - cmake -DBUILD_SHARED_LIBS=true -DGLFW_BUILD_EXAMPLES=false -DGLFW_BUILD_TESTS=false -DGLFW_BUILD_DOCS=false .; - sudo make -j $CPU_NUM install && cd ..; - fi - - if [ $TRAVIS_OS_NAME == osx ]; then - brew update; - brew install glfw3; - brew install sdl2; - fi - -script: - - make -C examples/example_glfw_opengl2 - - make -C examples/example_glfw_opengl3 - - make -C examples/example_sdl_opengl3 - - if [ $TRAVIS_OS_NAME == osx ]; then - xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos; - fi From d5b5a81946c5ecf40f1b083eee96ebf8ef472f79 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 23 Oct 2019 18:10:47 +0300 Subject: [PATCH 088/384] GitHub Actions CI script for Windows/Linux/MacOS/iOS/Emscripten builds. --- .github/workflows/build.yml | 108 ++++++++++++++++++++++++++++++++++++ docs/CHANGELOG.txt | 2 + docs/README.md | 4 +- 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..54d267ae --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,108 @@ +name: build + +on: [push, pull_request] + +jobs: + Windows: + runs-on: windows-2019 + env: + MSBUILD_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Fix Projects + shell: powershell + run: | + # Replace v110 toolset with v142. Only v141 and v142 toolsets are available on CI workers. + # Replace 8.1 platform sdk with 10.0.18362.0. Workers do not contain legacy SDKs. + # WARNING: This will need updating if toolset/sdk change in project files! + gci -recurse -filter "*.vcxproj" | ForEach-Object { + (Get-Content $_.FullName) -Replace "v110","v142" -Replace "8.1","10.0.18362.0" | Set-Content -Path $_.FullName + } + + - name: Build x86 + shell: cmd + run: | + "%MSBUILD_PATH%\MSBuild.exe" /p:Platform=Win32 /p:Configuration=Release examples/imgui_examples.sln + + - name: Build x64 + shell: cmd + run: | + "%MSBUILD_PATH%\MSBuild.exe" /p:Platform=x64 /p:Configuration=Release examples/imgui_examples.sln + + Linux: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y libglfw3-dev libsdl2-dev + + - name: Build + run: | + make -C examples/example_null + make -C examples/example_glfw_opengl2 + make -C examples/example_glfw_opengl3 + make -C examples/example_sdl_opengl2 + make -C examples/example_sdl_opengl3 + + MacOS: + runs-on: macOS-10.14 + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Install Dependencies + run: | + brew install glfw3 + brew install sdl2 + + - name: Build + run: | + make -C examples/example_null + make -C examples/example_glfw_opengl2 + make -C examples/example_glfw_opengl3 + make -C examples/example_glfw_metal + make -C examples/example_sdl_opengl2 + make -C examples/example_sdl_opengl3 + xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos + xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2 + + iOS: + runs-on: macOS-10.14 + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Build + run: | + # Code signing is required, but we disable it because it is irrelevant for CI builds. + xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_ios CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO + + Emscripten: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Install Dependencies + run: | + wget -q https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz + tar -xvf emsdk-portable.tar.gz + emsdk-portable/emsdk update + emsdk-portable/emsdk install latest + emsdk-portable/emsdk activate latest + + - name: Build + run: | + source emsdk-portable/emsdk_env.sh + make -C examples/example_emscripten diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 46948ecc..d52561d6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,8 @@ Other Changes: - Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] - Backends: GLFW: Previously installed user callbacks are now restored on shutdown. (#2836) [@malte-v] +- CI: Set up a bunch of continuous-integration tests using GitHub Actions. We now compile many of the example + applications on Windows, Linux, MacOS, iOS, Emscripten. Removed Travis integration. (#2865) [@rokups] ----------------------------------------------------------------------- diff --git a/docs/README.md b/docs/README.md index e91db64c..ac2e03a2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ dear imgui ===== -[![Build Status](https://api.travis-ci.com/ocornut/imgui.svg?branch=master)](https://travis-ci.com/ocornut/imgui) +[![Build Status](https://github.com/ocornut/imgui/workflows/build/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=build) [![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) @@ -33,7 +33,7 @@ Dear ImGui is particularly suited to integration in games engine (for tooling), **No specific build process is required**. You can add the .cpp files to your existing project. -You will need a backend to integrate Dear ImGui in your app. The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. +You will need a backend to integrate Dear ImGui in your app. The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices. **Backends for a variety of graphics api and rendering platforms** are provided in the [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder, along with example applications. See the [Integration](#integration) section of this document for details. You may also create your own backend. Anywhere where you can render textured triangles, you can render Dear ImGui. From 3c238ecae30b264aa8cf0509f1e24a6c8e1d6d21 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 24 Oct 2019 11:26:45 +0200 Subject: [PATCH 089/384] Move issue_template and pull_request_template to .github folder. --- {docs => .github}/issue_template.md | 0 {docs => .github}/pull_request_template.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {docs => .github}/issue_template.md (100%) rename {docs => .github}/pull_request_template.md (100%) diff --git a/docs/issue_template.md b/.github/issue_template.md similarity index 100% rename from docs/issue_template.md rename to .github/issue_template.md diff --git a/docs/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from docs/pull_request_template.md rename to .github/pull_request_template.md From 9b323a7ebfab1c0ce5840f1c2ed64f30c892d44e Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 25 Oct 2019 11:05:14 +0200 Subject: [PATCH 090/384] SplitterBehavior: not using FrameRounding in render (was in first commit of the function, not sure why). (#319) --- imgui_widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ca98f3ce..958a6904 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1348,7 +1348,7 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float // Render const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : (hovered && g.HoveredIdTimer >= hover_visibility_delay) ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); - window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, g.Style.FrameRounding); + window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, 0.0f); return held; } From 664fb38e399bd4b86f4adf75fb260b74fd8909ac Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 25 Oct 2019 11:13:51 +0200 Subject: [PATCH 091/384] Docking: child windows don't use style.ChildRounding. --- imgui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 48831461..731bb0bd 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6088,9 +6088,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->Pos = ImFloor(window->Pos); // Lock window rounding for the frame (so that altering them doesn't cause inconsistencies) - window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; - if (window->ViewportOwned) + if (window->ViewportOwned || window->DockIsActive) window->WindowRounding = 0.0f; + else + window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; // Apply window focus (new and reactivated windows are moved to front) bool want_focus = false; From 4d0c88e9e6f0c77c9fbf71f6843daac9fec78371 Mon Sep 17 00:00:00 2001 From: dawid Date: Fri, 25 Oct 2019 11:40:50 +0200 Subject: [PATCH 092/384] Backends: GL3: Fix compile for < 3.2 bindings where glDrawElementsBaseVertex is not available. (#2866, #2852) --- examples/imgui_impl_opengl3.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 3824647a..7f2c588e 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -120,14 +120,15 @@ #endif // Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have. -#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3) -#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 0 +#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3) || !defined(GL_VERSION_3_2) +#define IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX 0 #else -#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 1 +#define IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX 1 #endif // OpenGL Data static char g_GlslVersionString[32] = ""; +static GLuint g_GlVersion = 0; static GLuint g_FontTexture = 0; static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location @@ -137,11 +138,22 @@ static unsigned int g_VboHandle = 0, g_ElementsHandle = 0; // Functions bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { + // query for GL version +#if !defined(IMGUI_IMPL_OPENGL_ES2) + GLint major, minor; + glGetIntegerv (GL_MAJOR_VERSION, &major); + glGetIntegerv (GL_MINOR_VERSION, &minor); + g_GlVersion = major * 1000 + minor; +#else + g_GlVersion = 2000; // GLES 2 +#endif + // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = "imgui_impl_opengl3"; -#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX - io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. +#if IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX + if (g_GlVersion >= 3200) + io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. #endif // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. @@ -344,8 +356,11 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) // Bind texture, Draw glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); -#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX - glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); +#if IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX + if (g_GlVersion >= 3200) + glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); + else + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); #else glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); #endif From f002a1189888faa0f98cfde963deeb78f02f4b43 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 25 Oct 2019 11:56:36 +0200 Subject: [PATCH 093/384] Backends: OpenGL3: Fix building with pre-3.2 GL bindings which do not expose glDrawElementsBaseVertex(), using runtime GL version to decide if we set ImGuiBackendFlags_RendererHasVtxOffset. (#2866, #2852) [@dpilawa] --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_opengl3.cpp | 34 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d52561d6..72c7c18a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,6 +73,8 @@ Other Changes: - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] +- Backends: OpenGL3: Fix building with pre-3.2 GL loaders which do not expose glDrawElementsBaseVertex(), + using runtime GL version to decide if we set ImGuiBackendFlags_RendererHasVtxOffset. (#2866, #2852) [@dpilawa] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] - Backends: GLFW: Previously installed user callbacks are now restored on shutdown. (#2836) [@malte-v] - CI: Set up a bunch of continuous-integration tests using GitHub Actions. We now compile many of the example diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 7f2c588e..c1d44da6 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders. // 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility. // 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call. // 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. @@ -77,7 +78,7 @@ #include "TargetConditionals.h" #endif -// Auto-detect GL version +// Auto-enable GLES on matching platforms #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" @@ -99,9 +100,9 @@ #include #elif defined(IMGUI_IMPL_OPENGL_ES3) #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) -#include // Use GL ES 3 +#include // Use GL ES 3 #else -#include // Use GL ES 3 +#include // Use GL ES 3 #endif #else // About Desktop OpenGL function loaders: @@ -119,16 +120,16 @@ #endif #endif -// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have. +// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have. #if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3) || !defined(GL_VERSION_3_2) -#define IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX 0 +#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET 0 #else -#define IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX 1 +#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET 1 #endif // OpenGL Data -static char g_GlslVersionString[32] = ""; -static GLuint g_GlVersion = 0; +static GLuint g_GlVersion = 0; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries. +static char g_GlslVersionString[32] = ""; // Specified by user or detected based on compile time GL settings. static GLuint g_FontTexture = 0; static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location @@ -138,11 +139,11 @@ static unsigned int g_VboHandle = 0, g_ElementsHandle = 0; // Functions bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { - // query for GL version + // Query for GL version #if !defined(IMGUI_IMPL_OPENGL_ES2) GLint major, minor; - glGetIntegerv (GL_MAJOR_VERSION, &major); - glGetIntegerv (GL_MINOR_VERSION, &minor); + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); g_GlVersion = major * 1000 + minor; #else g_GlVersion = 2000; // GLES 2 @@ -151,12 +152,13 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = "imgui_impl_opengl3"; -#if IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX +#if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET if (g_GlVersion >= 3200) io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. #endif - // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. + // Store GLSL version string so we can refer to it later in case we recreate shaders. + // Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. #if defined(IMGUI_IMPL_OPENGL_ES2) if (glsl_version == NULL) glsl_version = "#version 100"; @@ -356,14 +358,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) // Bind texture, Draw glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); -#if IMGUI_IMPL_OPENGL_MAY_HAVE_DRAW_WITH_BASE_VERTEX +#if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET if (g_GlVersion >= 3200) glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); else - glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); -#else - glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); #endif + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); } } } From 4e56de757c76c9d713d4f05a0f6adf82d1aac068 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 25 Oct 2019 15:33:10 +0200 Subject: [PATCH 094/384] Doc: Promote Discord over Discourse. Obsoleting Discourse server. --- .github/issue_template.md | 2 +- docs/README.md | 4 ++-- imgui.cpp | 2 +- misc/fonts/README.txt | 7 ++----- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/issue_template.md b/.github/issue_template.md index bd05f0a5..e2c30e07 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -4,7 +4,7 @@ 2. PLEASE CAREFULLY READ: https://github.com/ocornut/imgui/issues/2261 -2. FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING/LOADING FONTS, please use the [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forum](https://discourse.dearimgui.org/c/getting-started). +2. FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING/LOADING FONTS, please use the [Discord server](http://discord.dearimgui.org). 3. PLEASE MAKE SURE that you have: read the FAQ; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1) (2). diff --git a/docs/README.md b/docs/README.md index ac2e03a2..c5d757be 100644 --- a/docs/README.md +++ b/docs/README.md @@ -155,7 +155,7 @@ See: [Wiki](https://github.com/ocornut/imgui/wiki) for many links, references, a See: [Articles about the IMGUI paradigm](https://github.com/ocornut/imgui/wiki#Articles-about-the-IMGUI-paradigm) to read/learn about the Immediate Mode GUI paradigm. -If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](https://discord.gg/NgJ4SEP) or [Discourse forums](https://discourse.dearimgui.org). +If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: you can use [Discord server](http://discord.dearimgui.org). Otherwise, for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully. @@ -176,7 +176,7 @@ How to help **How can I help?** -- You may participate in the [Discord server](https://discord.gg/NgJ4SEP), [Discourse forums](https://discourse.dearimgui.org), GitHub [issues tracker](https://github.com/ocornut/imgui/issues). +- You may participate in the [Discord server](http://discord.dearimgui.org), [GitHub forum/issues](https://github.com/ocornut/imgui/issues). - You may help with development and submit pull requests! Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance forever. PR should be crafted both in the interest in the end-users and also to ease the maintainer into understanding and accepting it. - See [Help wanted](https://github.com/ocornut/imgui/wiki/Help-Wanted) on the [Wiki](https://github.com/ocornut/imgui/wiki/) for some more ideas. - Have your company financially support this project. diff --git a/imgui.cpp b/imgui.cpp index cb4ff913..facc64d4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5,7 +5,7 @@ // Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui // Releases change-log at https://github.com/ocornut/imgui/releases -// Technical Support for Getting Started https://discourse.dearimgui.org/c/getting-started +// Technical Support for Getting Started https://github.com/ocornut/imgui/wiki // Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2847 // Developed by Omar Cornut and every direct or indirect contributors to the GitHub. diff --git a/misc/fonts/README.txt b/misc/fonts/README.txt index 4ddafe62..0f335c7d 100644 --- a/misc/fonts/README.txt +++ b/misc/fonts/README.txt @@ -13,10 +13,8 @@ You may also load external .TTF/.OTF files. The files in this folder are suggested fonts, provided as a convenience. Fonts are rasterized in a single texture at the time of calling either of io.Fonts->GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). -Also read the FAQ: https://www.dearimgui.org/faq - -If you have other loading/merging/adding fonts, you can post on the Dear ImGui "Getting Started" forum: - https://discourse.dearimgui.org/c/getting-started +Please read the FAQ: https://www.dearimgui.org/faq +Please use the Discord server: http://discord.dearimgui.org and not the Github issue tracker for basic font loading questions. --------------------------------------- @@ -45,7 +43,6 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui " u8"hello" u8"こんにちは" // this will be encoded as UTF-8 - If you want to include a backslash \ character in your string literal, you need to double them e.g. "folder\\filename". -- Please use the Discourse forum (https://discourse.dearimgui.org) and not the Github issue tracker for basic font loading questions. --------------------------------------- From 0b2d35f63fb0e6dd4f541e40430dbf762a2466ed Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 28 Oct 2019 12:46:45 +0100 Subject: [PATCH 095/384] Fix snprintf and vsnprintf definition inconsistencies. --- imgui_demo.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c9ee0f43..3eedda45 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -100,12 +100,17 @@ Index of this file: // Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n. #ifdef _WIN32 #define IM_NEWLINE "\r\n" -#define snprintf _snprintf -#define vsnprintf _vsnprintf #else #define IM_NEWLINE "\n" #endif +#if defined(_MSC_VER) && !defined(snprintf) +#define snprintf _snprintf +#endif +#if defined(_MSC_VER) && !defined(vsnprintf) +#define vsnprintf _vsnprintf +#endif + //----------------------------------------------------------------------------- // [SECTION] Forward Declarations, Helpers //----------------------------------------------------------------------------- From 32380a0112b088ac97360c1d6029c93de60be157 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 29 Oct 2019 16:43:11 +0100 Subject: [PATCH 096/384] Viewport: Store current dpi scale in context. --- imgui.cpp | 5 +++-- imgui_internal.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 731bb0bd..7e07a2e1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7391,8 +7391,7 @@ ImDrawList* ImGui::GetWindowDrawList() float ImGui::GetWindowDpiScale() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.CurrentViewport != NULL); - return g.CurrentViewport->DpiScale; + return g.CurrentDpiScale; } ImGuiViewport* ImGui::GetWindowViewport() @@ -10253,6 +10252,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view viewport->LastFrameActive = g.FrameCount; if (g.CurrentViewport == viewport) return; + g.CurrentDpiScale = viewport->DpiScale; g.CurrentViewport = viewport; //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); @@ -10408,6 +10408,7 @@ static void ImGui::UpdateViewportsNewFrame() main_viewport_platform_pos = (main_viewport->Flags & ImGuiViewportFlags_Minimized) ? main_viewport->Pos : g.PlatformIO.Platform_GetWindowPos(main_viewport); AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_platform_pos, main_viewport_platform_size, ImGuiViewportFlags_CanHostOtherWindows); + g.CurrentDpiScale = 0.0f; g.CurrentViewport = NULL; g.MouseViewport = NULL; for (int n = 0; n < g.Viewports.Size; n++) diff --git a/imgui_internal.h b/imgui_internal.h index 71d64469..b198612f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1079,6 +1079,7 @@ struct ImGuiContext // Viewports ImVector Viewports; // Active viewports (always 1+, and generally 1 unless multi-viewports are enabled). Each viewports hold their copy of ImDrawData. + float CurrentDpiScale; // == CurrentViewport->DpiScale ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport() ImGuiViewportP* MouseViewport; ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag. @@ -1271,6 +1272,7 @@ struct ImGuiContext LastActiveId = 0; LastActiveIdTimer = 0.0f; + CurrentDpiScale = 0.0f; CurrentViewport = NULL; MouseViewport = MouseLastHoveredViewport = NULL; PlatformLastFocusedViewport = 0; From c863c1f6a1eb2aba0c017168e105025fe1fda422 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 29 Oct 2019 17:04:13 +0100 Subject: [PATCH 097/384] Clean up number rounding. Now it is more obvious what code is doing. (#2862) Add IM_ROUND() macro Replace IM_FLOOR(n + 0.5f) and ImFloor(n + 0.5f) with IM_ROUND(n) --- imgui.cpp | 10 +++++----- imgui_draw.cpp | 4 ++-- imgui_internal.h | 5 +++-- imgui_widgets.cpp | 26 +++++++++++++------------- misc/freetype/imgui_freetype.cpp | 2 +- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index facc64d4..56ac3357 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4747,8 +4747,8 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size g.NextWindowData.SizeCallback(&data); new_size = data.DesiredSize; } - new_size.x = ImFloor(new_size.x); - new_size.y = ImFloor(new_size.y); + new_size.x = IM_FLOOR(new_size.x); + new_size.y = IM_FLOOR(new_size.y); } // Minimum size @@ -6453,7 +6453,7 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con if (size.x > 0.0f) { window->AutoFitFramesX = 0; - window->SizeFull.x = ImFloor(size.x); + window->SizeFull.x = IM_FLOOR(size.x); } else { @@ -6463,7 +6463,7 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con if (size.y > 0.0f) { window->AutoFitFramesY = 0; - window->SizeFull.y = ImFloor(size.y); + window->SizeFull.y = IM_FLOOR(size.y); } else { @@ -8267,7 +8267,7 @@ static void ImGui::NavUpdate() { // *Fallback* manual-scroll with Nav directional keys when window has no navigable item ImGuiWindow* window = g.NavWindow; - const float scroll_speed = ImFloor(window->CalcFontSize() * 100 * g.IO.DeltaTime + 0.5f); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported. + const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * g.IO.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported. if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest) { if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index e2b5ee86..544e9f3b 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2069,7 +2069,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float descent = ImFloor(unscaled_descent * font_scale + ((unscaled_descent > 0.0f) ? +1 : -1)); ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); const float font_off_x = cfg.GlyphOffset.x; - const float font_off_y = cfg.GlyphOffset.y + ImFloor(dst_font->Ascent + 0.5f); + const float font_off_y = cfg.GlyphOffset.y + IM_ROUND(dst_font->Ascent); for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++) { @@ -2591,7 +2591,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, glyph.AdvanceX = advance_x + ConfigData->GlyphExtraSpacing.x; // Bake spacing into AdvanceX if (ConfigData->PixelSnapH) - glyph.AdvanceX = IM_FLOOR(glyph.AdvanceX + 0.5f); + glyph.AdvanceX = IM_ROUND(glyph.AdvanceX); // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round) DirtyLookupTables = true; diff --git a/imgui_internal.h b/imgui_internal.h index f669b18e..26660ba3 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -145,6 +145,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds +#define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // // Debug Logging #ifndef IMGUI_DEBUG_LOG @@ -262,8 +263,8 @@ static inline float ImSaturate(float f) static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; } static inline float ImLengthSqr(const ImVec4& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y + lhs.z*lhs.z + lhs.w*lhs.w; } static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / ImSqrt(d); return fail_value; } -static inline float ImFloor(float f) { return (float)(int)f; } -static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)v.x, (float)(int)v.y); } +static inline float ImFloor(float f) { return (float)(int)(f); } +static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)(v.x), (float)(int)(v.y)); } static inline int ImModPositive(int a, int b) { return (a + b) % b; } static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; } static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 958a6904..f31b0138 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -852,7 +852,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa // Apply scroll // It is ok to modify Scroll here because we are being called in Begin() after the calculation of ContentSize and before setting up our starting position const float scroll_v_norm = ImSaturate((clicked_v_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm * 0.5f) / (1.0f - grab_h_norm)); - *p_scroll_v = IM_FLOOR(0.5f + scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); + *p_scroll_v = IM_ROUND(scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); // Update values for rendering scroll_ratio = ImSaturate(*p_scroll_v / scroll_max); @@ -1058,8 +1058,8 @@ bool ImGui::RadioButton(const char* label, bool active) return false; ImVec2 center = check_bb.GetCenter(); - center.x = IM_FLOOR(center.x + 0.5f); - center.y = IM_FLOOR(center.y + 0.5f); + center.x = IM_ROUND(center.x); + center.y = IM_ROUND(center.y); const float radius = (square_sz - 1.0f) * 0.5f; bool hovered, held; @@ -4796,13 +4796,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), col_white, hue_color32, hue_color32, col_white); draw_list->AddRectFilledMultiColor(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), 0, 0, col_black, col_black); RenderFrameBorder(picker_pos, picker_pos + ImVec2(sv_picker_size, sv_picker_size), 0.0f); - sv_cursor_pos.x = ImClamp(IM_FLOOR(picker_pos.x + ImSaturate(S) * sv_picker_size + 0.5f), picker_pos.x + 2, picker_pos.x + sv_picker_size - 2); // Sneakily prevent the circle to stick out too much - sv_cursor_pos.y = ImClamp(IM_FLOOR(picker_pos.y + ImSaturate(1 - V) * sv_picker_size + 0.5f), picker_pos.y + 2, picker_pos.y + sv_picker_size - 2); + sv_cursor_pos.x = ImClamp(IM_ROUND(picker_pos.x + ImSaturate(S) * sv_picker_size), picker_pos.x + 2, picker_pos.x + sv_picker_size - 2); // Sneakily prevent the circle to stick out too much + sv_cursor_pos.y = ImClamp(IM_ROUND(picker_pos.y + ImSaturate(1 - V) * sv_picker_size), picker_pos.y + 2, picker_pos.y + sv_picker_size - 2); // Render Hue Bar for (int i = 0; i < 6; ++i) draw_list->AddRectFilledMultiColor(ImVec2(bar0_pos_x, picker_pos.y + i * (sv_picker_size / 6)), ImVec2(bar0_pos_x + bars_width, picker_pos.y + (i + 1) * (sv_picker_size / 6)), col_hues[i], col_hues[i], col_hues[i + 1], col_hues[i + 1]); - float bar0_line_y = IM_FLOOR(picker_pos.y + H * sv_picker_size + 0.5f); + float bar0_line_y = IM_ROUND(picker_pos.y + H * sv_picker_size); RenderFrameBorder(ImVec2(bar0_pos_x, picker_pos.y), ImVec2(bar0_pos_x + bars_width, picker_pos.y + sv_picker_size), 0.0f); RenderArrowsForVerticalBar(draw_list, ImVec2(bar0_pos_x - 1, bar0_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f, style.Alpha); } @@ -4820,7 +4820,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl ImRect bar1_bb(bar1_pos_x, picker_pos.y, bar1_pos_x + bars_width, picker_pos.y + sv_picker_size); RenderColorRectWithAlphaCheckerboard(bar1_bb.Min, bar1_bb.Max, 0, bar1_bb.GetWidth() / 2.0f, ImVec2(0.0f, 0.0f)); draw_list->AddRectFilledMultiColor(bar1_bb.Min, bar1_bb.Max, user_col32_striped_of_alpha, user_col32_striped_of_alpha, user_col32_striped_of_alpha & ~IM_COL32_A_MASK, user_col32_striped_of_alpha & ~IM_COL32_A_MASK); - float bar1_line_y = IM_FLOOR(picker_pos.y + (1.0f - alpha) * sv_picker_size + 0.5f); + float bar1_line_y = IM_ROUND(picker_pos.y + (1.0f - alpha) * sv_picker_size); RenderFrameBorder(bar1_bb.Min, bar1_bb.Max, 0.0f); RenderArrowsForVerticalBar(draw_list, ImVec2(bar1_pos_x - 1, bar1_line_y), ImVec2(bars_triangles_half_sz + 1, bars_triangles_half_sz), bars_width + 2.0f, style.Alpha); } @@ -4877,7 +4877,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl bb_inner.Expand(off); if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col_rgb.w < 1.0f) { - float mid_x = IM_FLOOR((bb_inner.Min.x + bb_inner.Max.x) * 0.5f + 0.5f); + float mid_x = IM_ROUND((bb_inner.Min.x + bb_inner.Max.x) * 0.5f); RenderColorRectWithAlphaCheckerboard(ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col_rgb), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight| ImDrawCornerFlags_BotRight); window->DrawList->AddRectFilled(bb_inner.Min, ImVec2(mid_x, bb_inner.Max.y), GetColorU32(col_rgb_without_alpha), rounding, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotLeft); } @@ -6014,7 +6014,7 @@ bool ImGui::BeginMenuBar() // We don't clip with current 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 and small windows 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)); + ImRect clip_rect(IM_ROUND(bar_rect.Min.x), IM_ROUND(bar_rect.Min.y + window->WindowBorderSize), IM_ROUND(ImMax(bar_rect.Min.x, bar_rect.Max.x - window->WindowRounding)), IM_ROUND(bar_rect.Max.y)); clip_rect.ClipWith(window->OuterRectClipped); PushClipRect(clip_rect.Min, clip_rect.Max, false); @@ -6446,8 +6446,8 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG const ImU32 col = GetColorU32((flags & ImGuiTabBarFlags_IsFocused) ? ImGuiCol_TabActive : ImGuiCol_TabUnfocusedActive); const float y = tab_bar->BarRect.Max.y - 1.0f; { - const float separator_min_x = tab_bar->BarRect.Min.x - ImFloor(window->WindowPadding.x * 0.5f); - const float separator_max_x = tab_bar->BarRect.Max.x + ImFloor(window->WindowPadding.x * 0.5f); + const float separator_min_x = tab_bar->BarRect.Min.x - IM_FLOOR(window->WindowPadding.x * 0.5f); + const float separator_max_x = tab_bar->BarRect.Max.x + IM_FLOOR(window->WindowPadding.x * 0.5f); window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f); } return true; @@ -7443,8 +7443,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag { // Compute clipping rectangle ImGuiColumnData* column = &columns->Columns[n]; - float clip_x1 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n)); - float clip_x2 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n + 1) - 1.0f); + float clip_x1 = IM_ROUND(window->Pos.x + GetColumnOffset(n)); + float clip_x2 = IM_ROUND(window->Pos.x + GetColumnOffset(n + 1) - 1.0f); column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX); column->ClipRect.ClipWith(window->ClipRect); } diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 3a89df59..6695fb65 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -545,7 +545,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns const float descent = src_tmp.Font.Info.Descender; ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent); const float font_off_x = cfg.GlyphOffset.x; - const float font_off_y = cfg.GlyphOffset.y + IM_FLOOR(dst_font->Ascent + 0.5f); + const float font_off_y = cfg.GlyphOffset.y + IM_ROUND(dst_font->Ascent); const int padding = atlas->TexGlyphPadding; for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++) From 6bf5aed3254c7ec126b1fc10eb8ce38ac3bb5a9e Mon Sep 17 00:00:00 2001 From: stfx Date: Mon, 28 Oct 2019 13:02:59 +0100 Subject: [PATCH 098/384] Declaration and assignment can be joined, Member function may be 'const'. (#2875) --- imgui.h | 8 ++++---- imgui_draw.cpp | 9 ++++----- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/imgui.h b/imgui.h index 9662670a..841506f9 100644 --- a/imgui.h +++ b/imgui.h @@ -1630,11 +1630,11 @@ struct ImGuiTextBuffer IMGUI_API static char EmptyString[1]; ImGuiTextBuffer() { } - inline char operator[](int i) { IM_ASSERT(Buf.Data != NULL); return Buf.Data[i]; } + inline char operator[](int i) const { IM_ASSERT(Buf.Data != NULL); return Buf.Data[i]; } const char* begin() const { return Buf.Data ? &Buf.front() : EmptyString; } const char* end() const { return Buf.Data ? &Buf.back() : EmptyString; } // Buf is zero-terminated, so end() will point on the zero-terminator int size() const { return Buf.Size ? Buf.Size - 1 : 0; } - bool empty() { return Buf.Size <= 1; } + bool empty() const { return Buf.Size <= 1; } void clear() { Buf.clear(); } void reserve(int capacity) { Buf.reserve(capacity); } const char* c_str() const { return Buf.Data ? Buf.Data : EmptyString; } @@ -2111,7 +2111,7 @@ struct ImFontAtlas IMGUI_API bool Build(); // Build pixels data. This is called automatically for you by the GetTexData*** functions. IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel - bool IsBuilt() { return Fonts.Size > 0 && (TexPixelsAlpha8 != NULL || TexPixelsRGBA32 != NULL); } + bool IsBuilt() const { return Fonts.Size > 0 && (TexPixelsAlpha8 != NULL || TexPixelsRGBA32 != NULL); } void SetTexID(ImTextureID id) { TexID = id; } //------------------------------------------- @@ -2144,7 +2144,7 @@ struct ImFontAtlas const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } // [Internal] - IMGUI_API void CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max); + IMGUI_API void CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const; IMGUI_API bool GetMouseCursorTexData(ImGuiMouseCursor cursor, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2]); //------------------------------------------- diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 544e9f3b..f73e0e31 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1752,7 +1752,7 @@ int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int return CustomRects.Size - 1; // Return index } -void ImFontAtlas::CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) +void ImFontAtlas::CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const { IM_ASSERT(TexWidth > 0 && TexHeight > 0); // Font atlas needs to be built before we can calculate UV coordinates IM_ASSERT(rect->IsPacked()); // Make sure the rectangle has been packed @@ -3201,9 +3201,9 @@ static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, uns { const unsigned long ADLER_MOD = 65521; unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; - unsigned long blocklen, i; + unsigned long blocklen = buflen % 5552; - blocklen = buflen % 5552; + unsigned long i; while (buflen) { for (i=0; i + 7 < blocklen; i += 8) { s1 += buffer[0], s2 += s1; @@ -3230,10 +3230,9 @@ static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, uns static unsigned int stb_decompress(unsigned char *output, const unsigned char *i, unsigned int /*length*/) { - unsigned int olen; if (stb__in4(0) != 0x57bC0000) return 0; if (stb__in4(4) != 0) return 0; // error! stream is > 4GB - olen = stb_decompress_length(i); + const unsigned int olen = stb_decompress_length(i); stb__barrier_in_b = i; stb__barrier_out_e = output + olen; stb__barrier_out_b = output; diff --git a/imgui_internal.h b/imgui_internal.h index 26660ba3..3786b6fb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -624,7 +624,7 @@ struct IMGUI_API ImGuiMenuColumns ImGuiMenuColumns(); void Update(int count, float spacing, bool clear); float DeclColumns(float w0, float w1, float w2); - float CalcExtraSpace(float avail_w); + float CalcExtraSpace(float avail_w) const; }; // Internal state of the currently focused/edited text input box diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f31b0138..1a82f291 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5990,7 +5990,7 @@ float ImGuiMenuColumns::DeclColumns(float w0, float w1, float w2) // not using v return ImMax(Width, NextWidth); } -float ImGuiMenuColumns::CalcExtraSpace(float avail_w) +float ImGuiMenuColumns::CalcExtraSpace(float avail_w) const { return ImMax(0.0f, avail_w - Width); } From 6024051a2fcfc75d640ba5ed1660bc607ad49937 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 29 Oct 2019 21:18:01 +0100 Subject: [PATCH 099/384] Viewport: Fixed 32380a0 (#2876) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index de3ca78c..48898ba8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10252,7 +10252,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view viewport->LastFrameActive = g.FrameCount; if (g.CurrentViewport == viewport) return; - g.CurrentDpiScale = viewport->DpiScale; + g.CurrentDpiScale = viewport ? viewport->DpiScale : 1.0f; g.CurrentViewport = viewport; //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); From d62a413476cea8245bddb0f18f8f57b8009cfe17 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 29 Oct 2019 21:47:43 +0100 Subject: [PATCH 100/384] Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 72c7c18a..719e598f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,7 @@ Other Changes: incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) +- Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] diff --git a/imgui.cpp b/imgui.cpp index 56ac3357..2fdfb948 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1363,7 +1363,7 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) FILE* ImFileOpen(const char* filename, const char* mode) { -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can) const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; From 9f979c33f4c33a6afeec8357324638c97b93499a Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 09:49:57 +0200 Subject: [PATCH 101/384] CI: Fix builds failing because of missing v140 toolset and SDK on dx12 sample. (cherry picked from commit 8d91a77e9b42eac7a6d7d28c8563ccc468842e8b) --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54d267ae..932c6be2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,11 +15,14 @@ jobs: - name: Fix Projects shell: powershell run: | - # Replace v110 toolset with v142. Only v141 and v142 toolsets are available on CI workers. - # Replace 8.1 platform sdk with 10.0.18362.0. Workers do not contain legacy SDKs. # WARNING: This will need updating if toolset/sdk change in project files! gci -recurse -filter "*.vcxproj" | ForEach-Object { - (Get-Content $_.FullName) -Replace "v110","v142" -Replace "8.1","10.0.18362.0" | Set-Content -Path $_.FullName + # Fix SDK and toolset for most samples. + (Get-Content $_.FullName) -Replace "v110","v142" | Set-Content -Path $_.FullName + (Get-Content $_.FullName) -Replace "8.1","10.0.18362.0" | Set-Content -Path $_.FullName + # Fix SDK and toolset for samples that require newer SDK/toolset. At the moment it is only dx12. + (Get-Content $_.FullName) -Replace "v140","v142" | Set-Content -Path $_.FullName + (Get-Content $_.FullName) -Replace "10.0.14393.0","10.0.18362.0" | Set-Content -Path $_.FullName } - name: Build x86 From a4420be1a20ecf18416f306902c78b87e4ff6c0a Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 10:45:27 +0200 Subject: [PATCH 102/384] CI: Split builds of examples into separate jobs. (cherry picked from commit ee73b1b5a47f176ab123239aa3cbcc2cdf284383) --- .github/workflows/build.yml | 106 +++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 932c6be2..cbe8291e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,15 +25,51 @@ jobs: (Get-Content $_.FullName) -Replace "10.0.14393.0","10.0.18362.0" | Set-Content -Path $_.FullName } - - name: Build x86 + # Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long. + + - name: Build Win32 example_glfw_opengl2 shell: cmd - run: | - "%MSBUILD_PATH%\MSBuild.exe" /p:Platform=Win32 /p:Configuration=Release examples/imgui_examples.sln + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' - - name: Build x64 + - name: Build Win32 example_glfw_opengl3 shell: cmd - run: | - "%MSBUILD_PATH%\MSBuild.exe" /p:Platform=x64 /p:Configuration=Release examples/imgui_examples.sln + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_win32_directx9 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_win32_directx10 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx10/example_win32_directx10.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_win32_directx11 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build x64 example_glfw_opengl2 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_glfw_opengl3 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_win32_directx9 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_win32_directx10 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx10/example_win32_directx10.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_win32_directx11 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_win32_directx12 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx12/example_win32_directx12.vcxproj /p:Platform=x64 /p:Configuration=Release' Linux: runs-on: ubuntu-18.04 @@ -47,13 +83,20 @@ jobs: sudo apt-get update sudo apt-get install -y libglfw3-dev libsdl2-dev - - name: Build - run: | - make -C examples/example_null - make -C examples/example_glfw_opengl2 - make -C examples/example_glfw_opengl3 - make -C examples/example_sdl_opengl2 - make -C examples/example_sdl_opengl3 + - name: Build example_null + run: make -C examples/example_null + + - name: Build example_glfw_opengl2 + run: make -C examples/example_glfw_opengl2 + + - name: Build example_glfw_opengl3 + run: make -C examples/example_glfw_opengl3 + + - name: Build example_sdl_opengl2 + run: make -C examples/example_sdl_opengl2 + + - name: Build example_sdl_opengl3 + run: make -C examples/example_sdl_opengl3 MacOS: runs-on: macOS-10.14 @@ -67,16 +110,29 @@ jobs: brew install glfw3 brew install sdl2 - - name: Build - run: | - make -C examples/example_null - make -C examples/example_glfw_opengl2 - make -C examples/example_glfw_opengl3 - make -C examples/example_glfw_metal - make -C examples/example_sdl_opengl2 - make -C examples/example_sdl_opengl3 - xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos - xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2 + - name: Build example_null + run: make -C examples/example_null + + - name: Build example_glfw_opengl2 + run: make -C examples/example_glfw_opengl2 + + - name: Build example_glfw_opengl3 + run: make -C examples/example_glfw_opengl3 + + - name: Build example_glfw_metal + run: make -C examples/example_glfw_metal + + - name: Build example_sdl_opengl2 + run: make -C examples/example_sdl_opengl2 + + - name: Build example_sdl_opengl3 + run: make -C examples/example_sdl_opengl3 + + - name: Build example_apple_metal + run: xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_macos + + - name: Build example_apple_opengl2 + run: xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2 iOS: runs-on: macOS-10.14 @@ -85,7 +141,7 @@ jobs: with: fetch-depth: 1 - - name: Build + - name: Build example_apple_metal run: | # Code signing is required, but we disable it because it is irrelevant for CI builds. xcodebuild -project examples/example_apple_metal/example_apple_metal.xcodeproj -target example_apple_metal_ios CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO @@ -105,7 +161,7 @@ jobs: emsdk-portable/emsdk install latest emsdk-portable/emsdk activate latest - - name: Build + - name: Build example_emscripten run: | source emsdk-portable/emsdk_env.sh make -C examples/example_emscripten From 5ebd4e4c6e882cc197f3016c64d35f3e5821e270 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 11:30:46 +0200 Subject: [PATCH 103/384] CI: Install SDL SDK in windows workers and add SDL examples to the build. CI: Add Vulkan GLFW and SDL builds to windows build job. --- .github/workflows/build.yml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cbe8291e..1ee3e0d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,11 +7,22 @@ jobs: runs-on: windows-2019 env: MSBUILD_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ + # Until gh-actions allow us to use env variables inside other env variables (because we need %GITHUB_WORKSPACE%) we have to use relative path to imgui/examples/example_name directory. + SDL2_DIR: ..\..\SDL2-devel-2.0.10-VC\SDL2-2.0.10\ + VULKAN_SDK: ..\..\vulkan-sdk-1.1.121.2\ steps: - uses: actions/checkout@v1 with: fetch-depth: 1 + - name: Install Dependencies + shell: powershell + run: | + Invoke-WebRequest -Uri "https://www.libsdl.org/release/SDL2-devel-2.0.10-VC.zip" -OutFile "SDL2-devel-2.0.10-VC.zip" + Expand-Archive -Path SDL2-devel-2.0.10-VC.zip + Invoke-WebRequest -Uri "https://github.com/ocornut/imgui/files/3789205/vulkan-sdk-1.1.121.2.zip" -OutFile vulkan-sdk-1.1.121.2.zip + Expand-Archive -Path vulkan-sdk-1.1.121.2.zip + - name: Fix Projects shell: powershell run: | @@ -26,7 +37,6 @@ jobs: } # Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long. - - name: Build Win32 example_glfw_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' @@ -35,6 +45,26 @@ jobs: shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release' + - name: Build Win32 example_glfw_vulkan + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_sdl_vulkan + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_sdl_opengl2 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_sdl_opengl3 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release' + + - name: Build Win32 example_sdl_directx11 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_directx11/example_sdl_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release' + - name: Build Win32 example_win32_directx9 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=Win32 /p:Configuration=Release' @@ -55,6 +85,26 @@ jobs: shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release' + - name: Build x64 example_glfw_vulkan + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_sdl_vulkan + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_sdl_opengl2 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_sdl_opengl3 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release' + + - name: Build x64 example_sdl_directx11 + shell: cmd + run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_directx11/example_sdl_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release' + - name: Build x64 example_win32_directx9 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=x64 /p:Configuration=Release' From 5006639526494fb28f804dbc768eedcdf92e9ed4 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 16:10:43 +0200 Subject: [PATCH 104/384] CI: Add scheduled builds and limit some examples to build only on schedule in order to decrease time of builds performed on each push. (cherry picked from commit 6c0e1baca29b853586dadf75eb32ef75e2725f10) --- .github/workflows/build.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1ee3e0d8..0c7020c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,10 @@ name: build -on: [push, pull_request] +on: + push: {} + pull_request: {} + schedule: + - cron: '0 9 * * *' jobs: Windows: @@ -44,18 +48,22 @@ jobs: - name: Build Win32 example_glfw_opengl3 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build Win32 example_glfw_vulkan shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build Win32 example_sdl_vulkan shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build Win32 example_sdl_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build Win32 example_sdl_opengl3 shell: cmd @@ -64,6 +72,7 @@ jobs: - name: Build Win32 example_sdl_directx11 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_directx11/example_sdl_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build Win32 example_win32_directx9 shell: cmd @@ -76,10 +85,12 @@ jobs: - name: Build Win32 example_win32_directx11 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=Win32 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_glfw_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_glfw_opengl3 shell: cmd @@ -92,14 +103,17 @@ jobs: - name: Build x64 example_sdl_vulkan shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_sdl_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_sdl_opengl3 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_sdl_directx11 shell: cmd @@ -108,14 +122,17 @@ jobs: - name: Build x64 example_win32_directx9 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx9/example_win32_directx9.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_win32_directx10 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx10/example_win32_directx10.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_win32_directx11 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_win32_directx11/example_win32_directx11.vcxproj /p:Platform=x64 /p:Configuration=Release' + if: github.event_name == 'schedule' - name: Build x64 example_win32_directx12 shell: cmd @@ -141,9 +158,11 @@ jobs: - name: Build example_glfw_opengl3 run: make -C examples/example_glfw_opengl3 + if: github.event_name == 'schedule' - name: Build example_sdl_opengl2 run: make -C examples/example_sdl_opengl2 + if: github.event_name == 'schedule' - name: Build example_sdl_opengl3 run: make -C examples/example_sdl_opengl3 @@ -168,12 +187,14 @@ jobs: - name: Build example_glfw_opengl3 run: make -C examples/example_glfw_opengl3 + if: github.event_name == 'schedule' - name: Build example_glfw_metal run: make -C examples/example_glfw_metal - name: Build example_sdl_opengl2 run: make -C examples/example_sdl_opengl2 + if: github.event_name == 'schedule' - name: Build example_sdl_opengl3 run: make -C examples/example_sdl_opengl3 From 8fee5a434904fce02ef542b6f3f684e09afde29c Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 31 Oct 2019 11:15:40 +0100 Subject: [PATCH 105/384] Internals: Renaming for consistency. --- imgui.cpp | 30 +++++++++++++++--------------- imgui_internal.h | 10 +++++----- imgui_widgets.cpp | 16 ++++++++-------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2fdfb948..53b19fad 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5689,14 +5689,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->WorkRect.Max.x = window->WorkRect.Min.x + work_rect_size_x; window->WorkRect.Max.y = window->WorkRect.Min.y + work_rect_size_y; - // [LEGACY] Contents Region - // FIXME-OBSOLETE: window->ContentsRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it. + // [LEGACY] Content Region + // FIXME-OBSOLETE: window->ContentRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it. // Used by: // - Mouse wheel scrolling + many other things - window->ContentsRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x; - window->ContentsRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + decoration_up_height; - window->ContentsRegionRect.Max.x = window->ContentsRegionRect.Min.x + (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : (window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x)); - window->ContentsRegionRect.Max.y = window->ContentsRegionRect.Min.y + (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : (window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y)); + window->ContentRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x; + window->ContentRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + decoration_up_height; + window->ContentRegionRect.Max.x = window->ContentRegionRect.Min.x + (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : (window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x)); + window->ContentRegionRect.Max.y = window->ContentRegionRect.Min.y + (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : (window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y)); // Setup drawing context // (NB: That term "drawing context / DC" lost its meaning a long time ago. Initially was meant to hold transient data only. Nowadays difference between window-> and window->DC-> is dubious.) @@ -6599,7 +6599,7 @@ ImVec2 ImGui::GetContentRegionMax() { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImVec2 mx = window->ContentsRegionRect.Max - window->Pos; + ImVec2 mx = window->ContentRegionRect.Max - window->Pos; if (window->DC.CurrentColumns) mx.x = window->WorkRect.Max.x - window->Pos.x; return mx; @@ -6610,7 +6610,7 @@ ImVec2 ImGui::GetContentRegionMaxAbs() { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImVec2 mx = window->ContentsRegionRect.Max; + ImVec2 mx = window->ContentRegionRect.Max; if (window->DC.CurrentColumns) mx.x = window->WorkRect.Max.x; return mx; @@ -6626,19 +6626,19 @@ ImVec2 ImGui::GetContentRegionAvail() ImVec2 ImGui::GetWindowContentRegionMin() { ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentsRegionRect.Min - window->Pos; + return window->ContentRegionRect.Min - window->Pos; } ImVec2 ImGui::GetWindowContentRegionMax() { ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentsRegionRect.Max - window->Pos; + return window->ContentRegionRect.Max - window->Pos; } float ImGui::GetWindowContentRegionWidth() { ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentsRegionRect.GetWidth(); + return window->ContentRegionRect.GetWidth(); } float ImGui::GetTextLineHeight() @@ -9594,8 +9594,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) } // State - enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Contents, WRT_ContentsRegionRect, WRT_Count }; // Windows Rect Type - const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Contents", "ContentsRegionRect" }; + enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type + const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentRegionRect" }; static bool show_windows_rects = false; static int show_windows_rect_type = WRT_WorkRect; static bool show_windows_begin_order = false; @@ -9626,8 +9626,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) else if (rect_type == WRT_InnerRect) { return window->InnerRect; } else if (rect_type == WRT_InnerClipRect) { return window->InnerClipRect; } else if (rect_type == WRT_WorkRect) { return window->WorkRect; } - else if (rect_type == WRT_Contents) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); } - else if (rect_type == WRT_ContentsRegionRect) { return window->ContentsRegionRect; } + else if (rect_type == WRT_Content) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); } + else if (rect_type == WRT_ContentRegionRect) { return window->ContentRegionRect; } IM_ASSERT(0); return ImRect(); } diff --git a/imgui_internal.h b/imgui_internal.h index 3786b6fb..c1dda24e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1338,9 +1338,9 @@ struct IMGUI_API ImGuiWindow ImRect OuterRectClipped; // == Window->Rect() just after setup in Begin(). == window->Rect() for root window. ImRect InnerRect; // Inner rectangle (omit title bar, menu bar, scroll bar) ImRect InnerClipRect; // == InnerRect shrunk by WindowPadding*0.5f on each side, clipped within viewport or parent clip rect. - ImRect WorkRect; // Cover the whole scrolling region, shrunk by WindowPadding*1.0f on each side. This is meant to replace ContentsRegionRect over time (from 1.71+ onward). + ImRect WorkRect; // Cover the whole scrolling region, shrunk by WindowPadding*1.0f on each side. This is meant to replace ContentRegionRect over time (from 1.71+ onward). ImRect ClipRect; // Current clipping/scissoring rectangle, evolve as we are using PushClipRect(), etc. == DrawList->clip_rect_stack.back(). - ImRect ContentsRegionRect; // FIXME: This is currently confusing/misleading. It is essentially WorkRect but not handling of scrolling. We currently rely on it as right/bottom aligned sizing operation need some size to rely on. + ImRect ContentRegionRect; // FIXME: This is currently confusing/misleading. It is essentially WorkRect but not handling of scrolling. We currently rely on it as right/bottom aligned sizing operation need some size to rely on. int LastFrameActive; // Last frame number the window was Active. float LastTimeActive; // Last timestamp the window was Active (using float as we don't need high precision there) @@ -1415,7 +1415,7 @@ enum ImGuiTabBarFlagsPrivate_ // Extend ImGuiTabItemFlags_ enum ImGuiTabItemFlagsPrivate_ { - ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Store whether p_open is set or not, which we need to recompute WidthContents during layout. + ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Store whether p_open is set or not, which we need to recompute ContentWidth during layout. }; // Storage for one active tab item (sizeof() 26~32 bytes) @@ -1428,9 +1428,9 @@ struct ImGuiTabItem int NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames float Offset; // Position relative to beginning of tab float Width; // Width currently displayed - float WidthContents; // Width of actual contents, stored during BeginTabItem() call + float ContentWidth; // Width of actual contents, stored during BeginTabItem() call - ImGuiTabItem() { ID = Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = WidthContents = 0.0f; } + ImGuiTabItem() { ID = Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; } }; // Storage for a tab bar (sizeof() 92~96 bytes) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1a82f291..bf2f6617 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6566,13 +6566,13 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window. const char* tab_name = tab_bar->GetTabName(tab); const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) ? false : true; - tab->WidthContents = TabItemCalcSize(tab_name, has_close_button).x; + tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x; - width_total_contents += (tab_n > 0 ? g.Style.ItemInnerSpacing.x : 0.0f) + tab->WidthContents; + width_total_contents += (tab_n > 0 ? g.Style.ItemInnerSpacing.x : 0.0f) + tab->ContentWidth; // Store data so we can build an array sorted by width if we need to shrink tabs down g.ShrinkWidthBuffer[tab_n].Index = tab_n; - g.ShrinkWidthBuffer[tab_n].Width = tab->WidthContents; + g.ShrinkWidthBuffer[tab_n].Width = tab->ContentWidth; } // Compute width @@ -6592,7 +6592,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; - tab->Width = ImMin(tab->WidthContents, tab_max_width); + tab->Width = ImMin(tab->ContentWidth, tab_max_width); IM_ASSERT(tab->Width > 0.0f); } } @@ -6608,7 +6608,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) if (scroll_track_selected_tab_id == 0 && g.NavJustMovedToId == tab->ID) scroll_track_selected_tab_id = tab->ID; offset_x += tab->Width + g.Style.ItemInnerSpacing.x; - offset_x_ideal += tab->WidthContents + g.Style.ItemInnerSpacing.x; + offset_x_ideal += tab->ContentWidth + g.Style.ItemInnerSpacing.x; } tab_bar->OffsetMax = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f); tab_bar->OffsetMaxIdeal = ImMax(offset_x_ideal - g.Style.ItemInnerSpacing.x, 0.0f); @@ -6929,7 +6929,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, tab_is_new = true; } tab_bar->LastTabItemIdx = (short)tab_bar->Tabs.index_from_ptr(tab); - tab->WidthContents = size.x; + tab->ContentWidth = size.x; if (p_open == NULL) flags |= ImGuiTabItemFlags_NoCloseButton; @@ -7040,10 +7040,10 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, } #if 0 - if (hovered && g.HoveredIdNotActiveTimer > 0.50f && bb.GetWidth() < tab->WidthContents) + if (hovered && g.HoveredIdNotActiveTimer > 0.50f && bb.GetWidth() < tab->ContentWidth) { // Enlarge tab display when hovering - bb.Max.x = bb.Min.x + IM_FLOOR(ImLerp(bb.GetWidth(), tab->WidthContents, ImSaturate((g.HoveredIdNotActiveTimer - 0.40f) * 6.0f))); + bb.Max.x = bb.Min.x + IM_FLOOR(ImLerp(bb.GetWidth(), tab->ContentWidth, ImSaturate((g.HoveredIdNotActiveTimer - 0.40f) * 6.0f))); display_draw_list = GetForegroundDrawList(window); TabItemBackground(display_draw_list, bb, flags, GetColorU32(ImGuiCol_TitleBgActive)); } From 792a8631aafd3df8d45563e3af60e39feb20b31d Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 31 Oct 2019 14:01:35 +0100 Subject: [PATCH 106/384] Metrics: Expose basic details of each window key/value state storage. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 719e598f..a5f6b1ee 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -72,6 +72,7 @@ Other Changes: - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] +- Metrics: Expose basic details of each window key/value state storage. - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] - Backends: OpenGL3: Fix building with pre-3.2 GL loaders which do not expose glDrawElementsBaseVertex(), diff --git a/imgui.cpp b/imgui.cpp index 53b19fad..22f5395e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9762,7 +9762,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) NodeColumns(&window->ColumnsStorage[n]); ImGui::TreePop(); } - ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.size_in_bytes()); + NodeStorage(&window->StateStorage, "Storage"); ImGui::TreePop(); } @@ -9787,6 +9787,18 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } } + + static void NodeStorage(ImGuiStorage* storage, const char* label) + { + if (!ImGui::TreeNode(label, "%s: %d entries, %d bytes", label, storage->Data.Size, storage->Data.size_in_bytes())) + return; + for (int n = 0; n < storage->Data.Size; n++) + { + const ImGuiStorage::ImGuiStoragePair& p = storage->Data[n]; + ImGui::BulletText("Key 0x%08X Value { i: %d }", p.key, p.val_i); // Important: we currently don't store a type, real value may not be integer. + } + ImGui::TreePop(); + } }; Funcs::NodeWindows(g.Windows, "Windows"); From bcd752cfccb029ed60d93357e6eaa144a6df58da Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 4 Nov 2019 09:50:50 +0200 Subject: [PATCH 107/384] CI: Fix emscripten builds after portable SDK archive became unavailable. (cherry picked from commit 14b18697e653de80f75af18113033b2086846194) --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c7020c6..babd548a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -226,13 +226,13 @@ jobs: - name: Install Dependencies run: | - wget -q https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz - tar -xvf emsdk-portable.tar.gz - emsdk-portable/emsdk update - emsdk-portable/emsdk install latest - emsdk-portable/emsdk activate latest + wget -q https://github.com/emscripten-core/emsdk/archive/master.tar.gz + tar -xvf master.tar.gz + emsdk-master/emsdk update + emsdk-master/emsdk install latest-fastcomp + emsdk-master/emsdk activate latest-fastcomp - name: Build example_emscripten run: | - source emsdk-portable/emsdk_env.sh + source emsdk-master/emsdk_env.sh make -C examples/example_emscripten From c9ffa62e1f867c40df277df343d600af92220dc6 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 17:50:02 +0200 Subject: [PATCH 108/384] Add .gitattributes with rules for line endings of files. (cherry picked from commit f2a2be72b341f55c44a035b1257177d83489ea5c) --- .gitattributes | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..d48470ee --- /dev/null +++ b/.gitattributes @@ -0,0 +1,30 @@ +* text=auto + +*.c text +*.cpp text +*.h text +*.m text +*.mm text +*.md text +*.txt text +*.html text +*.bat text +*.frag text +*.vert text +*.mkb text +*.icf text + +*.sln text eol=crlf +*.vcxproj text eol=crlf +*.vcxproj.filters text eol=crlf +*.natvis text eol=crlf + +Makefile text eol=lf +*.sh text eol=lf +*.pbxproj text eol=lf +*.storyboard text eol=lf +*.plist text eol=lf + +*.png binary +*.ttf binary +*.lib binary From c9182424a83d949c663e3c80b0b7eda9c036f999 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 30 Oct 2019 17:50:11 +0200 Subject: [PATCH 109/384] Normalize all the line endings. (cherry picked from commit f1772d44be09fd78bf5f1ebda44b39b96180d319) --- .../example_sdl_directx11.vcxproj | 360 ++--- .../example_sdl_directx11.vcxproj.filters | 112 +- examples/libs/usynergy/uSynergy.c | 1272 ++++++++--------- 3 files changed, 872 insertions(+), 872 deletions(-) diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj index e28a5d25..7af2c9c0 100644 --- a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj @@ -1,181 +1,181 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {9E1987E3-1F19-45CA-B9C9-D31E791836D8} - example_sdl_directx11 - 8.1 - example_sdl_directx11 - - - - Application - true - MultiByte - v110 - - - Application - true - MultiByte - v110 - - - Application - false - true - MultiByte - v110 - - - Application - false - true - MultiByte - v110 - - - - - - - - - - - - - - - - - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - $(IncludePath) - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - $(IncludePath) - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - $(IncludePath) - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - $(IncludePath) - - - - Level4 - Disabled - ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) - - - true - %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - Console - msvcrt.lib - - - - - Level4 - Disabled - ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) - - - true - %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - Console - msvcrt.lib - - - - - Level4 - MaxSpeed - true - true - ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) - false - - - true - true - true - %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - Console - - - - - - - Level4 - MaxSpeed - true - true - ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) - false - - - true - true - true - %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - Console - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9E1987E3-1F19-45CA-B9C9-D31E791836D8} + example_sdl_directx11 + 8.1 + example_sdl_directx11 + + + + Application + true + MultiByte + v110 + + + Application + true + MultiByte + v110 + + + Application + false + true + MultiByte + v110 + + + Application + false + true + MultiByte + v110 + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + $(IncludePath) + + + + Level4 + Disabled + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + + + true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + Disabled + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + + + true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + Console + msvcrt.lib + + + + + Level4 + MaxSpeed + true + true + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + false + + + true + true + true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + Console + + + + + + + Level4 + MaxSpeed + true + true + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + false + + + true + true + true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + Console + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters index b2345067..879f0dbe 100644 --- a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters @@ -1,57 +1,57 @@ - - - - - {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} - - - {08e36723-ce4f-4cff-9662-c40801cf1acf} - - - - - imgui - - - imgui - - - imgui - - - sources - - - sources - - - - - imgui - - - sources - - - imgui - - - imgui - - - sources - - - imgui - - - sources - - - - - - sources - - + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + imgui + + + sources + + + sources + + + + + imgui + + + sources + + + imgui + + + imgui + + + sources + + + imgui + + + sources + + + + + + sources + + \ No newline at end of file diff --git a/examples/libs/usynergy/uSynergy.c b/examples/libs/usynergy/uSynergy.c index a8d01da4..8dce47b8 100644 --- a/examples/libs/usynergy/uSynergy.c +++ b/examples/libs/usynergy/uSynergy.c @@ -1,636 +1,636 @@ -/* -uSynergy client -- Implementation for the embedded Synergy client library - version 1.0.0, July 7th, 2012 - -Copyright (c) 2012 Alex Evans - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*/ -#include "uSynergy.h" -#include -#include - - - -//--------------------------------------------------------------------------------------------------------------------- -// Internal helpers -//--------------------------------------------------------------------------------------------------------------------- - - - -/** -@brief Read 16 bit integer in network byte order and convert to native byte order -**/ -static int16_t sNetToNative16(const unsigned char *value) -{ -#ifdef USYNERGY_LITTLE_ENDIAN - return value[1] | (value[0] << 8); -#else - return value[0] | (value[1] << 8); -#endif -} - - - -/** -@brief Read 32 bit integer in network byte order and convert to native byte order -**/ -static int32_t sNetToNative32(const unsigned char *value) -{ -#ifdef USYNERGY_LITTLE_ENDIAN - return value[3] | (value[2] << 8) | (value[1] << 16) | (value[0] << 24); -#else - return value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); -#endif -} - - - -/** -@brief Trace text to client -**/ -static void sTrace(uSynergyContext *context, const char* text) -{ - // Don't trace if we don't have a trace function - if (context->m_traceFunc != 0L) - context->m_traceFunc(context->m_cookie, text); -} - - - -/** -@brief Add string to reply packet -**/ -static void sAddString(uSynergyContext *context, const char *string) -{ - size_t len = strlen(string); - memcpy(context->m_replyCur, string, len); - context->m_replyCur += len; -} - - - -/** -@brief Add uint8 to reply packet -**/ -static void sAddUInt8(uSynergyContext *context, uint8_t value) -{ - *context->m_replyCur++ = value; -} - - - -/** -@brief Add uint16 to reply packet -**/ -static void sAddUInt16(uSynergyContext *context, uint16_t value) -{ - uint8_t *reply = context->m_replyCur; - *reply++ = (uint8_t)(value >> 8); - *reply++ = (uint8_t)value; - context->m_replyCur = reply; -} - - - -/** -@brief Add uint32 to reply packet -**/ -static void sAddUInt32(uSynergyContext *context, uint32_t value) -{ - uint8_t *reply = context->m_replyCur; - *reply++ = (uint8_t)(value >> 24); - *reply++ = (uint8_t)(value >> 16); - *reply++ = (uint8_t)(value >> 8); - *reply++ = (uint8_t)value; - context->m_replyCur = reply; -} - - - -/** -@brief Send reply packet -**/ -static uSynergyBool sSendReply(uSynergyContext *context) -{ - // Set header size - uint8_t *reply_buf = context->m_replyBuffer; - uint32_t reply_len = (uint32_t)(context->m_replyCur - reply_buf); /* Total size of reply */ - uint32_t body_len = reply_len - 4; /* Size of body */ - uSynergyBool ret; - reply_buf[0] = (uint8_t)(body_len >> 24); - reply_buf[1] = (uint8_t)(body_len >> 16); - reply_buf[2] = (uint8_t)(body_len >> 8); - reply_buf[3] = (uint8_t)body_len; - - // Send reply - ret = context->m_sendFunc(context->m_cookie, context->m_replyBuffer, reply_len); - - // Reset reply buffer write pointer - context->m_replyCur = context->m_replyBuffer+4; - return ret; -} - - - -/** -@brief Call mouse callback after a mouse event -**/ -static void sSendMouseCallback(uSynergyContext *context) -{ - // Skip if no callback is installed - if (context->m_mouseCallback == 0L) - return; - - // Send callback - context->m_mouseCallback(context->m_cookie, context->m_mouseX, context->m_mouseY, context->m_mouseWheelX, - context->m_mouseWheelY, context->m_mouseButtonLeft, context->m_mouseButtonRight, context->m_mouseButtonMiddle); -} - - - -/** -@brief Send keyboard callback when a key has been pressed or released -**/ -static void sSendKeyboardCallback(uSynergyContext *context, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) -{ - // Skip if no callback is installed - if (context->m_keyboardCallback == 0L) - return; - - // Send callback - context->m_keyboardCallback(context->m_cookie, key, modifiers, down, repeat); -} - - - -/** -@brief Send joystick callback -**/ -static void sSendJoystickCallback(uSynergyContext *context, uint8_t joyNum) -{ - int8_t *sticks; - - // Skip if no callback is installed - if (context->m_joystickCallback == 0L) - return; - - // Send callback - sticks = context->m_joystickSticks[joyNum]; - context->m_joystickCallback(context->m_cookie, joyNum, context->m_joystickButtons[joyNum], sticks[0], sticks[1], sticks[2], sticks[3]); -} - - - -/** -@brief Parse a single client message, update state, send callbacks and send replies -**/ -#define USYNERGY_IS_PACKET(pkt_id) memcmp(message+4, pkt_id, 4)==0 -static void sProcessMessage(uSynergyContext *context, const uint8_t *message) -{ - // We have a packet! - if (memcmp(message+4, "Synergy", 7)==0) - { - // Welcome message - // kMsgHello = "Synergy%2i%2i" - // kMsgHelloBack = "Synergy%2i%2i%s" - sAddString(context, "Synergy"); - sAddUInt16(context, USYNERGY_PROTOCOL_MAJOR); - sAddUInt16(context, USYNERGY_PROTOCOL_MINOR); - sAddUInt32(context, (uint32_t)strlen(context->m_clientName)); - sAddString(context, context->m_clientName); - if (!sSendReply(context)) - { - // Send reply failed, let's try to reconnect - sTrace(context, "SendReply failed, trying to reconnect in a second"); - context->m_connected = USYNERGY_FALSE; - context->m_sleepFunc(context->m_cookie, 1000); - } - else - { - // Let's assume we're connected - char buffer[256+1]; - sprintf(buffer, "Connected as client \"%s\"", context->m_clientName); - sTrace(context, buffer); - context->m_hasReceivedHello = USYNERGY_TRUE; - } - return; - } - else if (USYNERGY_IS_PACKET("QINF")) - { - // Screen info. Reply with DINF - // kMsgQInfo = "QINF" - // kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i" - uint16_t x = 0, y = 0, warp = 0; - sAddString(context, "DINF"); - sAddUInt16(context, x); - sAddUInt16(context, y); - sAddUInt16(context, context->m_clientWidth); - sAddUInt16(context, context->m_clientHeight); - sAddUInt16(context, warp); - sAddUInt16(context, 0); // mx? - sAddUInt16(context, 0); // my? - sSendReply(context); - return; - } - else if (USYNERGY_IS_PACKET("CIAK")) - { - // Do nothing? - // kMsgCInfoAck = "CIAK" - return; - } - else if (USYNERGY_IS_PACKET("CROP")) - { - // Do nothing? - // kMsgCResetOptions = "CROP" - return; - } - else if (USYNERGY_IS_PACKET("CINN")) - { - // Screen enter. Reply with CNOP - // kMsgCEnter = "CINN%2i%2i%4i%2i" - - // Obtain the Synergy sequence number - context->m_sequenceNumber = sNetToNative32(message + 12); - context->m_isCaptured = USYNERGY_TRUE; - - // Call callback - if (context->m_screenActiveCallback != 0L) - context->m_screenActiveCallback(context->m_cookie, USYNERGY_TRUE); - } - else if (USYNERGY_IS_PACKET("COUT")) - { - // Screen leave - // kMsgCLeave = "COUT" - context->m_isCaptured = USYNERGY_FALSE; - - // Call callback - if (context->m_screenActiveCallback != 0L) - context->m_screenActiveCallback(context->m_cookie, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DMDN")) - { - // Mouse down - // kMsgDMouseDown = "DMDN%1i" - char btn = message[8]-1; - if (btn==2) - context->m_mouseButtonRight = USYNERGY_TRUE; - else if (btn==1) - context->m_mouseButtonMiddle = USYNERGY_TRUE; - else - context->m_mouseButtonLeft = USYNERGY_TRUE; - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMUP")) - { - // Mouse up - // kMsgDMouseUp = "DMUP%1i" - char btn = message[8]-1; - if (btn==2) - context->m_mouseButtonRight = USYNERGY_FALSE; - else if (btn==1) - context->m_mouseButtonMiddle = USYNERGY_FALSE; - else - context->m_mouseButtonLeft = USYNERGY_FALSE; - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMMV")) - { - // Mouse move. Reply with CNOP - // kMsgDMouseMove = "DMMV%2i%2i" - context->m_mouseX = sNetToNative16(message+8); - context->m_mouseY = sNetToNative16(message+10); - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMWM")) - { - // Mouse wheel - // kMsgDMouseWheel = "DMWM%2i%2i" - // kMsgDMouseWheel1_0 = "DMWM%2i" - context->m_mouseWheelX += sNetToNative16(message+8); - context->m_mouseWheelY += sNetToNative16(message+10); - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DKDN")) - { - // Key down - // kMsgDKeyDown = "DKDN%2i%2i%2i" - // kMsgDKeyDown1_0 = "DKDN%2i%2i" - //uint16_t id = sNetToNative16(message+8); - uint16_t mod = sNetToNative16(message+10); - uint16_t key = sNetToNative16(message+12); - sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DKRP")) - { - // Key repeat - // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" - // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" - uint16_t mod = sNetToNative16(message+10); -// uint16_t count = sNetToNative16(message+12); - uint16_t key = sNetToNative16(message+14); - sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_TRUE); - } - else if (USYNERGY_IS_PACKET("DKUP")) - { - // Key up - // kMsgDKeyUp = "DKUP%2i%2i%2i" - // kMsgDKeyUp1_0 = "DKUP%2i%2i" - //uint16 id=Endian::sNetToNative(sbuf[4]); - uint16_t mod = sNetToNative16(message+10); - uint16_t key = sNetToNative16(message+12); - sSendKeyboardCallback(context, key, mod, USYNERGY_FALSE, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DGBT")) - { - // Joystick buttons - // kMsgDGameButtons = "DGBT%1i%2i"; - uint8_t joy_num = message[8]; - if (joy_numm_joystickButtons[joy_num] = (message[9] << 8) | message[10]; - sSendJoystickCallback(context, joy_num); - } - } - else if (USYNERGY_IS_PACKET("DGST")) - { - // Joystick sticks - // kMsgDGameSticks = "DGST%1i%1i%1i%1i%1i"; - uint8_t joy_num = message[8]; - if (joy_numm_joystickSticks[joy_num], message+9, 4); - sSendJoystickCallback(context, joy_num); - } - } - else if (USYNERGY_IS_PACKET("DSOP")) - { - // Set options - // kMsgDSetOptions = "DSOP%4I" - } - else if (USYNERGY_IS_PACKET("CALV")) - { - // Keepalive, reply with CALV and then CNOP - // kMsgCKeepAlive = "CALV" - sAddString(context, "CALV"); - sSendReply(context); - // now reply with CNOP - } - else if (USYNERGY_IS_PACKET("DCLP")) - { - // Clipboard message - // kMsgDClipboard = "DCLP%1i%4i%s" - // - // The clipboard message contains: - // 1 uint32: The size of the message - // 4 chars: The identifier ("DCLP") - // 1 uint8: The clipboard index - // 1 uint32: The sequence number. It's zero, because this message is always coming from the server? - // 1 uint32: The total size of the remaining 'string' (as per the Synergy %s string format (which is 1 uint32 for size followed by a char buffer (not necessarily null terminated)). - // 1 uint32: The number of formats present in the message - // And then 'number of formats' times the following: - // 1 uint32: The format of the clipboard data - // 1 uint32: The size n of the clipboard data - // n uint8: The clipboard data - const uint8_t * parse_msg = message+17; - uint32_t num_formats = sNetToNative32(parse_msg); - parse_msg += 4; - for (; num_formats; num_formats--) - { - // Parse clipboard format header - uint32_t format = sNetToNative32(parse_msg); - uint32_t size = sNetToNative32(parse_msg+4); - parse_msg += 8; - - // Call callback - if (context->m_clipboardCallback) - context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); - - parse_msg += size; - } - } - else - { - // Unknown packet, could be any of these - // kMsgCNoop = "CNOP" - // kMsgCClose = "CBYE" - // kMsgCClipboard = "CCLP%1i%4i" - // kMsgCScreenSaver = "CSEC%1i" - // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" - // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" - // kMsgDMouseRelMove = "DMRM%2i%2i" - // kMsgEIncompatible = "EICV%2i%2i" - // kMsgEBusy = "EBSY" - // kMsgEUnknown = "EUNK" - // kMsgEBad = "EBAD" - char buffer[64]; - sprintf(buffer, "Unknown packet '%c%c%c%c'", message[4], message[5], message[6], message[7]); - sTrace(context, buffer); - return; - } - - // Reply with CNOP maybe? - sAddString(context, "CNOP"); - sSendReply(context); -} -#undef USYNERGY_IS_PACKET - - - -/** -@brief Mark context as being disconnected -**/ -static void sSetDisconnected(uSynergyContext *context) -{ - context->m_connected = USYNERGY_FALSE; - context->m_hasReceivedHello = USYNERGY_FALSE; - context->m_isCaptured = USYNERGY_FALSE; - context->m_replyCur = context->m_replyBuffer + 4; - context->m_sequenceNumber = 0; -} - - - -/** -@brief Update a connected context -**/ -static void sUpdateContext(uSynergyContext *context) -{ - /* Receive data (blocking) */ - int receive_size = USYNERGY_RECEIVE_BUFFER_SIZE - context->m_receiveOfs; - int num_received = 0; - int packlen = 0; - if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer + context->m_receiveOfs, receive_size, &num_received) == USYNERGY_FALSE) - { - /* Receive failed, let's try to reconnect */ - char buffer[128]; - sprintf(buffer, "Receive failed (%d bytes asked, %d bytes received), trying to reconnect in a second", receive_size, num_received); - sTrace(context, buffer); - sSetDisconnected(context); - context->m_sleepFunc(context->m_cookie, 1000); - return; - } - context->m_receiveOfs += num_received; - - /* If we didn't receive any data then we're probably still polling to get connected and - therefore not getting any data back. To avoid overloading the system with a Synergy - thread that would hammer on polling, we let it rest for a bit if there's no data. */ - if (num_received == 0) - context->m_sleepFunc(context->m_cookie, 500); - - /* Check for timeouts */ - if (context->m_hasReceivedHello) - { - uint32_t cur_time = context->m_getTimeFunc(); - if (num_received == 0) - { - /* Timeout after 2 secs of inactivity (we received no CALV) */ - if ((cur_time - context->m_lastMessageTime) > USYNERGY_IDLE_TIMEOUT) - sSetDisconnected(context); - } - else - context->m_lastMessageTime = cur_time; - } - - /* Eat packets */ - for (;;) - { - /* Grab packet length and bail out if the packet goes beyond the end of the buffer */ - packlen = sNetToNative32(context->m_receiveBuffer); - if (packlen+4 > context->m_receiveOfs) - break; - - /* Process message */ - sProcessMessage(context, context->m_receiveBuffer); - - /* Move packet to front of buffer */ - memmove(context->m_receiveBuffer, context->m_receiveBuffer+packlen+4, context->m_receiveOfs-packlen-4); - context->m_receiveOfs -= packlen+4; - } - - /* Throw away over-sized packets */ - if (packlen > USYNERGY_RECEIVE_BUFFER_SIZE) - { - /* Oversized packet, ditch tail end */ - char buffer[128]; - sprintf(buffer, "Oversized packet: '%c%c%c%c' (length %d)", context->m_receiveBuffer[4], context->m_receiveBuffer[5], context->m_receiveBuffer[6], context->m_receiveBuffer[7], packlen); - sTrace(context, buffer); - num_received = context->m_receiveOfs-4; // 4 bytes for the size field - while (num_received != packlen) - { - int buffer_left = packlen - num_received; - int to_receive = buffer_left < USYNERGY_RECEIVE_BUFFER_SIZE ? buffer_left : USYNERGY_RECEIVE_BUFFER_SIZE; - int ditch_received = 0; - if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer, to_receive, &ditch_received) == USYNERGY_FALSE) - { - /* Receive failed, let's try to reconnect */ - sTrace(context, "Receive failed, trying to reconnect in a second"); - sSetDisconnected(context); - context->m_sleepFunc(context->m_cookie, 1000); - break; - } - else - { - num_received += ditch_received; - } - } - context->m_receiveOfs = 0; - } -} - - -//--------------------------------------------------------------------------------------------------------------------- -// Public interface -//--------------------------------------------------------------------------------------------------------------------- - - - -/** -@brief Initialize uSynergy context -**/ -void uSynergyInit(uSynergyContext *context) -{ - /* Zero memory */ - memset(context, 0, sizeof(uSynergyContext)); - - /* Initialize to default state */ - sSetDisconnected(context); -} - - -/** -@brief Update uSynergy -**/ -void uSynergyUpdate(uSynergyContext *context) -{ - if (context->m_connected) - { - /* Update context, receive data, call callbacks */ - sUpdateContext(context); - } - else - { - /* Try to connect */ - if (context->m_connectFunc(context->m_cookie)) - context->m_connected = USYNERGY_TRUE; - } -} - - - -/** -@brief Send clipboard data -**/ -void uSynergySendClipboard(uSynergyContext *context, const char *text) -{ - // Calculate maximum size that will fit in a reply packet - uint32_t overhead_size = 4 + /* Message size */ - 4 + /* Message ID */ - 1 + /* Clipboard index */ - 4 + /* Sequence number */ - 4 + /* Rest of message size (because it's a Synergy string from here on) */ - 4 + /* Number of clipboard formats */ - 4 + /* Clipboard format */ - 4; /* Clipboard data length */ - uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; - - // Clip text to max length - uint32_t text_length = (uint32_t)strlen(text); - if (text_length > max_length) - { - char buffer[128]; - sprintf(buffer, "Clipboard buffer too small, clipboard truncated at %d characters", max_length); - sTrace(context, buffer); - text_length = max_length; - } - - // Assemble packet - sAddString(context, "DCLP"); - sAddUInt8(context, 0); /* Clipboard index */ - sAddUInt32(context, context->m_sequenceNumber); - sAddUInt32(context, 4+4+4+text_length); /* Rest of message size: numFormats, format, length, data */ - sAddUInt32(context, 1); /* Number of formats (only text for now) */ - sAddUInt32(context, USYNERGY_CLIPBOARD_FORMAT_TEXT); - sAddUInt32(context, text_length); - sAddString(context, text); - sSendReply(context); -} +/* +uSynergy client -- Implementation for the embedded Synergy client library + version 1.0.0, July 7th, 2012 + +Copyright (c) 2012 Alex Evans + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#include "uSynergy.h" +#include +#include + + + +//--------------------------------------------------------------------------------------------------------------------- +// Internal helpers +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Read 16 bit integer in network byte order and convert to native byte order +**/ +static int16_t sNetToNative16(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[1] | (value[0] << 8); +#else + return value[0] | (value[1] << 8); +#endif +} + + + +/** +@brief Read 32 bit integer in network byte order and convert to native byte order +**/ +static int32_t sNetToNative32(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[3] | (value[2] << 8) | (value[1] << 16) | (value[0] << 24); +#else + return value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); +#endif +} + + + +/** +@brief Trace text to client +**/ +static void sTrace(uSynergyContext *context, const char* text) +{ + // Don't trace if we don't have a trace function + if (context->m_traceFunc != 0L) + context->m_traceFunc(context->m_cookie, text); +} + + + +/** +@brief Add string to reply packet +**/ +static void sAddString(uSynergyContext *context, const char *string) +{ + size_t len = strlen(string); + memcpy(context->m_replyCur, string, len); + context->m_replyCur += len; +} + + + +/** +@brief Add uint8 to reply packet +**/ +static void sAddUInt8(uSynergyContext *context, uint8_t value) +{ + *context->m_replyCur++ = value; +} + + + +/** +@brief Add uint16 to reply packet +**/ +static void sAddUInt16(uSynergyContext *context, uint16_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Add uint32 to reply packet +**/ +static void sAddUInt32(uSynergyContext *context, uint32_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 24); + *reply++ = (uint8_t)(value >> 16); + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Send reply packet +**/ +static uSynergyBool sSendReply(uSynergyContext *context) +{ + // Set header size + uint8_t *reply_buf = context->m_replyBuffer; + uint32_t reply_len = (uint32_t)(context->m_replyCur - reply_buf); /* Total size of reply */ + uint32_t body_len = reply_len - 4; /* Size of body */ + uSynergyBool ret; + reply_buf[0] = (uint8_t)(body_len >> 24); + reply_buf[1] = (uint8_t)(body_len >> 16); + reply_buf[2] = (uint8_t)(body_len >> 8); + reply_buf[3] = (uint8_t)body_len; + + // Send reply + ret = context->m_sendFunc(context->m_cookie, context->m_replyBuffer, reply_len); + + // Reset reply buffer write pointer + context->m_replyCur = context->m_replyBuffer+4; + return ret; +} + + + +/** +@brief Call mouse callback after a mouse event +**/ +static void sSendMouseCallback(uSynergyContext *context) +{ + // Skip if no callback is installed + if (context->m_mouseCallback == 0L) + return; + + // Send callback + context->m_mouseCallback(context->m_cookie, context->m_mouseX, context->m_mouseY, context->m_mouseWheelX, + context->m_mouseWheelY, context->m_mouseButtonLeft, context->m_mouseButtonRight, context->m_mouseButtonMiddle); +} + + + +/** +@brief Send keyboard callback when a key has been pressed or released +**/ +static void sSendKeyboardCallback(uSynergyContext *context, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +{ + // Skip if no callback is installed + if (context->m_keyboardCallback == 0L) + return; + + // Send callback + context->m_keyboardCallback(context->m_cookie, key, modifiers, down, repeat); +} + + + +/** +@brief Send joystick callback +**/ +static void sSendJoystickCallback(uSynergyContext *context, uint8_t joyNum) +{ + int8_t *sticks; + + // Skip if no callback is installed + if (context->m_joystickCallback == 0L) + return; + + // Send callback + sticks = context->m_joystickSticks[joyNum]; + context->m_joystickCallback(context->m_cookie, joyNum, context->m_joystickButtons[joyNum], sticks[0], sticks[1], sticks[2], sticks[3]); +} + + + +/** +@brief Parse a single client message, update state, send callbacks and send replies +**/ +#define USYNERGY_IS_PACKET(pkt_id) memcmp(message+4, pkt_id, 4)==0 +static void sProcessMessage(uSynergyContext *context, const uint8_t *message) +{ + // We have a packet! + if (memcmp(message+4, "Synergy", 7)==0) + { + // Welcome message + // kMsgHello = "Synergy%2i%2i" + // kMsgHelloBack = "Synergy%2i%2i%s" + sAddString(context, "Synergy"); + sAddUInt16(context, USYNERGY_PROTOCOL_MAJOR); + sAddUInt16(context, USYNERGY_PROTOCOL_MINOR); + sAddUInt32(context, (uint32_t)strlen(context->m_clientName)); + sAddString(context, context->m_clientName); + if (!sSendReply(context)) + { + // Send reply failed, let's try to reconnect + sTrace(context, "SendReply failed, trying to reconnect in a second"); + context->m_connected = USYNERGY_FALSE; + context->m_sleepFunc(context->m_cookie, 1000); + } + else + { + // Let's assume we're connected + char buffer[256+1]; + sprintf(buffer, "Connected as client \"%s\"", context->m_clientName); + sTrace(context, buffer); + context->m_hasReceivedHello = USYNERGY_TRUE; + } + return; + } + else if (USYNERGY_IS_PACKET("QINF")) + { + // Screen info. Reply with DINF + // kMsgQInfo = "QINF" + // kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i" + uint16_t x = 0, y = 0, warp = 0; + sAddString(context, "DINF"); + sAddUInt16(context, x); + sAddUInt16(context, y); + sAddUInt16(context, context->m_clientWidth); + sAddUInt16(context, context->m_clientHeight); + sAddUInt16(context, warp); + sAddUInt16(context, 0); // mx? + sAddUInt16(context, 0); // my? + sSendReply(context); + return; + } + else if (USYNERGY_IS_PACKET("CIAK")) + { + // Do nothing? + // kMsgCInfoAck = "CIAK" + return; + } + else if (USYNERGY_IS_PACKET("CROP")) + { + // Do nothing? + // kMsgCResetOptions = "CROP" + return; + } + else if (USYNERGY_IS_PACKET("CINN")) + { + // Screen enter. Reply with CNOP + // kMsgCEnter = "CINN%2i%2i%4i%2i" + + // Obtain the Synergy sequence number + context->m_sequenceNumber = sNetToNative32(message + 12); + context->m_isCaptured = USYNERGY_TRUE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("COUT")) + { + // Screen leave + // kMsgCLeave = "COUT" + context->m_isCaptured = USYNERGY_FALSE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DMDN")) + { + // Mouse down + // kMsgDMouseDown = "DMDN%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_TRUE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_TRUE; + else + context->m_mouseButtonLeft = USYNERGY_TRUE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMUP")) + { + // Mouse up + // kMsgDMouseUp = "DMUP%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_FALSE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_FALSE; + else + context->m_mouseButtonLeft = USYNERGY_FALSE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMMV")) + { + // Mouse move. Reply with CNOP + // kMsgDMouseMove = "DMMV%2i%2i" + context->m_mouseX = sNetToNative16(message+8); + context->m_mouseY = sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMWM")) + { + // Mouse wheel + // kMsgDMouseWheel = "DMWM%2i%2i" + // kMsgDMouseWheel1_0 = "DMWM%2i" + context->m_mouseWheelX += sNetToNative16(message+8); + context->m_mouseWheelY += sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DKDN")) + { + // Key down + // kMsgDKeyDown = "DKDN%2i%2i%2i" + // kMsgDKeyDown1_0 = "DKDN%2i%2i" + //uint16_t id = sNetToNative16(message+8); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DKRP")) + { + // Key repeat + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + uint16_t mod = sNetToNative16(message+10); +// uint16_t count = sNetToNative16(message+12); + uint16_t key = sNetToNative16(message+14); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("DKUP")) + { + // Key up + // kMsgDKeyUp = "DKUP%2i%2i%2i" + // kMsgDKeyUp1_0 = "DKUP%2i%2i" + //uint16 id=Endian::sNetToNative(sbuf[4]); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_FALSE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DGBT")) + { + // Joystick buttons + // kMsgDGameButtons = "DGBT%1i%2i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickButtons[joy_num] = (message[9] << 8) | message[10]; + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DGST")) + { + // Joystick sticks + // kMsgDGameSticks = "DGST%1i%1i%1i%1i%1i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickSticks[joy_num], message+9, 4); + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DSOP")) + { + // Set options + // kMsgDSetOptions = "DSOP%4I" + } + else if (USYNERGY_IS_PACKET("CALV")) + { + // Keepalive, reply with CALV and then CNOP + // kMsgCKeepAlive = "CALV" + sAddString(context, "CALV"); + sSendReply(context); + // now reply with CNOP + } + else if (USYNERGY_IS_PACKET("DCLP")) + { + // Clipboard message + // kMsgDClipboard = "DCLP%1i%4i%s" + // + // The clipboard message contains: + // 1 uint32: The size of the message + // 4 chars: The identifier ("DCLP") + // 1 uint8: The clipboard index + // 1 uint32: The sequence number. It's zero, because this message is always coming from the server? + // 1 uint32: The total size of the remaining 'string' (as per the Synergy %s string format (which is 1 uint32 for size followed by a char buffer (not necessarily null terminated)). + // 1 uint32: The number of formats present in the message + // And then 'number of formats' times the following: + // 1 uint32: The format of the clipboard data + // 1 uint32: The size n of the clipboard data + // n uint8: The clipboard data + const uint8_t * parse_msg = message+17; + uint32_t num_formats = sNetToNative32(parse_msg); + parse_msg += 4; + for (; num_formats; num_formats--) + { + // Parse clipboard format header + uint32_t format = sNetToNative32(parse_msg); + uint32_t size = sNetToNative32(parse_msg+4); + parse_msg += 8; + + // Call callback + if (context->m_clipboardCallback) + context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); + + parse_msg += size; + } + } + else + { + // Unknown packet, could be any of these + // kMsgCNoop = "CNOP" + // kMsgCClose = "CBYE" + // kMsgCClipboard = "CCLP%1i%4i" + // kMsgCScreenSaver = "CSEC%1i" + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + // kMsgDMouseRelMove = "DMRM%2i%2i" + // kMsgEIncompatible = "EICV%2i%2i" + // kMsgEBusy = "EBSY" + // kMsgEUnknown = "EUNK" + // kMsgEBad = "EBAD" + char buffer[64]; + sprintf(buffer, "Unknown packet '%c%c%c%c'", message[4], message[5], message[6], message[7]); + sTrace(context, buffer); + return; + } + + // Reply with CNOP maybe? + sAddString(context, "CNOP"); + sSendReply(context); +} +#undef USYNERGY_IS_PACKET + + + +/** +@brief Mark context as being disconnected +**/ +static void sSetDisconnected(uSynergyContext *context) +{ + context->m_connected = USYNERGY_FALSE; + context->m_hasReceivedHello = USYNERGY_FALSE; + context->m_isCaptured = USYNERGY_FALSE; + context->m_replyCur = context->m_replyBuffer + 4; + context->m_sequenceNumber = 0; +} + + + +/** +@brief Update a connected context +**/ +static void sUpdateContext(uSynergyContext *context) +{ + /* Receive data (blocking) */ + int receive_size = USYNERGY_RECEIVE_BUFFER_SIZE - context->m_receiveOfs; + int num_received = 0; + int packlen = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer + context->m_receiveOfs, receive_size, &num_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + char buffer[128]; + sprintf(buffer, "Receive failed (%d bytes asked, %d bytes received), trying to reconnect in a second", receive_size, num_received); + sTrace(context, buffer); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + return; + } + context->m_receiveOfs += num_received; + + /* If we didn't receive any data then we're probably still polling to get connected and + therefore not getting any data back. To avoid overloading the system with a Synergy + thread that would hammer on polling, we let it rest for a bit if there's no data. */ + if (num_received == 0) + context->m_sleepFunc(context->m_cookie, 500); + + /* Check for timeouts */ + if (context->m_hasReceivedHello) + { + uint32_t cur_time = context->m_getTimeFunc(); + if (num_received == 0) + { + /* Timeout after 2 secs of inactivity (we received no CALV) */ + if ((cur_time - context->m_lastMessageTime) > USYNERGY_IDLE_TIMEOUT) + sSetDisconnected(context); + } + else + context->m_lastMessageTime = cur_time; + } + + /* Eat packets */ + for (;;) + { + /* Grab packet length and bail out if the packet goes beyond the end of the buffer */ + packlen = sNetToNative32(context->m_receiveBuffer); + if (packlen+4 > context->m_receiveOfs) + break; + + /* Process message */ + sProcessMessage(context, context->m_receiveBuffer); + + /* Move packet to front of buffer */ + memmove(context->m_receiveBuffer, context->m_receiveBuffer+packlen+4, context->m_receiveOfs-packlen-4); + context->m_receiveOfs -= packlen+4; + } + + /* Throw away over-sized packets */ + if (packlen > USYNERGY_RECEIVE_BUFFER_SIZE) + { + /* Oversized packet, ditch tail end */ + char buffer[128]; + sprintf(buffer, "Oversized packet: '%c%c%c%c' (length %d)", context->m_receiveBuffer[4], context->m_receiveBuffer[5], context->m_receiveBuffer[6], context->m_receiveBuffer[7], packlen); + sTrace(context, buffer); + num_received = context->m_receiveOfs-4; // 4 bytes for the size field + while (num_received != packlen) + { + int buffer_left = packlen - num_received; + int to_receive = buffer_left < USYNERGY_RECEIVE_BUFFER_SIZE ? buffer_left : USYNERGY_RECEIVE_BUFFER_SIZE; + int ditch_received = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer, to_receive, &ditch_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + sTrace(context, "Receive failed, trying to reconnect in a second"); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + break; + } + else + { + num_received += ditch_received; + } + } + context->m_receiveOfs = 0; + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +// Public interface +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Initialize uSynergy context +**/ +void uSynergyInit(uSynergyContext *context) +{ + /* Zero memory */ + memset(context, 0, sizeof(uSynergyContext)); + + /* Initialize to default state */ + sSetDisconnected(context); +} + + +/** +@brief Update uSynergy +**/ +void uSynergyUpdate(uSynergyContext *context) +{ + if (context->m_connected) + { + /* Update context, receive data, call callbacks */ + sUpdateContext(context); + } + else + { + /* Try to connect */ + if (context->m_connectFunc(context->m_cookie)) + context->m_connected = USYNERGY_TRUE; + } +} + + + +/** +@brief Send clipboard data +**/ +void uSynergySendClipboard(uSynergyContext *context, const char *text) +{ + // Calculate maximum size that will fit in a reply packet + uint32_t overhead_size = 4 + /* Message size */ + 4 + /* Message ID */ + 1 + /* Clipboard index */ + 4 + /* Sequence number */ + 4 + /* Rest of message size (because it's a Synergy string from here on) */ + 4 + /* Number of clipboard formats */ + 4 + /* Clipboard format */ + 4; /* Clipboard data length */ + uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; + + // Clip text to max length + uint32_t text_length = (uint32_t)strlen(text); + if (text_length > max_length) + { + char buffer[128]; + sprintf(buffer, "Clipboard buffer too small, clipboard truncated at %d characters", max_length); + sTrace(context, buffer); + text_length = max_length; + } + + // Assemble packet + sAddString(context, "DCLP"); + sAddUInt8(context, 0); /* Clipboard index */ + sAddUInt32(context, context->m_sequenceNumber); + sAddUInt32(context, 4+4+4+text_length); /* Rest of message size: numFormats, format, length, data */ + sAddUInt32(context, 1); /* Number of formats (only text for now) */ + sAddUInt32(context, USYNERGY_CLIPBOARD_FORMAT_TEXT); + sAddUInt32(context, text_length); + sAddString(context, text); + sSendReply(context); +} From bff2d5d5e2e2d304a3c17d140a81b0bbce114c0b Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 5 Nov 2019 11:41:02 +0100 Subject: [PATCH 110/384] Update README.md --- docs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/README.md b/docs/README.md index c5d757be..c78cddb9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -214,6 +214,10 @@ Ongoing Dear ImGui development is financially supported by users and private spo And all other past and present supporters; THANK YOU! (Please contact me if you would like to be added or removed from this list) +Dear ImGui is using software and services kindly provided free of charge for open source projects: +- [PVS-Studio](https://www.viva64.com/en/b/0570/) for static analysis. +- [GitHub actions](https://github.com/features/actions) for continuous integration systems. + Credits ------- From 916487a653346d17d07226e5bb3c6bbc7f4bbf48 Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Thu, 31 Oct 2019 00:56:16 +0300 Subject: [PATCH 111/384] example_emscripten: skip outdated compiler option For more info see: https://github.com/ocornut/imgui/issues/2877 --- examples/example_emscripten/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/example_emscripten/Makefile b/examples/example_emscripten/Makefile index c9f2c054..480fabd7 100644 --- a/examples/example_emscripten/Makefile +++ b/examples/example_emscripten/Makefile @@ -22,9 +22,11 @@ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) EMS = -s USE_SDL=2 -s WASM=1 -EMS += -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE=clamp +EMS += -s ALLOW_MEMORY_GROWTH=1 EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0 EMS += -s ASSERTIONS=1 +# Uncomment next line to fix possible rendering bugs with emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) +#EMS += -s BINARYEN_TRAP_MODE=clamp #EMS += -s NO_FILESYSTEM=1 ## Getting "error: undefined symbol: $FS" if filesystem is removed #EMS += -s SAFE_HEAP=1 ## Adds overhead From 3929255b770d511301d8f65923c6f5f0adf8b126 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 5 Nov 2019 12:53:30 +0100 Subject: [PATCH 112/384] Examples: Emscripten: Removed BINARYEN_TRAP_MODE=clamp from Makefile which was removed in Emscripten 1.39.0 but required prior to 1.39.0, making life easier for absolutely no-one. (#2877, #2878) [@podsvirov] --- docs/CHANGELOG.txt | 2 ++ examples/example_emscripten/README.md | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a5f6b1ee..e4ea21dc 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,8 @@ Other Changes: - Metrics: Expose basic details of each window key/value state storage. - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] +- Examples: Emscripten: Removed BINARYEN_TRAP_MODE=clamp from Makefile which was removed in Emscripten 1.39.0 + but required prior to 1.39.0, making life easier for absolutely no-one. (#2877, #2878) [@podsvirov] - Backends: OpenGL3: Fix building with pre-3.2 GL loaders which do not expose glDrawElementsBaseVertex(), using runtime GL version to decide if we set ImGuiBackendFlags_RendererHasVtxOffset. (#2866, #2852) [@dpilawa] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] diff --git a/examples/example_emscripten/README.md b/examples/example_emscripten/README.md index c607ed73..dcb7c1a7 100644 --- a/examples/example_emscripten/README.md +++ b/examples/example_emscripten/README.md @@ -3,6 +3,10 @@ - You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions -``` -em++ -I.. -I../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp -s USE_SDL=2 -s USE_WEBGL2=1 -s WASM=1 -s FULL_ES3=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE=clamp --shell-file shell_minimal.html -o example-emscripten.html -``` +- Depending on your configuration, in Windows you may need to run `emsdk/emsdk_env.bat` in your console to access the Emscripten command-line tools. + +- Then build using `make` while in the `example_emscripten/` directory. + +- Note that Emscripten 1.39.0 (October 2019) obsoleted the `BINARYEN_TRAP_MODE=clamp` compilation flag which was required with version older than 1.39.0 to avoid rendering artefacts. See [#2877](https://github.com/ocornut/imgui/issues/2877) for details. If you use an older version, uncomment this line in the Makefile: + +`#EMS += -s BINARYEN_TRAP_MODE=clamp` From 4c13807b7d43ff0946b7ffea0ae3aee9e611d778 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 5 Nov 2019 22:43:53 +0100 Subject: [PATCH 113/384] Misc: Optimized storage of window settings data (reducing allocation count). --- docs/CHANGELOG.txt | 1 + imgui.cpp | 12 +++++++----- imgui_internal.h | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e4ea21dc..6aa29407 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,7 @@ Other Changes: incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) +- Misc: Optimized storage of window settings data (reducing allocation count). - Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. diff --git a/imgui.cpp b/imgui.cpp index 22f5395e..f58737ca 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3809,8 +3809,7 @@ void ImGui::Shutdown(ImGuiContext* context) g.PrivateClipboard.clear(); g.InputTextState.ClearFreeMemory(); - for (int i = 0; i < g.SettingsWindows.Size; i++) - IM_DELETE(g.SettingsWindows[i].Name); + g.SettingsWindowsNames.clear(); g.SettingsWindows.clear(); g.SettingsHandlers.clear(); @@ -9205,8 +9204,10 @@ ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name) if (const char* p = strstr(name, "###")) name = p; #endif - settings->Name = ImStrdup(name); - settings->ID = ImHashStr(name); + size_t name_len = strlen(name); + settings->NameOffset = g.SettingsWindowsNames.size(); + g.SettingsWindowsNames.append(name, name + name_len + 1); // Append with zero terminator + settings->ID = ImHashStr(name, name_len); return settings; } @@ -9387,7 +9388,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl for (int i = 0; i != g.SettingsWindows.Size; i++) { const ImGuiWindowSettings* settings = &g.SettingsWindows[i]; - buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name); + const char* settings_name = g.SettingsWindowsNames.c_str() + settings->NameOffset; + buf->appendf("[%s][%s]\n", handler->TypeName, settings_name); buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y); buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y); buf->appendf("Collapsed=%d\n", settings->Collapsed); diff --git a/imgui_internal.h b/imgui_internal.h index c1dda24e..c1998107 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -662,15 +662,16 @@ struct IMGUI_API ImGuiInputTextState }; // Windows data saved in imgui.ini file +// Because we never destroy or rename ImGuiWindowSettings, we can store the names in a separate buffer easily. struct ImGuiWindowSettings { - char* Name; + int NameOffset; // Offset into SettingsWindowNames[] ImGuiID ID; ImVec2ih Pos; ImVec2ih Size; bool Collapsed; - ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; } + ImGuiWindowSettings() { NameOffset = -1; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; } }; struct ImGuiSettingsHandler @@ -1039,6 +1040,7 @@ struct ImGuiContext ImGuiTextBuffer SettingsIniData; // In memory .ini settings ImVector SettingsHandlers; // List of .ini settings handlers ImVector SettingsWindows; // ImGuiWindow .ini settings entries (parsed from the last loaded .ini file and maintained on saving) + ImGuiTextBuffer SettingsWindowsNames; // Names for SettingsWindows // Logging bool LogEnabled; From 09b2310237d6295d4137aa625f59ef8b0d322c1a Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 6 Nov 2019 15:15:29 +0100 Subject: [PATCH 114/384] Internals: Added index of helpers and shuffled a few things. --- imgui.h | 10 +++++---- imgui_internal.h | 55 +++++++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/imgui.h b/imgui.h index 841506f9..ceac0879 100644 --- a/imgui.h +++ b/imgui.h @@ -1223,10 +1223,12 @@ template void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p //----------------------------------------------------------------------------- // Helper: ImVector<> // Lightweight std::vector<>-like class to avoid dragging dependencies (also, some implementations of STL with debug enabled are absurdly slow, we bypass it so our code runs fast in debug). -// You generally do NOT need to care or use this ever. But we need to make it available in imgui.h because some of our data structures are relying on it. -// Important: clear() frees memory, resize(0) keep the allocated buffer. We use resize(0) a lot to intentionally recycle allocated buffers across frames and amortize our costs. -// Important: our implementation does NOT call C++ constructors/destructors, we treat everything as raw data! This is intentional but be extra mindful of that, -// do NOT use this class as a std::vector replacement in your own code! Many of the structures used by dear imgui can be safely initialized by a zero-memset. +//----------------------------------------------------------------------------- +// - You generally do NOT need to care or use this ever. But we need to make it available in imgui.h because some of our public structures are relying on it. +// - We use std-like naming convention here, which is a little unusual for this codebase. +// - Important: clear() frees memory, resize(0) keep the allocated buffer. We use resize(0) a lot to intentionally recycle allocated buffers across frames and amortize our costs. +// - Important: our implementation does NOT call C++ constructors/destructors, we treat everything as raw data! This is intentional but be extra mindful of that, +// Do NOT use this class as a std::vector replacement in your own code! Many of the structures used by dear imgui can be safely initialized by a zero-memset. //----------------------------------------------------------------------------- template diff --git a/imgui_internal.h b/imgui_internal.h index c1998107..0fe8590a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -64,6 +64,7 @@ Index of this file: // Forward declarations //----------------------------------------------------------------------------- +struct ImBoolVector; // Store 1-bit per value struct ImRect; // An axis-aligned rectangle (2 points) struct ImDrawDataBuilder; // Helper to build a ImDrawData instance struct ImDrawListSharedData; // Data shared between all ImDrawList instances @@ -87,6 +88,7 @@ struct ImGuiTabItem; // Storage for a tab item (within a tab bar) struct ImGuiWindow; // Storage for one window struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame) struct ImGuiWindowSettings; // Storage for window settings stored in .ini file (we keep one of those even if the actual window wasn't instanced during this session) +template struct ImPool; // Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical @@ -133,7 +135,19 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer //----------------------------------------------------------------------------- // Generic helpers //----------------------------------------------------------------------------- +// - Macros +// - Helpers: Misc +// - Helpers: Bit manipulation +// - Helpers: Geometry +// - Helpers: String, Formatting +// - Helpers: UTF-8 <> wchar conversions +// - Helpers: ImVec2/ImVec4 operators +// - Helpers: Maths +// - Helper: ImBoolVector +// - Helper: ImPool<> +//----------------------------------------------------------------------------- +// Macros #define IM_PI 3.14159265358979323846f #ifdef _WIN32 #define IM_NEWLINE "\r\n" // Play it nice with Windows users (2018/05 news: Microsoft announced that Notepad will finally display Unix-style carriage returns!) @@ -159,28 +173,20 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IMGUI_CDECL #endif -// Helpers: UTF-8 <> wchar -IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count -IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // read one character. return input UTF-8 bytes count -IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count -IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) -IMGUI_API int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end); // return number of bytes to express one char in UTF-8 -IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string in UTF-8 - // Helpers: Misc -IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0); -IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size = NULL, int padding_bytes = 0); IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode); -static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } -static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } -static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } -static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } #define ImQsort qsort +IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0); +IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS static inline ImU32 ImHash(const void* data, int size, ImU32 seed = 0) { return size ? ImHashData(data, (size_t)size, seed) : ImHashStr((const char*)data, 0, seed); } // [moved to ImHashStr/ImHashData in 1.68] #endif +// Helpers: Bit manipulation +static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } +static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } + // Helpers: Geometry IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); @@ -188,7 +194,7 @@ IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); -// Helpers: String +// Helpers: String, Formatting IMGUI_API int ImStricmp(const char* str1, const char* str2); IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); @@ -206,6 +212,16 @@ IMGUI_API const char* ImParseFormatFindStart(const char* format); IMGUI_API const char* ImParseFormatFindEnd(const char* format); IMGUI_API const char* ImParseFormatTrimDecorations(const char* format, char* buf, size_t buf_size); IMGUI_API int ImParseFormatPrecision(const char* format, int default_value); +static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } +static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } + +// Helpers: UTF-8 <> wchar conversions +IMGUI_API int ImTextStrToUtf8(char* buf, int buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count +IMGUI_API int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // read one character. return input UTF-8 bytes count +IMGUI_API int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count +IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) +IMGUI_API int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end); // return number of bytes to express one char in UTF-8 +IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string in UTF-8 // Helpers: ImVec2/ImVec4 operators // We are keeping those disabled by default so they don't leak in user space, to allow user enabling implicit cast operators between ImVec2 and their own types (using IM_VEC2_CLASS_EXTRA etc.) @@ -271,9 +287,9 @@ static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } -// Helper: ImBoolVector. Store 1-bit per value. -// Note that Resize() currently clears the whole vector. -struct ImBoolVector +// Helper: ImBoolVector +// Store 1-bit per value. Note that Resize() currently clears the whole vector. +struct IMGUI_API ImBoolVector { ImVector Storage; ImBoolVector() { } @@ -283,7 +299,8 @@ struct ImBoolVector void SetBit(int n, bool v) { int off = (n >> 5); int mask = 1 << (n & 31); if (v) Storage[off] |= mask; else Storage[off] &= ~mask; } }; -// Helper: ImPool<>. Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID over a dense/hot buffer, +// Helper: ImPool<> +// Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID over a dense/hot buffer, // Honor constructor/destructor. Add/remove invalidate all pointers. Indexes have the same lifetime as the associated object. typedef int ImPoolIdx; template From 28f1d60de10929f7a96c8f880818e48fe08a05fe Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 6 Nov 2019 22:52:48 +0100 Subject: [PATCH 115/384] Internals: Renaming + added ImStrSkipBlank() from docking branch. (cherry picked from commit a573943fa0ce323ffb4080e57f5e8fe1bc777c36) --- imgui.cpp | 37 +++++++++++++++++++++++-------------- imgui_internal.h | 3 ++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f58737ca..29c44abb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -847,9 +847,9 @@ static void AddWindowToSortBuffer(ImVector* out_sorted static ImRect GetViewportRect(); // Settings -static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name); -static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line); -static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf); +static void* WindowSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name); +static void WindowSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line); +static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSettingsHandler*, ImGuiTextBuffer* buf); // Platform Dependents default implementation for IO functions static const char* GetClipboardTextFn_DefaultImpl(void* user_data); @@ -1242,6 +1242,13 @@ void ImStrTrimBlanks(char* buf) buf[p - p_start] = 0; // Zero terminate } +const char* ImStrSkipBlank(const char* str) +{ + while (str[0] == ' ' || str[0] == '\t') + str++; + return str; +} + // A) MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size). // Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm. // B) When buf==NULL vsnprintf() will return the output size. @@ -3744,13 +3751,15 @@ void ImGui::Initialize(ImGuiContext* context) IM_ASSERT(!g.Initialized && !g.SettingsLoaded); // Add .ini handle for ImGuiWindow type - ImGuiSettingsHandler ini_handler; - ini_handler.TypeName = "Window"; - ini_handler.TypeHash = ImHashStr("Window"); - ini_handler.ReadOpenFn = SettingsHandlerWindow_ReadOpen; - ini_handler.ReadLineFn = SettingsHandlerWindow_ReadLine; - ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll; - g.SettingsHandlers.push_back(ini_handler); + { + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Window"; + ini_handler.TypeHash = ImHashStr("Window"); + ini_handler.ReadOpenFn = WindowSettingsHandler_ReadOpen; + ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine; + ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; + g.SettingsHandlers.push_back(ini_handler); + } g.Initialized = true; } @@ -9342,7 +9351,7 @@ const char* ImGui::SaveIniSettingsToMemory(size_t* out_size) return g.SettingsIniData.c_str(); } -static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) +static void* WindowSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) { ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHashStr(name)); if (!settings) @@ -9350,7 +9359,7 @@ static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler* return (void*)settings; } -static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) +static void WindowSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) { ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; int x, y; @@ -9360,7 +9369,7 @@ static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, else if (sscanf(line, "Collapsed=%d", &i) == 1) settings->Collapsed = (i != 0); } -static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) +static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) { // Gather data from windows that were active during this session // (if a window wasn't opened in this session we preserve its settings) @@ -9393,7 +9402,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y); buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y); buf->appendf("Collapsed=%d\n", settings->Collapsed); - buf->appendf("\n"); + buf->append("\n"); } } diff --git a/imgui_internal.h b/imgui_internal.h index 0fe8590a..5d104fe3 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -87,7 +87,7 @@ struct ImGuiTabBar; // Storage for a tab bar struct ImGuiTabItem; // Storage for a tab item (within a tab bar) struct ImGuiWindow; // Storage for one window struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame) -struct ImGuiWindowSettings; // Storage for window settings stored in .ini file (we keep one of those even if the actual window wasn't instanced during this session) +struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session) template struct ImPool; // Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. @@ -206,6 +206,7 @@ IMGUI_API const char* ImStreolRange(const char* str, const char* str_end); IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); IMGUI_API void ImStrTrimBlanks(char* str); +IMGUI_API const char* ImStrSkipBlank(const char* str); IMGUI_API int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3); IMGUI_API int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3); IMGUI_API const char* ImParseFormatFindStart(const char* format); From a337e219b6f1c3791ab6e3c830f6b3372f7b616c Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 7 Nov 2019 15:01:19 +0100 Subject: [PATCH 116/384] Internals: ImPool: Renaming. --- imgui.cpp | 6 +++--- imgui_internal.h | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 29c44abb..c75eb179 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9830,9 +9830,9 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } - if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.Data.Size)) + if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetSize())) { - for (int n = 0; n < g.TabBars.Data.Size; n++) + for (int n = 0; n < g.TabBars.GetSize(); n++) Funcs::NodeTabBar(g.TabBars.GetByIndex(n)); ImGui::TreePop(); } @@ -9845,7 +9845,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) #endif #if 0 - if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.Data.Size)) + if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) { ImGui::TreePop(); } diff --git a/imgui_internal.h b/imgui_internal.h index 5d104fe3..6fe74a0d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -307,23 +307,23 @@ typedef int ImPoolIdx; template struct IMGUI_API ImPool { - ImVector Data; // Contiguous data + ImVector Buf; // Contiguous data ImGuiStorage Map; // ID->Index ImPoolIdx FreeIdx; // Next free idx to use ImPool() { FreeIdx = 0; } ~ImPool() { Clear(); } - T* GetByKey(ImGuiID key) { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Data[idx] : NULL; } - T* GetByIndex(ImPoolIdx n) { return &Data[n]; } - ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Data.Data && p < Data.Data + Data.Size); return (ImPoolIdx)(p - Data.Data); } - T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Data[*p_idx]; *p_idx = FreeIdx; return Add(); } - bool Contains(const T* p) const { return (p >= Data.Data && p < Data.Data + Data.Size); } - void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Data[idx].~T(); } Map.Clear(); Data.clear(); FreeIdx = 0; } - T* Add() { int idx = FreeIdx; if (idx == Data.Size) { Data.resize(Data.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Data[idx]; } IM_PLACEMENT_NEW(&Data[idx]) T(); return &Data[idx]; } + T* GetByKey(ImGuiID key) { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Buf[idx] : NULL; } + T* GetByIndex(ImPoolIdx n) { return &Buf[n]; } + ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Buf.Data && p < Buf.Data + Buf.Size); return (ImPoolIdx)(p - Buf.Data); } + T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Buf[*p_idx]; *p_idx = FreeIdx; return Add(); } + bool Contains(const T* p) const { return (p >= Buf.Data && p < Buf.Data + Buf.Size); } + void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Buf[idx].~T(); } Map.Clear(); Buf.clear(); FreeIdx = 0; } + T* Add() { int idx = FreeIdx; if (idx == Buf.Size) { Buf.resize(Buf.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Buf[idx]; } IM_PLACEMENT_NEW(&Buf[idx]) T(); return &Buf[idx]; } void Remove(ImGuiID key, const T* p) { Remove(key, GetIndex(p)); } - void Remove(ImGuiID key, ImPoolIdx idx) { Data[idx].~T(); *(int*)&Data[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); } - void Reserve(int capacity) { Data.reserve(capacity); Map.Data.reserve(capacity); } - int GetSize() const { return Data.Size; } + void Remove(ImGuiID key, ImPoolIdx idx) { Buf[idx].~T(); *(int*)&Buf[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); } + void Reserve(int capacity) { Buf.reserve(capacity); Map.Data.reserve(capacity); } + int GetSize() const { return Buf.Size; } }; //----------------------------------------------------------------------------- From d003674f2cc3a653ca61a6d4d3cc35a95fc83e1e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 7 Nov 2019 16:05:03 +0100 Subject: [PATCH 117/384] Internals: Added ImChunkStream, used by window settings. (more generic followup to 4c13807, the class will be used more extensively by Tables) --- imgui.cpp | 36 +++++++++++++++++++----------------- imgui_internal.h | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c75eb179..c15121a3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2525,7 +2525,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) LastTimeActive = -1.0f; ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; - SettingsIdx = -1; + SettingsOffset = -1; DrawList = &DrawListInst; DrawList->_OwnerName = Name; @@ -3818,7 +3818,6 @@ void ImGui::Shutdown(ImGuiContext* context) g.PrivateClipboard.clear(); g.InputTextState.ClearFreeMemory(); - g.SettingsWindowsNames.clear(); g.SettingsWindows.clear(); g.SettingsHandlers.clear(); @@ -4704,7 +4703,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) { // Retrieve settings from .ini file - window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings); + window->SettingsOffset = g.SettingsWindows.offset_from_ptr(settings); SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); window->Pos = ImVec2(settings->Pos.x, settings->Pos.y); window->Collapsed = settings->Collapsed; @@ -9205,27 +9204,31 @@ void ImGui::MarkIniSettingsDirty(ImGuiWindow* window) ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name) { ImGuiContext& g = *GImGui; - g.SettingsWindows.push_back(ImGuiWindowSettings()); - ImGuiWindowSettings* settings = &g.SettingsWindows.back(); + #if !IMGUI_DEBUG_INI_SETTINGS // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier. if (const char* p = strstr(name, "###")) name = p; #endif - size_t name_len = strlen(name); - settings->NameOffset = g.SettingsWindowsNames.size(); - g.SettingsWindowsNames.append(name, name + name_len + 1); // Append with zero terminator + const size_t name_len = strlen(name); + + // Allocate chunk + const size_t chunk_size = sizeof(ImGuiWindowSettings) + name_len + 1; + ImGuiWindowSettings* settings = g.SettingsWindows.alloc_chunk(chunk_size); + IM_PLACEMENT_NEW(settings) ImGuiWindowSettings(); settings->ID = ImHashStr(name, name_len); + memcpy(settings->GetName(), name, name_len + 1); // Store with zero terminator + return settings; } ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id) { ImGuiContext& g = *GImGui; - for (int i = 0; i != g.SettingsWindows.Size; i++) - if (g.SettingsWindows[i].ID == id) - return &g.SettingsWindows[i]; + for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) + if (settings->ID == id) + return settings; return NULL; } @@ -9380,11 +9383,11 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; - ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID); + ImGuiWindowSettings* settings = (window->SettingsOffset != -1) ? g.SettingsWindows.ptr_from_offset(window->SettingsOffset) : ImGui::FindWindowSettings(window->ID); if (!settings) { settings = ImGui::CreateNewWindowSettings(window->Name); - window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings); + window->SettingsOffset = g.SettingsWindows.offset_from_ptr(settings); } IM_ASSERT(settings->ID == window->ID); settings->Pos = ImVec2ih((short)window->Pos.x, (short)window->Pos.y); @@ -9393,11 +9396,10 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl } // Write to text buffer - buf->reserve(buf->size() + g.SettingsWindows.Size * 96); // ballpark reserve - for (int i = 0; i != g.SettingsWindows.Size; i++) + buf->reserve(buf->size() + g.SettingsWindows.size() * 6); // ballpark reserve + for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) { - const ImGuiWindowSettings* settings = &g.SettingsWindows[i]; - const char* settings_name = g.SettingsWindowsNames.c_str() + settings->NameOffset; + const char* settings_name = settings->GetName(); buf->appendf("[%s][%s]\n", handler->TypeName, settings_name); buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y); buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y); diff --git a/imgui_internal.h b/imgui_internal.h index 6fe74a0d..37d46020 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -88,7 +88,6 @@ struct ImGuiTabItem; // Storage for a tab item (within a tab bar) struct ImGuiWindow; // Storage for one window struct ImGuiWindowTempData; // Temporary storage for one window (that's the data which in theory we could ditch at the end of the frame) struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session) -template struct ImPool; // Basic keyed storage for contiguous instances, slow/amortized insertion, O(1) indexable, O(Log N) queries by ID // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical @@ -145,6 +144,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer // - Helpers: Maths // - Helper: ImBoolVector // - Helper: ImPool<> +// - Helper: ImChunkStream<> //----------------------------------------------------------------------------- // Macros @@ -326,6 +326,28 @@ struct IMGUI_API ImPool int GetSize() const { return Buf.Size; } }; +// Helper: ImChunkStream<> +// Build and iterate a contiguous stream of variable-sized structures. +// This is used by Settings to store persistent data while reducing allocation count. +// We store the chunk size first, and align the final size on 4 bytes boundaries (this what the '(X + 3) & ~3' statement is for) +// The tedious/zealous amount of casting is to avoid -Wcast-align warnings. +template +struct IMGUI_API ImChunkStream +{ + ImVector Buf; + + void clear() { Buf.clear(); } + bool empty() const { return Buf.Size == 0; } + int size() const { return Buf.Size; } + T* alloc_chunk(size_t sz) { size_t HDR_SZ = 4; sz = ((HDR_SZ + sz) + 3u) & ~3u; int off = Buf.Size; Buf.resize(off + (int)sz); ((int*)(void*)(Buf.Data + off))[0] = (int)sz; return (T*)(void*)(Buf.Data + off + (int)HDR_SZ); } + T* begin() { size_t HDR_SZ = 4; if (!Buf.Data) return NULL; return (T*)(void*)(Buf.Data + HDR_SZ); } + T* next_chunk(T* p) { size_t HDR_SZ = 4; IM_ASSERT(p >= begin() && p < end()); p = (T*)(void*)((char*)(void*)p + chunk_size(p)); if (p == (T*)(void*)((char*)end() + HDR_SZ)) return (T*)0; IM_ASSERT(p < end()); return p; } + int chunk_size(const T* p) { return ((const int*)p)[-1]; } + T* end() { return (T*)(void*)(Buf.Data + Buf.Size); } + int offset_from_ptr(const T* p) { IM_ASSERT(p >= begin() && p < end()); const ptrdiff_t off = (const char*)p - Buf.Data; return (int)off; } + T* ptr_from_offset(int off) { IM_ASSERT(off >= 4 && off < Buf.Size); return (T*)(void*)(Buf.Data + off); } +}; + //----------------------------------------------------------------------------- // Misc data structures //----------------------------------------------------------------------------- @@ -681,15 +703,16 @@ struct IMGUI_API ImGuiInputTextState // Windows data saved in imgui.ini file // Because we never destroy or rename ImGuiWindowSettings, we can store the names in a separate buffer easily. +// (this is designed to be stored in a ImChunkStream buffer, with the variable-length Name following our structure) struct ImGuiWindowSettings { - int NameOffset; // Offset into SettingsWindowNames[] ImGuiID ID; ImVec2ih Pos; ImVec2ih Size; bool Collapsed; - ImGuiWindowSettings() { NameOffset = -1; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; } + ImGuiWindowSettings() { ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; } + char* GetName() { return (char*)(this + 1); } }; struct ImGuiSettingsHandler @@ -1053,12 +1076,11 @@ struct ImGuiContext ImVec2 PlatformImeLastPos; // Settings - bool SettingsLoaded; - float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero - ImGuiTextBuffer SettingsIniData; // In memory .ini settings - ImVector SettingsHandlers; // List of .ini settings handlers - ImVector SettingsWindows; // ImGuiWindow .ini settings entries (parsed from the last loaded .ini file and maintained on saving) - ImGuiTextBuffer SettingsWindowsNames; // Names for SettingsWindows + bool SettingsLoaded; + float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero + ImGuiTextBuffer SettingsIniData; // In memory .ini settings + ImVector SettingsHandlers; // List of .ini settings handlers + ImChunkStream SettingsWindows; // ImGuiWindow .ini settings entries // Logging bool LogEnabled; @@ -1369,7 +1391,7 @@ struct IMGUI_API ImGuiWindow ImGuiStorage StateStorage; ImVector ColumnsStorage; float FontWindowScale; // User scale multiplier per-window, via SetWindowFontScale() - int SettingsIdx; // Index into SettingsWindow[] (indices are always valid as we only grow the array from the back) + int SettingsOffset; // Offset into SettingsWindows[] (offsets are always valid as we only grow the array from the back) ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) ImDrawList DrawListInst; From 037126ee0ef69a01b0f25ac4e7e52e6cd814b104 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 8 Nov 2019 14:57:56 +0100 Subject: [PATCH 118/384] TreeNode: Reworded code for ImGuiTreeNodeFlags_OpenOnArrow (follow up to f79b2d6c) to make it lightweight. Should be a no-op from user's point of view. Will facilitate using the arrow hovering information in the hot path. (#2886) --- imgui_widgets.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index bf2f6617..41f96c84 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5287,13 +5287,15 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l { if (pressed) { - const float arrow_x1 = text_pos.x - text_offset_x; - const float arrow_x2 = arrow_x1 + g.FontSize + padding.x * 2.0f; - toggled = !(flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) || (g.NavActivateId == id); + const float hit_padding_x = style.TouchExtraPadding.x; + const float arrow_hit_x1 = (text_pos.x - text_offset_x) - hit_padding_x; + const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x; if (flags & ImGuiTreeNodeFlags_OpenOnArrow) - toggled |= IsMouseHoveringRect(ImVec2(arrow_x1, interact_bb.Min.y), ImVec2(arrow_x2, interact_bb.Max.y)) && (!g.NavDisableMouseHover); - if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) - toggled |= g.IO.MouseDoubleClicked[0]; + toggled |= (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2) && (!g.NavDisableMouseHover); // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job + if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) + toggled = true; + if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0]) + toggled = true; if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. toggled = false; } From 011d475532dd7b416c43055d3fd44b8798f7e675 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 8 Nov 2019 15:13:21 +0100 Subject: [PATCH 119/384] TreeNode: The collapsing arrow accepts click even if modifier keys are being held, facilitating interactions with multi-select patterns. (#2886, #1896, #1861) --- docs/CHANGELOG.txt | 2 ++ imgui_internal.h | 2 +- imgui_widgets.cpp | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6aa29407..a28d9cc9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -66,6 +66,8 @@ Other Changes: - ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) +- TreeNode: The collapsing arrow accepts click even if modifier keys are being held, facilitating + interactions with multi-select patterns. (#2886, #1896, #1861) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) - Misc: Optimized storage of window settings data (reducing allocation count). diff --git a/imgui_internal.h b/imgui_internal.h index 37d46020..63357cea 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -365,7 +365,7 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_DontClosePopups = 1 << 7, // disable automatically closing parent popup on press // [UNUSED] ImGuiButtonFlags_Disabled = 1 << 8, // disable interactions ImGuiButtonFlags_AlignTextBaseLine = 1 << 9, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine - ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable interaction if a key modifier is held + ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable mouse interaction if a key modifier is held ImGuiButtonFlags_NoHoldingActiveID = 1 << 11, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_PressedOnDragDropHold = 1 << 12, // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) ImGuiButtonFlags_NoNavFocus = 1 << 13, // don't override navigation focus when activated diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 41f96c84..d5968315 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5269,7 +5269,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // - OpenOnDoubleClick .............. double-click anywhere to open // - OpenOnArrow .................... single-click on arrow to open // - OpenOnDoubleClick|OpenOnArrow .. single-click on arrow or double-click anywhere to open - ImGuiButtonFlags button_flags = ImGuiButtonFlags_NoKeyModifiers; + ImGuiButtonFlags button_flags = 0; if (flags & ImGuiTreeNodeFlags_AllowItemOverlap) button_flags |= ImGuiButtonFlags_AllowItemOverlap; if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) @@ -5277,6 +5277,15 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l if (!is_leaf) button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; + // We allow clicking on the arrow section with keyboard modifiers held, in order to easily + // allow browsing a tree while preserving selection with code implementing multi-selection patterns. + // When clicking on the rest of the tree node we always disallow keyboard modifiers. + const float hit_padding_x = style.TouchExtraPadding.x; + const float arrow_hit_x1 = (text_pos.x - text_offset_x) - hit_padding_x; + const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x; + if (window != g.HoveredWindow || !(g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2)) + button_flags |= ImGuiButtonFlags_NoKeyModifiers; + bool selected = (flags & ImGuiTreeNodeFlags_Selected) != 0; const bool was_selected = selected; @@ -5287,13 +5296,10 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l { if (pressed) { - const float hit_padding_x = style.TouchExtraPadding.x; - const float arrow_hit_x1 = (text_pos.x - text_offset_x) - hit_padding_x; - const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x; - if (flags & ImGuiTreeNodeFlags_OpenOnArrow) - toggled |= (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2) && (!g.NavDisableMouseHover); // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) toggled = true; + if (flags & ImGuiTreeNodeFlags_OpenOnArrow) + toggled |= (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2) && (!g.NavDisableMouseHover); // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0]) toggled = true; if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. From 57dc34f4e850c29ba9be7886afc7d07486a7ef59 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 8 Nov 2019 15:23:34 +0100 Subject: [PATCH 120/384] TreeNode: Added IsItemToggledOpen() to explicitly query if item was just open/closed, facilitating interactions with custom multi-selections patterns. (#1896, #1861) --- docs/CHANGELOG.txt | 4 +++- imgui.cpp | 6 ++++++ imgui.h | 1 + imgui_demo.cpp | 9 ++++++--- imgui_internal.h | 5 +++-- imgui_widgets.cpp | 3 ++- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a28d9cc9..a45a3b79 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,7 +67,9 @@ Other Changes: - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) - TreeNode: The collapsing arrow accepts click even if modifier keys are being held, facilitating - interactions with multi-select patterns. (#2886, #1896, #1861) + interactions with custom multi-selections patterns. (#2886, #1896, #1861) +- TreeNode: Added IsItemToggledOpen() to explicitly query if item was just open/closed, facilitating + interactions with custom multi-selections patterns. (#1896, #1861) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) - Misc: Optimized storage of window settings data (reducing allocation count). diff --git a/imgui.cpp b/imgui.cpp index c15121a3..e21c8a0d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4458,6 +4458,12 @@ bool ImGui::IsItemClicked(int mouse_button) return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_None); } +bool ImGui::IsItemToggledOpen() +{ + ImGuiContext& g = *GImGui; + return (g.CurrentWindow->DC.LastItemStatusFlags & ImGuiItemStatusFlags_ToggledOpen) ? true : false; +} + bool ImGui::IsItemToggledSelection() { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index ceac0879..bde32ceb 100644 --- a/imgui.h +++ b/imgui.h @@ -636,6 +636,7 @@ namespace ImGui IMGUI_API bool IsItemActivated(); // was the last item just made active (item was previously inactive). IMGUI_API bool IsItemDeactivated(); // was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that requires continuous editing. IMGUI_API bool IsItemDeactivatedAfterEdit(); // was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that requires continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item). + IMGUI_API bool IsItemToggledOpen(); // was the last item open state toggled? set by TreeNode(). IMGUI_API bool IsAnyItemHovered(); // is any item hovered? IMGUI_API bool IsAnyItemActive(); // is any item active? IMGUI_API bool IsAnyItemFocused(); // is any item focused? diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 3eedda45..b98eb766 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1613,7 +1613,7 @@ static void ShowDemoWindowWidgets() { // Submit an item (various types available) so we can query their status in the following block. static int item_type = 1; - ImGui::Combo("Item Type", &item_type, "Text\0Button\0Button (w/ repeat)\0Checkbox\0SliderFloat\0InputText\0InputFloat\0InputFloat3\0ColorEdit4\0MenuItem\0TreeNode (w/ double-click)\0ListBox\0"); + ImGui::Combo("Item Type", &item_type, "Text\0Button\0Button (w/ repeat)\0Checkbox\0SliderFloat\0InputText\0InputFloat\0InputFloat3\0ColorEdit4\0MenuItem\0TreeNode\0TreeNode (w/ double-click)\0ListBox\0", 20); ImGui::SameLine(); HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions."); bool ret = false; @@ -1630,8 +1630,9 @@ static void ShowDemoWindowWidgets() if (item_type == 7) { ret = ImGui::InputFloat3("ITEM: InputFloat3", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged) if (item_type == 8) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged) if (item_type == 9) { ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy) - if (item_type == 10){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy. - if (item_type == 11){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); } + if (item_type == 10){ ret = ImGui::TreeNode("ITEM: TreeNode"); if (ret) ImGui::TreePop(); } // Testing tree node + if (item_type == 11){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy. + if (item_type == 12){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); } // Display the value of IsItemHovered() and other common item state functions. // Note that the ImGuiHoveredFlags_XXX flags can be combined. @@ -1652,6 +1653,7 @@ static void ShowDemoWindowWidgets() "IsItemDeactivatedAfterEdit() = %d\n" "IsItemVisible() = %d\n" "IsItemClicked() = %d\n" + "IsItemToggledOpen() = %d\n" "GetItemRectMin() = (%.1f, %.1f)\n" "GetItemRectMax() = (%.1f, %.1f)\n" "GetItemRectSize() = (%.1f, %.1f)", @@ -1669,6 +1671,7 @@ static void ShowDemoWindowWidgets() ImGui::IsItemDeactivatedAfterEdit(), ImGui::IsItemVisible(), ImGui::IsItemClicked(), + ImGui::IsItemToggledOpen(), ImGui::GetItemRectMin().x, ImGui::GetItemRectMin().y, ImGui::GetItemRectMax().x, ImGui::GetItemRectMax().y, ImGui::GetItemRectSize().x, ImGui::GetItemRectSize().y diff --git a/imgui_internal.h b/imgui_internal.h index 63357cea..42d296db 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -444,8 +444,9 @@ enum ImGuiItemStatusFlags_ ImGuiItemStatusFlags_HasDisplayRect = 1 << 1, ImGuiItemStatusFlags_Edited = 1 << 2, // Value exposed by item was edited in the current frame (should match the bool return value of most widgets) ImGuiItemStatusFlags_ToggledSelection = 1 << 3, // Set when Selectable(), TreeNode() reports toggling a selection. We can't report "Selected" because reporting the change allows us to handle clipping with less issues. - ImGuiItemStatusFlags_HasDeactivated = 1 << 4, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. - ImGuiItemStatusFlags_Deactivated = 1 << 5 // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. + ImGuiItemStatusFlags_ToggledOpen = 1 << 4, // Set when TreeNode() reports toggling their open state. + ImGuiItemStatusFlags_HasDeactivated = 1 << 5, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. + ImGuiItemStatusFlags_Deactivated = 1 << 6 // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. #ifdef IMGUI_ENABLE_TEST_ENGINE , // [imgui_tests only] diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d5968315..2757ac6f 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5291,9 +5291,9 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l bool hovered, held; bool pressed = ButtonBehavior(interact_bb, id, &hovered, &held, button_flags); - bool toggled = false; if (!is_leaf) { + bool toggled = false; if (pressed) { if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) @@ -5321,6 +5321,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l { is_open = !is_open; window->DC.StateStorage->SetInt(id, is_open); + window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_ToggledOpen; } } if (flags & ImGuiTreeNodeFlags_AllowItemOverlap) From 6e8e2c0fa9e9cc5347a3c3962d30515830a89fcf Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 8 Nov 2019 19:00:49 +0100 Subject: [PATCH 121/384] Scrollbar: Fixed an issue where scrollbars wouldn't display on the frame following a frame where all child window contents would be culled. Demo: Fixed a small bug with scrolling demo. Metrics: Tweaks. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 12 +++++++++--- imgui_demo.cpp | 44 +++++++++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a45a3b79..80d2229f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -63,6 +63,8 @@ Other Changes: multi-line label and no frame padding, such as: multi-line text, small button, tree node item, etc. The second item was correctly offset to match text baseline, and would interact/display correctly, but it wouldn't push the contents area boundary low enough. +- Scrollbar: Fixed an issue where scrollbars wouldn't display on the frame following a frame where + all child window contents would be culled. - ColorPicker: Fixed SV triangle gradient to block (broken in 1.73). (#2864, #2711). [@lewa-j] - TreeNode: Fixed combination of ImGuiTreeNodeFlags_SpanFullWidth and ImGuiTreeNodeFlags_OpenOnArrow incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897) diff --git a/imgui.cpp b/imgui.cpp index e21c8a0d..db6d05a3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5054,6 +5054,9 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar ImGuiStyle& style = g.Style; ImGuiWindowFlags flags = window->Flags; + // Ensure that ScrollBar doesn't read last frame's SkipItems + window->SkipItems = false; + // Draw window + handle manual resize // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame. const float window_rounding = window->WindowRounding; @@ -9754,7 +9757,10 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::BulletText("%s: NULL", label); return; } - if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, (window->Active || window->WasActive), window)) + bool open = ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, (window->Active || window->WasActive), window); + if (ImGui::IsItemHovered() && window->WasActive) + ImGui::GetForegroundDrawList()->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255)); + if (!open) return; ImGuiWindowFlags flags = window->Flags; NodeDrawList(window, window->DrawList, "DrawList"); @@ -9763,7 +9769,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) (flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "", (flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "", (flags & ImGuiWindowFlags_NoMouseInputs)? "NoMouseInputs":"", (flags & ImGuiWindowFlags_NoNavInputs) ? "NoNavInputs" : "", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : ""); - ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, window->ScrollMax.x, window->Scroll.y, window->ScrollMax.y); + ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f) Scrollbar:%s%s", window->Scroll.x, window->ScrollMax.x, window->Scroll.y, window->ScrollMax.y, window->ScrollbarX ? "X" : "", window->ScrollbarY ? "Y" : ""); ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1); ImGui::BulletText("Appearing: %d, Hidden: %d (CanSkip %d Cannot %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesCanSkipItems, window->HiddenFramesCannotSkipItems, window->SkipItems); ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask); @@ -9821,7 +9827,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) }; Funcs::NodeWindows(g.Windows, "Windows"); - if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size)) + if (ImGui::TreeNode("DrawLists", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size)) { for (int i = 0; i < g.DrawDataBuilder.Layers[0].Size; i++) Funcs::NodeDrawList(NULL, g.DrawDataBuilder.Layers[0][i], "DrawList"); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b98eb766..deaf4bc4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2215,7 +2215,7 @@ static void ShowDemoWindowLayout() ImGui::TextUnformatted(names[i]); ImGuiWindowFlags child_flags = enable_extra_decorations ? ImGuiWindowFlags_MenuBar : 0; - ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true, child_flags); + bool window_visible = ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true, child_flags); if (ImGui::BeginMenuBar()) { ImGui::TextUnformatted("abc"); @@ -2225,16 +2225,19 @@ static void ShowDemoWindowLayout() ImGui::SetScrollY(scroll_to_off_px); if (scroll_to_pos) ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_pos_px, i * 0.25f); - for (int item = 0; item < 100; item++) + if (window_visible) // Avoid calling SetScrollHereY when running with culled items { - if (enable_track && item == track_item) + for (int item = 0; item < 100; item++) { - ImGui::TextColored(ImVec4(1,1,0,1), "Item %d", item); - ImGui::SetScrollHereY(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom - } - else - { - ImGui::Text("Item %d", item); + if (enable_track && item == track_item) + { + ImGui::TextColored(ImVec4(1, 1, 0, 1), "Item %d", item); + ImGui::SetScrollHereY(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom + } + else + { + ImGui::Text("Item %d", item); + } } } float scroll_y = ImGui::GetScrollY(); @@ -2253,23 +2256,26 @@ static void ShowDemoWindowLayout() { float child_height = ImGui::GetTextLineHeight() + style.ScrollbarSize + style.WindowPadding.y * 2.0f; ImGuiWindowFlags child_flags = ImGuiWindowFlags_HorizontalScrollbar | (enable_extra_decorations ? ImGuiWindowFlags_AlwaysVerticalScrollbar : 0); - ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(-100, child_height), true, child_flags); + bool window_visible = ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(-100, child_height), true, child_flags); if (scroll_to_off) ImGui::SetScrollX(scroll_to_off_px); if (scroll_to_pos) ImGui::SetScrollFromPosX(ImGui::GetCursorStartPos().x + scroll_to_pos_px, i * 0.25f); - for (int item = 0; item < 100; item++) + if (window_visible) // Avoid calling SetScrollHereY when running with culled items { - if (enable_track && item == track_item) - { - ImGui::TextColored(ImVec4(1, 1, 0, 1), "Item %d", item); - ImGui::SetScrollHereX(i * 0.25f); // 0.0f:left, 0.5f:center, 1.0f:right - } - else + for (int item = 0; item < 100; item++) { - ImGui::Text("Item %d", item); + if (enable_track && item == track_item) + { + ImGui::TextColored(ImVec4(1, 1, 0, 1), "Item %d", item); + ImGui::SetScrollHereX(i * 0.25f); // 0.0f:left, 0.5f:center, 1.0f:right + } + else + { + ImGui::Text("Item %d", item); + } + ImGui::SameLine(); } - ImGui::SameLine(); } float scroll_x = ImGui::GetScrollX(); float scroll_max_x = ImGui::GetScrollMaxX(); From c3fd4ae473352ed1989738e927af55ad4fd4b1c4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 12 Nov 2019 11:06:02 +0100 Subject: [PATCH 122/384] Docking: comments --- docs/TODO.txt | 57 ++++++++++++++++++++++++------------------------ imgui.cpp | 1 + imgui.h | 4 +++- imgui_demo.cpp | 3 ++- imgui_internal.h | 10 +++++---- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index bd3bca91..828ef8ad 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -153,34 +153,35 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - separator: width, thickness, centering (#1643) - splitter: formalize the splitter idiom into an official api (we want to handle n-way split) (#319) - - dock: merge docking branch (#2109) - - dock: B: ordering currently held in tab bar should be implicitly held by windows themselves (also see #2304) - - dock: B- tab bar: the order/focus restoring code could be part of TabBar and not DockNode? (#8) - - dock: B~ rework code to be able to lazily create tab bar instance in a single place. The _Unsorted tab flag could be replacing a trailing-counter in DockNode? - - dock: B~ fully track windows/settings reference in dock nodes. perhaps find a representation that allows facilitate use of dock builder functions. - - dock: B~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete). this is mostly working but the DockBuilderXXX api are not exposed/finished. - - dock: B: when docking outer, perform size locking on neighbors nodes the same way we do it with splitters, so other nodes are not resized. - - dock: B~ central node resizing behavior incorrect. - - dock: B: changing title font/style per-window is not supported as dock nodes are created in NewFrame. - - dock: B- dock node inside its own viewports creates 1 temporary viewport per window on startup before ditching them (doesn't affect the user nor request platform windows to be created, but unnecessary) - - dock: B- resize sibling locking behavior may be less desirable if we merged same-axis sibling in a same node level? - - dock: B- single visible node part of a hidden split hierarchy (OnlyNodeWithWindows != NULL) should show a normal title bar (not a tab bar) - - dock: B~ SetNextWindowDock() calls (with conditional) -> defer everything to DockContextUpdate (repro: Documents->[X]Windows->Dock 1 elsewhere->Click Redock All - - dock: B~ tidy up tab list popup buttons features (available with manual tab-bar, see ImGuiTabBarFlags_NoTabListPopupButton code, not used by docking nodes) - - dock: B- SetNextWindowDockId(0) with a second Begin() in the frame will asserts - - dock: B: resize grip drawn in host window typically appears under scrollbar. - - dock: B- SetNextWindowFocus() doesn't seem to apply if the window is hidden this frame, need repro (#4) - - dock: B- resizing a dock tree small currently has glitches (overlapping collapse and close button, etc.) - - dock: B- dpi: look at interaction with the hi-dpi and multi-dpi stuff. - - dock: B- tab bar: appearing on first frame with a dumb layout would do less harm that not appearing? (when behind dynamic branch) or store titles + render in EndTabBar() - - dock: B- tab bar: make selected tab always shows its full title? - - dock: B- nav: design interactions so nav controls can dock/undock - - dock: B- dockspace: flag to lock the dock tree and/or sizes (ImGuiDockNodeFlags_Locked?) - - dock: B- reintroduce collapsing a floating dock node. also collapsing a docked dock node! - - dock: B- allow dragging a non-floating dock node by clicking on the title-bar-looking section (not just the collapse/menu button) - - dock: B- option to remember undocked window size? (instead of keeping their docked size) (relate to #2104) - - dock: C- nav: CTRL+TAB highlighting tabs shows the mismatch between focus-stack and tab-order (not visible in VS because it doesn't highlight the tabs) - - dock: C- after a dock/undock, the Scrollbar Status update in Begin() should use an updated e.g. size_y_for_scrollbars to avoid a 1 frame scrollbar flicker. + - docking: merge docking branch (#2109) + - docking: B: ordering currently held in tab bar should be implicitly held by windows themselves (also see #2304) + - docking: B- tab bar: the order/focus restoring code could be part of TabBar and not DockNode? (#8) + - docking: B~ rework code to be able to lazily create tab bar instance in a single place. The _Unsorted tab flag could be replacing a trailing-counter in DockNode? + - docking: B~ fully track windows/settings reference in dock nodes. perhaps find a representation that allows facilitate use of dock builder functions. + - docking: B~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete). this is mostly working but the DockBuilderXXX api are not exposed/finished. + - docking: B: when docking outer, perform size locking on neighbors nodes the same way we do it with splitters, so other nodes are not resized. + - docking: B~ central node resizing behavior incorrect. + - docking: B: changing title font/style per-window is not supported as dock nodes are created in NewFrame. + - docking: B- dock node inside its own viewports creates 1 temporary viewport per window on startup before ditching them (doesn't affect the user nor request platform windows to be created, but unnecessary) + - docking: B- resize sibling locking behavior may be less desirable if we merged same-axis sibling in a same node level? + - docking: B- single visible node part of a hidden split hierarchy (OnlyNodeWithWindows != NULL) should show a normal title bar (not a tab bar) + - docking: B~ SetNextWindowDock() calls (with conditional) -> defer everything to DockContextUpdate (repro: Documents->[X]Windows->Dock 1 elsewhere->Click Redock All + - docking: B~ tidy up tab list popup buttons features (available with manual tab-bar, see ImGuiTabBarFlags_NoTabListPopupButton code, not used by docking nodes) + - docking: B- SetNextWindowDockId(0) with a second Begin() in the frame will asserts + - docking: B: resize grip drawn in host window typically appears under scrollbar. + - docking: B- SetNextWindowFocus() doesn't seem to apply if the window is hidden this frame, need repro (#4) + - docking: B- resizing a dock tree small currently has glitches (overlapping collapse and close button, etc.) + - docking: B- dpi: look at interaction with the hi-dpi and multi-dpi stuff. + - docking: B- tab bar: appearing on first frame with a dumb layout would do less harm that not appearing? (when behind dynamic branch) or store titles + render in EndTabBar() + - docking: B- tab bar: make selected tab always shows its full title? + - docking: B- hide close button on single tab bar? + - docking: B- nav: design interactions so nav controls can dock/undock + - docking: B- dockspace: flag to lock the dock tree and/or sizes (ImGuiDockNodeFlags_Locked?) + - docking: B- reintroduce collapsing a floating dock node. also collapsing a docked dock node! + - docking: B- allow dragging a non-floating dock node by clicking on the title-bar-looking section (not just the collapse/menu button) + - docking: B- option to remember undocked window size? (instead of keeping their docked size) (relate to #2104) + - docking: C- nav: CTRL+TAB highlighting tabs shows the mismatch between focus-stack and tab-order (not visible in VS because it doesn't highlight the tabs) + - docking: C- after a dock/undock, the Scrollbar Status update in Begin() should use an updated e.g. size_y_for_scrollbars to avoid a 1 frame scrollbar flicker. - tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing. - tabs: persistent order/focus in BeginTabBar() api (#261, #351) diff --git a/imgui.cpp b/imgui.cpp index 1fce28e5..5a8e987a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13481,6 +13481,7 @@ void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond) // Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default. // The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors. +// DockSpace() needs to be submitted _before_ any window they can host. If you use a dockspace, submit it early in your app. void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags flags, const ImGuiWindowClass* window_class) { ImGuiContext* ctx = GImGui; diff --git a/imgui.h b/imgui.h index 7322963a..92abcf25 100644 --- a/imgui.h +++ b/imgui.h @@ -611,10 +611,12 @@ namespace ImGui // Docking // [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable. - // Note: you DO NOT need to call DockSpace() to use most Docking facilities! + // Note: You can use most Docking facilities without calling any API. You DO NOT need to call DockSpace() to use Docking! // - To dock windows: if io.ConfigDockingWithShift == false (default) drag window from their title bar. // - To dock windows: if io.ConfigDockingWithShift == true: hold SHIFT anywhere while moving windows. + // About DockSpace: // - Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details. + // - DockSpace() needs to be submitted _before_ any window they can host. If you use a dockspace, submit it early in your app. IMGUI_API void DockSpace(ImGuiID id, const ImVec2& size = ImVec2(0, 0), ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL); IMGUI_API ImGuiID DockSpaceOverViewport(ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL); IMGUI_API void SetNextWindowDockID(ImGuiID dock_id, ImGuiCond cond = 0); // set next window dock id (FIXME-DOCK) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e03396dd..fddeb47e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4652,7 +4652,8 @@ void ShowExampleAppDockSpace(bool* p_open) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; } - // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background. + // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background + // and handle the pass-thru hole, so we ask Begin() to not render a background. if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) window_flags |= ImGuiWindowFlags_NoBackground; diff --git a/imgui_internal.h b/imgui_internal.h index dc5621fe..cdd3e1c1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1865,12 +1865,14 @@ namespace ImGui IMGUI_API void BeginAsDockableDragDropTarget(ImGuiWindow* window); IMGUI_API void SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond); - // Docking - Builder function needs to be generally called before the DockSpace() node is submitted. + // Docking - Builder function needs to be generally called before the node is used/submitted. // - The DockBuilderXXX functions are designed to _eventually_ become a public API, but it is too early to expose it and guarantee stability. - // - You can create dockspace _or_ floating nodes with this API. To create a dockspace node, make sure to set the ImGuiDockNodeFlags_DockSpace flag. - // - If you intend to split the node immediately after creation using DockBuilderSplitNode(), make sure to call DockBuilderSetNodeSize() beforehand. + // - Do not hold on ImGuiDockNode* pointers! They may be invalidated by any split/merge/remove operation and every frame. + // - To create a DockSpace() node, make sure to set the ImGuiDockNodeFlags_DockSpace flag when calling DockBuilderAddNode(). + // You can create dockspace nodes (attached to a window) _or_ floating nodes (carry its own window) with this API. + // - If you intend to split the node immediately after creation using DockBuilderSplitNode(), make sure + // to call DockBuilderSetNodeSize() beforehand. If you don't, the resulting split sizes may not be reliable. // - Call DockBuilderFinish() after you are done. - // - Important: do not hold on ImGuiDockNode* pointers! They may be invalidated by any split/merge/remove operation and every frame. IMGUI_API void DockBuilderDockWindow(const char* window_name, ImGuiID node_id); IMGUI_API ImGuiDockNode*DockBuilderGetNode(ImGuiID node_id); inline ImGuiDockNode* DockBuilderGetCentralNode(ImGuiID node_id) { ImGuiDockNode* node = DockBuilderGetNode(node_id); if (!node) return NULL; return DockNodeGetRootNode(node)->CentralNode; } From 7c441e37faef9211b0684b6c7a4548b40dcc9507 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 11 Nov 2019 14:47:39 +0100 Subject: [PATCH 123/384] CI: Update jobs to MacOS latest (Catalina) Metrics: Added description to Item Picker. --- .github/workflows/build.yml | 4 ++-- imgui.cpp | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index babd548a..86f5de6e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -168,7 +168,7 @@ jobs: run: make -C examples/example_sdl_opengl3 MacOS: - runs-on: macOS-10.14 + runs-on: macOS-latest steps: - uses: actions/checkout@v1 with: @@ -206,7 +206,7 @@ jobs: run: xcodebuild -project examples/example_apple_opengl2/example_apple_opengl2.xcodeproj -target example_osx_opengl2 iOS: - runs-on: macOS-10.14 + runs-on: macOS-latest steps: - uses: actions/checkout@v1 with: diff --git a/imgui.cpp b/imgui.cpp index db6d05a3..b3b39711 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -351,7 +351,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. - - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. Grep this log for details and new names, or see how they were implemented until 1.73. + - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73. - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). @@ -9607,6 +9607,19 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int, int) {} //----------------------------------------------------------------------------- #ifndef IMGUI_DISABLE_METRICS_WINDOW +static void HelpMarker(const char* desc) +{ + ImGui::TextDisabled("(?)"); + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } +} + void ImGui::ShowMetricsWindow(bool* p_open) { if (!ImGui::Begin("Dear ImGui Metrics", p_open)) @@ -9890,6 +9903,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. if (ImGui::Button("Item Picker..")) ImGui::DebugStartItemPicker(); + ImGui::SameLine(); + HelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); ImGui::Checkbox("Show windows begin order", &show_windows_begin_order); ImGui::Checkbox("Show windows rectangles", &show_windows_rects); From b138f8cbcd0bce666a9584f37d4616041e91a5f4 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 12 Nov 2019 23:54:22 +0100 Subject: [PATCH 124/384] Internal: Nav rename preparing for nav inputs ownership changes. IsNavInputPressed() -> IsNavInputTest() --- imgui.cpp | 23 ++++++++++++----------- imgui_internal.h | 6 +----- imgui_widgets.cpp | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b3b39711..9c4f1949 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8169,7 +8169,7 @@ static void ImGui::NavUpdate() g.IO.NavVisible = (g.IO.NavActive && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL); // Process NavCancel input (to close a popup, get back to parent, clear focus) - if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed)) + if (IsNavInputTest(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed)) { if (g.ActiveId != 0) { @@ -8213,14 +8213,14 @@ static void ImGui::NavUpdate() if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { bool activate_down = IsNavInputDown(ImGuiNavInput_Activate); - bool activate_pressed = activate_down && IsNavInputPressed(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed); + bool activate_pressed = activate_down && IsNavInputTest(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed); if (g.ActiveId == 0 && activate_pressed) g.NavActivateId = g.NavId; if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_down) g.NavActivateDownId = g.NavId; if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_pressed) g.NavActivatePressedId = g.NavId; - if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && IsNavInputPressed(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed)) + if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && IsNavInputTest(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed)) g.NavInputId = g.NavId; } if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) @@ -8241,10 +8241,11 @@ static void ImGui::NavUpdate() g.NavMoveRequestFlags = ImGuiNavMoveFlags_None; if (g.NavWindow && !g.NavWindowingTarget && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { - if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadLeft, ImGuiNavInput_KeyLeft_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Left; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadRight,ImGuiNavInput_KeyRight_,ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Right; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadUp, ImGuiNavInput_KeyUp_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Up; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && IsNavInputPressedAnyOfTwo(ImGuiNavInput_DpadDown, ImGuiNavInput_KeyDown_, ImGuiInputReadMode_Repeat)) { g.NavMoveDir = ImGuiDir_Down; } + const ImGuiInputReadMode read_mode = ImGuiInputReadMode_Repeat; + if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsNavInputTest(ImGuiNavInput_DpadLeft, read_mode) || IsNavInputTest(ImGuiNavInput_KeyLeft_, read_mode))) { g.NavMoveDir = ImGuiDir_Left; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsNavInputTest(ImGuiNavInput_DpadRight, read_mode) || IsNavInputTest(ImGuiNavInput_KeyRight_, read_mode))) { g.NavMoveDir = ImGuiDir_Right; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsNavInputTest(ImGuiNavInput_DpadUp, read_mode) || IsNavInputTest(ImGuiNavInput_KeyUp_, read_mode))) { g.NavMoveDir = ImGuiDir_Up; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsNavInputTest(ImGuiNavInput_DpadDown, read_mode) || IsNavInputTest(ImGuiNavInput_KeyDown_, read_mode))) { g.NavMoveDir = ImGuiDir_Down; } } g.NavMoveClipDir = g.NavMoveDir; } @@ -8539,7 +8540,7 @@ static void ImGui::NavUpdateWindowing() } // Start CTRL-TAB or Square+L/R window selection - bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed); + bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputTest(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed); bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard); if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1)) @@ -8558,7 +8559,7 @@ static void ImGui::NavUpdateWindowing() g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // Select window to focus - const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow); + const int focus_change_dir = (int)IsNavInputTest(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputTest(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow); if (focus_change_dir != 0) { NavUpdateWindowingHighlightWindow(focus_change_dir); @@ -8590,9 +8591,9 @@ static void ImGui::NavUpdateWindowing() // Keyboard: Press and Release ALT to toggle menu layer // FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of back-end clearing releases all keys on ALT-TAB - if (IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed)) + if (IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed)) g.NavWindowingToggleLayer = true; - if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released)) + if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released)) if (IsMousePosValid(&g.IO.MousePos) == IsMousePosValid(&g.IO.MousePosPrev)) apply_toggle_layer = true; diff --git a/imgui_internal.h b/imgui_internal.h index 42d296db..0d0dda3e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -956,7 +956,6 @@ struct ImGuiContext bool ActiveIdPreviousFrameIsAlive; bool ActiveIdPreviousFrameHasBeenEditedBefore; ImGuiWindow* ActiveIdPreviousFrameWindow; - ImGuiID LastActiveId; // Store the last non-zero ActiveId, useful for animation. float LastActiveIdTimer; // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation. @@ -1145,12 +1144,10 @@ struct ImGuiContext ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = NULL; ActiveIdSource = ImGuiInputSource_None; - ActiveIdPreviousFrame = 0; ActiveIdPreviousFrameIsAlive = false; ActiveIdPreviousFrameHasBeenEditedBefore = false; ActiveIdPreviousFrameWindow = NULL; - LastActiveId = 0; LastActiveIdTimer = 0.0f; @@ -1639,8 +1636,7 @@ namespace ImGui IMGUI_API bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } - inline bool IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode) { return GetNavInputAmount(n, mode) > 0.0f; } - inline bool IsNavInputPressedAnyOfTwo(ImGuiNavInput n1, ImGuiNavInput n2, ImGuiInputReadMode mode) { return (GetNavInputAmount(n1, mode) + GetNavInputAmount(n2, mode)) > 0.0f; } + inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } // Drag and Drop IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2757ac6f..353f97d9 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -549,7 +549,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.NavActivateDownId == id) { bool nav_activated_by_code = (g.NavActivateId == id); - bool nav_activated_by_inputs = IsNavInputPressed(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiInputReadMode_Repeat : ImGuiInputReadMode_Pressed); + bool nav_activated_by_inputs = IsNavInputTest(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiInputReadMode_Repeat : ImGuiInputReadMode_Pressed); if (nav_activated_by_code || nav_activated_by_inputs) pressed = true; if (nav_activated_by_code || nav_activated_by_inputs || g.ActiveId == id) From 25eee91542adaef308270fa864fc92b0d9d6eb61 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 13 Nov 2019 21:35:42 +0100 Subject: [PATCH 125/384] Error handling: Assert if user mistakenly calls End() instead of EndChild() on a child window. (#1651) Internals: Moved some error handling code. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 118 ++++++++++++++++++++++++++++----------------- imgui_internal.h | 23 ++++----- 3 files changed, 88 insertions(+), 54 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 80d2229f..29e869b0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,7 @@ Other Changes: interactions with custom multi-selections patterns. (#1896, #1861) - DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data to clarify how they are used, and more comments redirecting to the demo code. (#2844) +- Error handling: Assert if user mistakenly calls End() instead of EndChild() on a child window. (#1651) - Misc: Optimized storage of window settings data (reducing allocation count). - Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] diff --git a/imgui.cpp b/imgui.cpp index 9c4f1949..42b7f454 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -54,6 +54,7 @@ CODE // [SECTION] ImGuiListClipper // [SECTION] RENDER HELPERS // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) +// [SECTION] ERROR CHECKING // [SECTION] SCROLLING // [SECTION] TOOLTIPS // [SECTION] POPUPS @@ -838,7 +839,6 @@ static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 2.00f; // Lock static void SetCurrentWindow(ImGuiWindow* window); static void FindHoveredWindow(); static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags); -static void CheckStacksSize(ImGuiWindow* window, bool write); static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool snap_on_edges); static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* draw_list); @@ -874,6 +874,10 @@ static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_win static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window); static int FindWindowFocusIndex(ImGuiWindow* window); +// Error Checking +static void ErrorCheckEndFrame(); +static void ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write); + // Misc static void UpdateMouseInputs(); static void UpdateMouseWheel(); @@ -3539,7 +3543,7 @@ void ImGui::NewFrame() } g.Time += g.IO.DeltaTime; - g.FrameScopeActive = true; + g.WithinFrameScope = true; g.FrameCount += 1; g.TooltipOverrideCount = 0; g.WindowsActiveCount = 0; @@ -3713,7 +3717,7 @@ void ImGui::NewFrame() // This fallback is particularly important as it avoid ImGui:: calls from crashing. SetNextWindowSize(ImVec2(400,400), ImGuiCond_FirstUseEver); Begin("Debug##Default"); - g.FrameScopePushedImplicitWindow = true; + g.WithinFrameScopeWithImplicitWindow = true; #ifdef IMGUI_ENABLE_TEST_ENGINE ImGuiTestEngineHook_PostNewFrame(&g); @@ -3982,7 +3986,7 @@ void ImGui::EndFrame() IM_ASSERT(g.Initialized); if (g.FrameCountEnded == g.FrameCount) // Don't process EndFrame() multiple times. return; - IM_ASSERT(g.FrameScopeActive && "Forgot to call ImGui::NewFrame()?"); + IM_ASSERT(g.WithinFrameScope && "Forgot to call ImGui::NewFrame()?"); // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) if (g.IO.ImeSetInputScreenPosFn && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImeLastPos - g.PlatformImePos) > 0.0001f)) @@ -3991,24 +3995,10 @@ void ImGui::EndFrame() g.PlatformImeLastPos = g.PlatformImePos; } - // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you - // to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API). - if (g.CurrentWindowStack.Size != 1) - { - if (g.CurrentWindowStack.Size > 1) - { - IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); - while (g.CurrentWindowStack.Size > 1) // FIXME-ERRORHANDLING - End(); - } - else - { - IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); - } - } + ErrorCheckEndFrame(); // Hide implicit/fallback "Debug" window if it hasn't been used - g.FrameScopePushedImplicitWindow = false; + g.WithinFrameScopeWithImplicitWindow = false; if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed) g.CurrentWindow->Active = false; End(); @@ -4035,7 +4025,7 @@ void ImGui::EndFrame() } // End frame - g.FrameScopeActive = false; + g.WithinFrameScope = false; g.FrameCountEnded = g.FrameCount; // Initiate moving window + handle left-click and right-click focus @@ -4602,7 +4592,10 @@ void ImGui::EndChild() ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; + IM_ASSERT(g.WithinEndChild == false); IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() callss + + g.WithinEndChild = true; if (window->BeginCount > 1) { End(); @@ -4634,6 +4627,7 @@ void ImGui::EndChild() ItemAdd(bb, 0); } } + g.WithinEndChild = false; } // Helper to create a child window / scrolling region that looks like a normal widget frame. @@ -4656,22 +4650,6 @@ void ImGui::EndChildFrame() EndChild(); } -// Save and compare stack sizes on Begin()/End() to detect usage errors -static void CheckStacksSize(ImGuiWindow* window, bool write) -{ - // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) - ImGuiContext& g = *GImGui; - short* p_backup = &window->DC.StackSizesBackup[0]; - { int current = window->IDStack.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup == current && "PushID/PopID or TreeNode/TreePop Mismatch!"); p_backup++; } // Too few or too many PopID()/TreePop() - { int current = window->DC.GroupStack.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup == current && "BeginGroup/EndGroup Mismatch!"); p_backup++; } // Too few or too many EndGroup() - { int current = g.BeginPopupStack.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup == current && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch"); p_backup++;}// Too few or too many EndMenu()/EndPopup() - // For color, style and font stacks there is an incentive to use Push/Begin/Pop/.../End patterns, so we relax our checks a little to allow them. - { int current = g.ColorModifiers.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup >= current && "PushStyleColor/PopStyleColor Mismatch!"); p_backup++; } // Too few or too many PopStyleColor() - { int current = g.StyleModifiers.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup >= current && "PushStyleVar/PopStyleVar Mismatch!"); p_backup++; } // Too few or too many PopStyleVar() - { int current = g.FontStack.Size; if (write) *p_backup = (short)current; else IM_ASSERT(*p_backup >= current && "PushFont/PopFont Mismatch!"); p_backup++; } // Too few or too many PopFont() - IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); -} - static void SetWindowConditionAllowFlags(ImGuiWindow* window, ImGuiCond flags, bool enabled) { window->SetWindowPosAllowFlags = enabled ? (window->SetWindowPosAllowFlags | flags) : (window->SetWindowPosAllowFlags & ~flags); @@ -5238,7 +5216,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; IM_ASSERT(name != NULL && name[0] != '\0'); // Window name required - IM_ASSERT(g.FrameScopeActive); // Forgot to call ImGui::NewFrame() + IM_ASSERT(g.WithinFrameScope); // Forgot to call ImGui::NewFrame() IM_ASSERT(g.FrameCountEnded != g.FrameCount); // Called ImGui::Render() or ImGui::EndFrame() and haven't called ImGui::NewFrame() again yet // Find or create @@ -5300,7 +5278,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow() g.CurrentWindowStack.push_back(window); g.CurrentWindow = NULL; - CheckStacksSize(window, true); + ErrorCheckBeginEndCompareStacksSize(window, true); if (flags & ImGuiWindowFlags_Popup) { ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size]; @@ -5839,16 +5817,22 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) void ImGui::End() { ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; - if (g.CurrentWindowStack.Size <= 1 && g.FrameScopePushedImplicitWindow) + // Error checking: verify that user hasn't called End() too many times! + // FIXME-ERRORHANDLING + if (g.CurrentWindowStack.Size <= 1 && g.WithinFrameScopeWithImplicitWindow) { IM_ASSERT(g.CurrentWindowStack.Size > 1 && "Calling End() too many times!"); - return; // FIXME-ERRORHANDLING + return; } IM_ASSERT(g.CurrentWindowStack.Size > 0); - ImGuiWindow* window = g.CurrentWindow; + // Error checking: verify that user doesn't directly call End() on a child window. + if (window->Flags & ImGuiWindowFlags_ChildWindow) + IM_ASSERT(g.WithinEndChild && "Must call EndChild() and not End()!"); + // Close anything that is open if (window->DC.CurrentColumns) EndColumns(); PopClipRect(); // Inner window clip rectangle @@ -5861,7 +5845,7 @@ void ImGui::End() g.CurrentWindowStack.pop_back(); if (window->Flags & ImGuiWindowFlags_Popup) g.BeginPopupStack.pop_back(); - CheckStacksSize(window, false); + ErrorCheckBeginEndCompareStacksSize(window, false); SetCurrentWindow(g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back()); } @@ -7007,6 +6991,54 @@ void ImGui::Unindent(float indent_w) } +//----------------------------------------------------------------------------- +// [SECTION] ERROR CHECKING +//----------------------------------------------------------------------------- + +static void ImGui::ErrorCheckEndFrame() +{ + // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you + // to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API). + ImGuiContext& g = *GImGui; + if (g.CurrentWindowStack.Size != 1) + { + if (g.CurrentWindowStack.Size > 1) + { + IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + while (g.CurrentWindowStack.Size > 1) // FIXME-ERRORHANDLING + End(); + } + else + { + IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); + } + } + +} + +// Save and compare stack sizes on Begin()/End() to detect usage errors +// Begin() calls this with write=true +// End() calls this with write=false +static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write) +{ + ImGuiContext& g = *GImGui; + short* p = &window->DC.StackSizesBackup[0]; + + // Window stacks + // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) + { int n = window->IDStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "PushID/PopID or TreeNode/TreePop Mismatch!"); p++; } // Too few or too many PopID()/TreePop() + { int n = window->DC.GroupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginGroup/EndGroup Mismatch!"); p++; } // Too few or too many EndGroup() + + // Global stacks + // For color, style and font stacks there is an incentive to use Push/Begin/Pop/.../End patterns, so we relax our checks a little to allow them. + { int n = g.BeginPopupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch!"); p++; }// Too few or too many EndMenu()/EndPopup() + { int n = g.ColorModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleColor/PopStyleColor Mismatch!"); p++; } // Too few or too many PopStyleColor() + { int n = g.StyleModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleVar/PopStyleVar Mismatch!"); p++; } // Too few or too many PopStyleVar() + { int n = g.FontStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushFont/PopFont Mismatch!"); p++; } // Too few or too many PopFont() + IM_ASSERT(p == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); +} + + //----------------------------------------------------------------------------- // [SECTION] SCROLLING //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 0d0dda3e..3b7ad26e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -903,9 +903,7 @@ struct ImGuiPtrOrIndex struct ImGuiContext { bool Initialized; - bool FrameScopeActive; // Set by NewFrame(), cleared by EndFrame() - bool FrameScopePushedImplicitWindow; // Set by NewFrame(), cleared by EndFrame() - bool FontAtlasOwnedByContext; // Io.Fonts-> is owned by the ImGuiContext and will be destructed along with it. + bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it. ImGuiIO IO; ImGuiStyle Style; ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() @@ -916,19 +914,22 @@ struct ImGuiContext int FrameCount; int FrameCountEnded; int FrameCountRendered; + bool WithinFrameScope; // Set by NewFrame(), cleared by EndFrame() + bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed + bool WithinEndChild; // Set within EndChild() // Windows state ImVector Windows; // Windows, sorted in display order, back to front ImVector WindowsFocusOrder; // Windows, sorted in focus order, back to front ImVector WindowsSortBuffer; ImVector CurrentWindowStack; - ImGuiStorage WindowsById; - int WindowsActiveCount; - ImGuiWindow* CurrentWindow; // Being drawn into + ImGuiStorage WindowsById; // Map window's ImGuiID to ImGuiWindow* + int WindowsActiveCount; // Number of unique windows submitted by frame + ImGuiWindow* CurrentWindow; // Window being drawn into ImGuiWindow* HoveredWindow; // Will catch mouse inputs ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only) ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow. - ImGuiWindow* WheelingWindow; + ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window. ImVec2 WheelingWindowRefMousePos; float WheelingWindowTimer; @@ -1057,9 +1058,9 @@ struct ImGuiContext ImFont InputTextPasswordFont; ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets - float ColorEditLastHue; + float ColorEditLastHue; // Backup of last Hue associated to LastColor[3], so we can restore Hue in lossy RGB<>HSV round trips float ColorEditLastColor[3]; - ImVec4 ColorPickerRef; + ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. bool DragCurrentAccumDirty; float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio @@ -1082,7 +1083,7 @@ struct ImGuiContext ImVector SettingsHandlers; // List of .ini settings handlers ImChunkStream SettingsWindows; // ImGuiWindow .ini settings entries - // Logging + // Capture/Logging bool LogEnabled; ImGuiLogType LogType; FILE* LogFile; // If != NULL log to stdout/ file @@ -1109,7 +1110,6 @@ struct ImGuiContext ImGuiContext(ImFontAtlas* shared_font_atlas) : BackgroundDrawList(&DrawListSharedData), ForegroundDrawList(&DrawListSharedData) { Initialized = false; - FrameScopeActive = FrameScopePushedImplicitWindow = false; Font = NULL; FontSize = FontBaseSize = 0.0f; FontAtlasOwnedByContext = shared_font_atlas ? false : true; @@ -1117,6 +1117,7 @@ struct ImGuiContext Time = 0.0f; FrameCount = 0; FrameCountEnded = FrameCountRendered = -1; + WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; WindowsActiveCount = 0; CurrentWindow = NULL; From 03852470deabade6cf2f4c960a480e2c806c94e2 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 13 Nov 2019 21:58:18 +0100 Subject: [PATCH 126/384] Internals: Routing recoverable user errors via IMGUI_USER_ERROR() macro. (#1651) --- imgui.cpp | 11 +++++------ imgui_internal.h | 5 +++++ imgui_widgets.cpp | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 42b7f454..1706086a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5820,17 +5820,16 @@ void ImGui::End() ImGuiWindow* window = g.CurrentWindow; // Error checking: verify that user hasn't called End() too many times! - // FIXME-ERRORHANDLING if (g.CurrentWindowStack.Size <= 1 && g.WithinFrameScopeWithImplicitWindow) { - IM_ASSERT(g.CurrentWindowStack.Size > 1 && "Calling End() too many times!"); + IMGUI_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!"); return; } IM_ASSERT(g.CurrentWindowStack.Size > 0); // Error checking: verify that user doesn't directly call End() on a child window. if (window->Flags & ImGuiWindowFlags_ChildWindow) - IM_ASSERT(g.WithinEndChild && "Must call EndChild() and not End()!"); + IMGUI_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!"); // Close anything that is open if (window->DC.CurrentColumns) @@ -7004,13 +7003,13 @@ static void ImGui::ErrorCheckEndFrame() { if (g.CurrentWindowStack.Size > 1) { - IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); - while (g.CurrentWindowStack.Size > 1) // FIXME-ERRORHANDLING + IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + while (g.CurrentWindowStack.Size > 1) End(); } else { - IM_ASSERT(g.CurrentWindowStack.Size == 1 && "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); + IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); } } diff --git a/imgui_internal.h b/imgui_internal.h index 3b7ad26e..f04d4e42 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -161,6 +161,11 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds #define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // +// Error handling +#ifndef IMGUI_USER_ERROR +#define IMGUI_USER_ERROR(_EXPR, _MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error +#endif + // Debug Logging #ifndef IMGUI_DEBUG_LOG #define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 353f97d9..beeffba6 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6472,8 +6472,8 @@ void ImGui::EndTabBar() ImGuiTabBar* tab_bar = g.CurrentTabBar; if (tab_bar == NULL) { - IM_ASSERT(tab_bar != NULL && "Mismatched BeginTabBar()/EndTabBar()!"); - return; // FIXME-ERRORHANDLING + IMGUI_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!"); + return; } if (tab_bar->WantLayout) TabBarLayout(tab_bar); @@ -6869,8 +6869,8 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f ImGuiTabBar* tab_bar = g.CurrentTabBar; if (tab_bar == NULL) { - IM_ASSERT(tab_bar && "Needs to be called between BeginTabBar() and EndTabBar()!"); - return false; // FIXME-ERRORHANDLING + IMGUI_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!"); + return false; } bool ret = TabItemEx(tab_bar, label, p_open, flags); if (ret && !(flags & ImGuiTabItemFlags_NoPushId)) From be436e2b0bed33921817ac8c77ea9c44b2abacfe Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 13 Nov 2019 22:04:16 +0100 Subject: [PATCH 127/384] Fix HelpMarker() symbol collision for unity builds (#2893) --- imgui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1706086a..fc89ef4c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9639,7 +9639,8 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int, int) {} //----------------------------------------------------------------------------- #ifndef IMGUI_DISABLE_METRICS_WINDOW -static void HelpMarker(const char* desc) +// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. +static void MetricsHelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); if (ImGui::IsItemHovered()) @@ -9936,7 +9937,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (ImGui::Button("Item Picker..")) ImGui::DebugStartItemPicker(); ImGui::SameLine(); - HelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); + MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); ImGui::Checkbox("Show windows begin order", &show_windows_begin_order); ImGui::Checkbox("Show windows rectangles", &show_windows_rects); From b23dcab6e13ddf8c973288fbbd1866dbc809dada Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 14 Nov 2019 16:06:39 +0100 Subject: [PATCH 128/384] Fix 25eee91 incorrect assert when ending a child-popup (rarely used but used by sub-nenus) --- imgui.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fc89ef4c..3e564668 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7516,13 +7516,19 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla void ImGui::EndPopup() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.CurrentWindow->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls + ImGuiWindow* window = g.CurrentWindow; + IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls IM_ASSERT(g.BeginPopupStack.Size > 0); // Make all menus and popups wrap around for now, may need to expose that policy. - NavMoveRequestTryWrapping(g.CurrentWindow, ImGuiNavMoveFlags_LoopY); + NavMoveRequestTryWrapping(window, ImGuiNavMoveFlags_LoopY); + // Child-popups don't need to be layed out + IM_ASSERT(g.WithinEndChild == false); + if (window->Flags & ImGuiWindowFlags_ChildWindow) + g.WithinEndChild = true; End(); + g.WithinEndChild = false; } bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) From be05e12e21050f91435fdbb027da1206c6b6adab Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 14 Nov 2019 18:02:18 +0100 Subject: [PATCH 129/384] Misc: Using static_assert() when using C++11, instead of our own construct (avoid zealous Clang warnings). --- docs/CHANGELOG.txt | 1 + imgui_internal.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 29e869b0..0531da37 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,6 +77,7 @@ Other Changes: - Error handling: Assert if user mistakenly calls End() instead of EndChild() on a child window. (#1651) - Misc: Optimized storage of window settings data (reducing allocation count). - Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) +- Misc: Using static_assert() when using C++11, instead of our own construct (avoid zealous Clang warnings). - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] diff --git a/imgui_internal.h b/imgui_internal.h index f04d4e42..027d3804 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -155,7 +155,11 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IM_NEWLINE "\n" #endif #define IM_TABSIZE (4) +#if (__cplusplus >= 201100) +#define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") +#else #define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] +#endif #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds From 8f40020ca6e561216f1562898c5961973b36baad Mon Sep 17 00:00:00 2001 From: Tracy Ma <1991md@gmail.com> Date: Fri, 15 Nov 2019 16:51:48 +0800 Subject: [PATCH 130/384] Disable Win32 clipboard and IME functions when build target UWP (#2892, #2895) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0531da37..513cd335 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,6 +77,7 @@ Other Changes: - Error handling: Assert if user mistakenly calls End() instead of EndChild() on a child window. (#1651) - Misc: Optimized storage of window settings data (reducing allocation count). - Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) +- Misc: Windows: Disabled win32 function by default when building with UWP. (#2892, #2895) - Misc: Using static_assert() when using C++11, instead of our own construct (avoid zealous Clang warnings). - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. diff --git a/imgui.cpp b/imgui.cpp index 3e564668..bfe4b178 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9483,6 +9483,10 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #else #include #endif +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have Win32 functions +#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS +#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS +#endif #elif defined(__APPLE__) #include #endif From 7e232092a629ce13369e3964946a9537b753ff49 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 15 Nov 2019 16:44:16 +0100 Subject: [PATCH 131/384] Internals: Added GetWindowResizeID(), renamed GetScrollbarID() to GetWindowScrollbarID(). Using integer for resize ID so they matches regardless of the pointer size. Internals: Renamed IMGUI_USER_ERROR to IM_ASSERT_USER_ERROR(). --- imgui.cpp | 31 +++++++++++++++++++++---------- imgui_internal.h | 7 ++++--- imgui_widgets.cpp | 12 ++++++------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bfe4b178..76c11c16 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4840,10 +4840,10 @@ struct ImGuiResizeGripDef static const ImGuiResizeGripDef resize_grip_def[4] = { - { ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower right - { ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower left - { ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper left - { ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper right + { ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower-right + { ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower-left + { ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper-left (Unused) + { ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper-right (Unused) }; static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_padding, float thickness) @@ -4858,6 +4858,17 @@ static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_ return ImRect(); } +// 0..3: corners (Lower-right, Lower-left, Unused, Unused) +// 4..7: borders (Top, Right, Bottom, Left) +ImGuiID ImGui::GetWindowResizeID(ImGuiWindow* window, int n) +{ + IM_ASSERT(n >= 0 && n <= 7); + ImGuiID id = window->ID; + id = ImHashStr("#RESIZE", 0, id); + id = ImHashData(&n, sizeof(int), id); + return id; +} + // Handle resize for: Resize Grips, Borders, Gamepad // Return true when using auto-fit (double click on resize grip) static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]) @@ -4895,7 +4906,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); bool hovered, held; - ButtonBehavior(resize_rect, window->GetID((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); + ButtonBehavior(resize_rect, window->GetID(resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); if (hovered || held) g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; @@ -4921,7 +4932,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au { bool hovered, held; ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); - ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren); + ButtonBehavior(border_rect, window->GetID(border_n + 4), &hovered, &held, ImGuiButtonFlags_FlattenChildren); //GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held) { @@ -5822,14 +5833,14 @@ void ImGui::End() // Error checking: verify that user hasn't called End() too many times! if (g.CurrentWindowStack.Size <= 1 && g.WithinFrameScopeWithImplicitWindow) { - IMGUI_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!"); + IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!"); return; } IM_ASSERT(g.CurrentWindowStack.Size > 0); // Error checking: verify that user doesn't directly call End() on a child window. if (window->Flags & ImGuiWindowFlags_ChildWindow) - IMGUI_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!"); + IM_ASSERT_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!"); // Close anything that is open if (window->DC.CurrentColumns) @@ -7003,13 +7014,13 @@ static void ImGui::ErrorCheckEndFrame() { if (g.CurrentWindowStack.Size > 1) { - IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); while (g.CurrentWindowStack.Size > 1) End(); } else { - IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); + IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); } } diff --git a/imgui_internal.h b/imgui_internal.h index 027d3804..e6329b27 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -166,8 +166,8 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // // Error handling -#ifndef IMGUI_USER_ERROR -#define IMGUI_USER_ERROR(_EXPR, _MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error +#ifndef IM_ASSERT_USER_ERROR +#define IM_ASSERT_USER_ERROR(_EXPR,_MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error #endif // Debug Logging @@ -1712,7 +1712,8 @@ namespace ImGui IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags); IMGUI_API void Scrollbar(ImGuiAxis axis); IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawCornerFlags rounding_corners); - IMGUI_API ImGuiID GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis); + IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis); + IMGUI_API ImGuiID GetWindowResizeID(ImGuiWindow* window, int n); // 0..3: corners, 4..7: borders IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags); // Widgets low-level behaviors diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index beeffba6..0277c036 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -774,7 +774,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos) return pressed; } -ImGuiID ImGui::GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis) +ImGuiID ImGui::GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis) { return window->GetIDNoKeepAlive(axis == ImGuiAxis_X ? "#SCROLLX" : "#SCROLLY"); } @@ -881,7 +881,7 @@ void ImGui::Scrollbar(ImGuiAxis axis) ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - const ImGuiID id = GetScrollbarID(window, axis); + const ImGuiID id = GetWindowScrollbarID(window, axis); KeepAliveID(id); // Calculate scrollbar bounding box @@ -3464,8 +3464,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const bool user_clicked = hovered && io.MouseClicked[0]; const bool user_nav_input_start = (g.ActiveId != id) && ((g.NavInputId == id) || (g.NavActivateId == id && g.NavInputSource == ImGuiInputSource_NavKeyboard)); - const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetScrollbarID(draw_window, ImGuiAxis_Y); - const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetScrollbarID(draw_window, ImGuiAxis_Y); + const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetWindowScrollbarID(draw_window, ImGuiAxis_Y); + const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetWindowScrollbarID(draw_window, ImGuiAxis_Y); bool clear_active_id = false; bool select_all = (g.ActiveId != id) && ((flags & ImGuiInputTextFlags_AutoSelectAll) != 0 || user_nav_input_start) && (!is_multiline); @@ -6472,7 +6472,7 @@ void ImGui::EndTabBar() ImGuiTabBar* tab_bar = g.CurrentTabBar; if (tab_bar == NULL) { - IMGUI_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!"); + IM_ASSERT_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!"); return; } if (tab_bar->WantLayout) @@ -6869,7 +6869,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f ImGuiTabBar* tab_bar = g.CurrentTabBar; if (tab_bar == NULL) { - IMGUI_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!"); + IM_ASSERT_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!"); return false; } bool ret = TabItemEx(tab_bar, label, p_open, flags); From ca30ef4269150e71a950106c6cfa8f94898581da Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 15 Nov 2019 18:36:06 +0100 Subject: [PATCH 132/384] Drag and drop: Increase local payload buffer from 8 to 16 bytes. --- imgui_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index e6329b27..bbdf0b6a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1053,7 +1053,7 @@ struct ImGuiContext ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source ImVector DragDropPayloadBufHeap; // We don't expose the ImVector<> directly - unsigned char DragDropPayloadBufLocal[8]; // Local buffer for small payloads + unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads // Tab bars ImGuiTabBar* CurrentTabBar; From 9efaf2828bab245768306627a4505145b7234d92 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 19 Nov 2019 15:22:42 +0100 Subject: [PATCH 133/384] Doc comments. Removed .ini parsing code from 1.53 that parsed entries without the [Window] tag (which enabled importing an old .ini file) --- docs/TODO.txt | 4 ++-- imgui.cpp | 63 +++++++++++++++++++++------------------------------ 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index b9fcecee..94fc2ec8 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -159,10 +159,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing. - tabs: persistent order/focus in BeginTabBar() api (#261, #351) - - button: provide a button that looks framed. (?) - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? - image button: not taking an explicit id can be problematic. (#2464, #1390) + - button: provide a button that looks framed. (?) - slider/drag: ctrl+click when format doesn't include a % character.. disable? display underlying value in default format? (see TempInputTextScalar) - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946) @@ -233,7 +233,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - settings: write more decent code to allow saving/loading new fields: columns, selected tree nodes? - settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file (#437) - - stb: add defines to disable stb implementations + - settings/persistence: helpers to make TreeNodeBehavior persist (even during dev!) - may need to store some semantic and/or data type in ImGuiStoragePair - style: better default styles. (#707) - style: add a highlighted text color (for headers, etc.) diff --git a/imgui.cpp b/imgui.cpp index 76c11c16..eaa36d25 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -29,12 +29,12 @@ DOCUMENTATION - MISSION STATEMENT - END-USER GUIDE - PROGRAMMER GUIDE - - Read first. - - How to update to a newer version of Dear ImGui. - - Getting started with integrating Dear ImGui in your code/engine. - - This is how a simple application may look like (2 variations). - - This is how a simple rendering function may look like. - - Using gamepad/keyboard navigation controls. + - READ FIRST + - HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI + - GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE + - HOW A SIMPLE APPLICATION MAY LOOK LIKE (2 variations) + - HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE + - USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS - API BREAKING CHANGES (read me when you update!) - FREQUENTLY ASKED QUESTIONS (FAQ) - Read all answers online: https://www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer) @@ -118,8 +118,8 @@ CODE PROGRAMMER GUIDE ================ - READ FIRST: - + READ FIRST + ---------- - Remember to read the FAQ (https://www.dearimgui.org/faq) - Your code creates the UI, if your code doesn't run the UI is gone! The UI can be highly dynamic, there are no construction or destruction steps, less superfluous data retention on your side, less state duplication, less state synchronization, less bugs. @@ -140,8 +140,8 @@ CODE However, imgui_internal.h can optionally export math operators for ImVec2/ImVec4, which we use in this codebase. - C++: pay attention that ImVector<> manipulates plain-old-data and does not honor construction/destruction (avoid using it in your code!). - HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI: - + HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI + ---------------------------------------------- - Overwrite all the sources files except for imconfig.h (if you have made modification to your copy of imconfig.h) - Or maintain your own branch where you have imconfig.h modified. - Read the "API BREAKING CHANGES" section (below). This is where we list occasional API breaking changes. @@ -150,8 +150,8 @@ CODE likely be a comment about it. Please report any issue to the GitHub page! - Try to keep your copy of dear imgui reasonably up to date. - GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE: - + GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE + --------------------------------------------------------------- - Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library. - Add the Dear ImGui source files to your projects or using your preferred build system. It is recommended you build and statically link the .cpp files as part of your project and not as shared library (DLL). @@ -163,7 +163,8 @@ CODE - Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code. - If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder. - HOW A SIMPLE APPLICATION MAY LOOK LIKE: + HOW A SIMPLE APPLICATION MAY LOOK LIKE + -------------------------------------- EXHIBIT 1: USING THE EXAMPLE BINDINGS (imgui_impl_XXX.cpp files from the examples/ folder). // Application init: create a dear imgui context, setup some options, load fonts @@ -199,8 +200,7 @@ CODE ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); - HOW A SIMPLE APPLICATION MAY LOOK LIKE: - EXHIBIT 2: IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE. + EXHIBIT 2: IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE // Application init: create a dear imgui context, setup some options, load fonts ImGui::CreateContext(); @@ -254,8 +254,8 @@ CODE // Shutdown ImGui::DestroyContext(); - HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE: - + HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE + --------------------------------------------- void void MyImGuiRenderFunction(ImDrawData* draw_data) { // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled @@ -307,7 +307,7 @@ CODE - Refer to the FAQ for more information. Amusingly, it is called a FAQ because people frequently run into the same issues! USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS - + ------------------------------------------ - The gamepad/keyboard navigation is fairly functional and keeps being improved. - Gamepad support is particularly useful to use dear imgui on a console system (e.g. PS4, Switch, XB1) without a mouse! - You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787 @@ -470,14 +470,9 @@ CODE - 2016/09/25 (1.50) - style.WindowTitleAlign is now a ImVec2 (ImGuiAlign enum was removed). set to (0.5f,0.5f) for horizontal+vertical centering, (0.0f,0.0f) for upper-left, etc. - 2016/07/30 (1.50) - SameLine(x) with x>0.0f is now relative to left of column/group if any, and not always to left of window. This was sort of always the intent and hopefully breakage should be minimal. - 2016/05/12 (1.49) - title bar (using ImGuiCol_TitleBg/ImGuiCol_TitleBgActive colors) isn't rendered over a window background (ImGuiCol_WindowBg color) anymore. - If your TitleBg/TitleBgActive alpha was 1.0f or you are using the default theme it will not affect you. - If your TitleBg/TitleBgActive alpha was <1.0f you need to tweak your custom theme to readjust for the fact that we don't draw a WindowBg background behind the title bar. - This helper function will convert an old TitleBg/TitleBgActive color into a new one with the same visual output, given the OLD color and the OLD WindowBg color. - ImVec4 ConvertTitleBgCol(const ImVec4& win_bg_col, const ImVec4& title_bg_col) - { - float new_a = 1.0f - ((1.0f - win_bg_col.w) * (1.0f - title_bg_col.w)), k = title_bg_col.w / new_a; - return ImVec4((win_bg_col.x * win_bg_col.w + title_bg_col.x) * k, (win_bg_col.y * win_bg_col.w + title_bg_col.y) * k, (win_bg_col.z * win_bg_col.w + title_bg_col.z) * k, new_a); - } + If your TitleBg/TitleBgActive alpha was 1.0f or you are using the default theme it will not affect you, otherwise if <1.0f you need tweak your custom theme to readjust for the fact that we don't draw a WindowBg background behind the title bar. + This helper function will convert an old TitleBg/TitleBgActive color into a new one with the same visual output, given the OLD color and the OLD WindowBg color: + ImVec4 ConvertTitleBgCol(const ImVec4& win_bg_col, const ImVec4& title_bg_col) { float new_a = 1.0f - ((1.0f - win_bg_col.w) * (1.0f - title_bg_col.w)), k = title_bg_col.w / new_a; return ImVec4((win_bg_col.x * win_bg_col.w + title_bg_col.x) * k, (win_bg_col.y * win_bg_col.w + title_bg_col.y) * k, (win_bg_col.z * win_bg_col.w + title_bg_col.z) * k, new_a); } If this is confusing, pick the RGB value from title bar from an old screenshot and apply this as TitleBg/TitleBgActive. Or you may just create TitleBgActive from a tweaked TitleBg color. - 2016/05/07 (1.49) - removed confusing set of GetInternalState(), GetInternalStateSize(), SetInternalState() functions. Now using CreateContext(), DestroyContext(), GetCurrentContext(), SetCurrentContext(). - 2016/05/02 (1.49) - renamed SetNextTreeNodeOpened() to SetNextTreeNodeOpen(), no redirection. @@ -5534,7 +5529,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Handle manual resize: Resize Grips, Borders, Gamepad int border_held = -1; ImU32 resize_grip_col[4] = {}; - const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4 + const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it. const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); if (!window->Collapsed) if (UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0])) @@ -9354,18 +9349,12 @@ void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size) line_end[-1] = 0; const char* name_end = line_end - 1; const char* type_start = line + 1; - char* type_end = (char*)(intptr_t)ImStrchrRange(type_start, name_end, ']'); + char* type_end = (char*)(void*)ImStrchrRange(type_start, name_end, ']'); const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL; if (!type_end || !name_start) - { - name_start = type_start; // Import legacy entries that have no type - type_start = "Window"; - } - else - { - *type_end = 0; // Overwrite first ']' - name_start++; // Skip second '[' - } + continue; + *type_end = 0; // Overwrite first ']' + name_start++; // Skip second '[' entry_handler = FindSettingsHandler(type_start); entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL; } From 93efa5415f42e0dbf2901cd2b3b611c34ae8e628 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 19 Nov 2019 20:48:11 +0100 Subject: [PATCH 134/384] Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS. (#1038) Renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS. --- docs/CHANGELOG.txt | 2 ++ imconfig.h | 6 +++--- imgui.cpp | 6 ++++-- imgui_demo.cpp | 8 ++++---- imgui_internal.h | 12 ++++++++++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 513cd335..37382268 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,6 +50,8 @@ Breaking Changes: Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. +- Misc: Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS. (#1038) +- Misc: Renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS. - Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] diff --git a/imconfig.h b/imconfig.h index 45e75ecf..97194541 100644 --- a/imconfig.h +++ b/imconfig.h @@ -34,9 +34,9 @@ //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). -//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices'). -//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf. -//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h. +//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). +//#define IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) +//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). //---- Include imgui_user.h at the end of imgui.h as a convenience diff --git a/imgui.cpp b/imgui.cpp index eaa36d25..b5da86a4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -352,6 +352,8 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS for consistency. + - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73. - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. @@ -1251,7 +1253,7 @@ const char* ImStrSkipBlank(const char* str) // A) MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size). // Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm. // B) When buf==NULL vsnprintf() will return the output size. -#ifndef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS +#ifndef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS //#define IMGUI_USE_STB_SPRINTF #ifdef IMGUI_USE_STB_SPRINTF @@ -1295,7 +1297,7 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) buf[w] = 0; return w; } -#endif // #ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS +#endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS // CRC32 needs a 1KB lookup table (not cache friendly) // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily: diff --git a/imgui_demo.cpp b/imgui_demo.cpp index deaf4bc4..e45756f1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3106,11 +3106,11 @@ void ImGui::ShowAboutWindow(bool* p_open) #ifdef IMGUI_DISABLE_WIN32_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_WIN32_FUNCTIONS"); #endif -#ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS - ImGui::Text("define: IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS"); +#ifdef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS + ImGui::Text("define: IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS"); #endif -#ifdef IMGUI_DISABLE_MATH_FUNCTIONS - ImGui::Text("define: IMGUI_DISABLE_MATH_FUNCTIONS"); +#ifdef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS + ImGui::Text("define: IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS"); #endif #ifdef IMGUI_DISABLE_DEFAULT_ALLOCATORS ImGui::Text("define: IMGUI_DISABLE_DEFAULT_ALLOCATORS"); diff --git a/imgui_internal.h b/imgui_internal.h index bbdf0b6a..2696e748 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -31,7 +31,7 @@ Index of this file: #error Must include imgui.h before imgui_internal.h #endif -#include // FILE* +#include // FILE*, sscanf #include // NULL, malloc, free, qsort, atoi, atof #include // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf #include // INT_MIN, INT_MAX @@ -60,6 +60,14 @@ Index of this file: #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif +// Legacy defines +#ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Obsolete Since 1.74 +#error Use IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS +#endif +#ifdef IMGUI_DISABLE_MATH_FUNCTIONS // Obsolete Since 1.74 +#error Use IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS +#endif + //----------------------------------------------------------------------------- // Forward declarations //----------------------------------------------------------------------------- @@ -254,7 +262,7 @@ static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) // Helpers: Maths // - Wrapper for standard libs functions. (Note that imgui_demo.cpp does _not_ use them to keep the code easy to copy) -#ifndef IMGUI_DISABLE_MATH_FUNCTIONS +#ifndef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS static inline float ImFabs(float x) { return fabsf(x); } static inline float ImSqrt(float x) { return sqrtf(x); } static inline float ImPow(float x, float y) { return powf(x, y); } From 4e90906b04be67591bf7632c882d09f7bc5f00c3 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 19 Nov 2019 21:14:44 +0100 Subject: [PATCH 135/384] Added IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS / IMGUI_DISABLE_FILE_FUNCTIONS #2734) Using in Emscripten example. --- docs/CHANGELOG.txt | 2 + examples/example_emscripten/Makefile | 2 +- imconfig.h | 1 + imgui.cpp | 77 +++++++++++++++++++--------- imgui_demo.cpp | 6 +++ imgui_internal.h | 30 +++++++++-- 6 files changed, 90 insertions(+), 28 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 37382268..014e7c67 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -81,6 +81,8 @@ Other Changes: - Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815) - Misc: Windows: Disabled win32 function by default when building with UWP. (#2892, #2895) - Misc: Using static_assert() when using C++11, instead of our own construct (avoid zealous Clang warnings). +- Misc: Added IMGUI_DISABLE_FILE_FUNCTIONS/IMGUI_DISABLE_DEFAULT_FILE_FUNCTION to nullify or disable + default implementationof ImFileXXX functions linking with fopen/fclose/fread/fwrite. (#2734) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] diff --git a/examples/example_emscripten/Makefile b/examples/example_emscripten/Makefile index 480fabd7..f5b7369a 100644 --- a/examples/example_emscripten/Makefile +++ b/examples/example_emscripten/Makefile @@ -25,9 +25,9 @@ EMS = -s USE_SDL=2 -s WASM=1 EMS += -s ALLOW_MEMORY_GROWTH=1 EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0 EMS += -s ASSERTIONS=1 +EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS # Uncomment next line to fix possible rendering bugs with emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) #EMS += -s BINARYEN_TRAP_MODE=clamp -#EMS += -s NO_FILESYSTEM=1 ## Getting "error: undefined symbol: $FS" if filesystem is removed #EMS += -s SAFE_HEAP=1 ## Adds overhead CPPFLAGS = -I../ -I../../ diff --git a/imconfig.h b/imconfig.h index 97194541..9e0c1451 100644 --- a/imconfig.h +++ b/imconfig.h @@ -37,6 +37,7 @@ //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). //#define IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. +//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). //---- Include imgui_user.h at the end of imgui.h as a convenience diff --git a/imgui.cpp b/imgui.cpp index b5da86a4..ef23e1b4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -46,6 +46,7 @@ CODE // [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) // [SECTION] MISC HELPERS/UTILITIES (Maths, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (File functions) // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) // [SECTION] MISC HELPERS/UTILITIES (Color functions) // [SECTION] ImGuiStorage @@ -1369,10 +1370,16 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) return ~crc; } -FILE* ImFileOpen(const char* filename, const char* mode) +//----------------------------------------------------------------------------- +// [SECTION] MISC HELPERS/UTILITIES (File functions) +//----------------------------------------------------------------------------- + +// Default file functions +#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS +ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) - // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can) + // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; ImVector buf; @@ -1384,43 +1391,47 @@ FILE* ImFileOpen(const char* filename, const char* mode) return fopen(filename, mode); #endif } +int ImFileClose(ImFileHandle f) { return fclose(f); } +size_t ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (size_t)sz : (size_t)-1; } +size_t ImFileRead(void* data, size_t sz, size_t count, ImFileHandle f) { return fread(data, sz, count, f); } +size_t ImFileWrite(const void* data, size_t sz, size_t count, ImFileHandle f) { return fwrite(data, sz, count, f); } +#endif // #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS -// Load file content into memory +// Helper: Load file content into memory // Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() -void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size, int padding_bytes) +void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes) { - IM_ASSERT(filename && file_open_mode); + IM_ASSERT(filename && mode); if (out_file_size) *out_file_size = 0; - FILE* f; - if ((f = ImFileOpen(filename, file_open_mode)) == NULL) + ImFileHandle f; + if ((f = ImFileOpen(filename, mode)) == NULL) return NULL; - long file_size_signed; - if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) + size_t file_size = ImFileGetSize(f); + if (file_size == (size_t)-1) { - fclose(f); + ImFileClose(f); return NULL; } - size_t file_size = (size_t)file_size_signed; void* file_data = IM_ALLOC(file_size + padding_bytes); if (file_data == NULL) { - fclose(f); + ImFileClose(f); return NULL; } - if (fread(file_data, 1, file_size, f) != file_size) + if (ImFileRead(file_data, 1, file_size, f) != file_size) { - fclose(f); + ImFileClose(f); IM_FREE(file_data); return NULL; } if (padding_bytes > 0) memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); - fclose(f); + ImFileClose(f); if (out_file_size) *out_file_size = file_size; @@ -3822,9 +3833,12 @@ void ImGui::Shutdown(ImGuiContext* context) g.SettingsWindows.clear(); g.SettingsHandlers.clear(); - if (g.LogFile && g.LogFile != stdout) + if (g.LogFile) { - fclose(g.LogFile); +#ifndef IMGUI_DISABLE_TTY_FUNCTIONS + if (g.LogFile != stdout) +#endif + ImFileClose(g.LogFile); g.LogFile = NULL; } g.LogBuffer.clear(); @@ -9055,9 +9069,15 @@ void ImGui::LogText(const char* fmt, ...) va_list args; va_start(args, fmt); if (g.LogFile) - vfprintf(g.LogFile, fmt, args); + { + g.LogBuffer.Buf.resize(0); + g.LogBuffer.appendfv(fmt, args); + ImFileWrite(g.LogBuffer.c_str(), sizeof(char), (size_t)g.LogBuffer.size(), g.LogFile); + } else + { g.LogBuffer.appendfv(fmt, args); + } va_end(args); } @@ -9134,8 +9154,11 @@ void ImGui::LogToTTY(int auto_open_depth) ImGuiContext& g = *GImGui; if (g.LogEnabled) return; + IM_UNUSED(auto_open_depth); +#ifndef IMGUI_DISABLE_TTY_FUNCTIONS LogBegin(ImGuiLogType_TTY, auto_open_depth); g.LogFile = stdout; +#endif } // Start logging/capturing text output to given file @@ -9152,8 +9175,8 @@ void ImGui::LogToFile(int auto_open_depth, const char* filename) filename = g.IO.LogFilename; if (!filename || !filename[0]) return; - FILE* f = ImFileOpen(filename, "ab"); - if (f == NULL) + ImFileHandle f = ImFileOpen(filename, "ab"); + if (!f) { IM_ASSERT(0); return; @@ -9190,10 +9213,12 @@ void ImGui::LogFinish() switch (g.LogType) { case ImGuiLogType_TTY: +#ifndef IMGUI_DISABLE_TTY_FUNCTIONS fflush(g.LogFile); +#endif break; case ImGuiLogType_File: - fclose(g.LogFile); + ImFileClose(g.LogFile); break; case ImGuiLogType_Buffer: break; @@ -9219,7 +9244,11 @@ void ImGui::LogButtons() ImGuiContext& g = *GImGui; PushID("LogButtons"); +#ifndef IMGUI_DISABLE_TTY_FUNCTIONS const bool log_to_tty = Button("Log To TTY"); SameLine(); +#else + const bool log_to_tty = false; +#endif const bool log_to_file = Button("Log To File"); SameLine(); const bool log_to_clipboard = Button("Log To Clipboard"); SameLine(); PushAllowKeyboardFocus(false); @@ -9379,11 +9408,11 @@ void ImGui::SaveIniSettingsToDisk(const char* ini_filename) size_t ini_data_size = 0; const char* ini_data = SaveIniSettingsToMemory(&ini_data_size); - FILE* f = ImFileOpen(ini_filename, "wt"); + ImFileHandle f = ImFileOpen(ini_filename, "wt"); if (!f) return; - fwrite(ini_data, sizeof(char), ini_data_size, f); - fclose(f); + ImFileWrite(ini_data, sizeof(char), ini_data_size, f); + ImFileClose(f); } // Call registered handlers (e.g. SettingsHandlerWindow_WriteAll() + custom handlers) to write their stuff into a text buffer diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e45756f1..d451451b 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3112,6 +3112,12 @@ void ImGui::ShowAboutWindow(bool* p_open) #ifdef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS"); #endif +#ifdef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS + ImGui::Text("define: IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS"); +#endif +#ifdef IMGUI_DISABLE_FILE_FUNCTIONS + ImGui::Text("define: IMGUI_DISABLE_FILE_FUNCTIONS"); +#endif #ifdef IMGUI_DISABLE_DEFAULT_ALLOCATORS ImGui::Text("define: IMGUI_DISABLE_DEFAULT_ALLOCATORS"); #endif diff --git a/imgui_internal.h b/imgui_internal.h index 2696e748..9d29cb2a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -191,8 +191,6 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #endif // Helpers: Misc -IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size = NULL, int padding_bytes = 0); -IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode); #define ImQsort qsort IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0); IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); @@ -260,6 +258,32 @@ static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); } #endif +// Helpers: File System +#if defined(__EMSCRIPTEN__) && !defined(IMGUI_DISABLE_FILE_FUNCTIONS) +#define IMGUI_DISABLE_FILE_FUNCTIONS +#endif +#ifdef IMGUI_DISABLE_FILE_FUNCTIONS +#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS +typedef void* ImFileHandle; +static inline ImFileHandle ImFileOpen(const char*, const char*) { return NULL; } +static inline int ImFileClose(ImFileHandle) { return -1; } +static inline size_t ImFileGetSize(ImFileHandle) { return (size_t)-1; } +static inline size_t ImFileRead(void*, size_t, size_t, ImFileHandle) { return 0; } +static inline size_t ImFileWrite(const void*, size_t, size_t, ImFileHandle) { return 0; } +#endif + +#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS +typedef FILE* ImFileHandle; +IMGUI_API ImFileHandle ImFileOpen(const char* filename, const char* mode); +IMGUI_API int ImFileClose(ImFileHandle file); +IMGUI_API size_t ImFileGetSize(ImFileHandle file); +IMGUI_API size_t ImFileRead(void* data, size_t size, size_t count, ImFileHandle file); +IMGUI_API size_t ImFileWrite(const void* data, size_t size, size_t count, ImFileHandle file); +#else +#define IMGUI_DISABLE_TTY_FUNCTIONS // Can't use stdout, fflush if we are not using default file functions +#endif +IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size = NULL, int padding_bytes = 0); + // Helpers: Maths // - Wrapper for standard libs functions. (Note that imgui_demo.cpp does _not_ use them to keep the code easy to copy) #ifndef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS @@ -1103,7 +1127,7 @@ struct ImGuiContext // Capture/Logging bool LogEnabled; ImGuiLogType LogType; - FILE* LogFile; // If != NULL log to stdout/ file + ImFileHandle LogFile; // If != NULL log to stdout/ file ImGuiTextBuffer LogBuffer; // Accumulation buffer when log to clipboard. This is pointer so our GImGui static constructor doesn't call heap allocators. float LogLinePosY; bool LogLineFirstItem; From ecbedc8c2654eb1dadb7d92f47ebb051bfd9b3ba Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 19 Nov 2019 21:20:46 +0100 Subject: [PATCH 136/384] Tweaks, ammend 93efa54, rename to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS (#1038) --- docs/CHANGELOG.txt | 3 +-- imconfig.h | 2 +- imgui.cpp | 12 ++++++++---- imgui_demo.cpp | 4 ++-- imgui_internal.h | 6 +++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 014e7c67..ec3a781d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -50,7 +50,7 @@ Breaking Changes: Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate. If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. -- Misc: Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS. (#1038) +- Misc: Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS. (#1038) - Misc: Renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS. - Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] @@ -88,7 +88,6 @@ Other Changes: - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Metrics: Expose basic details of each window key/value state storage. - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. -- Examples: Emscripten: Removed NO_FILESYSTEM from Makefile, seems to fail on some setup. (#2734) [@Funto] - Examples: Emscripten: Removed BINARYEN_TRAP_MODE=clamp from Makefile which was removed in Emscripten 1.39.0 but required prior to 1.39.0, making life easier for absolutely no-one. (#2877, #2878) [@podsvirov] - Backends: OpenGL3: Fix building with pre-3.2 GL loaders which do not expose glDrawElementsBaseVertex(), diff --git a/imconfig.h b/imconfig.h index 9e0c1451..f9963614 100644 --- a/imconfig.h +++ b/imconfig.h @@ -35,7 +35,7 @@ //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). -//#define IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) +//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). diff --git a/imgui.cpp b/imgui.cpp index ef23e1b4..710ccc3e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,7 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. - - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS for consistency. + - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73. - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. @@ -1254,12 +1254,16 @@ const char* ImStrSkipBlank(const char* str) // A) MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size). // Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm. // B) When buf==NULL vsnprintf() will return the output size. -#ifndef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS +#ifndef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +// We support stb_sprintf which is much faster (see: https://github.com/nothings/stb/blob/master/stb_sprintf.h) +// You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +// and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are +// designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.) //#define IMGUI_USE_STB_SPRINTF #ifdef IMGUI_USE_STB_SPRINTF #define STB_SPRINTF_IMPLEMENTATION -#include "imstb_sprintf.h" +#include "stb_sprintf.h" #endif #if defined(_MSC_VER) && !defined(vsnprintf) @@ -1298,7 +1302,7 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) buf[w] = 0; return w; } -#endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS +#endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // CRC32 needs a 1KB lookup table (not cache friendly) // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily: diff --git a/imgui_demo.cpp b/imgui_demo.cpp index d451451b..e19d7fb9 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3106,8 +3106,8 @@ void ImGui::ShowAboutWindow(bool* p_open) #ifdef IMGUI_DISABLE_WIN32_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_WIN32_FUNCTIONS"); #endif -#ifdef IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS - ImGui::Text("define: IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS"); +#ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS + ImGui::Text("define: IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS"); #endif #ifdef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS"); diff --git a/imgui_internal.h b/imgui_internal.h index 9d29cb2a..2d923272 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -61,10 +61,10 @@ Index of this file: #endif // Legacy defines -#ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Obsolete Since 1.74 -#error Use IMGUI_DISABLE_DEFAULT_FORMAT_STRING_FUNCTIONS +#ifdef IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Renamed in 1.74 +#error Use IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS #endif -#ifdef IMGUI_DISABLE_MATH_FUNCTIONS // Obsolete Since 1.74 +#ifdef IMGUI_DISABLE_MATH_FUNCTIONS // Renamed in 1.74 #error Use IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS #endif From a899c1e5705b4c895f5838aa340a66eb5cb84bfc Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 20 Nov 2019 10:40:14 +0100 Subject: [PATCH 137/384] Internals: Using ImU64 for internal ImFile api so we can later wrap them to fseeko/ftello//_fseeki64/_ftelli64 (#2734) --- imgui.cpp | 14 ++++++++------ imgui_internal.h | 18 +++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 710ccc3e..bb38f1fc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1395,10 +1395,12 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) return fopen(filename, mode); #endif } -int ImFileClose(ImFileHandle f) { return fclose(f); } -size_t ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (size_t)sz : (size_t)-1; } -size_t ImFileRead(void* data, size_t sz, size_t count, ImFileHandle f) { return fread(data, sz, count, f); } -size_t ImFileWrite(const void* data, size_t sz, size_t count, ImFileHandle f) { return fwrite(data, sz, count, f); } + +// We should in theory be using fseeko()/ftello() with off_t and _fseeki64()/_ftelli64() with __int64, waiting for the PR that does that in a very portable pre-C++11 zero-warnings way. +bool ImFileClose(ImFileHandle f) { return fclose(f) == 0; } +ImU64 ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (ImU64)sz : (ImU64)-1; } +ImU64 ImFileRead(void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fread(data, (size_t)sz, (size_t)count, f); } +ImU64 ImFileWrite(const void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fwrite(data, (size_t)sz, (size_t)count, f); } #endif // #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Helper: Load file content into memory @@ -1413,7 +1415,7 @@ void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_f if ((f = ImFileOpen(filename, mode)) == NULL) return NULL; - size_t file_size = ImFileGetSize(f); + size_t file_size = (size_t)ImFileGetSize(f); if (file_size == (size_t)-1) { ImFileClose(f); @@ -9076,7 +9078,7 @@ void ImGui::LogText(const char* fmt, ...) { g.LogBuffer.Buf.resize(0); g.LogBuffer.appendfv(fmt, args); - ImFileWrite(g.LogBuffer.c_str(), sizeof(char), (size_t)g.LogBuffer.size(), g.LogFile); + ImFileWrite(g.LogBuffer.c_str(), sizeof(char), (ImU64)g.LogBuffer.size(), g.LogFile); } else { diff --git a/imgui_internal.h b/imgui_internal.h index 2d923272..ad259d26 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -266,19 +266,19 @@ static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) #define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS typedef void* ImFileHandle; static inline ImFileHandle ImFileOpen(const char*, const char*) { return NULL; } -static inline int ImFileClose(ImFileHandle) { return -1; } -static inline size_t ImFileGetSize(ImFileHandle) { return (size_t)-1; } -static inline size_t ImFileRead(void*, size_t, size_t, ImFileHandle) { return 0; } -static inline size_t ImFileWrite(const void*, size_t, size_t, ImFileHandle) { return 0; } +static inline bool ImFileClose(ImFileHandle) { return false; } +static inline ImU64 ImFileGetSize(ImFileHandle) { return (ImU64)-1; } +static inline ImU64 ImFileRead(void*, ImU64, ImU64, ImFileHandle) { return 0; } +static inline ImU64 ImFileWrite(const void*, ImU64, ImU64, ImFileHandle) { return 0; } #endif #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS typedef FILE* ImFileHandle; IMGUI_API ImFileHandle ImFileOpen(const char* filename, const char* mode); -IMGUI_API int ImFileClose(ImFileHandle file); -IMGUI_API size_t ImFileGetSize(ImFileHandle file); -IMGUI_API size_t ImFileRead(void* data, size_t size, size_t count, ImFileHandle file); -IMGUI_API size_t ImFileWrite(const void* data, size_t size, size_t count, ImFileHandle file); +IMGUI_API bool ImFileClose(ImFileHandle file); +IMGUI_API ImU64 ImFileGetSize(ImFileHandle file); +IMGUI_API ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file); +IMGUI_API ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file); #else #define IMGUI_DISABLE_TTY_FUNCTIONS // Can't use stdout, fflush if we are not using default file functions #endif @@ -1512,7 +1512,7 @@ struct ImGuiTabItem float Width; // Width currently displayed float ContentWidth; // Width of actual contents, stored during BeginTabItem() call - ImGuiTabItem() { ID = Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; } + ImGuiTabItem() { ID = 0; Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; } }; // Storage for a tab bar (sizeof() 92~96 bytes) From ca63349eb4d3d97adf9214eb02ee066d85029a17 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 20 Nov 2019 11:58:25 +0100 Subject: [PATCH 138/384] Renamed XX-bits -> XX-bit in comments to match what the world appears to be using. --- docs/CHANGELOG.txt | 8 ++++---- examples/imgui_impl_allegro5.cpp | 6 +++--- examples/imgui_impl_dx10.cpp | 2 +- examples/imgui_impl_dx10.h | 2 +- examples/imgui_impl_dx11.cpp | 2 +- examples/imgui_impl_dx11.h | 2 +- examples/imgui_impl_dx12.cpp | 2 +- examples/imgui_impl_dx12.h | 2 +- examples/imgui_impl_dx9.cpp | 2 +- examples/imgui_impl_dx9.h | 2 +- examples/imgui_impl_metal.h | 2 +- examples/imgui_impl_metal.mm | 2 +- examples/imgui_impl_opengl2.cpp | 2 +- examples/imgui_impl_opengl3.cpp | 4 ++-- examples/imgui_impl_opengl3.h | 2 +- examples/imgui_impl_vulkan.cpp | 2 +- examples/imgui_impl_vulkan.h | 2 +- imconfig.h | 6 +++--- imgui.cpp | 8 ++++---- imgui.h | 14 +++++++------- imgui_widgets.cpp | 6 +++--- misc/fonts/binary_to_compressed_c.cpp | 2 +- 22 files changed, 41 insertions(+), 41 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ec3a781d..d2609d05 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -310,11 +310,11 @@ Other Changes: collapsing/docking button to the other side of the title bar. - Style: Made window close button cross slightly smaller. - Log/Capture: Fixed BeginTabItem() label not being included in a text log/capture. -- ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bits indices. +- ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bit indices. The renderer back-end needs to set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' to enable this, and honor the ImDrawCmd::VtxOffset field. Otherwise the value will always be zero. This has the advantage of preserving smaller index buffers and allowing to execute on hardware that do not - support 32-bits indices. Most examples back-ends have been modified to support the VtxOffset field. + support 32-bit indices. Most examples back-ends have been modified to support the VtxOffset field. - ImDrawList: Added ImDrawCmd::IdxOffset value, equivalent to summing element count for each draw command. This is provided for convenience and consistency with VtxOffset. - ImDrawCallback: Allow to override the signature of ImDrawCallback by #define-ing it. This is meant to @@ -328,7 +328,7 @@ Other Changes: dealing with Win32, and to facilitate integration in custom engines. (#2546) [@andrewwillmott] - Backends: OSX: imgui_impl_osx: Added mouse cursor support. (#2585, #1873) [@actboy168] - Examples/Backends: DirectX9/10/11/12, Metal, Vulkan, OpenGL3 (Desktop GL only): Added support for large meshes - (64k+ vertices) with 16-bits indices, enable 'ImGuiBackendFlags_RendererHasVtxOffset' in those back-ends. + (64k+ vertices) with 16-bit indices, enable 'ImGuiBackendFlags_RendererHasVtxOffset' in those back-ends. - Examples/Backends: Don't filter characters under 0x10000 before calling io.AddInputCharacter(), the filtering is done in io.AddInputCharacter() itself. This is in prevision for fuller Unicode support. (#2538, #2541) @@ -1735,7 +1735,7 @@ Changes: - Fixed border rendering in various situations when using non-pixel aligned glyphs. - Fixed border rendering of windows to always contain the border within the window. - Fixed Shutdown() leaking font atlas data if NewFrame() was never called. (#396, #303) -- Fixed int>void\* warnings for 64-bits architectures with fancy warnings enabled. +- Fixed int>void\* warnings for 64-bit architectures with fancy warnings enabled. - Renamed the dubious Color() helpers to ValueColor() - dangerously named, rarely used and probably to be made obsolete. - InputText(): Fixed and better handling of using keyboard while mouse button if being held and dragging. (#429) - InputText(): Replace OS IME (Input Method Editor) cursor on top-left when we are not text editing. diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp index 8cee95f0..18671625 100644 --- a/examples/imgui_impl_allegro5.cpp +++ b/examples/imgui_impl_allegro5.cpp @@ -25,7 +25,7 @@ // 2018-06-13: Renderer: Backup/restore transform and clipping rectangle. // 2018-06-11: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag. // 2018-04-18: Misc: Renamed file from imgui_impl_a5.cpp to imgui_impl_allegro5.cpp. -// 2018-04-18: Misc: Added support for 32-bits vertex indices to avoid conversion at runtime. Added imconfig_allegro5.h to enforce 32-bit indices when included from imgui.h. +// 2018-04-18: Misc: Added support for 32-bit vertex indices to avoid conversion at runtime. Added imconfig_allegro5.h to enforce 32-bit indices when included from imgui.h. // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplAllegro5_RenderDrawData() in the .h file so you can call it yourself. // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. // 2018-02-06: Inputs: Added mapping for ImGuiKey_Space. @@ -108,7 +108,7 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; // Allegro's implementation of al_draw_indexed_prim() for DX9 is completely broken. Unindex our buffers ourselves. - // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 float as well.. + // FIXME-OPT: Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 float as well.. static ImVector vertices; vertices.resize(cmd_list->IdxBuffer.Size); for (int i = 0; i < cmd_list->IdxBuffer.Size; i++) @@ -257,7 +257,7 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display) io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5"; // Create custom vertex declaration. - // Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats. + // Unfortunately Allegro doesn't support 32-bit packed colors so we have to convert them to 4 floats. // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion. ALLEGRO_VERTEX_ELEMENT elems[] = { diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 362756db..7eb4e5af 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h index 94e6db80..85281d79 100644 --- a/examples/imgui_impl_dx10.h +++ b/examples/imgui_impl_dx10.h @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index 2b80f766..97e17ff1 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp diff --git a/examples/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h index 5eee80d5..c54d4379 100644 --- a/examples/imgui_impl_dx11.h +++ b/examples/imgui_impl_dx11.h @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 83d68527..e7bb5e9c 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // Issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 6c05805b..8f307dc5 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // Issues: // [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301 diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 82b96475..342f9d54 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h index a0413e00..b36e95b2 100644 --- a/examples/imgui_impl_dx9.h +++ b/examples/imgui_impl_dx9.h @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_metal.h b/examples/imgui_impl_metal.h index 7fa558fa..f09a115d 100644 --- a/examples/imgui_impl_metal.h +++ b/examples/imgui_impl_metal.h @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm index 9d1045f1..7cdda733 100644 --- a/examples/imgui_impl_metal.mm +++ b/examples/imgui_impl_metal.mm @@ -3,7 +3,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index a3496225..de4b128c 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -201,7 +201,7 @@ bool ImGui_ImplOpenGL2_CreateFontsTexture() ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; - io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. // Upload texture to graphics system GLint last_texture; diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index c1d44da6..4f3334b2 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -5,7 +5,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! -// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices. +// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. @@ -404,7 +404,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture() ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; - io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. + io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. // Upload texture to graphics system GLint last_texture; diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 2d10ea30..4c72ec47 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -5,7 +5,7 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! -// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices. +// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 2b8a3702..095a7f26 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // Missing features: // [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h index 5b0bd7b3..a74cdb5a 100644 --- a/examples/imgui_impl_vulkan.h +++ b/examples/imgui_impl_vulkan.h @@ -2,7 +2,7 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // Missing features: // [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 diff --git a/imconfig.h b/imconfig.h index f9963614..25cad5f5 100644 --- a/imconfig.h +++ b/imconfig.h @@ -65,9 +65,9 @@ operator MyVec4() const { return MyVec4(x,y,z,w); } */ -//---- Using 32-bits vertex indices (default is 16-bits) is one way to allow large meshes with more than 64K vertices. -// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bits indices). -// Another way to allow large meshes while keeping 16-bits indices is to handle ImDrawCmd::VtxOffset in your renderer. +//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. +// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices). +// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. //#define ImDrawIdx unsigned int diff --git a/imgui.cpp b/imgui.cpp index bb38f1fc..4b58b776 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -293,7 +293,7 @@ CODE MyEngineScissor((int)(pcmd->ClipRect.x - pos.x), (int)(pcmd->ClipRect.y - pos.y), (int)(pcmd->ClipRect.z - pos.x), (int)(pcmd->ClipRect.w - pos.y)); // Render 'pcmd->ElemCount/3' indexed triangles. - // By default the indices ImDrawIdx are 16-bits, you can change them to 32-bits in imconfig.h if your engine doesn't support 16-bits indices. + // By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices. MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer); } idx_buffer += pcmd->ElemCount; @@ -1186,7 +1186,7 @@ const char* ImStrchrRange(const char* str, const char* str_end, char c) int ImStrlenW(const ImWchar* str) { - //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits + //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bit int n = 0; while (*str++) n++; return n; @@ -1448,7 +1448,7 @@ void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_f // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) //----------------------------------------------------------------------------- -// Convert UTF-8 to 32-bits character, process single character input. +// Convert UTF-8 to 32-bit character, process single character input. // Based on stb_from_utf8() from github.com/nothings/stb/ // We handle UTF-8 decoding error by skipping forward. int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end) @@ -3910,7 +3910,7 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d // (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'. // Most example back-ends already support this from 1.71. Pre-1.71 back-ends won't. // Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them. - // (B) Or handle 32-bits indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h. + // (B) Or handle 32-bit indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h. // Most example back-ends already support this. For example, the OpenGL example code detect index size at compile-time: // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); // Your own engine or render API may use different parameters or function calls to specify index sizes. diff --git a/imgui.h b/imgui.h index bde32ceb..1d51d93c 100644 --- a/imgui.h +++ b/imgui.h @@ -1025,7 +1025,7 @@ enum ImGuiBackendFlags_ ImGuiBackendFlags_HasGamepad = 1 << 0, // Back-end Platform supports gamepad and currently has one connected. ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Back-end Platform supports honoring GetMouseCursor() value to change the OS cursor shape. ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Back-end Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set). - ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3 // Back-end Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bits indices. + ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3 // Back-end Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices. }; // Enumeration for PushStyleColor() / PopStyleColor() @@ -1727,7 +1727,7 @@ struct ImGuiListClipper IMGUI_API void End(); // Automatically called on the last call of Step() that returns false. }; -// Helpers macros to generate 32-bits encoded colors +// Helpers macros to generate 32-bit encoded colors #ifdef IMGUI_USE_BGRA_PACKED_COLOR #define IM_COL32_R_SHIFT 16 #define IM_COL32_G_SHIFT 8 @@ -1791,13 +1791,13 @@ typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* c // Typically, 1 command = 1 GPU draw call (unless command is a callback) // Pre 1.71 back-ends will typically ignore the VtxOffset/IdxOffset fields. When 'io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset' -// is enabled, those fields allow us to render meshes larger than 64K vertices while keeping 16-bits indices. +// is enabled, those fields allow us to render meshes larger than 64K vertices while keeping 16-bit indices. struct ImDrawCmd { unsigned int ElemCount; // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[]. ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates ImTextureID TextureId; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas. - unsigned int VtxOffset; // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0. With ImGuiBackendFlags_RendererHasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bits indices. + unsigned int VtxOffset; // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0. With ImGuiBackendFlags_RendererHasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bit indices. unsigned int IdxOffset; // Start offset in index buffer. Always equal to sum of ElemCount drawn so far. ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally. void* UserCallbackData; // The draw callback code can access this. @@ -1806,8 +1806,8 @@ struct ImDrawCmd }; // Vertex index -// (to allow large meshes with 16-bits indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end) -// (to use 32-bits indices: override with '#define ImDrawIdx unsigned int' in imconfig.h) +// (to allow large meshes with 16-bit indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end) +// (to use 32-bit indices: override with '#define ImDrawIdx unsigned int' in imconfig.h) #ifndef ImDrawIdx typedef unsigned short ImDrawIdx; #endif @@ -1916,7 +1916,7 @@ struct ImDrawList // Primitives // - For rectangular primitives, "p_min" and "p_max" represent the upper-left and lower-right corners. IMGUI_API void AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness = 1.0f); - IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size), rounding_corners_flags: 4-bits corresponding to which corner to round + IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size), rounding_corners_flags: 4 bits corresponding to which corner to round IMGUI_API void AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All); // a: upper-left, b: lower-right (== upper-left + size) IMGUI_API void AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); IMGUI_API void AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness = 1.0f); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0277c036..19f09436 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2474,7 +2474,7 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ return value_changed; } -// For 32-bits and larger types, slider bounds are limited to half the natural type range. +// For 32-bit and larger types, slider bounds are limited to half the natural type range. // So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2 will be ok. // It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders. bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb) @@ -3987,7 +3987,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // In multi-line mode, we never exit the loop until all lines are counted, so add one extra to the searches_remaining counter. searches_remaining += is_multiline ? 1 : 0; int line_count = 0; - //for (const ImWchar* s = text_begin; (s = (const ImWchar*)wcschr((const wchar_t*)s, (wchar_t)'\n')) != NULL; s++) // FIXME-OPT: Could use this when wchar_t are 16-bits + //for (const ImWchar* s = text_begin; (s = (const ImWchar*)wcschr((const wchar_t*)s, (wchar_t)'\n')) != NULL; s++) // FIXME-OPT: Could use this when wchar_t are 16-bit for (const ImWchar* s = text_begin; *s != 0; s++) if (*s == '\n') { @@ -4064,7 +4064,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ break; if (rect_pos.y < clip_rect.y) { - //p = (const ImWchar*)wmemchr((const wchar_t*)p, '\n', text_selected_end - p); // FIXME-OPT: Could use this when wchar_t are 16-bits + //p = (const ImWchar*)wmemchr((const wchar_t*)p, '\n', text_selected_end - p); // FIXME-OPT: Could use this when wchar_t are 16-bit //p = p ? p + 1 : text_selected_end; while (p < text_selected_end) if (*p++ == '\n') diff --git a/misc/fonts/binary_to_compressed_c.cpp b/misc/fonts/binary_to_compressed_c.cpp index 4d3522d4..27569537 100644 --- a/misc/fonts/binary_to_compressed_c.cpp +++ b/misc/fonts/binary_to_compressed_c.cpp @@ -3,7 +3,7 @@ // The data is first compressed with stb_compress() to reduce source code size, // then encoded in Base85 to fit in a string so we can fit roughly 4 bytes of compressed data into 5 bytes of source code (suggested by @mmalex) -// (If we used 32-bits constants it would require take 11 bytes of source code to encode 4 bytes, and be endianness dependent) +// (If we used 32-bit constants it would require take 11 bytes of source code to encode 4 bytes, and be endianness dependent) // Note that even with compression, the output array is likely to be bigger than the binary file.. // Load compressed TTF fonts with ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF() From 51a02b319c86b89f5dad2d22dbf0431a3c6d03d7 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 29 Oct 2019 22:50:34 +0100 Subject: [PATCH 139/384] Added IM_UNICODE_CODEPOINT_MAX. Changed specs of ImFontAtlas::AddCustomRectRegular() (breaking change). --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 15 ++++++++------- imgui.h | 16 +++++++++------- imgui_demo.cpp | 6 +++--- imgui_draw.cpp | 17 +++++++++-------- imgui_widgets.cpp | 8 ++++++-- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d2609d05..be749e21 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -52,6 +52,8 @@ Breaking Changes: If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you. - Misc: Renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS. (#1038) - Misc: Renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS. +- Fonts: ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to + conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] diff --git a/imgui.cpp b/imgui.cpp index 4b58b776..2621a6ed 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,6 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73. @@ -1061,7 +1062,7 @@ ImGuiIO::ImGuiIO() // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message void ImGuiIO::AddInputCharacter(unsigned int c) { - if (c > 0 && c < 0x10000) + if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX) InputQueueCharacters.push_back((ImWchar)c); } @@ -1071,7 +1072,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) { unsigned int c = 0; utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL); - if (c > 0 && c < 0x10000) + if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX) InputQueueCharacters.push_back((ImWchar)c); } } @@ -1463,7 +1464,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* } if ((*str & 0xe0) == 0xc0) { - *out_char = 0xFFFD; // will be invalid but not end of string + *out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string if (in_text_end && in_text_end - (const char*)str < 2) return 1; if (*str < 0xc2) return 2; c = (unsigned int)((*str++ & 0x1f) << 6); @@ -1474,7 +1475,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* } if ((*str & 0xf0) == 0xe0) { - *out_char = 0xFFFD; // will be invalid but not end of string + *out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string if (in_text_end && in_text_end - (const char*)str < 3) return 1; if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 3; if (*str == 0xed && str[1] > 0x9f) return 3; // str[1] < 0x80 is checked below @@ -1488,7 +1489,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* } if ((*str & 0xf8) == 0xf0) { - *out_char = 0xFFFD; // will be invalid but not end of string + *out_char = IM_UNICODE_CODEPOINT_INVALID; // will be invalid but not end of string if (in_text_end && in_text_end - (const char*)str < 4) return 1; if (*str > 0xf4) return 4; if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 4; @@ -1519,7 +1520,7 @@ int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const cha in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); if (c == 0) break; - if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes + if (c <= IM_UNICODE_CODEPOINT_MAX) // FIXME: Losing characters that don't fit in 2 bytes *buf_out++ = (ImWchar)c; } *buf_out = 0; @@ -1537,7 +1538,7 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end) in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); if (c == 0) break; - if (c < 0x10000) + if (c <= IM_UNICODE_CODEPOINT_MAX) char_count++; } return char_count; diff --git a/imgui.h b/imgui.h index 1d51d93c..e2b8f603 100644 --- a/imgui.h +++ b/imgui.h @@ -80,6 +80,8 @@ Index of this file: #else #define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro. #endif +#define IM_UNICODE_CODEPOINT_MAX 0xFFFF // Last Unicode code point supported by this build. +#define IM_UNICODE_CODEPOINT_INVALID 0xFFFD // Standard invalid Unicode code point. // Warnings #if defined(__clang__) @@ -2045,7 +2047,7 @@ struct ImFontGlyphRangesBuilder ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used) ImFontGlyphRangesBuilder() { Clear(); } - inline void Clear() { int size_in_bytes = 0x10000 / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); } + inline void Clear() { int size_in_bytes = (IM_UNICODE_CODEPOINT_MAX+1) / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); } inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array inline void AddChar(ImWchar c) { SetBit(c); } // Add character @@ -2057,12 +2059,12 @@ struct ImFontGlyphRangesBuilder // See ImFontAtlas::AddCustomRectXXX functions. struct ImFontAtlasCustomRect { - unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data. + unsigned int ID; // Input // User ID. Use < 0x110000 to map into a font glyph, >= 0x110000 for other/internal/custom texture data. unsigned short Width, Height; // Input // Desired rectangle dimension unsigned short X, Y; // Output // Packed position in Atlas - float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance - ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset - ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font + float GlyphAdvanceX; // Input // For custom font glyphs only (ID < 0x110000): glyph xadvance + ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID < 0x110000): glyph display offset + ImFont* Font; // Input // For custom font glyphs only (ID < 0x110000): target font ImFontAtlasCustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; } bool IsPacked() const { return X != 0xFFFF; } }; @@ -2142,8 +2144,8 @@ struct ImFontAtlas // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), // so you can render e.g. custom colorful icons and use them as regular glyphs. // Read misc/fonts/README.txt for more details about using colorful icons. - IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList - IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font. + IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x110000. Id >= 0x80000000 are reserved for ImGui and ImDrawList + IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x110000 to register a rectangle to map into a specific font. const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } // [Internal] diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e19d7fb9..1269ace0 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3416,10 +3416,10 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) { // Display all glyphs of the fonts in separate pages of 256 characters - for (int base = 0; base < 0x10000; base += 256) + for (unsigned int base = 0; base <= IM_UNICODE_CODEPOINT_MAX; base += 256) { int count = 0; - for (int n = 0; n < 256; n++) + for (unsigned int n = 0; n < 256; n++) count += font->FindGlyphNoFallback((ImWchar)(base + n)) ? 1 : 0; if (count > 0 && ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base + 255, count, count > 1 ? "glyphs" : "glyph")) { @@ -3427,7 +3427,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) float cell_spacing = style.ItemSpacing.y; ImVec2 base_pos = ImGui::GetCursorScreenPos(); ImDrawList* draw_list = ImGui::GetWindowDrawList(); - for (int n = 0; n < 256; n++) + for (unsigned int n = 0; n < 256; n++) { ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size + cell_spacing), base_pos.y + (n / 16) * (cell_size + cell_spacing)); ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index f73e0e31..1e4301b3 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1725,7 +1725,8 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed int ImFontAtlas::AddCustomRectRegular(unsigned int id, int width, int height) { - IM_ASSERT(id >= 0x10000); + // Breaking change on 2019/11/21 (1.74): ImFontAtlas::AddCustomRectRegular() now requires an ID >= 0x110000 (instead of >= 0x10000) + IM_ASSERT(id >= 0x110000); IM_ASSERT(width > 0 && width <= 0xFFFF); IM_ASSERT(height > 0 && height <= 0xFFFF); ImFontAtlasCustomRect r; @@ -1905,7 +1906,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1); for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) - for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) + for (unsigned int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) { if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true) continue; @@ -2189,7 +2190,7 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas) for (int i = 0; i < atlas->CustomRects.Size; i++) { const ImFontAtlasCustomRect& r = atlas->CustomRects[i]; - if (r.Font == NULL || r.ID > 0x10000) + if (r.Font == NULL || r.ID >= 0x110000) continue; IM_ASSERT(r.Font->ContainerAtlas == atlas); @@ -2453,7 +2454,7 @@ void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end) text += c_len; if (c_len == 0) break; - if (c < 0x10000) + if (c <= IM_UNICODE_CODEPOINT_MAX) AddChar((ImWchar)c); } } @@ -2467,12 +2468,12 @@ void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges) void ImFontGlyphRangesBuilder::BuildRanges(ImVector* out_ranges) { - int max_codepoint = 0x10000; - for (int n = 0; n < max_codepoint; n++) + const int max_codepoint = IM_UNICODE_CODEPOINT_MAX; + for (int n = 0; n <= max_codepoint; n++) if (GetBit(n)) { out_ranges->push_back((ImWchar)n); - while (n < max_codepoint - 1 && GetBit(n + 1)) + while (n < max_codepoint && GetBit(n + 1)) n++; out_ranges->push_back((ImWchar)n); } @@ -2601,7 +2602,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst) { IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function. - int index_size = IndexLookup.Size; + unsigned int index_size = (unsigned int)IndexLookup.Size; if (dst < index_size && IndexLookup.Data[dst] == (ImWchar)-1 && !overwrite_dst) // 'dst' already exists return; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 19f09436..0c5a1967 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3157,7 +3157,7 @@ namespace ImStb static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return obj->CurLenW; } static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->TextW[idx]; } static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *GImGui; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); } -static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; } +static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x200000 ? 0 : key; } static ImWchar STB_TEXTEDIT_NEWLINE = '\n'; static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx) { @@ -3340,6 +3340,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f if (c >= 0xE000 && c <= 0xF8FF) return false; + // Filter Unicode ranges we are not handling in this build. + if (c > IM_UNICODE_CODEPOINT_MAX) + return false; + // Generic named filters if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)) { @@ -3763,7 +3767,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ s += ImTextCharFromUtf8(&c, s, NULL); if (c == 0) break; - if (c >= 0x10000 || !InputTextFilterCharacter(&c, flags, callback, callback_user_data)) + if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data)) continue; clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; } From 51e2e9b239536ba9c5cdbbf5ac89d2478a2e1961 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Nov 2019 10:56:23 +0100 Subject: [PATCH 140/384] ImVector: Added shrink() helper. ImFont::RenderText minor optimisation for debug build. Misc: Metrics shows tab names because we now have them. --- imgui.cpp | 2 +- imgui.h | 1 + imgui_draw.cpp | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2621a6ed..2699071c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9900,7 +9900,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::PushID(tab); if (ImGui::SmallButton("<")) { TabBarQueueChangeTabOrder(tab_bar, tab, -1); } ImGui::SameLine(0, 2); if (ImGui::SmallButton(">")) { TabBarQueueChangeTabOrder(tab_bar, tab, +1); } ImGui::SameLine(); - ImGui::Text("%02d%c Tab 0x%08X", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID); + ImGui::Text("%02d%c Tab 0x%08X '%s'", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : ""); ImGui::PopID(); } ImGui::TreePop(); diff --git a/imgui.h b/imgui.h index e2b8f603..27982042 100644 --- a/imgui.h +++ b/imgui.h @@ -1273,6 +1273,7 @@ struct ImVector inline int _grow_capacity(int sz) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > sz ? new_capacity : sz; } inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } + inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; } // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1e4301b3..1efb2cb4 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3021,9 +3021,9 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col x += char_width; } - // Give back unused vertices - draw_list->VtxBuffer.resize((int)(vtx_write - draw_list->VtxBuffer.Data)); - draw_list->IdxBuffer.resize((int)(idx_write - draw_list->IdxBuffer.Data)); + // Give back unused vertices (clipped ones, blanks) ~ this is essentially a PrimUnreserve() action. + draw_list->VtxBuffer.Size = (int)(vtx_write - draw_list->VtxBuffer.Data); // Same as calling shrink() + draw_list->IdxBuffer.Size = (int)(idx_write - draw_list->IdxBuffer.Data); draw_list->CmdBuffer[draw_list->CmdBuffer.Size-1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size); draw_list->_VtxWritePtr = vtx_write; draw_list->_IdxWritePtr = idx_write; From b205ab01f2b7ed1e40e7bc45d7b3034c1eace48a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Nov 2019 14:45:44 +0100 Subject: [PATCH 141/384] Internals: Added IM_ASSERT_PARANOID, IMGUI_DEBUG_PARANOID define. Shuffled a bit of the macros section in imgui_internal.h --- imgui_internal.h | 70 +++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index ad259d26..405bea26 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -140,48 +140,47 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #endif //----------------------------------------------------------------------------- -// Generic helpers -//----------------------------------------------------------------------------- -// - Macros -// - Helpers: Misc -// - Helpers: Bit manipulation -// - Helpers: Geometry -// - Helpers: String, Formatting -// - Helpers: UTF-8 <> wchar conversions -// - Helpers: ImVec2/ImVec4 operators -// - Helpers: Maths -// - Helper: ImBoolVector -// - Helper: ImPool<> -// - Helper: ImChunkStream<> +// Macros //----------------------------------------------------------------------------- -// Macros -#define IM_PI 3.14159265358979323846f -#ifdef _WIN32 -#define IM_NEWLINE "\r\n" // Play it nice with Windows users (2018/05 news: Microsoft announced that Notepad will finally display Unix-style carriage returns!) -#else -#define IM_NEWLINE "\n" +// Debug Logging +#ifndef IMGUI_DEBUG_LOG +#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) #endif -#define IM_TABSIZE (4) + +// Static Asserts #if (__cplusplus >= 201100) #define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") #else #define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] #endif -#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose -#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 -#define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds -#define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // + +// "Paranoid" Debug Asserts are meant to only be enabled during specific debugging/work, otherwise would slow down the code too much. +#define IMGUI_DEBUG_PARANOID 1 +#if IMGUI_DEBUG_PARANOID +#define IM_ASSERT_PARANOID(_EXPR) IM_ASSERT(_EXPR) +#else +#define IM_ASSERT_PARANOID(_EXPR) +#endif // Error handling +// Down the line in some frameworks/languages we would like to have a way to redirect those to the programmer and recover from more faults. #ifndef IM_ASSERT_USER_ERROR -#define IM_ASSERT_USER_ERROR(_EXPR,_MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error +#define IM_ASSERT_USER_ERROR(_EXP,_MSG) IM_ASSERT((_EXP) && (_MSG)) // Recoverable User Error #endif -// Debug Logging -#ifndef IMGUI_DEBUG_LOG -#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) +// Misc Macros +#define IM_PI 3.14159265358979323846f +#ifdef _WIN32 +#define IM_NEWLINE "\r\n" // Play it nice with Windows users (Update: since 2018-05, Notepad finally appears to support Unix-style carriage returns!) +#else +#define IM_NEWLINE "\n" #endif +#define IM_TABSIZE (4) +#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose +#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 +#define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds +#define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) // // Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall #ifdef _MSC_VER @@ -190,6 +189,21 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IMGUI_CDECL #endif +//----------------------------------------------------------------------------- +// Generic helpers +//----------------------------------------------------------------------------- +// - Helpers: Misc +// - Helpers: Bit manipulation +// - Helpers: Geometry +// - Helpers: String, Formatting +// - Helpers: UTF-8 <> wchar conversions +// - Helpers: ImVec2/ImVec4 operators +// - Helpers: Maths +// - Helper: ImBoolVector +// - Helper: ImPool<> +// - Helper: ImChunkStream<> +//----------------------------------------------------------------------------- + // Helpers: Misc #define ImQsort qsort IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0); From 106184bbeac4de9471f9acfd6af200ee5a1bd94c Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Nov 2019 22:13:52 +0100 Subject: [PATCH 142/384] Docking: Fixed node->HasCloseButton not honoring ImGuiDockNodeFlags_NoCloseButton in a floating node, leading to empty space at the right of tab-bars with those flags. (#2109) --- imgui.cpp | 2 +- imgui.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cf592d90..7305baa6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12329,7 +12329,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) { // [Automatic root or child nodes] node->EnableCloseButton = false; - node->HasCloseButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0; + node->HasCloseButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoCloseButton) == 0; node->HasWindowMenuButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0; for (int window_n = 0; window_n < node->Windows.Size; window_n++) { diff --git a/imgui.h b/imgui.h index 92abcf25..6baf9161 100644 --- a/imgui.h +++ b/imgui.h @@ -1614,7 +1614,7 @@ struct ImGuiWindowClass ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not. ImGuiViewportFlags ViewportFlagsOverrideSet; // Viewport flags to set when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. ImGuiViewportFlags ViewportFlagsOverrideClear; // Viewport flags to clear when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. - bool DockingAlwaysTabBar; // Set to true to enforce windows of this class always having their own tab (equivalent of setting the global io.ConfigDockingAlwaysTabBar) + bool DockingAlwaysTabBar; // Set to true to enforce single floating windows of this class always having their own tab bar (equivalent of setting the global io.ConfigDockingAlwaysTabBar) bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window. ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideSet = ViewportFlagsOverrideClear = 0x00; DockingAlwaysTabBar = false; DockingAllowUnclassed = true; } From 3a82994429544030337fbaae109e99ecb3685fb5 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Nov 2019 22:35:04 +0100 Subject: [PATCH 143/384] Docking: Can undock from the small triangle button. (#2109,. #2645) --- imgui.cpp | 14 +++++++++----- imgui.h | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7305baa6..250eb461 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5511,18 +5511,22 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize); } - // Docking: Unhide tab bar (small triangle in the corner) - if (window->DockNode && window->DockNode->IsHiddenTabBar() && !window->DockNode->IsNoTabBar()) + // Docking: Unhide tab bar (small triangle in the corner), drag from small triangle to quickly undock + ImGuiDockNode* node = window->DockNode; + if (node && window->DockIsActive && node->IsHiddenTabBar() && !node->IsNoTabBar()) { float unhide_sz_draw = ImFloor(g.FontSize * 0.70f); float unhide_sz_hit = ImFloor(g.FontSize * 0.55f); - ImVec2 p = window->DockNode->Pos; + ImVec2 p = node->Pos; ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit)); bool hovered, held; if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren)) - window->DockNode->WantHiddenTabBarToggle = true; + node->WantHiddenTabBarToggle = true; + else if (held && IsMouseDragging(0)) + StartMouseDragFromTitleBar(window, node, true); + // FIXME-DOCK: Ideally we'd use ImGuiCol_TitleBgActive/ImGuiCol_TitleBg here, but neither is guaranteed to be visible enough at this sort of size.. - ImU32 col = GetColorU32(((held && hovered) || (window->DockNode->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + ImU32 col = GetColorU32(((held && hovered) || (node->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); window->DrawList->AddTriangleFilled(p, p + ImVec2(unhide_sz_draw, 0.0f), p + ImVec2(0.0f, unhide_sz_draw), col); } diff --git a/imgui.h b/imgui.h index 6baf9161..1b4ce621 100644 --- a/imgui.h +++ b/imgui.h @@ -1610,11 +1610,11 @@ struct ImGuiSizeCallbackData // Provide hints to the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) and OS level parent/child relationships. struct ImGuiWindowClass { - ImGuiID ClassId; // User data. 0 = Default class (unclassed) + ImGuiID ClassId; // User data. 0 = Default class (unclassed). Windows of different classes cannot be docked with each others. ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not. ImGuiViewportFlags ViewportFlagsOverrideSet; // Viewport flags to set when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. ImGuiViewportFlags ViewportFlagsOverrideClear; // Viewport flags to clear when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. - bool DockingAlwaysTabBar; // Set to true to enforce single floating windows of this class always having their own tab bar (equivalent of setting the global io.ConfigDockingAlwaysTabBar) + bool DockingAlwaysTabBar; // Set to true to enforce single floating windows of this class always having their own docking node (equivalent of setting the global io.ConfigDockingAlwaysTabBar) bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window. ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideSet = ViewportFlagsOverrideClear = 0x00; DockingAlwaysTabBar = false; DockingAllowUnclassed = true; } From 0cb1c633ff27d50c00249bdac7df8e222f3a65ca Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 24 Nov 2019 23:11:53 +0100 Subject: [PATCH 144/384] Demo: tweaked demo help section, reference to "Examples" and "Tools". Reference to Keyboard navigation. Removed some of the more "obvious/standard" controls. --- imgui_demo.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 1269ace0..4091bcfe 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -157,25 +157,28 @@ void ImGui::ShowUserGuide() ImGuiIO& io = ImGui::GetIO(); ImGui::BulletText("Double-click on title bar to collapse window."); ImGui::BulletText("Click and drag on lower corner to resize window\n(double-click to auto fit window to its contents)."); - if (io.ConfigWindowsMoveFromTitleBarOnly) - ImGui::BulletText("Click and drag on title bar to move window."); - else - ImGui::BulletText("Click and drag on any empty space to move window."); - ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text."); + ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields."); if (io.FontAllowUserScaling) ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); - ImGui::BulletText("Mouse Wheel to scroll."); - ImGui::BulletText("While editing text:\n"); + ImGui::BulletText("While inputing text:\n"); ImGui::Indent(); - ImGui::BulletText("Hold SHIFT or use mouse to select text."); ImGui::BulletText("CTRL+Left/Right to word jump."); ImGui::BulletText("CTRL+A or double-click to select all."); - ImGui::BulletText("CTRL+X,CTRL+C,CTRL+V to use clipboard."); + ImGui::BulletText("CTRL+X/C/V to use clipboard cut/copy/paste."); ImGui::BulletText("CTRL+Z,CTRL+Y to undo/redo."); ImGui::BulletText("ESCAPE to revert."); ImGui::BulletText("You can apply arithmetic operators +,*,/ on numerical values.\nUse +- to subtract."); ImGui::Unindent(); + ImGui::BulletText("With keyboard navigation enabled:"); + ImGui::Indent(); + ImGui::BulletText("Arrow keys to navigate."); + ImGui::BulletText("Space to activate a widget."); + ImGui::BulletText("Return to input text into a widget."); + ImGui::BulletText("Escape to deactivate a widget, close popup, exit child window."); + ImGui::BulletText("Alt to jump to the menu layer of a window."); + ImGui::BulletText("CTRL+Tab to select a window."); + ImGui::Unindent(); } //----------------------------------------------------------------------------- @@ -316,12 +319,20 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::CollapsingHeader("Help")) { + ImGui::Text("ABOUT THIS DEMO:"); + ImGui::BulletText("Sections below are demonstrating many aspects of the library."); + ImGui::BulletText("The \"Examples\" menu above leads to more demo contents."); + ImGui::BulletText("The \"Tools\" menu above gives access to: About Box, Style Editor,\n" + "and Metrics (general purpose Dear ImGui debugging tool)."); + ImGui::Separator(); + ImGui::Text("PROGRAMMER GUIDE:"); - ImGui::BulletText("Please see the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!"); - ImGui::BulletText("Please see the comments in imgui.cpp."); - ImGui::BulletText("Please see the examples/ application."); - ImGui::BulletText("Enable 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls."); - ImGui::BulletText("Enable 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls."); + ImGui::BulletText("See the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!"); + ImGui::BulletText("See comments in imgui.cpp."); + ImGui::BulletText("See example applications in the examples/ folder."); + ImGui::BulletText("Read the FAQ at http://www.dearimgui.org/faq/"); + ImGui::BulletText("Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls."); + ImGui::BulletText("Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls."); ImGui::Separator(); ImGui::Text("USER GUIDE:"); @@ -365,7 +376,7 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::TreeNode("Backend Flags")) { - HelpMarker("Those flags are set by the back-ends (imgui_impl_xxx files) to specify their capabilities."); + HelpMarker("Those flags are set by the back-ends (imgui_impl_xxx files) to specify their capabilities.\nHere we expose then as read-only fields to avoid breaking interactions with your back-end."); ImGuiBackendFlags backend_flags = io.BackendFlags; // Make a local copy to avoid modifying actual back-end flags. ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasGamepad); ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasMouseCursors); @@ -377,6 +388,7 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::TreeNode("Style")) { + HelpMarker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function."); ImGui::ShowStyleEditor(); ImGui::TreePop(); ImGui::Separator(); From aeb57952d68aa473c0aba8df91885427c4d852c3 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 22 Nov 2019 20:22:03 +0900 Subject: [PATCH 145/384] Added area calculation for draw lists in metrics Added ability to hover over a draw list's summary stats and see all the contents in wireframe (cherry picked from commit fd808347bd68a07ad318af6c151028bc9f7b82e7) --- imgui.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2699071c..ee4385de 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9768,7 +9768,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (window && !window->WasActive) ImGui::Text("(Note: owning Window is inactive: DrawList is not being rendered!)"); - int elem_offset = 0; + unsigned int elem_offset = 0; for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) { if (pcmd->UserCallback == NULL && pcmd->ElemCount == 0) @@ -9778,16 +9778,44 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData); continue; } + ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; + + // Calculate approximate coverage area (touched pixel count) + // This will be in pixels squared as long there's no post-scaling happening to the ImGui output + // Optionally also draw all the polys in the list in wireframe when hovering over + + float total_area = 0.0f; + + for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) + { + ImVec2 triangles_pos[3]; + for (int n = 0; n < 3; n++) + { + int vtx_i = idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n); + ImDrawVert& v = draw_list->VtxBuffer[vtx_i]; + triangles_pos[n] = v.pos; + } + + // Calculate triangle area and accumulate + + float area = abs((triangles_pos[0].x * (triangles_pos[1].y - triangles_pos[2].y)) + + (triangles_pos[1].x * (triangles_pos[2].y - triangles_pos[0].y)) + + (triangles_pos[2].x * (triangles_pos[0].y - triangles_pos[1].y))) * 0.5f; + + total_area += area; + } + char buf[300]; - ImFormatString(buf, IM_ARRAYSIZE(buf), "Draw %4d triangles, tex 0x%p, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)", - pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); + ImFormatString(buf, IM_ARRAYSIZE(buf), "Draw %4d triangles, tex 0x%p, area %.0fpx^2, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)", + pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, total_area, + pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf); if (show_drawcmd_clip_rects && fg_draw_list && ImGui::IsItemHovered()) { ImRect clip_rect = pcmd->ClipRect; ImRect vtxs_rect; - for (int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) + for (unsigned int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); clip_rect.Floor(); fg_draw_list->AddRect(clip_rect.Min, clip_rect.Max, IM_COL32(255,0,255,255)); vtxs_rect.Floor(); fg_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, IM_COL32(255,255,0,255)); @@ -9795,8 +9823,34 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (!pcmd_node_open) continue; + // Display vertex information summary. Hover to get all triangles drawn in wireframe + ImFormatString(buf, IM_ARRAYSIZE(buf), "ElemCount: %d, ElemCount/3: %d, VtxOffset: +%d, IdxOffset: +%d", pcmd->ElemCount, pcmd->ElemCount/3, pcmd->VtxOffset, pcmd->IdxOffset); + ImGui::Selectable(buf, false); + + if (fg_draw_list && ImGui::IsItemHovered()) + { + // Draw wireframe version of everything + + ImDrawListFlags backup_flags = fg_draw_list->Flags; + fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles. + + for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) + { + ImVec2 triangles_pos[3]; + for (int n = 0; n < 3; n++) + { + int vtx_i = idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n); + ImDrawVert& v = draw_list->VtxBuffer[vtx_i]; + triangles_pos[n] = v.pos; + } + + fg_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); + } + + fg_draw_list->Flags = backup_flags; + } + // Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted. - ImGui::Text("ElemCount: %d, ElemCount/3: %d, VtxOffset: +%d, IdxOffset: +%d", pcmd->ElemCount, pcmd->ElemCount/3, pcmd->VtxOffset, pcmd->IdxOffset); ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible. while (clipper.Step()) for (int prim = clipper.DisplayStart, idx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++) @@ -9811,6 +9865,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n", (n == 0) ? "elem" : " ", idx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col); } + ImGui::Selectable(buf, false); if (fg_draw_list && ImGui::IsItemHovered()) { From bbe040994255a5d09883c1c9411f0c72ddf2e66b Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 25 Nov 2019 12:01:04 +0100 Subject: [PATCH 146/384] Metrics: Show wire-frame mesh and approximate surface area when hovering ImDrawCmd. Amend aeb5795. Internals: Added ImTriangleArea() --- docs/CHANGELOG.txt | 3 +- imgui.cpp | 97 ++++++++++++++++++---------------------------- imgui_demo.cpp | 2 +- imgui_internal.h | 17 ++++---- 4 files changed, 49 insertions(+), 70 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index be749e21..bbd9b044 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -84,10 +84,11 @@ Other Changes: - Misc: Windows: Disabled win32 function by default when building with UWP. (#2892, #2895) - Misc: Using static_assert() when using C++11, instead of our own construct (avoid zealous Clang warnings). - Misc: Added IMGUI_DISABLE_FILE_FUNCTIONS/IMGUI_DISABLE_DEFAULT_FILE_FUNCTION to nullify or disable - default implementationof ImFileXXX functions linking with fopen/fclose/fread/fwrite. (#2734) + default implementation of ImFileXXX functions linking with fopen/fclose/fread/fwrite. (#2734) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] +- Metrics: Show wire-frame mesh and approximate surface area when hovering ImDrawCmd. [@ShironekoBen] - Metrics: Expose basic details of each window key/value state storage. - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Examples: Emscripten: Removed BINARYEN_TRAP_MODE=clamp from Makefile which was removed in Emscripten 1.39.0 diff --git a/imgui.cpp b/imgui.cpp index ee4385de..923c794c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -45,7 +45,7 @@ CODE // [SECTION] FORWARD DECLARATIONS // [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) -// [SECTION] MISC HELPERS/UTILITIES (Maths, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (Geomtry, String, Format, Hash, File functions) // [SECTION] MISC HELPERS/UTILITIES (File functions) // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) // [SECTION] MISC HELPERS/UTILITIES (Color functions) @@ -1083,7 +1083,7 @@ void ImGuiIO::ClearInputCharacters() } //----------------------------------------------------------------------------- -// [SECTION] MISC HELPERS/UTILITIES (Maths, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions) //----------------------------------------------------------------------------- ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p) @@ -9715,7 +9715,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) static bool show_windows_rects = false; static int show_windows_rect_type = WRT_WorkRect; static bool show_windows_begin_order = false; - static bool show_drawcmd_clip_rects = true; + static bool show_drawcmd_details = true; // Basic info ImGuiContext& g = *GImGui; @@ -9766,7 +9766,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) return; if (window && !window->WasActive) - ImGui::Text("(Note: owning Window is inactive: DrawList is not being rendered!)"); + ImGui::TextDisabled("Warning: owning Window is inactive. This DrawList is not being rendered!"); unsigned int elem_offset = 0; for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) @@ -9780,73 +9780,51 @@ void ImGui::ShowMetricsWindow(bool* p_open) } ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; - - // Calculate approximate coverage area (touched pixel count) - // This will be in pixels squared as long there's no post-scaling happening to the ImGui output - // Optionally also draw all the polys in the list in wireframe when hovering over - - float total_area = 0.0f; - - for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) - { - ImVec2 triangles_pos[3]; - for (int n = 0; n < 3; n++) - { - int vtx_i = idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n); - ImDrawVert& v = draw_list->VtxBuffer[vtx_i]; - triangles_pos[n] = v.pos; - } - - // Calculate triangle area and accumulate - - float area = abs((triangles_pos[0].x * (triangles_pos[1].y - triangles_pos[2].y)) + - (triangles_pos[1].x * (triangles_pos[2].y - triangles_pos[0].y)) + - (triangles_pos[2].x * (triangles_pos[0].y - triangles_pos[1].y))) * 0.5f; - - total_area += area; - } - char buf[300]; - ImFormatString(buf, IM_ARRAYSIZE(buf), "Draw %4d triangles, tex 0x%p, area %.0fpx^2, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)", - pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, total_area, + ImFormatString(buf, IM_ARRAYSIZE(buf), "DrawCmd: %4d triangles, Tex 0x%p, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f)", + pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf); - if (show_drawcmd_clip_rects && fg_draw_list && ImGui::IsItemHovered()) + if (show_drawcmd_details && fg_draw_list && ImGui::IsItemHovered()) { ImRect clip_rect = pcmd->ClipRect; ImRect vtxs_rect; for (unsigned int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); - clip_rect.Floor(); fg_draw_list->AddRect(clip_rect.Min, clip_rect.Max, IM_COL32(255,0,255,255)); - vtxs_rect.Floor(); fg_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, IM_COL32(255,255,0,255)); + fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255,0,255,255)); + fg_draw_list->AddRect(ImFloor(vtxs_rect.Min), ImFloor(vtxs_rect.Max), IM_COL32(255,255,0,255)); } if (!pcmd_node_open) continue; - // Display vertex information summary. Hover to get all triangles drawn in wireframe - ImFormatString(buf, IM_ARRAYSIZE(buf), "ElemCount: %d, ElemCount/3: %d, VtxOffset: +%d, IdxOffset: +%d", pcmd->ElemCount, pcmd->ElemCount/3, pcmd->VtxOffset, pcmd->IdxOffset); - ImGui::Selectable(buf, false); - - if (fg_draw_list && ImGui::IsItemHovered()) + // Calculate approximate coverage area (touched pixel count) + // This will be in pixels squared as long there's no post-scaling happening to the renderer output. + float total_area = 0.0f; + for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) { - // Draw wireframe version of everything + ImVec2 triangle[3]; + for (int n = 0; n < 3; n++) + triangle[n] = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos; + total_area += ImTriangleArea(triangle[0], triangle[1], triangle[2]); + } + // Display vertex information summary. Hover to get all triangles drawn in wire-frame + ImFormatString(buf, IM_ARRAYSIZE(buf), "Mesh: ElemCount: %d, VtxOffset: +%d, IdxOffset: +%d, Area: ~%0.f px", pcmd->ElemCount, pcmd->VtxOffset, pcmd->IdxOffset, total_area); + ImGui::Selectable(buf); + if (fg_draw_list && ImGui::IsItemHovered() && show_drawcmd_details) + { + // Draw wire-frame version of everything ImDrawListFlags backup_flags = fg_draw_list->Flags; - fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles. - + fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles. + ImRect clip_rect = pcmd->ClipRect; + fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255, 0, 255, 255)); for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) { - ImVec2 triangles_pos[3]; + ImVec2 triangle[3]; for (int n = 0; n < 3; n++) - { - int vtx_i = idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n); - ImDrawVert& v = draw_list->VtxBuffer[vtx_i]; - triangles_pos[n] = v.pos; - } - - fg_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); + triangle[n] = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos; + fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); } - fg_draw_list->Flags = backup_flags; } @@ -9856,22 +9834,21 @@ void ImGui::ShowMetricsWindow(bool* p_open) for (int prim = clipper.DisplayStart, idx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++) { char *buf_p = buf, *buf_end = buf + IM_ARRAYSIZE(buf); - ImVec2 triangles_pos[3]; + ImVec2 triangle[3]; for (int n = 0; n < 3; n++, idx_i++) { - int vtx_i = idx_buffer ? idx_buffer[idx_i] : idx_i; - ImDrawVert& v = draw_list->VtxBuffer[vtx_i]; - triangles_pos[n] = v.pos; + ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[idx_i] : idx_i]; + triangle[n] = v.pos; buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n", - (n == 0) ? "elem" : " ", idx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col); + (n == 0) ? "Vert:" : " ", idx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col); } ImGui::Selectable(buf, false); if (fg_draw_list && ImGui::IsItemHovered()) { ImDrawListFlags backup_flags = fg_draw_list->Flags; - fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles. - fg_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f); + fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles. + fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255,255,0,255), true, 1.0f); fg_draw_list->Flags = backup_flags; } } @@ -10058,7 +10035,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) } ImGui::Unindent(); } - ImGui::Checkbox("Show clipping rectangle when hovering ImDrawCmd node", &show_drawcmd_clip_rects); + ImGui::Checkbox("Show details when hovering ImDrawCmd node", &show_drawcmd_details); ImGui::TreePop(); } diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4091bcfe..1a296784 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3421,7 +3421,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar); ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar, font->EllipsisChar); const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface); - ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt); + ImGui::Text("Texture Area: about %d px ~%dx%d px", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt); for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) if (const ImFontConfig* cfg = &font->ConfigData[config_i]) ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH); diff --git a/imgui_internal.h b/imgui_internal.h index 405bea26..33730c1e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -194,11 +194,11 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer //----------------------------------------------------------------------------- // - Helpers: Misc // - Helpers: Bit manipulation -// - Helpers: Geometry // - Helpers: String, Formatting // - Helpers: UTF-8 <> wchar conversions // - Helpers: ImVec2/ImVec4 operators // - Helpers: Maths +// - Helpers: Geometry // - Helper: ImBoolVector // - Helper: ImPool<> // - Helper: ImChunkStream<> @@ -216,13 +216,6 @@ static inline ImU32 ImHash(const void* data, int size, ImU32 seed = 0) { ret static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } -// Helpers: Geometry -IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); -IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); -IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); -IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); -IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); - // Helpers: String, Formatting IMGUI_API int ImStricmp(const char* str1, const char* str2); IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); @@ -343,6 +336,14 @@ static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; } static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } +// Helpers: Geometry +IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); +IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); +IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); +IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w); +inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; } +IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); + // Helper: ImBoolVector // Store 1-bit per value. Note that Resize() currently clears the whole vector. struct IMGUI_API ImBoolVector From 1615e9ea2a3eff1c0fc755c26f85b2969e065332 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 25 Nov 2019 14:02:47 +0200 Subject: [PATCH 147/384] CI: Enable extended warnings in example_null builds. CI: Add MinGW build with extra warnings on windows. (cherry picked from commit ebc98c273054d0f9b305a1346db98052616a8b21) --- .github/workflows/build.yml | 11 +++++++---- examples/example_null/Makefile | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86f5de6e..60f8f642 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,9 @@ jobs: } # Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long. + - name: Build example_null (extra warnings) + run: mingw32-make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build Win32 example_glfw_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' @@ -150,8 +153,8 @@ jobs: sudo apt-get update sudo apt-get install -y libglfw3-dev libsdl2-dev - - name: Build example_null - run: make -C examples/example_null + - name: Build example_null (extra warnings) + run: make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 @@ -179,8 +182,8 @@ jobs: brew install glfw3 brew install sdl2 - - name: Build example_null - run: make -C examples/example_null + - name: Build example_null (extra warnings) + run: make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 012758fe..909f1982 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -8,27 +8,42 @@ SOURCES = main.cpp SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) +EXTRA_WARNINGS ?= 0 CXXFLAGS = -I../ -I../../ CXXFLAGS += -g -Wall -Wformat LIBS = +# We use the EXTRA_WARNINGS flag on our CI setup to eagerly catch zealous warnings +ifeq ($(EXTRA_WARNINGS), 1) + CXXFLAGS += -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros +endif + ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM ##--------------------------------------------------------------------- ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" + ifneq ($(EXTRA_WARNINGS), 0) + CXXFLAGS += -Wextra -pedantic + endif CFLAGS = $(CXXFLAGS) endif ifeq ($(UNAME_S), Darwin) #APPLE ECHO_MESSAGE = "Mac OS X" + ifneq ($(EXTRA_WARNINGS), 0) + CXXFLAGS += -Weverything -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-padded -Wno-c++11-long-long + endif CFLAGS = $(CXXFLAGS) endif ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) ECHO_MESSAGE = "MinGW" + ifneq ($(EXTRA_WARNINGS), 0) + CXXFLAGS += -Wextra -pedantic + endif CFLAGS = $(CXXFLAGS) endif From 26d177bc039d3dd901f590c3487aee8065800ddf Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 25 Nov 2019 18:29:28 +0100 Subject: [PATCH 148/384] Docs: Moved misc/fonts/README.txt to docs/FONTS.txt. + tweaks --- docs/CHANGELOG.txt | 1 + docs/FAQ.md | 8 +- misc/fonts/README.txt => docs/FONTS.txt | 151 ++++++++++++---------- examples/example_allegro5/main.cpp | 2 +- examples/example_apple_opengl2/main.mm | 2 +- examples/example_emscripten/main.cpp | 2 +- examples/example_glfw_metal/main.mm | 2 +- examples/example_glfw_opengl2/main.cpp | 2 +- examples/example_glfw_opengl3/main.cpp | 2 +- examples/example_glfw_vulkan/main.cpp | 2 +- examples/example_glut_opengl2/main.cpp | 2 +- examples/example_marmalade/main.cpp | 2 +- examples/example_sdl_directx11/main.cpp | 2 +- examples/example_sdl_opengl2/main.cpp | 2 +- examples/example_sdl_opengl3/main.cpp | 2 +- examples/example_sdl_vulkan/main.cpp | 2 +- examples/example_win32_directx10/main.cpp | 2 +- examples/example_win32_directx11/main.cpp | 2 +- examples/example_win32_directx12/main.cpp | 2 +- examples/example_win32_directx9/main.cpp | 2 +- imgui.cpp | 2 +- imgui.h | 2 +- imgui_demo.cpp | 12 +- 23 files changed, 113 insertions(+), 97 deletions(-) rename misc/fonts/README.txt => docs/FONTS.txt (87%) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bbd9b044..cb9e540a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -86,6 +86,7 @@ Other Changes: - Misc: Added IMGUI_DISABLE_FILE_FUNCTIONS/IMGUI_DISABLE_DEFAULT_FILE_FUNCTION to nullify or disable default implementation of ImFileXXX functions linking with fopen/fclose/fread/fwrite. (#2734) - Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut] +- Docs: Moved misc/fonts/README.txt to docs/FONTS.txt. - Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page. - Demo: Added simple item reordering demo in Widgets -> Drag and Drop section. (#2823, #143) [@rokups] - Metrics: Show wire-frame mesh and approximate surface area when hovering ImDrawCmd. [@ShironekoBen] diff --git a/docs/FAQ.md b/docs/FAQ.md index 6430f678..052cfd26 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -436,7 +436,7 @@ Default is ProggyClean.ttf, monospace, rendered at size 13, embedded in dear img (Tip: monospace fonts are convenient because they allow to facilitate horizontal alignment directly at the string level.) -(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file for more details about font loading.) +(Read the [docs/FONTS.txt](https://github.com/ocornut/imgui/blob/master/docs/FONTS.txt) file for more details about font loading.) New programmers: remember that in C/C++ and most programming languages if you want to use a backslash \ within a string literal, you need to write it double backslash "\\": @@ -453,15 +453,15 @@ io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT The most convenient and practical way is to merge an icon font such as FontAwesome inside you main font. Then you can refer to icons within your strings. You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment. -(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file for more details about icons font loading.) +(Read the [docs/FONTS.txt](https://github.com/ocornut/imgui/blob/master/docs/FONTS.txt) file for more details about icons font loading.) With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, -and copying your own graphics data into it. See misc/fonts/README.txt about using the AddCustomRectFontGlyph API. +and copying your own graphics data into it. See docs/FONTS.txt about using the AddCustomRectFontGlyph API. --- ### Q: How can I load multiple fonts? Use the font atlas to pack them into a single texture: -(Read the [misc/fonts/README.txt](https://github.com/ocornut/imgui/blob/master/misc/fonts/README.txt) file and the code in ImFontAtlas for more details.) +(Read the [docs/FONTS.txt](https://github.com/ocornut/imgui/blob/master/docs/FONTS.txt) file and the code in ImFontAtlas for more details.) ```cpp ImGuiIO& io = ImGui::GetIO(); diff --git a/misc/fonts/README.txt b/docs/FONTS.txt similarity index 87% rename from misc/fonts/README.txt rename to docs/FONTS.txt index 0f335c7d..14947970 100644 --- a/misc/fonts/README.txt +++ b/docs/FONTS.txt @@ -1,8 +1,9 @@ ---------------------------------------------------------------------- dear imgui, v1.74 WIP ---------------------------------------------------------------------- - misc/fonts/README.txt + docs/FONTS.txt This is the Readme dedicated to fonts. + Also read https://www.dearimgui.org/faq for more ideas. ---------------------------------------------------------------------- The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' (by Tristan Grimmer), @@ -12,7 +13,6 @@ We embed it font in source code so you can use Dear ImGui without any file syste You may also load external .TTF/.OTF files. The files in this folder are suggested fonts, provided as a convenience. -Fonts are rasterized in a single texture at the time of calling either of io.Fonts->GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). Please read the FAQ: https://www.dearimgui.org/faq Please use the Discord server: http://discord.dearimgui.org and not the Github issue tracker for basic font loading questions. @@ -22,13 +22,13 @@ Please use the Discord server: http://discord.dearimgui.org and not the Github i --------------------------------------- - Readme First / FAQ -- Using Icons - Fonts Loading Instructions -- FreeType rasterizer, Small font sizes +- Using Icons +- Using FreeType rasterizer - Building Custom Glyph Ranges - Using custom colorful icons - Embedding Fonts in Source Code -- Credits/Licences for fonts included in this folder +- Credits/Licences for fonts included in repository - Fonts Links @@ -38,52 +38,13 @@ Please use the Discord server: http://discord.dearimgui.org and not the Github i - You can use the style editor ImGui::ShowStyleEditor() in the "Fonts" section to browse your fonts and understand what's going on if you have an issue. -- Make sure your font ranges data are persistent (available during the call to GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). +- Fonts are rasterized in a single texture at the time of calling either of io.Fonts->GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). +- Make sure your font ranges data are persistent and available at the time the font atlas is being built. - Use C++11 u8"my text" syntax to encode literal strings as UTF-8. e.g.: u8"hello" u8"こんにちは" // this will be encoded as UTF-8 - If you want to include a backslash \ character in your string literal, you need to double them e.g. "folder\\filename". - - ---------------------------------------- - USING ICONS ---------------------------------------- - -Using an icon font (such as FontAwesome: http://fontawesome.io or OpenFontIcons. https://github.com/traverseda/OpenFontIcons) -is an easy and practical way to use icons in your Dear ImGui application. -A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without -having to change fonts back and forth. - -To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut: - https://github.com/juliettef/IconFontCppHeaders - -The C++11 version of those files uses the u8"" utf-8 encoding syntax + \u - #define ICON_FA_SEARCH u8"\uf002" -The pre-C++11 version has the values directly encoded as utf-8: - #define ICON_FA_SEARCH "\xEF\x80\x82" - -Example Setup: - - // Merge icons into default tool font - #include "IconsFontAwesome.h" - ImGuiIO& io = ImGui::GetIO(); - io.Fonts->AddFontDefault(); - - ImFontConfig config; - config.MergeMode = true; - config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced - static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; - io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges); - -Example Usage: - - // Usage, e.g. - ImGui::Text("%s among %d items", ICON_FA_SEARCH, count); - ImGui::Button(ICON_FA_SEARCH " Search"); - // C string _literals_ can be concatenated at compilation time, e.g. "hello" " world" - // ICON_FA_SEARCH is defined as a string literal so this is the same as "A" "B" becoming "AB" - -See Links below for other icons fonts and related tools. + Read FAQ for details. --------------------------------------- @@ -97,6 +58,11 @@ Load default font: Load .TTF/.OTF file with: + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); + +Load multiple fonts: + ImGuiIO& io = ImGui::GetIO(); ImFont* font1 = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); ImFont* font2 = io.Fonts->AddFontFromFileTTF("anotherfont.otf", size_pixels); @@ -115,23 +81,6 @@ For advanced options create a ImFontConfig structure and pass it to the AddFont config.GlyphExtraSpacing.x = 1.0f; ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); -Read about oversampling here: - https://github.com/nothings/stb/blob/master/tests/oversample - -If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API. -The typical result of failing to upload a texture is if every glyphs appears as white rectangles. -In particular, using a large range such as GetGlyphRangesChineseSimplifiedCommon() is not recommended unless you -set OversampleH/OversampleV to 1 and use a small font size. -Mind the fact that some graphics drivers have texture size limitation. -If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours. -Some solutions: - - - 1) Reduce glyphs ranges by calculating them from source localization data. - You can use ImFontGlyphRangesBuilder for this purpose, this will be the biggest win! - - 2) You may reduce oversampling, e.g. config.OversampleH = config.OversampleV = 1, this will largely reduce your texture size. - - 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function). - - 4) Set io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; to disable rounding the texture height to the next power of two. - Combine two fonts into one: // Load a first font @@ -147,6 +96,25 @@ Combine two fonts into one: io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges); io.Fonts->Build(); +Font atlas is too large? + +- If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API. +- The typical result of failing to upload a texture is if every glyphs appears as white rectangles. +- In particular, using a large range such as GetGlyphRangesChineseSimplifiedCommon() is not recommended + unless you set OversampleH/OversampleV to 1 and use a small font size. +- Mind the fact that some graphics drivers have texture size limitation. +- If you are building a PC application, mind the fact that users may run on hardware with lower specs than yours. + +Some solutions: + + - 1) Reduce glyphs ranges by calculating them from source localization data. + You can use ImFontGlyphRangesBuilder for this purpose, this will be the biggest win! + - 2) You may reduce oversampling, e.g. config.OversampleH = config.OversampleV = 1, this will largely reduce your texture size. + - 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function). + - 4) Set io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; to disable rounding the texture height to the next power of two. + - Read about oversampling here: https://github.com/nothings/stb/blob/master/tests/oversample + + Add a fourth parameter to bake specific font ranges only: // Basic Latin, Extended Latin @@ -165,6 +133,49 @@ Offset font vertically by altering the io.Font->DisplayOffset value: font->DisplayOffset.y = 1; // Render 1 pixel down +--------------------------------------- + USING ICONS +--------------------------------------- + +Using an icon font (such as FontAwesome: http://fontawesome.io or OpenFontIcons. https://github.com/traverseda/OpenFontIcons) +is an easy and practical way to use icons in your Dear ImGui application. +A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without +having to change fonts back and forth. + +To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut: + + https://github.com/juliettef/IconFontCppHeaders + +Those files contains a bunch of named #define which you can use to refer to specific icons of the font, e.g.: + + #define ICON_FA_MUSIC "\xef\x80\x81" + #define ICON_FA_SEARCH "\xef\x80\x82" + +Example Setup: + + // Merge icons into default tool font + #include "IconsFontAwesome.h" + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->AddFontDefault(); + + ImFontConfig config; + config.MergeMode = true; + config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced + static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; + io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges); + +Example Usage: + + // Usage, e.g. + ImGui::Text("%s among %d items", ICON_FA_SEARCH, count); + ImGui::Button(ICON_FA_SEARCH " Search"); + +Important to understand: C string _literals_ can be concatenated at compilation time, e.g. "hello" " world" +ICON_FA_SEARCH is defined as a string literal so this is the same as "A" "B" becoming "AB" + +See Links below for other icons fonts and related tools. + + --------------------------------------- FREETYPE RASTERIZER, SMALL FONT SIZES --------------------------------------- @@ -258,9 +269,11 @@ or: --------------------------------------- - CREDITS/LICENSES FOR FONTS INCLUDED IN THIS FOLDER + CREDITS/LICENSES FOR FONTS INCLUDED IN REPOSITORY --------------------------------------- +Some fonts are available in the misc/fonts/ folder: + Roboto-Medium.ttf Apache License 2.0 @@ -333,15 +346,17 @@ REGULAR FONTS (Japanese) M+ fonts by Coji Morishita are free http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html -MONOSPACE FONTS +MONOSPACE FONTS (PIXEL PERFECT) - (Pixel Perfect) Proggy Fonts, by Tristan Grimmer + Proggy Fonts, by Tristan Grimmer http://www.proggyfonts.net or http://upperbounds.net - (Pixel Perfect) Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) + Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) https://github.com/kmar/Sweet16Font Also include .inl file to use directly in dear imgui. +MONOSPACE FONTS (REGULAR) + Google Noto Mono Fonts https://www.google.com/get/noto/ diff --git a/examples/example_allegro5/main.cpp b/examples/example_allegro5/main.cpp index 59e19370..5a026840 100644 --- a/examples/example_allegro5/main.cpp +++ b/examples/example_allegro5/main.cpp @@ -40,7 +40,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_apple_opengl2/main.mm b/examples/example_apple_opengl2/main.mm index 72f934a3..e8f2768b 100644 --- a/examples/example_apple_opengl2/main.mm +++ b/examples/example_apple_opengl2/main.mm @@ -253,7 +253,7 @@ // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_emscripten/main.cpp b/examples/example_emscripten/main.cpp index 5679d08d..d9a6406d 100644 --- a/examples/example_emscripten/main.cpp +++ b/examples/example_emscripten/main.cpp @@ -81,7 +81,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 3a25a9de..959846a4 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -38,7 +38,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 4b4a5fe3..5630b6c3 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -59,7 +59,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 4833d1b0..a658ec86 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -103,7 +103,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index fb92bad8..910d4738 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -400,7 +400,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 75e48ca2..34c26dbe 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -125,7 +125,7 @@ int main(int argc, char** argv) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_marmalade/main.cpp b/examples/example_marmalade/main.cpp index 27a4acd9..82435f20 100644 --- a/examples/example_marmalade/main.cpp +++ b/examples/example_marmalade/main.cpp @@ -34,7 +34,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index b6345bd1..812b40f4 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -69,7 +69,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 9a0f07c6..b55cb22f 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -57,7 +57,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 03cd3a7b..2220537d 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -98,7 +98,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index 1969b452..c4e529e1 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -384,7 +384,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index d05268aa..024e5eb7 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -62,7 +62,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 0a8f09b2..fe462e74 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -62,7 +62,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 968ef7d9..87235125 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -94,7 +94,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index 9e8dba95..3586bd6f 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -60,7 +60,7 @@ int main(int, char**) // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. - // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! //io.Fonts->AddFontDefault(); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); diff --git a/imgui.cpp b/imgui.cpp index 923c794c..bfb60bd2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -746,7 +746,7 @@ CODE Q: How can I easily use icons in my application? Q: How can I load multiple fonts? Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? - >> See https://www.dearimgui.org/faq and misc/fonts/README.txt + >> See https://www.dearimgui.org/faq and docs/FONTS.txt Q&A: Community ============== diff --git a/imgui.h b/imgui.h index 27982042..e73ac3e2 100644 --- a/imgui.h +++ b/imgui.h @@ -2144,7 +2144,7 @@ struct ImFontAtlas // After calling Build(), you can query the rectangle position and render your pixels. // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), // so you can render e.g. custom colorful icons and use them as regular glyphs. - // Read misc/fonts/README.txt for more details about using colorful icons. + // Read docs/FONTS.txt for more details about using colorful icons. IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x110000. Id >= 0x80000000 are reserved for ImGui and ImDrawList IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x110000 to register a rectangle to map into a specific font. const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 1a296784..2bcab47b 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -137,7 +137,7 @@ static void ShowExampleAppCustomRendering(bool* p_open); static void ShowExampleMenuFile(); // Helper to display a little (?) mark which shows a tooltip when hovered. -// In your own code you may want to display an actual icon if you are using a merged icon fonts (see misc/fonts/README.txt) +// In your own code you may want to display an actual icon if you are using a merged icon fonts (see docs/FONTS.txt) static void HelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); @@ -770,14 +770,14 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("UTF-8 Text")) { // UTF-8 test with Japanese characters - // (Needs a suitable font, try Noto, or Arial Unicode, or M+ fonts. Read misc/fonts/README.txt for details.) + // (Needs a suitable font, try Noto, or Arial Unicode, or M+ fonts. Read docs/FONTS.txt for details.) // - From C++11 you can use the u8"my text" syntax to encode literal strings as UTF-8 // - For earlier compiler, you may be able to encode your sources as UTF-8 (e.g. Visual Studio save your file as 'UTF-8 without signature') // - FOR THIS DEMO FILE ONLY, BECAUSE WE WANT TO SUPPORT OLD COMPILERS, WE ARE *NOT* INCLUDING RAW UTF-8 CHARACTERS IN THIS SOURCE FILE. // Instead we are encoding a few strings with hexadecimal constants. Don't do this in your application! // Please use u8"text in any language" in your application! // Note that characters values are preserved even by InputText() if the font cannot be displayed, so you can safely copy & paste garbled characters into another application. - ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->AddFontFromFileTTF() manually to load extra character ranges. Read misc/fonts/README.txt for details."); + ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->AddFontFromFileTTF() manually to load extra character ranges. Read docs/FONTS.txt for details."); ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)"); // Normally we would use u8"blah blah" with the proper characters directly in the string. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)"); static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"; @@ -3255,7 +3255,7 @@ void ImGui::ShowFontSelector(const char* label) HelpMarker( "- Load additional fonts with io.Fonts->AddFontFromFileTTF().\n" "- The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build().\n" - "- Read FAQ and documentation in misc/fonts/ for more details.\n" + "- Read FAQ and docs/FONTS.txt for more details.\n" "- If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame()."); } @@ -3383,7 +3383,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) if (memcmp(&style.Colors[i], &ref->Colors[i], sizeof(ImVec4)) != 0) { // Tips: in a real user application, you may want to merge and use an icon font into the main font, so instead of "Save"/"Revert" you'd use icons. - // Read the FAQ and misc/fonts/README.txt about using icon fonts. It's really easy and super convenient! + // Read the FAQ and docs/FONTS.txt about using icon fonts. It's really easy and super convenient! ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); if (ImGui::Button("Revert")) style.Colors[i] = ref->Colors[i]; } @@ -3401,7 +3401,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) { ImGuiIO& io = ImGui::GetIO(); ImFontAtlas* atlas = io.Fonts; - HelpMarker("Read FAQ and misc/fonts/README.txt for details on font loading."); + HelpMarker("Read FAQ and docs/FONTS.txt for details on font loading."); ImGui::PushItemWidth(120); for (int i = 0; i < atlas->Fonts.Size; i++) { From bdce8336364595d1a446957a6164c97363349a53 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 25 Nov 2019 18:38:53 +0100 Subject: [PATCH 149/384] Version 1.74 --- docs/CHANGELOG.txt | 2 +- docs/FONTS.txt | 11 ++++------- examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 2 +- misc/fonts/binary_to_compressed_c.cpp | 3 ++- 10 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index cb9e540a..7232b97e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,7 +30,7 @@ HOW TO UPDATE? ----------------------------------------------------------------------- - VERSION 1.74 WIP (In Progress) + VERSION 1.74 (Released 2019-11-25) ----------------------------------------------------------------------- Breaking Changes: diff --git a/docs/FONTS.txt b/docs/FONTS.txt index 14947970..e3690f14 100644 --- a/docs/FONTS.txt +++ b/docs/FONTS.txt @@ -1,10 +1,7 @@ ----------------------------------------------------------------------- - dear imgui, v1.74 WIP ----------------------------------------------------------------------- - docs/FONTS.txt - This is the Readme dedicated to fonts. - Also read https://www.dearimgui.org/faq for more ideas. ----------------------------------------------------------------------- +dear imgui +FONTS DOCUMENTATION + +Also read https://www.dearimgui.org/faq for more fonts related infos. The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' (by Tristan Grimmer), a 13 pixels high, pixel-perfect font used by default. diff --git a/examples/README.txt b/examples/README.txt index 2c73c89d..cf605ad1 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.74 WIP + dear imgui, v1.74 ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index bfb60bd2..c2b489ad 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (main code and documentation) // Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. diff --git a/imgui.h b/imgui.h index e73ac3e2..9fcdaeaa 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (headers) // See imgui.cpp file for documentation. @@ -47,8 +47,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.74 WIP" -#define IMGUI_VERSION_NUM 17301 +#define IMGUI_VERSION "1.74" +#define IMGUI_VERSION_NUM 17400 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 2bcab47b..7e475992 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (demo code) // Message to the person tempted to delete this file when integrating Dear ImGui into their code base: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1efb2cb4..8089bbef 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index 33730c1e..73880098 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! @@ -156,7 +156,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #endif // "Paranoid" Debug Asserts are meant to only be enabled during specific debugging/work, otherwise would slow down the code too much. -#define IMGUI_DEBUG_PARANOID 1 +#define IMGUI_DEBUG_PARANOID 0 #if IMGUI_DEBUG_PARANOID #define IM_ASSERT_PARANOID(_EXPR) IM_ASSERT(_EXPR) #else diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0c5a1967..ec6f51a9 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 WIP +// dear imgui, v1.74 // (widgets code) /* diff --git a/misc/fonts/binary_to_compressed_c.cpp b/misc/fonts/binary_to_compressed_c.cpp index 27569537..4c6f1200 100644 --- a/misc/fonts/binary_to_compressed_c.cpp +++ b/misc/fonts/binary_to_compressed_c.cpp @@ -1,4 +1,5 @@ -// ImGui - binary_to_compressed_c.cpp +// dear imgui +// (binary_to_compressed_c.cpp) // Helper tool to turn a file into a C array, if you want to embed font data in your source code. // The data is first compressed with stb_compress() to reduce source code size, From f60518b430d9d1974949594dec576cf39aac085f Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 26 Nov 2019 16:28:49 +0100 Subject: [PATCH 150/384] Update FAQ.md --- docs/FAQ.md | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 052cfd26..c777d87f 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -44,11 +44,10 @@ or view this file with any Markdown viewer. ### Q: Where is the documentation? **This library is poorly documented at the moment and expects of the user to be acquainted with C/C++.** -- Run the examples/ and explore them. -- See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. -- The demo covers most features of Dear ImGui, so you can read the code and see its output. +- Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. You can run those applications and explore them. +- See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. The demo covers most features of Dear ImGui, so you can read the code and see its output. - See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h). -- Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder to explain how to integrate Dear ImGui with your own engine/application. +- The [Wiki](https://github.com/ocornut/imgui/wiki) has many resources and links. - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. --- @@ -131,13 +130,14 @@ e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` ### Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) - You can control Dear ImGui with a gamepad. Read about navigation in "Using gamepad/keyboard navigation controls". (short version: map gamepad inputs into the io.NavInputs[] array + set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad`). +- See navigation [control sheets for gamepads](http://www.dearimgui.org/controls_sheets) (for PS4, XB1, Switch gamepads). - You can share your computer mouse seamlessly with your console/tablet/phone using [Synergy](https://symless.com/synergy) This is the preferred solution for developer productivity. In particular, the [micro-synergy-client repository](https://github.com/symless/micro-synergy-client) has simple and portable source code (uSynergy.c/.h) for a small embeddable client that you can use on any platform to connect to your host computer, based on the Synergy 1.x protocol. Make sure you download the Synergy 1 server on your computer. Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-like protocols. -- You may also use a third party solution such as [Remote ImGui](https://github.com/JordiRos/remoteimgui) or [imgui-ws](https://github.com/ggerganov/imgui-ws) which sends the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. See Wiki index for most details. +- You may also use a third party solution such as [Remote ImGui](https://github.com/JordiRos/remoteimgui) or [imgui-ws](https://github.com/ggerganov/imgui-ws) which sends the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. See [Wiki](https://github.com/ocornut/imgui/wiki) index for most details. - For touch inputs, you can increase the hit box of widgets (via the `style.TouchPadding` setting) to accommodate for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing for screen real-estate and precision. @@ -283,7 +283,7 @@ node open/closed state differently. See what makes more sense in your situation! ### Q: How can I display an image? What is ImTextureID, how does it work? Short explanation: -- Please read Wiki entry for examples: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples +- Refer to [Image Loading and Displaying Examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples) on the [Wiki](https://github.com/ocornut/imgui/wiki). - You may use functions such as `ImGui::Image()`, `ImGui::ImageButton()` or lower-level `ImDrawList::AddImage()` to emit draw calls that will use your own textures. - Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value. - Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). @@ -301,15 +301,18 @@ Dear ImGui doesn't know or understand what you are storing in ImTextureID, it me OpenGL: - ImTextureID = GLuint - See ImGui_ImplOpenGL3_RenderDrawData() function in imgui_impl_opengl3.cpp - +``` +``` DirectX9: - ImTextureID = LPDIRECT3DTEXTURE9 - See ImGui_ImplDX9_RenderDrawData() function in imgui_impl_dx9.cpp - +``` +``` DirectX11: - ImTextureID = ID3D11ShaderResourceView* - See ImGui_ImplDX11_RenderDrawData() function in imgui_impl_dx11.cpp - +``` +``` DirectX12: - ImTextureID = D3D12_GPU_DESCRIPTOR_HANDLE - See ImGui_ImplDX12_RenderDrawData() function in imgui_impl_dx12.cpp @@ -337,7 +340,7 @@ Once you understand this design you will understand that loading image files and This is by design and is actually a good thing, because it means your code has full control over your data types and how you display them. If you want to display an image file (e.g. PNG file) into the screen, please refer to documentation and tutorials for the graphics API you are using. -Refer to the Wiki to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples +Refer to [Image Loading and Displaying Examples](https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples) on the [Wiki](https://github.com/ocornut/imgui/wiki) to find simplified examples for loading textures with OpenGL, DirectX9 and DirectX11. C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa. Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*. @@ -442,7 +445,7 @@ New programmers: remember that in C/C++ and most programming languages if you wa backslash \ within a string literal, you need to write it double backslash "\\": ```c -io.Fonts->AddFontFromFileTTF("MyFolder\MyFont.ttf", size); // WRONG (you are escape the M here!) +io.Fonts->AddFontFromFileTTF("MyFolder\MyFont.ttf", size); // WRONG (you are escaping the M here!) io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size; // CORRECT io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT ``` @@ -452,7 +455,7 @@ io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT ### Q: How can I easily use icons in my application? The most convenient and practical way is to merge an icon font such as FontAwesome inside you main font. Then you can refer to icons within your strings. -You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment. +You may want to see `ImFontConfig::GlyphMinAdvanceX` to make your icon look monospace to facilitate alignment. (Read the [docs/FONTS.txt](https://github.com/ocornut/imgui/blob/master/docs/FONTS.txt) file for more details about icons font loading.) With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, and copying your own graphics data into it. See docs/FONTS.txt about using the AddCustomRectFontGlyph API. @@ -513,7 +516,7 @@ by using the u8"hello" syntax. Specifying literal in your source code using a lo (such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8. -Text input: it is up to your application to pass the right character code by calling io.AddInputCharacter(). +Text input: it is up to your application to pass the right character code by calling `io.AddInputCharacter()`. The applications in examples/ are doing that. Windows: you can use the WM_CHAR or WM_UNICHAR or WM_IME_CHAR message (depending if your app is built using Unicode or MultiByte mode). You may also use MultiByteToWideChar() or ToUnicode() to retrieve Unicode codepoints from MultiByte characters or keyboard state. @@ -529,8 +532,8 @@ the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft - Businesses: convince your company to fund development via support contracts/sponsoring! This is among the most useful thing you can do for Dear ImGui. With increased funding we will be able to hire more people working on this project. - Individuals: you can also become a [Patron](http://www.patreon.com/imgui) or donate on PayPal! See README. - Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. -You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. -But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. -- If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete pR. +You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. Disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. +- If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete PR. ##### [Return to Index](#index) + From 1c3a9c8e7452ae491143c5210dba70ef9b311460 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 26 Nov 2019 20:25:54 +0100 Subject: [PATCH 151/384] Docking: Remove Size > 0.0f asserts added in 718e15c7 and 7c183dc6. (#2690, #2109, #2906) In #2906 the zero input came from a minimized viewport, but even without it we cannot prevent DockNode size from eventually reaching zero as padding are taken from the starting size. In a separate commit we'll however shortcut some of the existing codepath on zero-sized viewport to reduce the likehood of lossy side-effects (just like we don't call ClampWindowRect in Begin) --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1aae6351..e04267e8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13278,7 +13278,6 @@ void ImGui::DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 si { // During the regular dock node update we write to all nodes. // 'only_write_to_marked_nodes' is only set when turning a node visible mid-frame and we need its size right-away. - IM_ASSERT(size.x > 0.0f && size.y > 0.0f); const bool write_to_node = (only_write_to_marked_nodes == false) || (node->MarkedForPosSizeWrite); if (write_to_node) { @@ -14223,9 +14222,10 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) return; } + // We can have zero-sized nodes (e.g. children of a small-size dockspace) IM_ASSERT(node->HostWindow); IM_ASSERT(node->IsLeafNode()); - IM_ASSERT(node->Size.x > 0.0f && node->Size.y > 0.0f); + IM_ASSERT(node->Size.x >= 0.0f && node->Size.y >= 0.0f); node->State = ImGuiDockNodeState_HostWindowVisible; // Undock if we are submitted earlier than the host window From 3096e7a9cd25946a2bd5f526e15d482cc98c9124 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 26 Nov 2019 21:02:28 +0100 Subject: [PATCH 152/384] Viewports: Preserve last known size for minimized main viewport to be consistent with secondary viewports. Amend 606175b9, d8ab2c1a. However becomes inconsistent with viewport-enabled setup. Should report some of that logic in master, need back-end rework. --- imgui.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e04267e8..374f5a90 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10476,7 +10476,8 @@ static void ImGui::UpdateViewportsNewFrame() IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size); // Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport) - if ((g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) + const bool viewports_enabled = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != 0; + if (viewports_enabled) { for (int n = 0; n < g.Viewports.Size; n++) { @@ -10493,15 +10494,19 @@ static void ImGui::UpdateViewportsNewFrame() } } - // Create/update main viewport with current platform position and size + // Create/update main viewport with current platform position. + // FIXME-VIEWPORT: Size is driven by back-end/user code for backward-compatibility but we should aim to make this more consistent. ImGuiViewportP* main_viewport = g.Viewports[0]; IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID); IM_ASSERT(main_viewport->Window == NULL); - ImVec2 main_viewport_platform_pos = ImVec2(0.0f, 0.0f); - ImVec2 main_viewport_platform_size = g.IO.DisplaySize; - if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) - main_viewport_platform_pos = (main_viewport->Flags & ImGuiViewportFlags_Minimized) ? main_viewport->Pos : g.PlatformIO.Platform_GetWindowPos(main_viewport); - AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_platform_pos, main_viewport_platform_size, ImGuiViewportFlags_CanHostOtherWindows); + ImVec2 main_viewport_pos = viewports_enabled ? g.PlatformIO.Platform_GetWindowPos(main_viewport) : ImVec2(0.0f, 0.0f); + ImVec2 main_viewport_size = g.IO.DisplaySize; + if (viewports_enabled && (main_viewport->Flags & ImGuiViewportFlags_Minimized)) + { + main_viewport_pos = main_viewport->Pos; // Preserve last pos/size when minimized (FIXME: We don't do the same for Size outside of the viewport path) + main_viewport_size = main_viewport->Size; + } + AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_pos, main_viewport_size, ImGuiViewportFlags_CanHostOtherWindows); g.CurrentDpiScale = 0.0f; g.CurrentViewport = NULL; @@ -10535,7 +10540,7 @@ static void ImGui::UpdateViewportsNewFrame() } const bool platform_funcs_available = viewport->PlatformWindowCreated; - if ((g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) + if (viewports_enabled) { // Update Position and Size (from Platform Window to ImGui) if requested. // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities. @@ -10585,7 +10590,7 @@ static void ImGui::UpdateViewportsNewFrame() viewport->DpiScale = new_dpi_scale; } - if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) + if (!viewports_enabled) { g.MouseViewport = main_viewport; return; From a8092085b1984cdb69d20899f7d127c8fccf3cb2 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Nov 2019 14:02:05 +0100 Subject: [PATCH 153/384] Internal: Added unused parameter named to facilitate cimgui parsing of imgui_internal.h https://github.com/cimgui/cimgui/issues/108 --- imgui_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index 73880098..a0728217 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1600,7 +1600,7 @@ namespace ImGui IMGUI_API void SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } - inline ImDrawList* GetForegroundDrawList(ImGuiWindow*) { ImGuiContext& g = *GImGui; return &g.ForegroundDrawList; } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. + inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { IM_UNUSED(window); ImGuiContext& g = *GImGui; return &g.ForegroundDrawList; } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. // Init IMGUI_API void Initialize(ImGuiContext* context); From 8d1b82d5961a03021b1cc3c6ce8bedeb1a846be4 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Nov 2019 15:33:31 +0100 Subject: [PATCH 154/384] Docking: Internals: Rename StartMouseDragFromTitleBar() -> StartMouseMovingWindowOrNode(), clarify. --- imgui.cpp | 45 ++++++++++++++++++++++++++------------------- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 374f5a90..42e10aef 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3296,26 +3296,32 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window) g.MovingWindow = window; } -void ImGui::StartMouseDragFromTitleBar(ImGuiWindow* window, ImGuiDockNode* node, bool from_collapse_button) +// We use 'undock_floating_node == false' when dragging from title bar to allow moving groups of floating nodes without undocking them. +// - undock_floating_node == true: when dragging from a floating node within a hierarchy, always undock the node. +// - undock_floating_node == false: when dragging from a floating node within a hierarchy, move root window. +void ImGui::StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* node, bool undock_floating_node) { ImGuiContext& g = *GImGui; - bool can_extract_dock_node = false; + bool can_undock_node = false; if (node != NULL && node->VisibleWindow && (node->VisibleWindow->Flags & ImGuiWindowFlags_NoMove) == 0) { + // Can undock if: + // - part of a floating node hierarchy with more than one visible node (if only one is visible, we'll just move the whole hierarchy) + // - part of a dockspace node hierarchy (trivia: undocking from a fixed/central node will create a new node and copy windows) ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (root_node->OnlyNodeWithWindows != node || (root_node->CentralNode != NULL)) - if (from_collapse_button || root_node->IsDockSpace()) - can_extract_dock_node = true; + if (root_node->OnlyNodeWithWindows != node || root_node->CentralNode != NULL) + if (undock_floating_node || root_node->IsDockSpace()) + can_undock_node = true; } const bool clicked = IsMouseClicked(0); const bool dragging = IsMouseDragging(0, g.IO.MouseDragThreshold * 1.70f); - if (can_extract_dock_node && dragging) + if (can_undock_node && dragging) { DockContextQueueUndockNode(&g, node); g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - node->Pos; } - else if (!can_extract_dock_node && (clicked || dragging) && g.MovingWindow != window) + else if (!can_undock_node && (clicked || dragging) && g.MovingWindow != window) { StartMouseMovingWindow(window); g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindow->Pos; @@ -5541,7 +5547,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren)) node->WantHiddenTabBarToggle = true; else if (held && IsMouseDragging(0)) - StartMouseDragFromTitleBar(window, node, true); + StartMouseMovingWindowOrNode(window, node, true); // FIXME-DOCK: Ideally we'd use ImGuiCol_TitleBgActive/ImGuiCol_TitleBg here, but neither is guaranteed to be visible enough at this sort of size.. ImU32 col = GetColorU32(((held && hovered) || (node->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); @@ -12188,18 +12194,19 @@ static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* nod remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount); remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabID == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame remove |= (window->DockTabWantClose); - if (!remove) - continue; - window->DockTabWantClose = false; - if (node->Windows.Size == 1 && !node->IsCentralNode()) + if (remove) { - DockNodeHideHostWindow(node); - node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow; - DockNodeRemoveWindow(node, window, node->ID); // Will delete the node so it'll be invalid on return - return; + window->DockTabWantClose = false; + if (node->Windows.Size == 1 && !node->IsCentralNode()) + { + DockNodeHideHostWindow(node); + node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow; + DockNodeRemoveWindow(node, window, node->ID); // Will delete the node so it'll be invalid on return + return; + } + DockNodeRemoveWindow(node, window, node->ID); + window_n--; } - DockNodeRemoveWindow(node, window, node->ID); - window_n--; } // Auto-hide tab bar option @@ -12798,7 +12805,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w // Forward moving request to selected window if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId)) - StartMouseDragFromTitleBar(tab->Window, node, false); + StartMouseMovingWindowOrNode(tab->Window, node, false); } } diff --git a/imgui_internal.h b/imgui_internal.h index ba03351b..40db1209 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1805,7 +1805,7 @@ namespace ImGui // NewFrame IMGUI_API void UpdateHoveredWindowAndCaptureFlags(); IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window); - IMGUI_API void StartMouseDragFromTitleBar(ImGuiWindow* window, ImGuiDockNode* node, bool from_collapse_button); + IMGUI_API void StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* node, bool undock_floating_node); IMGUI_API void UpdateMouseMovingWindowNewFrame(); IMGUI_API void UpdateMouseMovingWindowEndFrame(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b938e09c..088639bf 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -776,7 +776,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_no // Switch to moving the window after mouse is moved beyond the initial drag threshold if (IsItemActive() && IsMouseDragging(0)) - StartMouseDragFromTitleBar(window, dock_node, true); + StartMouseMovingWindowOrNode(window, dock_node, true); return pressed; } From 1742ca45c5aace614be83b237af2f014b4c2d90d Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 26 Nov 2019 11:24:01 +0200 Subject: [PATCH 155/384] CI: Add unity builds test. (#2893) --- .github/workflows/build.yml | 9 +++++++++ examples/example_null/Makefile | 11 ++++++++--- examples/example_null/unity_build.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 examples/example_null/unity_build.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60f8f642..8b0b09fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,6 +44,9 @@ jobs: - name: Build example_null (extra warnings) run: mingw32-make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (unity build) + run: mingw32-make -C examples/example_null UNITY_BUILD=1 + - name: Build Win32 example_glfw_opengl2 shell: cmd run: '"%MSBUILD_PATH%\MSBuild.exe" examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj /p:Platform=Win32 /p:Configuration=Release' @@ -156,6 +159,9 @@ jobs: - name: Build example_null (extra warnings) run: make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (unity build) + run: make -C examples/example_null UNITY_BUILD=1 + - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 @@ -185,6 +191,9 @@ jobs: - name: Build example_null (extra warnings) run: make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (unity build) + run: make -C examples/example_null UNITY_BUILD=1 + - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 909f1982..16802cba 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -4,11 +4,16 @@ # EXE = example_null -SOURCES = main.cpp -SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp +EXTRA_WARNINGS ?= 0 +UNITY_BUILD ?= 0 +ifeq ($(UNITY_BUILD), 1) + SOURCES = unity_build.cpp +else + SOURCES = main.cpp + SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp +endif OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -EXTRA_WARNINGS ?= 0 CXXFLAGS = -I../ -I../../ CXXFLAGS += -g -Wall -Wformat diff --git a/examples/example_null/unity_build.cpp b/examples/example_null/unity_build.cpp new file mode 100644 index 00000000..c6040016 --- /dev/null +++ b/examples/example_null/unity_build.cpp @@ -0,0 +1,6 @@ +// Unity build test - build this example as a single compilation unit. +#include "main.cpp" +#include "../../imgui.cpp" +#include "../../imgui_demo.cpp" +#include "../../imgui_draw.cpp" +#include "../../imgui_widgets.cpp" From bf6d1ba3d12772a487e6b7cb8af1d90fbe00fdb1 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 26 Nov 2019 12:17:58 +0200 Subject: [PATCH 156/384] CI: Add 32/64 bit build variations to builds with extra warnings. --- .github/workflows/build.yml | 23 ++++++++++++++++++++--- examples/example_null/Makefile | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b0b09fa..265c400d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -154,10 +154,27 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y libglfw3-dev libsdl2-dev + sudo apt-get install -y libglfw3-dev libsdl2-dev gcc-multilib g++-multilib - - name: Build example_null (extra warnings) - run: make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (extra warnings, gcc 32-bit) + run: | + make -C examples/example_null clean + CXXFLAGS="$CXXFLAGS -m32" make -C examples/example_null EXTRA_WARNINGS=1 + + - name: Build example_null (extra warnings, gcc 64-bit) + run: | + make -C examples/example_null clean + CXXFLAGS="$CXXFLAGS -m64" make -C examples/example_null EXTRA_WARNINGS=1 + + - name: Build example_null (extra warnings, clang 32-bit) + run: | + make -C examples/example_null clean + CXXFLAGS="$CXXFLAGS -m32" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + + - name: Build example_null (extra warnings, clang 64-bit) + run: | + make -C examples/example_null clean + CXXFLAGS="$CXXFLAGS -m64" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (unity build) run: make -C examples/example_null UNITY_BUILD=1 diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 16802cba..56c5f3da 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -15,7 +15,7 @@ endif OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS = -I../ -I../../ +CXXFLAGS += -I../ -I../../ CXXFLAGS += -g -Wall -Wformat LIBS = From 71a58261f6d14fdda4eb8c907b6d3aa0c1abcf10 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Nov 2019 18:21:04 +0100 Subject: [PATCH 157/384] Docking: Internals: Removed redundancy in code path leading to the BeginAsDockableDragDropSource(), clarified UpdateMouseMovingWindowEndFrame() Note that the ConfigWindowsMoveFromTitleBarOnly path for UpdateMouseMovingWindowEndFrame() would previously test the window->RootWindow title bar instead of window->RootWindowDockStop. This didn't have any side effect afaik because we wouldn't enter that function anyway as clicking on any tab bar would trigger the move before UpdateMouseMovingWindowEndFrame() does it. However for consistency made the UpdateMouseMovingWindowEndFrame()code more correct. + minor renaming --- docs/TODO.txt | 1 + imgui.cpp | 49 +++++++++++++++++++++++++----------------------- imgui_internal.h | 4 ++-- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index e78447b3..cb5a06d6 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -169,6 +169,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - docking: B~ tidy up tab list popup buttons features (available with manual tab-bar, see ImGuiTabBarFlags_NoTabListPopupButton code, not used by docking nodes) - docking: B- SetNextWindowDockId(0) with a second Begin() in the frame will asserts - docking: B: resize grip drawn in host window typically appears under scrollbar. + - docking: B: resize grip auto-resize on multiple node hierarchy doesn't make much sense or should be improved? - docking: B- SetNextWindowFocus() doesn't seem to apply if the window is hidden this frame, need repro (#4) - docking: B- resizing a dock tree small currently has glitches (overlapping collapse and close button, etc.) - docking: B- dpi: look at interaction with the hi-dpi and multi-dpi stuff. diff --git a/imgui.cpp b/imgui.cpp index 42e10aef..7f57bba8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3382,10 +3382,10 @@ void ImGui::UpdateMouseMovingWindowNewFrame() } } -// Initiate moving window, handle left-click and right-click focus +// Initiate moving window when clicking on empty space or title bar. +// Handle left-click and right-click focus. void ImGui::UpdateMouseMovingWindowEndFrame() { - // Initiate moving window ImGuiContext& g = *GImGui; if (g.ActiveId != 0 || g.HoveredId != 0) return; @@ -3394,15 +3394,18 @@ void ImGui::UpdateMouseMovingWindowEndFrame() if (g.NavWindow && g.NavWindow->Appearing) return; - // Click to focus window and start moving (after we're done with all our widgets) + // Click on void to focus window and start moving + // (after we're done with all our widgets, so e.g. clicking on docking tab-bar which have set HoveredId already and not get us here!) if (g.IO.MouseClicked[0]) { - if (g.HoveredRootWindow != NULL) + ImGuiWindow* root_window = g.HoveredWindow->RootWindowDockStop; + if (root_window != NULL) { StartMouseMovingWindow(g.HoveredWindow); - if (g.IO.ConfigWindowsMoveFromTitleBarOnly && (!(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoTitleBar) || g.HoveredWindow->RootWindowDockStop->DockIsActive)) - if (!g.HoveredRootWindow->TitleBarRect().Contains(g.IO.MouseClickedPos[0])) - g.MovingWindow = NULL; + if (g.IO.ConfigWindowsMoveFromTitleBarOnly) + if (!(root_window->Flags & ImGuiWindowFlags_NoTitleBar) || root_window->DockIsActive) + if (!root_window->TitleBarRect().Contains(g.IO.MouseClickedPos[0])) + g.MovingWindow = NULL; } else if (g.NavWindow != NULL && GetTopMostPopupModal() == NULL) { @@ -6406,17 +6409,16 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) { // Docking: Dragging a dockable window (or any of its child) turns it into a drag and drop source. - // We need to do this _before_ we overwrite window->DC.LastItemId below because BeginAsDockableDragDropSource() also overwrites it. - if ((g.ActiveId == window->MoveId) && (g.IO.ConfigDockingWithShift == g.IO.KeyShift)) - if ((window->Flags & ImGuiWindowFlags_NoMove) == 0) - if ((window->RootWindow->Flags & (ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking)) == 0) - BeginAsDockableDragDropSource(window); + // We need to do this _before_ we overwrite window->DC.LastItemId below because BeginDockableDragDropSource() also overwrites it. + if ((g.MovingWindow == window) && (g.IO.ConfigDockingWithShift == g.IO.KeyShift)) + if ((window->RootWindow->Flags & ImGuiWindowFlags_NoDocking) == 0) + BeginDockableDragDropSource(window); - // Docking: Any dockable window can act as a target. For dock node hosts we call BeginAsDockableDragDropTarget() in DockNodeUpdate() instead. + // Docking: Any dockable window can act as a target. For dock node hosts we call BeginDockableDragDropTarget() in DockNodeUpdate() instead. if (g.DragDropActive && !(flags & ImGuiWindowFlags_NoDocking)) if (g.MovingWindow == NULL || g.MovingWindow->RootWindow != window) if ((window == window->RootWindow) && !(window->Flags & ImGuiWindowFlags_DockNodeHost)) - BeginAsDockableDragDropTarget(window); + BeginDockableDragDropTarget(window); } // We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin(). @@ -11817,8 +11819,7 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) DockSettingsRenameNodeReferences(node->ID, new_node->ID); for (int n = 0; n < new_node->Windows.Size; n++) UpdateWindowParentAndRootLinks(new_node->Windows[n], new_node->Windows[n]->Flags, NULL); - new_node->AuthorityForPos = new_node->AuthorityForSize = ImGuiDataAuthority_Window; - new_node->WantMouseMove = true; + node = new_node; } else { @@ -11829,9 +11830,9 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) DockNodeTreeMerge(ctx, node->ParentNode, node->ParentNode->ChildNodes[index_in_parent ^ 1]); node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport node->ParentNode = NULL; - node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_Window; - node->WantMouseMove = true; } + node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_Window; + node->WantMouseMove = true; MarkIniSettingsDirty(); } @@ -12525,7 +12526,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Draw payload drop target if (host_window && node->IsVisible) if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindow != host_window)) - BeginAsDockableDragDropTarget(host_window); + BeginDockableDragDropTarget(host_window); // We update this after DockNodeUpdateTabBar() node->LastFrameActive = g.FrameCount; @@ -14099,9 +14100,10 @@ void ImGui::DockBuilderFinish(ImGuiID root_id) // Docking: Begin/End Support Functions (called from Begin/End) //----------------------------------------------------------------------------- // - GetWindowAlwaysWantOwnTabBar() +// - DockContextBindNodeToWindow() // - BeginDocked() -// - BeginAsDockableDragDropSource() -// - BeginAsDockableDragDropTarget() +// - BeginDockableDragDropSource() +// - BeginDockableDragDropTarget() //----------------------------------------------------------------------------- bool ImGui::GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window) @@ -14281,10 +14283,11 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) window->ChildId = parent_window->GetID(window->Name); } -void ImGui::BeginAsDockableDragDropSource(ImGuiWindow* window) +void ImGui::BeginDockableDragDropSource(ImGuiWindow* window) { ImGuiContext& g = *GImGui; IM_ASSERT(g.ActiveId == window->MoveId); + IM_ASSERT(g.MovingWindow == window); window->DC.LastItemId = window->MoveId; window = window->RootWindow; @@ -14297,7 +14300,7 @@ void ImGui::BeginAsDockableDragDropSource(ImGuiWindow* window) } } -void ImGui::BeginAsDockableDragDropTarget(ImGuiWindow* window) +void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) { ImGuiContext* ctx = GImGui; ImGuiContext& g = *ctx; diff --git a/imgui_internal.h b/imgui_internal.h index 40db1209..40800193 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1914,8 +1914,8 @@ namespace ImGui inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; } IMGUI_API bool GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window); IMGUI_API void BeginDocked(ImGuiWindow* window, bool* p_open); - IMGUI_API void BeginAsDockableDragDropSource(ImGuiWindow* window); - IMGUI_API void BeginAsDockableDragDropTarget(ImGuiWindow* window); + IMGUI_API void BeginDockableDragDropSource(ImGuiWindow* window); + IMGUI_API void BeginDockableDragDropTarget(ImGuiWindow* window); IMGUI_API void SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond); // Docking - Builder function needs to be generally called before the node is used/submitted. From 4dff49b2f1408e48418f4a67461036f4900a3eca Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Nov 2019 19:13:15 +0100 Subject: [PATCH 158/384] Docking, Viewports: Moving code. Moved NewFrame() sanity checks in NewFrameSanityChecks(). Moved some of DockNodeUpdate() into DockNodeUpdateForRootNode(). --- imgui.cpp | 98 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7f57bba8..ab1c4aba 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3693,22 +3693,8 @@ static void NewFrameSanityChecks() // Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly. if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors)) g.IO.ConfigWindowsResizeFromEdges = false; -} - -void ImGui::NewFrame() -{ - IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); - ImGuiContext& g = *GImGui; - -#ifdef IMGUI_ENABLE_TEST_ENGINE - ImGuiTestEngineHook_PreNewFrame(&g); -#endif - - // Check and assert for various common IO and Configuration mistakes - NewFrameSanityChecks(); // Perform simple check: error if Docking or Viewport are enabled _exactly_ on frame 1 (instead of frame 0 or later), which is a common error leading to loss of .ini data. - g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame; if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_DockingEnable) == 0) IM_ASSERT(0 && "Please set DockingEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!"); if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable) == 0) @@ -3720,12 +3706,12 @@ void ImGui::NewFrame() if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) { IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() in main loop after EndFrame()? Check examples/ applications for reference."); - IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?"); + IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?"); - IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?"); - IM_ASSERT(g.PlatformIO.Platform_SetWindowPos != NULL && "Platform init didn't install handlers?"); - IM_ASSERT(g.PlatformIO.Platform_GetWindowSize != NULL && "Platform init didn't install handlers?"); - IM_ASSERT(g.PlatformIO.Platform_SetWindowSize != NULL && "Platform init didn't install handlers?"); + IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?"); + IM_ASSERT(g.PlatformIO.Platform_SetWindowPos != NULL && "Platform init didn't install handlers?"); + IM_ASSERT(g.PlatformIO.Platform_GetWindowSize != NULL && "Platform init didn't install handlers?"); + IM_ASSERT(g.PlatformIO.Platform_SetWindowSize != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Monitors.Size > 0 && "Platform init didn't setup Monitors list?"); IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport."); if (g.IO.ConfigDockingTransparentPayload && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) @@ -3750,6 +3736,20 @@ void ImGui::NewFrame() IM_ASSERT(mon.DpiScale != 0.0f); } } +} + +void ImGui::NewFrame() +{ + IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); + ImGuiContext& g = *GImGui; + +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiTestEngineHook_PreNewFrame(&g); +#endif + + // Check and assert for various common IO and Configuration mistakes + g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame; + NewFrameSanityChecks(); g.ConfigFlagsCurrFrame = g.IO.ConfigFlags; // Load settings on first frame (if not explicitly loaded manually before) @@ -11232,6 +11232,7 @@ namespace ImGui static void DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id); static void DockNodeHideHostWindow(ImGuiDockNode* node); static void DockNodeUpdate(ImGuiDockNode* node); + static void DockNodeUpdateForRootNode(ImGuiDockNode* node); static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node); static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window); static void DockNodeAddTabBar(ImGuiDockNode* node); @@ -12168,7 +12169,6 @@ static ImGuiWindow* ImGui::DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID i static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node) { ImGuiContext& g = *GImGui; - IM_ASSERT(node->ParentNode == NULL || node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node); // Inherit most flags @@ -12247,6 +12247,36 @@ static void ImGui::DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWind g.ActiveIdClickOffset = backup_active_click_offset; } +// Update CentralNode, OnlyNodeWithWindows, LastFocusedNodeID. Copy window class. +static void ImGui::DockNodeUpdateForRootNode(ImGuiDockNode* node) +{ + DockNodeUpdateVisibleFlagAndInactiveChilds(node); + + // FIXME-DOCK: Merge this scan into the one above. + // - Setup central node pointers + // - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!) + ImGuiDockNodeFindInfoResults results; + DockNodeFindInfo(node, &results); + node->CentralNode = results.CentralNode; + node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL; + if (node->LastFocusedNodeID == 0 && results.FirstNodeWithWindows != NULL) + node->LastFocusedNodeID = results.FirstNodeWithWindows->ID; + + // Copy the window class from of our first window so it can be used for proper dock filtering. + // When node has mixed windows, prioritize the class with the most constraint (DockingAllowUnclassed = false) as the reference to copy. + // FIXME-DOCK: We don't recurse properly, this code could be reworked to work from DockNodeUpdateScanRec. + if (ImGuiDockNode* first_node_with_windows = results.FirstNodeWithWindows) + { + node->WindowClass = first_node_with_windows->Windows[0]->WindowClass; + for (int n = 1; n < first_node_with_windows->Windows.Size; n++) + if (first_node_with_windows->Windows[n]->WindowClass.DockingAllowUnclassed == false) + { + node->WindowClass = first_node_with_windows->Windows[n]->WindowClass; + break; + } + } +} + static void ImGui::DockNodeUpdate(ImGuiDockNode* node) { ImGuiContext& g = *GImGui; @@ -12256,33 +12286,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) node->CentralNode = node->OnlyNodeWithWindows = NULL; if (node->IsRootNode()) - { - DockNodeUpdateVisibleFlagAndInactiveChilds(node); - - // FIXME-DOCK: Merge this scan into the one above. - // - Setup central node pointers - // - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!) - ImGuiDockNodeFindInfoResults results; - DockNodeFindInfo(node, &results); - node->CentralNode = results.CentralNode; - node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL; - if (node->LastFocusedNodeID == 0 && results.FirstNodeWithWindows != NULL) - node->LastFocusedNodeID = results.FirstNodeWithWindows->ID; - - // Copy the window class from of our first window so it can be used for proper dock filtering. - // When node has mixed windows, prioritize the class with the most constraint (DockingAllowUnclassed = false) as the reference to copy. - // FIXME-DOCK: We don't recurse properly, this code could be reworked to work from DockNodeUpdateScanRec. - if (ImGuiDockNode* first_node_with_windows = results.FirstNodeWithWindows) - { - node->WindowClass = first_node_with_windows->Windows[0]->WindowClass; - for (int n = 1; n < first_node_with_windows->Windows.Size; n++) - if (first_node_with_windows->Windows[n]->WindowClass.DockingAllowUnclassed == false) - { - node->WindowClass = first_node_with_windows->Windows[n]->WindowClass; - break; - } - } - } + DockNodeUpdateForRootNode(node); // Remove tab bar if not needed if (node->TabBar && node->IsNoTabBar()) From 28dd8d7efdb6c66bddb18d1f6f48ddf2b5249d28 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Nov 2019 19:27:44 +0100 Subject: [PATCH 159/384] Docking: Fixed various conflicts not properly resolved on 813e0c1 New git client confusion. --- docs/CHANGELOG.txt | 4 ---- examples/imgui_impl_dx9.h | 4 ---- examples/imgui_impl_metal.mm | 6 +----- examples/imgui_impl_vulkan.cpp | 6 +----- 4 files changed, 2 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c765a54d..4deca1ec 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,7 +30,6 @@ HOW TO UPDATE? ----------------------------------------------------------------------- -<<<<<<< HEAD DOCKING BRANCH (In Progress) ----------------------------------------------------------------------- @@ -100,10 +99,7 @@ Other changes: ----------------------------------------------------------------------- - VERSION 1.74 WIP (In Progress) -======= VERSION 1.74 (Released 2019-11-25) ->>>>>>> master ----------------------------------------------------------------------- Breaking Changes: diff --git a/examples/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h index ccbd0eeb..339645e3 100644 --- a/examples/imgui_impl_dx9.h +++ b/examples/imgui_impl_dx9.h @@ -3,12 +3,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! -<<<<<<< HEAD // [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. -======= // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. ->>>>>>> master // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm index 5bf60bea..10814b46 100644 --- a/examples/imgui_impl_metal.mm +++ b/examples/imgui_impl_metal.mm @@ -3,13 +3,9 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! -<<<<<<< HEAD -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. +// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // Missing features: // [ ] Renderer: Multi-viewport / platform windows. -======= -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. ->>>>>>> master // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 3e726bb7..a503703e 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -2,12 +2,8 @@ // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // Implemented features: -<<<<<<< HEAD -// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices. -// [x] Platform: Multi-viewport / platform windows. With issues (flickering when creating a new viewport). -======= // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. ->>>>>>> master +// [x] Platform: Multi-viewport / platform windows. With issues (flickering when creating a new viewport). // Missing features: // [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 From a1e4af62d35bdd271b3e0546258f8533b7f7ea5e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 28 Nov 2019 17:34:26 +0100 Subject: [PATCH 160/384] Docking: Fix bug added in 71a58261 + Misc docking omments --- imgui.cpp | 8 +++++--- imgui.h | 9 +++++++-- imgui_internal.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ab1c4aba..92af81d0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3398,7 +3398,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame() // (after we're done with all our widgets, so e.g. clicking on docking tab-bar which have set HoveredId already and not get us here!) if (g.IO.MouseClicked[0]) { - ImGuiWindow* root_window = g.HoveredWindow->RootWindowDockStop; + ImGuiWindow* root_window = g.HoveredWindow ? g.HoveredWindow->RootWindowDockStop : NULL; if (root_window != NULL) { StartMouseMovingWindow(g.HoveredWindow); @@ -13006,6 +13006,7 @@ bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir } // host_node may be NULL if the window doesn't have a DockNode already. +// FIXME-DOCK: This is misnamed since it's also doing the filtering. static void ImGui::DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) { ImGuiContext& g = *GImGui; @@ -14253,7 +14254,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) return; } - // Position window + // Position/Size window SetNextWindowPos(node->Pos); SetNextWindowSize(node->Size); g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos() @@ -14346,7 +14347,8 @@ void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) const bool do_preview = payload->IsPreview() || payload->IsDelivery(); if (do_preview && (node != NULL || allow_null_target_node)) { - ImGuiDockPreviewData split_inner, split_outer; + ImGuiDockPreviewData split_inner; + ImGuiDockPreviewData split_outer; ImGuiDockPreviewData* split_data = &split_inner; if (node && (node->ParentNode || node->IsCentralNode())) if (ImGuiDockNode* root_node = DockNodeGetRootNode(node)) diff --git a/imgui.h b/imgui.h index a1f50e07..3766ce53 100644 --- a/imgui.h +++ b/imgui.h @@ -1609,8 +1609,13 @@ struct ImGuiSizeCallbackData ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing. }; -// [BETA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions. -// Provide hints to the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) and OS level parent/child relationships. +// [ALPHA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions. +// Important: the content of this class is still highly WIP and likely to change and be refactored +// before we stabilize Docking features. Please be mindful if using this. +// Provide hints: +// - To the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) +// - To the platform back-end for OS level parent/child relationships of viewport. +// - To the docking system for various options and filtering. struct ImGuiWindowClass { ImGuiID ClassId; // User data. 0 = Default class (unclassed). Windows of different classes cannot be docked with each others. diff --git a/imgui_internal.h b/imgui_internal.h index 40800193..eeaefb7b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1912,6 +1912,7 @@ namespace ImGui IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos); inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; } + inline ImGuiDockNode* GetWindowDockNode() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DockNode; } IMGUI_API bool GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window); IMGUI_API void BeginDocked(ImGuiWindow* window, bool* p_open); IMGUI_API void BeginDockableDragDropSource(ImGuiWindow* window); From abaf0256b8891206c9a3283bd336e23fca3ea964 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 28 Nov 2019 20:58:16 +0100 Subject: [PATCH 161/384] Version 1.75 WIP Added message to font file loading assert. --- docs/CHANGELOG.txt | 5 +++++ examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 4 ++-- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7232b97e..451ad93f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -29,6 +29,11 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.75 WIP (In Progress) +----------------------------------------------------------------------- + + ----------------------------------------------------------------------- VERSION 1.74 (Released 2019-11-25) ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index cf605ad1..cf92f41b 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.74 + dear imgui, v1.75 WIP ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index c2b489ad..375768cd 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (main code and documentation) // Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. diff --git a/imgui.h b/imgui.h index 9fcdaeaa..6613efb1 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (headers) // See imgui.cpp file for documentation. @@ -47,8 +47,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.74" -#define IMGUI_VERSION_NUM 17400 +#define IMGUI_VERSION "1.75 WIP" +#define IMGUI_VERSION_NUM 17401 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 7e475992..ca8eb262 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (demo code) // Message to the person tempted to delete this file when integrating Dear ImGui into their code base: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 8089bbef..0e1b3465 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (drawing and font code) /* @@ -1673,7 +1673,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); if (!data) { - IM_ASSERT(0); // Could not load file. + IM_ASSERT_USER_ERROR(0, "Could not font load file."); return NULL; } ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); diff --git a/imgui_internal.h b/imgui_internal.h index a0728217..091bd3e8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! @@ -166,7 +166,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer // Error handling // Down the line in some frameworks/languages we would like to have a way to redirect those to the programmer and recover from more faults. #ifndef IM_ASSERT_USER_ERROR -#define IM_ASSERT_USER_ERROR(_EXP,_MSG) IM_ASSERT((_EXP) && (_MSG)) // Recoverable User Error +#define IM_ASSERT_USER_ERROR(_EXP,_MSG) IM_ASSERT((_EXP) && _MSG) // Recoverable User Error #endif // Misc Macros diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ec6f51a9..915816b2 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.74 +// dear imgui, v1.75 WIP // (widgets code) /* From 927580d4a86acd1e131d20627d3cb42a13a969c3 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 28 Nov 2019 22:44:29 +0100 Subject: [PATCH 162/384] Docking: Cleanup, rename DockNodePreviewDockCalc() -> DockNodePreviewDockSetup() --- imgui.cpp | 42 ++++++++++++++++++++++-------------------- imgui_internal.h | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 92af81d0..eb6f9359 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11241,7 +11241,7 @@ namespace ImGui static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node); static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window); static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window); - static void DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking); + static void DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking); static void DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, const ImGuiDockPreviewData* preview_data); static void DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos); static void DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired); @@ -11740,7 +11740,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) // We can dock a split payload into a node that already has windows _only_ if our payload is a node tree with a single visible node. // In this situation, we move the windows of the target node into the currently visible node of the payload. // This allows us to preserve some of the underlying dock tree settings nicely. - IM_ASSERT(payload_node->OnlyNodeWithWindows != NULL); // The docking should have been blocked by DockNodePreviewDockCalc() early on and never submitted. + IM_ASSERT(payload_node->OnlyNodeWithWindows != NULL); // The docking should have been blocked by DockNodePreviewDockSetup() early on and never submitted. ImGuiDockNode* visible_node = payload_node->OnlyNodeWithWindows; if (visible_node->TabBar) IM_ASSERT(visible_node->TabBar->Tabs.Size > 0); @@ -11847,7 +11847,7 @@ bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* else { ImGuiDockPreviewData split_data; - DockNodePreviewDockCalc(target, target_node, payload, &split_data, false, split_outer); + DockNodePreviewDockSetup(target, target_node, payload, &split_data, false, split_outer); if (split_data.DropRectsDraw[split_dir+1].IsInverted()) return false; *out_pos = split_data.DropRectsDraw[split_dir+1].GetCenter(); @@ -11882,7 +11882,7 @@ bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* // - DockNodeCalcTabBarLayout() // - DockNodeCalcSplitRects() // - DockNodeCalcDropRectsAndTestMousePos() -// - DockNodePreviewDockCalc() +// - DockNodePreviewDockSetup() // - DockNodePreviewDockRender() //----------------------------------------------------------------------------- @@ -13007,40 +13007,42 @@ bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir // host_node may be NULL if the window doesn't have a DockNode already. // FIXME-DOCK: This is misnamed since it's also doing the filtering. -static void ImGui::DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) +static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) { ImGuiContext& g = *GImGui; // There is an edge case when docking into a dockspace which only has inactive nodes. // In this case DockNodeTreeFindNodeByPos() will have selected a leaf node which is inactive. // Because the inactive leaf node doesn't have proper pos/size yet, we'll use the root node as reference. + ImGuiDockNode* root_payload_as_host = root_payload->DockNodeAsHost; ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node; if (ref_node_for_rect) IM_ASSERT(ref_node_for_rect->IsVisible); - // Build a tentative future node (reuse same structure because it is practical) - data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton); - data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0); - data->FutureNode.Pos = host_node ? ref_node_for_rect->Pos : host_window->Pos; - data->FutureNode.Size = host_node ? ref_node_for_rect->Size : host_window->Size; - - // Figure out here we are allowed to dock + // Filter, figure out where we are allowed to dock ImGuiDockNodeFlags host_node_flags = host_node ? host_node->GetMergedFlags() : 0; - const bool src_is_visibly_splitted = root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode() && (root_payload->DockNodeAsHost->OnlyNodeWithWindows == NULL); - data->IsCenterAvailable = !is_outer_docking; - if (src_is_visibly_splitted && (!host_node || !host_node->IsEmpty())) + data->IsCenterAvailable = true; + if (is_outer_docking) + data->IsCenterAvailable = false; + else if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDocking)) data->IsCenterAvailable = false; - if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDocking)) + else if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode()) data->IsCenterAvailable = false; - if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode()) + else if ((!host_node || !host_node->IsEmpty()) && root_payload_as_host && root_payload_as_host->IsSplitNode() && (root_payload_as_host->OnlyNodeWithWindows == NULL)) // Is _visibly_ split? data->IsCenterAvailable = false; data->IsSidesAvailable = true; if ((host_node && (host_node_flags & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit) data->IsSidesAvailable = false; - if (!is_outer_docking && host_node && host_node->ParentNode == NULL && host_node->IsCentralNode()) + else if (!is_outer_docking && host_node && host_node->ParentNode == NULL && host_node->IsCentralNode()) data->IsSidesAvailable = false; + // Build a tentative future node (reuse same structure because it is practical. Shape will be readjusted when previewing a split) + data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton); + data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0); + data->FutureNode.Pos = host_node ? ref_node_for_rect->Pos : host_window->Pos; + data->FutureNode.Size = host_node ? ref_node_for_rect->Size : host_window->Size; + // Calculate drop shapes geometry for allowed splitting directions IM_ASSERT(ImGuiDir_None == -1); data->SplitNode = host_node; @@ -14353,11 +14355,11 @@ void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) if (node && (node->ParentNode || node->IsCentralNode())) if (ImGuiDockNode* root_node = DockNodeGetRootNode(node)) { - DockNodePreviewDockCalc(window, root_node, payload_window, &split_outer, is_explicit_target, true); + DockNodePreviewDockSetup(window, root_node, payload_window, &split_outer, is_explicit_target, true); if (split_outer.IsSplitDirExplicit) split_data = &split_outer; } - DockNodePreviewDockCalc(window, node, payload_window, &split_inner, is_explicit_target, false); + DockNodePreviewDockSetup(window, node, payload_window, &split_inner, is_explicit_target, false); if (split_data == &split_outer) split_inner.IsDropAllowed = false; diff --git a/imgui_internal.h b/imgui_internal.h index eeaefb7b..a7e8ed72 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1053,7 +1053,7 @@ struct ImGuiDockNode ImVec2 Size; // Current size ImVec2 SizeRef; // [Split node only] Last explicitly written-to size (overridden when using a splitter affecting the node), used to calculate Size. int SplitAxis; // [Split node only] Split axis (X or Y) - ImGuiWindowClass WindowClass; + ImGuiWindowClass WindowClass; // [Root node only] ImGuiDockNodeState State; ImGuiWindow* HostWindow; From b5cad20d79330c1d73636fb6beb4a1f55f2f0743 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 2 Dec 2019 10:36:59 +0200 Subject: [PATCH 163/384] Implement new GLFW 3.4 resizing cursors. --- examples/imgui_impl_glfw.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index a28634e2..005c605d 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -50,6 +50,7 @@ #define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity #define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale #define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface +#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE // Data enum GlfwClientApi @@ -171,12 +172,18 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); - g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR); - g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. - g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); // FIXME: GLFW doesn't have this. g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR); +#if GLFW_HAS_NEW_CURSORS + g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR); + g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR); + g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR); +#else + g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); + g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); + g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); +#endif // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. g_PrevUserCallbackMousebutton = NULL; From 945a5097734265baf4db188fb9dfa2093733bb91 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 2 Dec 2019 10:52:06 +0200 Subject: [PATCH 164/384] Implement ImGuiMouseCursor_NotAllowed mouse cursor. --- examples/imgui_impl_allegro5.cpp | 1 + examples/imgui_impl_glfw.cpp | 2 ++ examples/imgui_impl_osx.mm | 1 + examples/imgui_impl_sdl.cpp | 1 + examples/imgui_impl_win32.cpp | 1 + imgui.h | 1 + 6 files changed, 7 insertions(+) diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp index 18671625..d856d28b 100644 --- a/examples/imgui_impl_allegro5.cpp +++ b/examples/imgui_impl_allegro5.cpp @@ -390,6 +390,7 @@ static void ImGui_ImplAllegro5_UpdateMouseCursor() case ImGuiMouseCursor_ResizeEW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E; break; case ImGuiMouseCursor_ResizeNESW: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE; break; case ImGuiMouseCursor_ResizeNWSE: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW; break; + case ImGuiMouseCursor_NotAllowed: cursor_id = ALLEGRO_SYSTEM_MOUSE_CURSOR_UNAVAILABLE; break; } al_set_system_mouse_cursor(g_Display, cursor_id); } diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 005c605d..8918440a 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -179,10 +179,12 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR); + g_MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR); #else g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); + g_MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); #endif // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index 4f4e9753..3fbebacd 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -78,6 +78,7 @@ bool ImGui_ImplOSX_Init() g_MouseCursors[ImGuiMouseCursor_TextInput] = [NSCursor IBeamCursor]; g_MouseCursors[ImGuiMouseCursor_ResizeAll] = [NSCursor closedHandCursor]; g_MouseCursors[ImGuiMouseCursor_Hand] = [NSCursor pointingHandCursor]; + g_MouseCursors[ImGuiMouseCursor_NotAllowed] = [NSCursor operationNotAllowedCursor]; g_MouseCursors[ImGuiMouseCursor_ResizeNS] = [NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)] ? [NSCursor _windowResizeNorthSouthCursor] : [NSCursor resizeUpDownCursor]; g_MouseCursors[ImGuiMouseCursor_ResizeEW] = [NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)] ? [NSCursor _windowResizeEastWestCursor] : [NSCursor resizeLeftRightCursor]; g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = [NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)] ? [NSCursor _windowResizeNorthEastSouthWestCursor] : [NSCursor closedHandCursor]; diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 06d27b21..fcbe9a7f 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -165,6 +165,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW); g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE); g_MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); + g_MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); #ifdef _WIN32 SDL_SysWMinfo wmInfo; diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 8d46d942..2c2034bb 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -120,6 +120,7 @@ static bool ImGui_ImplWin32_UpdateMouseCursor() case ImGuiMouseCursor_ResizeNESW: win32_cursor = IDC_SIZENESW; break; case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break; case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break; + case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break; } ::SetCursor(::LoadCursor(NULL, win32_cursor)); } diff --git a/imgui.h b/imgui.h index 6613efb1..6a2d706f 100644 --- a/imgui.h +++ b/imgui.h @@ -1188,6 +1188,7 @@ enum ImGuiMouseCursor_ ImGuiMouseCursor_ResizeNESW, // When hovering over the bottom-left corner of a window ImGuiMouseCursor_ResizeNWSE, // When hovering over the bottom-right corner of a window ImGuiMouseCursor_Hand, // (Unused by Dear ImGui functions. Use for e.g. hyperlinks) + ImGuiMouseCursor_NotAllowed, // When hovering something with disallowed interaction. Usually a crossed circle. ImGuiMouseCursor_COUNT // Obsolete names (will be removed) From 8342e5b91a26a5def2db8bcb3c5e601adb1aec8e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 5 Dec 2019 15:43:05 +0100 Subject: [PATCH 165/384] Amend previous commits (added ImGuiMouseCursor_NotAllowed enum + new cursors in GLFW 3.4) Amend b5cad20d79330c1d73636fb6beb4a1f55f2f0743, 945a5097734265baf4db188fb9dfa2093733bb91 + unrelated minor typos --- docs/CHANGELOG.txt | 5 +++++ docs/TODO.txt | 1 - examples/imgui_impl_allegro5.cpp | 1 + examples/imgui_impl_glfw.cpp | 5 +++-- examples/imgui_impl_osx.mm | 1 + examples/imgui_impl_sdl.cpp | 1 + examples/imgui_impl_win32.cpp | 1 + imgui.cpp | 2 +- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- 10 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 451ad93f..7ba017bf 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -33,6 +33,11 @@ HOW TO UPDATE? VERSION 1.75 WIP (In Progress) ----------------------------------------------------------------------- +Other Changes: +- Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] +- Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] + ----------------------------------------------------------------------- VERSION 1.74 (Released 2019-11-25) diff --git a/docs/TODO.txt b/docs/TODO.txt index 94fc2ec8..e37af88a 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -340,7 +340,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - inputs: support track pad style scrolling & slider edit. - inputs/io: backspace and arrows in the context of a text input could use system repeat rate. - inputs/io: clarify/standardize/expose repeat rate and repeat delays (#1808) - - inputs: add mouse cursor for unavailable/no? IDC_NO/SDL_SYSTEM_CURSOR_NO. - inputs/scrolling: support for smooth scrolling (#2462, #2569) - misc: idle: expose "woken up" boolean (set by inputs) and/or animation time (for cursor blink) for back-end to be able stop refreshing easily. diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp index d856d28b..76f74a3f 100644 --- a/examples/imgui_impl_allegro5.cpp +++ b/examples/imgui_impl_allegro5.cpp @@ -15,6 +15,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-05-11: Inputs: Don't filter character value from ALLEGRO_EVENT_KEY_CHAR before calling AddInputCharacter(). // 2019-04-30: Renderer: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 8918440a..fd70bad5 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -6,7 +6,7 @@ // Implemented features: // [X] Platform: Clipboard support. // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. -// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. +// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. @@ -15,6 +15,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor). // 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter(). @@ -50,7 +51,7 @@ #define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity #define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale #define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface -#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE +#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR // Data enum GlfwClientApi diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm index 3fbebacd..54b23d07 100644 --- a/examples/imgui_impl_osx.mm +++ b/examples/imgui_impl_osx.mm @@ -14,6 +14,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-10-11: Inputs: Fix using Backspace key. // 2019-07-21: Re-added clipboard handlers as they are not enabled by default in core imgui.cpp (reverted 2019-05-18 change). // 2019-05-28: Inputs: Added mouse cursor shape and visibility support. diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index fcbe9a7f..05498c09 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -17,6 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application). // 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized. diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 2c2034bb..ffe1e8bf 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -18,6 +18,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). // 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent. // 2019-01-17: Inputs: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages. diff --git a/imgui.cpp b/imgui.cpp index 375768cd..7cc44585 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -45,7 +45,7 @@ CODE // [SECTION] FORWARD DECLARATIONS // [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) -// [SECTION] MISC HELPERS/UTILITIES (Geomtry, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions) // [SECTION] MISC HELPERS/UTILITIES (File functions) // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) // [SECTION] MISC HELPERS/UTILITIES (Color functions) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index ca8eb262..10171d8f 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3051,7 +3051,7 @@ static void ShowDemoWindowMisc() if (ImGui::TreeNode("Mouse cursors")) { - const char* mouse_cursors_names[] = { "Arrow", "TextInput", "Move", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand" }; + const char* mouse_cursors_names[] = { "Arrow", "TextInput", "ResizeAll", "ResizeNS", "ResizeEW", "ResizeNESW", "ResizeNWSE", "Hand", "NotAllowed" }; IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT); ImGui::Text("Current mouse cursor = %d: %s", ImGui::GetMouseCursor(), mouse_cursors_names[ImGui::GetMouseCursor()]); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 0e1b3465..91305a2e 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1673,7 +1673,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); if (!data) { - IM_ASSERT_USER_ERROR(0, "Could not font load file."); + IM_ASSERT_USER_ERROR(0, "Could not load font file!"); return NULL; } ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); From 6d9a54a90495fcd109401831a7f49929d678f546 Mon Sep 17 00:00:00 2001 From: Max Thrun Date: Sun, 1 Dec 2019 23:11:58 -0800 Subject: [PATCH 166/384] Examples: Metal: Wrap main event loop body in an @autoreleasepool block to ensure allocations get freed even if underlying system event loop gets paused due to app nap (#2910, #2917) --- docs/CHANGELOG.txt | 2 + examples/example_glfw_metal/main.mm | 141 ++++++++++++++-------------- 2 files changed, 74 insertions(+), 69 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7ba017bf..196f8f82 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -37,6 +37,8 @@ Other Changes: - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] +- Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed + even if underlying system event loop gets paused due to app nap (#2910, #2917). [@bear24rw] ----------------------------------------------------------------------- diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 959846a4..45dbb37b 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -82,77 +82,80 @@ int main(int, char**) // Main loop while (!glfwWindowShouldClose(window)) { - // Poll and handle events (inputs, window resize, etc.) - // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. - // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. - // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. - // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. - glfwPollEvents(); - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - layer.drawableSize = CGSizeMake(width, height); - id drawable = [layer nextDrawable]; - - id commandBuffer = [commandQueue commandBuffer]; - renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); - renderPassDescriptor.colorAttachments[0].texture = drawable.texture; - renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; - renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; - id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; - [renderEncoder pushDebugGroup:@"ImGui demo"]; - - // Start the Dear ImGui frame - ImGui_ImplMetal_NewFrame(renderPassDescriptor); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); - - // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). - if (show_demo_window) - ImGui::ShowDemoWindow(&show_demo_window); - - // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + @autoreleasepool { - static float f = 0.0f; - static int counter = 0; - - ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. - - ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) - ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state - ImGui::Checkbox("Another Window", &show_another_window); - - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f - ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color - - if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) - counter++; - ImGui::SameLine(); - ImGui::Text("counter = %d", counter); - - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - ImGui::End(); + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + + int width, height; + glfwGetFramebufferSize(window, &width, &height); + layer.drawableSize = CGSizeMake(width, height); + id drawable = [layer nextDrawable]; + + id commandBuffer = [commandQueue commandBuffer]; + renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); + renderPassDescriptor.colorAttachments[0].texture = drawable.texture; + renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; + renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; + id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + [renderEncoder pushDebugGroup:@"ImGui demo"]; + + // Start the Dear ImGui frame + ImGui_ImplMetal_NewFrame(renderPassDescriptor); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::End(); + } + + // 3. Show another simple window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + ImGui::Text("Hello from another window!"); + if (ImGui::Button("Close Me")) + show_another_window = false; + ImGui::End(); + } + + // Rendering + ImGui::Render(); + ImGui_ImplMetal_RenderDrawData(ImGui::GetDrawData(), commandBuffer, renderEncoder); + + [renderEncoder popDebugGroup]; + [renderEncoder endEncoding]; + + [commandBuffer presentDrawable:drawable]; + [commandBuffer commit]; } - - // 3. Show another simple window. - if (show_another_window) - { - ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) - ImGui::Text("Hello from another window!"); - if (ImGui::Button("Close Me")) - show_another_window = false; - ImGui::End(); - } - - // Rendering - ImGui::Render(); - ImGui_ImplMetal_RenderDrawData(ImGui::GetDrawData(), commandBuffer, renderEncoder); - - [renderEncoder popDebugGroup]; - [renderEncoder endEncoding]; - - [commandBuffer presentDrawable:drawable]; - [commandBuffer commit]; } // Cleanup From b521cd357d929d25409bea6656b311760847b43c Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 5 Dec 2019 18:30:27 +0100 Subject: [PATCH 167/384] Removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions. (none of the other functions have it). --- docs/CHANGELOG.txt | 4 ++++ imgui.cpp | 1 + imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_widgets.cpp | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 196f8f82..736c47ea 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -33,6 +33,10 @@ HOW TO UPDATE? VERSION 1.75 WIP (In Progress) ----------------------------------------------------------------------- +Breaking Changes: +- Removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent + with other mouse functions (none of the other functions have it). + Other Changes: - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] diff --git a/imgui.cpp b/imgui.cpp index 7cc44585..343d7e87 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,6 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/12/06 (1.75) - removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). - 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. diff --git a/imgui.h b/imgui.h index 6a2d706f..5268b59f 100644 --- a/imgui.h +++ b/imgui.h @@ -680,7 +680,7 @@ namespace ImGui IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down) (0=left, 1=right, 2=middle) IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down) - IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold + IMGUI_API bool IsMouseDragging(int button, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block. IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls @@ -754,8 +754,8 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_ChildMenu = 1 << 28 // Don't use! For internal use by BeginMenu() // [Obsolete] - //ImGuiWindowFlags_ShowBorders = 1 << 7, // --> Set style.FrameBorderSize=1.0f / style.WindowBorderSize=1.0f to enable borders around windows and items - //ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // --> Set io.ConfigWindowsResizeFromEdges and make sure mouse cursors are supported by back-end (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) + //ImGuiWindowFlags_ShowBorders = 1 << 7, // --> Set style.FrameBorderSize=1.0f or style.WindowBorderSize=1.0f to enable borders around items or windows. + //ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // --> Set io.ConfigWindowsResizeFromEdges=true and make sure mouse cursors are supported by back-end (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) }; // Flags for ImGui::InputText() diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 10171d8f..bdc97384 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2445,7 +2445,7 @@ static void ShowDemoWindowLayout() ImVec2 pos = ImGui::GetCursorScreenPos(); ImVec4 clip_rect(pos.x, pos.y, pos.x + size.x, pos.y + size.y); ImGui::InvisibleButton("##dummy", size); - if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } + if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(90, 90, 120, 255)); ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x + offset.x, pos.y + offset.y), IM_COL32(255, 255, 255, 255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect); ImGui::TreePop(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 915816b2..572c829c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -768,7 +768,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos) RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f); // Switch to moving the window after mouse is moved beyond the initial drag threshold - if (IsItemActive() && IsMouseDragging()) + if (IsItemActive() && IsMouseDragging(0)) StartMouseMovingWindow(window); return pressed; From 7ff13f4ee1652289bddf5802b222e3c3c824f41e Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 6 Dec 2019 10:43:27 +0100 Subject: [PATCH 168/384] Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the opengl3 backend might automatically use it). [#2919, #2798] --- docs/CHANGELOG.txt | 3 +++ examples/example_glfw_opengl2/Makefile | 2 +- examples/example_glfw_opengl3/Makefile | 2 +- examples/example_null/Makefile | 4 ---- examples/example_sdl_opengl3/Makefile | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 736c47ea..0a04fc4c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,9 @@ Other Changes: - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] +- Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking + settings (otherwise if another loader such as Glew is accessible, the opengl3 backend might + automatically use it). [#2919, #2798] - Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed even if underlying system event loop gets paused due to app nap (#2910, #2917). [@bear24rw] diff --git a/examples/example_glfw_opengl2/Makefile b/examples/example_glfw_opengl2/Makefile index 3649b717..38f865ba 100644 --- a/examples/example_glfw_opengl2/Makefile +++ b/examples/example_glfw_opengl2/Makefile @@ -52,7 +52,7 @@ ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) ECHO_MESSAGE = "MinGW" LIBS += -lglfw3 -lgdi32 -lopengl32 -limm32 - CXXFLAGS += -I../libs/gl3w `pkg-config --cflags glfw3` + CXXFLAGS += `pkg-config --cflags glfw3` CFLAGS = $(CXXFLAGS) endif diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index 7e17476c..f72f4669 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -31,7 +31,7 @@ LIBS = ## Using OpenGL loader: gl3w [default] SOURCES += ../libs/gl3w/GL/gl3w.c -CXXFLAGS += -I../libs/gl3w +CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W ## Using OpenGL loader: glew ## (This assumes a system-wide installation) diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 56c5f3da..3930eb27 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -65,10 +65,6 @@ endif %.o:../../%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -%.o:../libs/gl3w/GL/%.c -# %.o:../libs/glad/src/%.c - $(CC) $(CFLAGS) -c -o $@ $< - all: $(EXE) @echo Build complete for $(ECHO_MESSAGE) diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 9e84df92..12d8b57c 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -31,7 +31,7 @@ LIBS = ## Using OpenGL loader: gl3w [default] SOURCES += ../libs/gl3w/GL/gl3w.c -CXXFLAGS += -I../libs/gl3w +CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W ## Using OpenGL loader: glew ## (This assumes a system-wide installation) From 03b7170dac6637748fd2e32c99cd11c2bf0bfb38 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 6 Dec 2019 16:08:04 +0200 Subject: [PATCH 169/384] Backends: GLFW: Added workaround for people who use development version of GLFW which is older than commit that added required cursor support. (#2922) --- examples/imgui_impl_glfw.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index fd70bad5..142b6409 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -51,7 +51,11 @@ #define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity #define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale #define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface +#ifdef GLFW_RESIZE_NESW_CURSOR // let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? #define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR +#else +#define GLFW_HAS_NEW_CURSORS (0) +#endif // Data enum GlfwClientApi From 6cbed03d4ad7111d5da2d301fca9c07966e9c9ae Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 6 Dec 2019 16:06:29 +0100 Subject: [PATCH 170/384] Comments, clarified mouse button ordering. --- imgui.cpp | 24 +++++++++++++----------- imgui.h | 33 +++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 343d7e87..e7bfeda7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4217,7 +4217,8 @@ int ImGui::GetKeyIndex(ImGuiKey imgui_key) return g.IO.KeyMap[imgui_key]; } -// Note that imgui doesn't know the semantic of each entry of io.KeysDown[]. Use your own indices/enums according to how your back-end/engine stored them into io.KeysDown[]! +// Note that dear imgui doesn't know the semantic of each entry of io.KeysDown[]! +// Use your own indices/enums according to how your back-end/engine stored them into io.KeysDown[]! bool ImGui::IsKeyDown(int user_key_index) { if (user_key_index < 0) @@ -4284,15 +4285,6 @@ bool ImGui::IsMouseDown(int button) return g.IO.MouseDown[button]; } -bool ImGui::IsAnyMouseDown() -{ - ImGuiContext& g = *GImGui; - for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++) - if (g.IO.MouseDown[n]) - return true; - return false; -} - bool ImGui::IsMouseClicked(int button, bool repeat) { ImGuiContext& g = *GImGui; @@ -4347,7 +4339,8 @@ bool ImGui::IsMouseDragging(int button, float lock_threshold) ImVec2 ImGui::GetMousePos() { - return GImGui->IO.MousePos; + ImGuiContext& g = *GImGui; + return g.IO.MousePos; } // NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed! @@ -4370,6 +4363,15 @@ bool ImGui::IsMousePosValid(const ImVec2* mouse_pos) return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID; } +bool ImGui::IsAnyMouseDown() +{ + ImGuiContext& g = *GImGui; + for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++) + if (g.IO.MouseDown[n]) + return true; + return false; +} + // Return the delta from the initial clicking position while the mouse button is clicked or was just released. // This is locked and return 0.0f until the mouse moves past a distance threshold at least once. // NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window. diff --git a/imgui.h b/imgui.h index 5268b59f..a1cb880d 100644 --- a/imgui.h +++ b/imgui.h @@ -669,27 +669,32 @@ namespace ImGui IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); - // Inputs Utilities + // Inputs Utilities: Keyboard + // - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[]. + // - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index. IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key] - IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. note that imgui doesn't know the semantic of each entry of io.KeysDown[]. Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]! - IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down). if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate - IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down).. + IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. + IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate + IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down)? IMGUI_API int GetKeyPressedAmount(int key_index, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate - IMGUI_API bool IsMouseDown(int button); // is mouse button held (0=left, 1=right, 2=middle) - IMGUI_API bool IsAnyMouseDown(); // is any mouse button held - IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down) (0=left, 1=right, 2=middle) - IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. - IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down) - IMGUI_API bool IsMouseDragging(int button, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold - IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block. - IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse + IMGUI_API void CaptureKeyboardFromApp(bool want_capture_keyboard_value = true); // attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call. + + // Inputs Utilities: Mouse + // - Mouse buttons are referred to as simple integer, and it is guaranteed that 0=Left, 1=Right, 2=Middle. + IMGUI_API bool IsMouseDown(int button); // is mouse button held? + IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked? (went from !Down to Down) + IMGUI_API bool IsMouseReleased(int button); // did mouse button released? (went from Down to !Down) + IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked? A double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. + IMGUI_API bool IsMouseDragging(int button, float lock_threshold = -1.0f); // is mouse dragging? if lock_threshold < -1.0f uses io.MouseDraggingThreshold + IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true);// is mouse hovering given bounding rect (in screen space)? clipped by current clipping settings if 'clip=true', but disregarding of other consideration of focus/window ordering/popup-block. + IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse available + IMGUI_API bool IsAnyMouseDown(); // is any mouse button held? IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse position at the time of opening popup we have BeginPopup() into IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and return 0.0f until the mouse moves past a distance threshold at least once. If lock_threshold < -1.0f uses io.MouseDraggingThreshold. IMGUI_API void ResetMouseDragDelta(int button = 0); // IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you - IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type - IMGUI_API void CaptureKeyboardFromApp(bool want_capture_keyboard_value = true); // attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call. + IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired cursor type IMGUI_API void CaptureMouseFromApp(bool want_capture_mouse_value = true); // attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse_value;" after the next NewFrame() call. // Clipboard Utilities (also see the LogToClipboard() function to capture or output text data to the clipboard) From f656e7775e638987251031a1147dfbdb144853d5 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 6 Dec 2019 16:29:22 +0100 Subject: [PATCH 171/384] Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 30 +++++++++++++++--------------- imgui.h | 44 +++++++++++++++++++++++++++++--------------- imgui_internal.h | 2 +- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0a04fc4c..e190aae4 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,6 +38,8 @@ Breaking Changes: with other mouse functions (none of the other functions have it). Other Changes: +- Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). + We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] diff --git a/imgui.cpp b/imgui.cpp index e7bfeda7..409dbe41 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1001,6 +1001,7 @@ ImGuiIO::ImGuiIO() { // Most fields are initialized with zero memset(this, 0, sizeof(*this)); + IM_STATIC_ASSERT(IM_ARRAYSIZE(MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(MouseClicked) == ImGuiMouseButton_COUNT); // Settings ConfigFlags = ImGuiConfigFlags_None; @@ -4278,14 +4279,14 @@ bool ImGui::IsKeyReleased(int user_key_index) return g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index]; } -bool ImGui::IsMouseDown(int button) +bool ImGui::IsMouseDown(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); return g.IO.MouseDown[button]; } -bool ImGui::IsMouseClicked(int button, bool repeat) +bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4300,18 +4301,17 @@ bool ImGui::IsMouseClicked(int button, bool repeat) if (amount > 0) return true; } - return false; } -bool ImGui::IsMouseReleased(int button) +bool ImGui::IsMouseReleased(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); return g.IO.MouseReleased[button]; } -bool ImGui::IsMouseDoubleClicked(int button) +bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4319,7 +4319,7 @@ bool ImGui::IsMouseDoubleClicked(int button) } // [Internal] This doesn't test if the button is pressed -bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold) +bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4328,7 +4328,7 @@ bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold) return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; } -bool ImGui::IsMouseDragging(int button, float lock_threshold) +bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4375,7 +4375,7 @@ bool ImGui::IsAnyMouseDown() // Return the delta from the initial clicking position while the mouse button is clicked or was just released. // This is locked and return 0.0f until the mouse moves past a distance threshold at least once. // NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window. -ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) +ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4388,7 +4388,7 @@ ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) return ImVec2(0.0f, 0.0f); } -void ImGui::ResetMouseDragDelta(int button) +void ImGui::ResetMouseDragDelta(ImGuiMouseButton button) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); @@ -4464,7 +4464,7 @@ bool ImGui::IsItemFocused() return true; } -bool ImGui::IsItemClicked(int mouse_button) +bool ImGui::IsItemClicked(ImGuiMouseButton mouse_button) { return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_None); } @@ -7563,7 +7563,7 @@ void ImGui::EndPopup() g.WithinEndChild = false; } -bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) +bool ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiMouseButton mouse_button) { ImGuiWindow* window = GImGui->CurrentWindow; if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) @@ -7579,7 +7579,7 @@ bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button) // This is a helper to handle the simplest case of associating one named popup to one given widget. // You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters). // You can pass a NULL str_id to use the identifier of the last item. -bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button) +bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button) { ImGuiWindow* window = GImGui->CurrentWindow; if (window->SkipItems) @@ -7591,7 +7591,7 @@ bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button) return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); } -bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool also_over_items) +bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mouse_button, bool also_over_items) { if (!str_id) str_id = "window_context"; @@ -7602,7 +7602,7 @@ bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool a return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings); } -bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button) +bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiMouseButton mouse_button) { if (!str_id) str_id = "void_context"; @@ -8796,7 +8796,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) bool source_drag_active = false; ImGuiID source_id = 0; ImGuiID source_parent_id = 0; - int mouse_button = 0; + ImGuiMouseButton mouse_button = ImGuiMouseButton_Left; if (!(flags & ImGuiDragDropFlags_SourceExtern)) { source_id = window->DC.LastItemId; diff --git a/imgui.h b/imgui.h index a1cb880d..9b75aae1 100644 --- a/imgui.h +++ b/imgui.h @@ -138,6 +138,7 @@ typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A typedef int ImGuiDir; // -> enum ImGuiDir_ // Enum: A cardinal direction typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier (ImGui-side enum) typedef int ImGuiNavInput; // -> enum ImGuiNavInput_ // Enum: An input identifier for navigation +typedef int ImGuiMouseButton; // -> enum ImGuiMouseButton_ // Enum: A mouse button identifier (0=left, 1=right, 2=middle) typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor identifier typedef int ImGuiStyleVar; // -> enum ImGuiStyleVar_ // Enum: A variable identifier for styling typedef int ImDrawCornerFlags; // -> enum ImDrawCornerFlags_ // Flags: for ImDrawList::AddRect(), AddRectFilled() etc. @@ -565,16 +566,17 @@ namespace ImGui // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. // - Their visibility state (~bool) is held internally by imgui instead of being held by the programmer as we are used to with regular Begin() calls. // User can manipulate the visibility state by calling OpenPopup(). + // - We default to use the right mouse (ImGuiMouseButton_Right=1) for the Popup Context functions. // (*) You can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup. // Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time. IMGUI_API void OpenPopup(const char* str_id); // call to mark popup as open (don't call every frame!). popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. By default, Selectable()/MenuItem() are calling CloseCurrentPopup(). Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). IMGUI_API bool BeginPopup(const char* str_id, ImGuiWindowFlags flags = 0); // return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returns true! - IMGUI_API bool BeginPopupContextItem(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id. If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp! - IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, int mouse_button = 1, bool also_over_items = true); // helper to open and begin popup when clicked on current window. - IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (where there are no imgui windows). + IMGUI_API bool BeginPopupContextItem(const char* str_id = NULL, ImGuiMouseButton mouse_button = 1); // helper to open and begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id. If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp! + IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, ImGuiMouseButton mouse_button = 1, bool also_over_items = true); // helper to open and begin popup when clicked on current window. + IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, ImGuiMouseButton mouse_button = 1); // helper to open and begin popup when clicked in void (where there are no imgui windows). IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags flags = 0); // modal dialog (regular window with title bar, block interactions behind the modal window, can't close the modal window by clicking outside) IMGUI_API void EndPopup(); // only call EndPopup() if BeginPopupXXX() returns true! - IMGUI_API bool OpenPopupOnItemClick(const char* str_id = NULL, int mouse_button = 1); // helper to open popup when clicked on last item (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors). return true when just opened. + IMGUI_API bool OpenPopupOnItemClick(const char* str_id = NULL, ImGuiMouseButton mouse_button = 1); // helper to open popup when clicked on last item (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors). return true when just opened. IMGUI_API bool IsPopupOpen(const char* str_id); // return true if the popup is open at the current begin-ed level of the popup stack. IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup. @@ -632,7 +634,7 @@ namespace ImGui IMGUI_API bool IsItemHovered(ImGuiHoveredFlags flags = 0); // is the last item hovered? (and usable, aka not blocked by a popup, etc.). See ImGuiHoveredFlags for more options. IMGUI_API bool IsItemActive(); // is the last item active? (e.g. button being held, text field being edited. This will continuously return true while holding mouse button on an item. Items that don't interact will always return false) IMGUI_API bool IsItemFocused(); // is the last item focused for keyboard/gamepad navigation? - IMGUI_API bool IsItemClicked(int mouse_button = 0); // is the last item clicked? (e.g. button/node just clicked on) == IsMouseClicked(mouse_button) && IsItemHovered() + IMGUI_API bool IsItemClicked(ImGuiMouseButton mouse_button = 0); // is the last item clicked? (e.g. button/node just clicked on) == IsMouseClicked(mouse_button) && IsItemHovered() IMGUI_API bool IsItemVisible(); // is the last item visible? (items may be out of sight because of clipping/scrolling) IMGUI_API bool IsItemEdited(); // did the last item modify its underlying value this frame? or was pressed? This is generally the same as the "bool" return value of many widgets. IMGUI_API bool IsItemActivated(); // was the last item just made active (item was previously inactive). @@ -680,19 +682,21 @@ namespace ImGui IMGUI_API void CaptureKeyboardFromApp(bool want_capture_keyboard_value = true); // attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call. // Inputs Utilities: Mouse - // - Mouse buttons are referred to as simple integer, and it is guaranteed that 0=Left, 1=Right, 2=Middle. - IMGUI_API bool IsMouseDown(int button); // is mouse button held? - IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked? (went from !Down to Down) - IMGUI_API bool IsMouseReleased(int button); // did mouse button released? (went from Down to !Down) - IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked? A double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. - IMGUI_API bool IsMouseDragging(int button, float lock_threshold = -1.0f); // is mouse dragging? if lock_threshold < -1.0f uses io.MouseDraggingThreshold - IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true);// is mouse hovering given bounding rect (in screen space)? clipped by current clipping settings if 'clip=true', but disregarding of other consideration of focus/window ordering/popup-block. + // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right. + // - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle. + // - Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold') + IMGUI_API bool IsMouseDown(ImGuiMouseButton button); // is mouse button held? + IMGUI_API bool IsMouseClicked(ImGuiMouseButton button, bool repeat = false); // did mouse button clicked? (went from !Down to Down) + IMGUI_API bool IsMouseReleased(ImGuiMouseButton button); // did mouse button released? (went from Down to !Down) + IMGUI_API bool IsMouseDoubleClicked(ImGuiMouseButton button); // did mouse button double-clicked? a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime. + IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true);// is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block. IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse available IMGUI_API bool IsAnyMouseDown(); // is any mouse button held? IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls - IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse position at the time of opening popup we have BeginPopup() into - IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and return 0.0f until the mouse moves past a distance threshold at least once. If lock_threshold < -1.0f uses io.MouseDraggingThreshold. - IMGUI_API void ResetMouseDragDelta(int button = 0); // + IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve mouse position at the time of opening popup we have BeginPopup() into (helper to avoid user backing that value themselves) + IMGUI_API bool IsMouseDragging(ImGuiMouseButton button, float lock_threshold = -1.0f); // is mouse dragging? (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) + IMGUI_API ImVec2 GetMouseDragDelta(ImGuiMouseButton button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and return 0.0f until the mouse moves past a distance threshold at least once (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) + IMGUI_API void ResetMouseDragDelta(ImGuiMouseButton button = 0); // IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired cursor type IMGUI_API void CaptureMouseFromApp(bool want_capture_mouse_value = true); // attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse_value;" after the next NewFrame() call. @@ -1180,6 +1184,16 @@ enum ImGuiColorEditFlags_ #endif }; +// Identify a mouse button. +// Those values are guaranteed to be stable and we frequently use 0/1 directly. Named enums provided for convenience. +enum ImGuiMouseButton_ +{ + ImGuiMouseButton_Left = 0, + ImGuiMouseButton_Right = 1, + ImGuiMouseButton_Middle = 2, + ImGuiMouseButton_COUNT = 5 +}; + // Enumeration for GetMouseCursor() // User code may request binding to display given cursor by calling SetMouseCursor(), which is why we have some cursors that are marked unused here enum ImGuiMouseCursor_ diff --git a/imgui_internal.h b/imgui_internal.h index 091bd3e8..4cc2af84 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1690,7 +1690,7 @@ namespace ImGui inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; } inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; IM_ASSERT(key < 64); return (g.ActiveIdUsingKeyInputMask & ((ImU64)1 << key)) != 0; } - IMGUI_API bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); + IMGUI_API bool IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold = -1.0f); inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } From e4a59d0025e288a38523b90ba9c3e014cb359a35 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 7 Dec 2019 16:22:07 +0100 Subject: [PATCH 172/384] TabItem: honor ImGuiTabItemFlags_NoCloseButton passed as parameter (although undocumented and part of private api) (#2923) --- imgui_demo.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index bdc97384..c9f9c73a 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2027,7 +2027,7 @@ static void ShowDemoWindowLayout() if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags)) { for (int n = 0; n < IM_ARRAYSIZE(opened); n++) - if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n])) + if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n], ImGuiTabItemFlags_None)) { ImGui::Text("This is the %s tab!", names[n]); if (n & 1) diff --git a/imgui_internal.h b/imgui_internal.h index 4cc2af84..af661afb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1512,7 +1512,7 @@ enum ImGuiTabBarFlagsPrivate_ // Extend ImGuiTabItemFlags_ enum ImGuiTabItemFlagsPrivate_ { - ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Store whether p_open is set or not, which we need to recompute ContentWidth during layout. + ImGuiTabItemFlags_NoCloseButton = 1 << 20 // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout) }; // Storage for one active tab item (sizeof() 26~32 bytes) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 572c829c..d605e2d7 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6927,6 +6927,12 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, return false; } + // Store into ImGuiTabItemFlags_NoCloseButton, also honor ImGuiTabItemFlags_NoCloseButton passed by user (although not documented) + if (flags & ImGuiTabItemFlags_NoCloseButton) + p_open = NULL; + else if (p_open == NULL) + flags |= ImGuiTabItemFlags_NoCloseButton; + // Calculate tab contents size ImVec2 size = TabItemCalcSize(label, p_open != NULL); @@ -6944,9 +6950,6 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, tab_bar->LastTabItemIdx = (short)tab_bar->Tabs.index_from_ptr(tab); tab->ContentWidth = size.x; - if (p_open == NULL) - flags |= ImGuiTabItemFlags_NoCloseButton; - const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount); const bool tab_bar_focused = (tab_bar->Flags & ImGuiTabBarFlags_IsFocused) != 0; const bool tab_appearing = (tab->LastFrameVisible + 1 < g.FrameCount); From 697f15e339779e98951d06d2074d84ef368e7bc1 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Fri, 22 Nov 2019 22:06:44 +0900 Subject: [PATCH 173/384] Added PrimUnreserve() API. Obsoleted calling ImDrawList::PrimReserve() with a negative count. --- docs/CHANGELOG.txt | 6 ++++++ imgui.cpp | 1 + imgui.h | 3 ++- imgui_draw.cpp | 18 ++++++++++++++++-- imgui_internal.h | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e190aae4..0c904576 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,6 +36,12 @@ HOW TO UPDATE? Breaking Changes: - Removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). +- Obsoleted calling ImDrawList::PrimReserve() with a negative count (which was vaguely + documented and rarely if ever used). Instead we added an explicit PrimUnreserve() API + which can be implemented faster. Also clarified pre-existing constraints which weren't + documented (can only unreserve from the last reserve call). If you suspect you ever + used that feature before, #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing + calls. [@ShironekoBen] Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). diff --git a/imgui.cpp b/imgui.cpp index 409dbe41..8dbbd540 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,6 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/12/08 (1.75) - obsoleted calling ImDrawList::PrimReserve() with a negative count (which was the vaguely documented and rarely if ever used). Instead we added an explicit PrimUnreserve() API. - 2019/12/06 (1.75) - removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). - 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. diff --git a/imgui.h b/imgui.h index 9b75aae1..d0cd8494 100644 --- a/imgui.h +++ b/imgui.h @@ -1293,7 +1293,7 @@ struct ImVector inline int _grow_capacity(int sz) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > sz ? new_capacity : sz; } inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; } inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } - inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } + inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } // Resize a vector to a smaller size, guaranteed not to cause a reallocation inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; } // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. @@ -1990,6 +1990,7 @@ struct ImDrawList IMGUI_API void Clear(); IMGUI_API void ClearFreeMemory(); IMGUI_API void PrimReserve(int idx_count, int vtx_count); + IMGUI_API void PrimUnreserve(int idx_count, int vtx_count); IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col); // Axis aligned rectangle (composed of two triangles) IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col); IMGUI_API void PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 91305a2e..18029f4d 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -516,10 +516,13 @@ void ImDrawList::PopTextureID() UpdateTextureID(); } -// NB: this can be called with negative count for removing primitives (as long as the result does not underflow) +// Reserve space for a number of vertices and indices. +// You must finish filling your reserved data before calling PrimReserve() again, as it may reallocate or +// submit the intermediate results. PrimUnreserve() can be used to release unused allocations. void ImDrawList::PrimReserve(int idx_count, int vtx_count) { // Large mesh support (when enabled) + IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0); if (sizeof(ImDrawIdx) == 2 && (_VtxCurrentIdx + vtx_count >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset)) { _VtxCurrentOffset = VtxBuffer.Size; @@ -527,7 +530,7 @@ void ImDrawList::PrimReserve(int idx_count, int vtx_count) AddDrawCmd(); } - ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size-1]; + ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size - 1]; draw_cmd.ElemCount += idx_count; int vtx_buffer_old_size = VtxBuffer.Size; @@ -539,6 +542,17 @@ void ImDrawList::PrimReserve(int idx_count, int vtx_count) _IdxWritePtr = IdxBuffer.Data + idx_buffer_old_size; } +// Release the a number of reserved vertices/indices from the end of the last reservation made with PrimReserve(). +void ImDrawList::PrimUnreserve(int idx_count, int vtx_count) +{ + IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0); + + ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size - 1]; + draw_cmd.ElemCount -= idx_count; + VtxBuffer.shrink(VtxBuffer.Size - vtx_count); + IdxBuffer.shrink(IdxBuffer.Size - idx_count); +} + // Fully unrolled with inline call to keep our debug builds decently fast. void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col) { diff --git a/imgui_internal.h b/imgui_internal.h index af661afb..26cf3a15 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -847,7 +847,7 @@ struct IMGUI_API ImDrawListSharedData ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas ImFont* Font; // Current/default font (optional, for simplified AddText overload) float FontSize; // Current/default font size (optional, for simplified AddText overload) - float CurveTessellationTol; + float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) From e42c1e1668640f923ad03be24f57eab794c13f1c Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Dec 2019 16:12:44 +0100 Subject: [PATCH 174/384] Exposed IMGUI_DEBUG_PARANOID in imconfig.h + using a #define with no value to match other uses in imconfig.h --- imconfig.h | 11 ++++++++--- imgui_internal.h | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/imconfig.h b/imconfig.h index 25cad5f5..39f24a02 100644 --- a/imconfig.h +++ b/imconfig.h @@ -77,14 +77,19 @@ //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); //#define ImDrawCallback MyImDrawCallback -//---- Debug Tools -// Use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging. +//---- Debug Tools: Macro to break in Debugger +// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) //#define IM_DEBUG_BREAK IM_ASSERT(0) //#define IM_DEBUG_BREAK __debugbreak() -// Have the Item Picker break in the ItemAdd() function instead of ItemHoverable() - which is earlier in the code, will catch a few extra items, allow picking items other than Hovered one. + +//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), +// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) // This adds a small runtime cost which is why it is not enabled by default. //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX +//---- Debug Tools: Enable slower asserts +//#define IMGUI_DEBUG_PARANOID + //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. /* namespace ImGui diff --git a/imgui_internal.h b/imgui_internal.h index 26cf3a15..013d5dca 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -156,8 +156,9 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #endif // "Paranoid" Debug Asserts are meant to only be enabled during specific debugging/work, otherwise would slow down the code too much. -#define IMGUI_DEBUG_PARANOID 0 -#if IMGUI_DEBUG_PARANOID +// We currently don't have many of those so the effect is currently negligible, but onward intent to add more aggressive ones in the code. +//#define IMGUI_DEBUG_PARANOID +#ifdef IMGUI_DEBUG_PARANOID #define IM_ASSERT_PARANOID(_EXPR) IM_ASSERT(_EXPR) #else #define IM_ASSERT_PARANOID(_EXPR) From f9c26d23dea0301a63195c7f7d914a6220a6372b Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 8 Dec 2019 16:26:47 +0100 Subject: [PATCH 175/384] Removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017). Comments --- docs/CHANGELOG.txt | 13 +++++++++++++ imconfig.h | 2 +- imgui.cpp | 34 ++++++++++++++++++++++++---------- imgui.h | 26 ++++++-------------------- imgui_demo.cpp | 4 ---- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0c904576..5cd00a75 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,6 +34,19 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Breaking Changes: +- Removed redirecting functions/enums names that were marked obsolete in 1.53 (December 2017): + - ShowTestWindow() -> use ShowDemoWindow() + - IsRootWindowFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootWindow) + - IsRootWindowOrAnyChildFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) + - SetNextWindowContentWidth(w) -> use SetNextWindowContentSize(ImVec2(w, 0.0f) + - GetItemsLineHeightWithSpacing() -> use GetFrameHeightWithSpacing() + - ImGuiCol_ChildWindowBg -> use ImGuiCol_ChildBg + - ImGuiStyleVar_ChildWindowRounding -> use ImGuiStyleVar_ChildRounding + - ImGuiTreeNodeFlags_AllowOverlapMode -> use ImGuiTreeNodeFlags_AllowItemOverlap + - IMGUI_DISABLE_TEST_WINDOWS -> use IMGUI_DISABLE_DEMO_WINDOWS + If you were still using the old names, while you are cleaning up, considering enabling + IMGUI_DISABLE_OBSOLETE_FUNCTIONS in imconfig.h even temporarily to have a pass at finding + and removing up old API calls, if any remaining. - Removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). - Obsoleted calling ImDrawList::PrimReserve() with a negative count (which was vaguely diff --git a/imconfig.h b/imconfig.h index 39f24a02..c4f7891e 100644 --- a/imconfig.h +++ b/imconfig.h @@ -22,7 +22,7 @@ //#define IMGUI_API __declspec( dllexport ) //#define IMGUI_API __declspec( dllimport ) -//---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. +//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) diff --git a/imgui.cpp b/imgui.cpp index 8dbbd540..44792232 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,12 +353,27 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/12/08 (1.75) - removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017): + - ShowTestWindow() -> use ShowDemoWindow() + - IsRootWindowFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootWindow) + - IsRootWindowOrAnyChildFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) + - SetNextWindowContentWidth(w) -> use SetNextWindowContentSize(ImVec2(w, 0.0f) + - GetItemsLineHeightWithSpacing() -> use GetFrameHeightWithSpacing() + - ImGuiCol_ChildWindowBg -> use ImGuiCol_ChildBg + - ImGuiStyleVar_ChildWindowRounding -> use ImGuiStyleVar_ChildRounding + - ImGuiTreeNodeFlags_AllowOverlapMode -> use ImGuiTreeNodeFlags_AllowItemOverlap + - IMGUI_DISABLE_TEST_WINDOWS -> use IMGUI_DISABLE_DEMO_WINDOWS - 2019/12/08 (1.75) - obsoleted calling ImDrawList::PrimReserve() with a negative count (which was the vaguely documented and rarely if ever used). Instead we added an explicit PrimUnreserve() API. - 2019/12/06 (1.75) - removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). - 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. - - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. See docs/Changelog.txt or grep this log for details and new names, or see how they were implemented until 1.73. + - 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): + - Begin() [old 5 args version] -> use Begin() [3 args], use SetNextWindowSize() SetNextWindowBgAlpha() if needed + - IsRootWindowOrAnyChildHovered() -> use IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) + - AlignFirstTextHeightToWidgets() -> use AlignTextToFramePadding() + - SetNextWindowPosCenter() -> use SetNextWindowPos() with a pivot of (0.5f, 0.5f) + - ImFont::Glyph -> use ImFontGlyph - 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function. if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix. The function was triggering on: 0.0 and (delay+rate*N) where (N>=1). Fixed formula responds to (N>=0). Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay). @@ -537,14 +552,13 @@ CODE - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused) - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions. - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader. - (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels. - font init: { const void* png_data; unsigned int png_size; ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); <..Upload texture to GPU..>; } - became: { unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); <..Upload texture to GPU>; io.Fonts->TexId = YourTextureIdentifier; } - you now have more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs. - it is now recommended that you sample the font texture with bilinear interpolation. - (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID. - (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix) - (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets + - 2015/01/11 (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels. + - old: const void* png_data; unsigned int png_size; ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); [..Upload texture to GPU..]; + - new: unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); [..Upload texture to GPU..]; io.Fonts->TexId = YourTexIdentifier; + you now have more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs. It is now recommended that you sample the font texture with bilinear interpolation. + - 2015/01/11 (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID. + - 2015/01/11 (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix) + - 2015/01/11 (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver) - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph) - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility @@ -1002,7 +1016,7 @@ ImGuiIO::ImGuiIO() { // Most fields are initialized with zero memset(this, 0, sizeof(*this)); - IM_STATIC_ASSERT(IM_ARRAYSIZE(MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(MouseClicked) == ImGuiMouseButton_COUNT); + IM_ASSERT(IM_ARRAYSIZE(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT); // Our pre-C++11 IM_STATIC_ASSERT() macros triggers warning on modern compilers so we don't use it here. // Settings ConfigFlags = ImGuiConfigFlags_None; diff --git a/imgui.h b/imgui.h index d0cd8494..0eef98d9 100644 --- a/imgui.h +++ b/imgui.h @@ -815,11 +815,6 @@ enum ImGuiTreeNodeFlags_ ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop) //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 14, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog - - // Obsolete names (will be removed) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiTreeNodeFlags_AllowOverlapMode = ImGuiTreeNodeFlags_AllowItemOverlap // [renamed in 1.53] -#endif }; // Flags for ImGui::Selectable() @@ -1095,9 +1090,7 @@ enum ImGuiCol_ // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS , ImGuiCol_ModalWindowDarkening = ImGuiCol_ModalWindowDimBg // [renamed in 1.63] - , ImGuiCol_ChildWindowBg = ImGuiCol_ChildBg // [renamed in 1.53] - //ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered, // [unused since 1.60+] the close button now uses regular button colors. - //ImGuiCol_ComboBg, // [unused since 1.53+] ComboBg has been merged with PopupBg, so a redirect isn't accurate. + //, ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered// [unused since 1.60+] the close button now uses regular button colors. #endif }; @@ -1134,8 +1127,7 @@ enum ImGuiStyleVar_ // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiStyleVar_Count_ = ImGuiStyleVar_COUNT // [renamed in 1.60] - , ImGuiStyleVar_ChildWindowRounding = ImGuiStyleVar_ChildRounding // [renamed in 1.53] + , ImGuiStyleVar_Count_ = ImGuiStyleVar_COUNT // [renamed in 1.60] #endif }; @@ -1410,9 +1402,9 @@ struct ImGuiIO // Optional: Platform/Renderer back-end name (informational only! will be displayed in About Window) + User data for back-end/wrappers to store their own stuff. const char* BackendPlatformName; // = NULL const char* BackendRendererName; // = NULL - void* BackendPlatformUserData; // = NULL - void* BackendRendererUserData; // = NULL - void* BackendLanguageUserData; // = NULL + void* BackendPlatformUserData; // = NULL // User data for platform back-end + void* BackendRendererUserData; // = NULL // User data for renderer back-end + void* BackendLanguageUserData; // = NULL // User data for non C++ programming language back-end // Optional: Access OS clipboard // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) @@ -1474,7 +1466,7 @@ struct ImGuiIO ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. //------------------------------------------------------------------ - // [Internal] ImGui will maintain those fields. Forward compatibility not guaranteed! + // [Internal] Dear ImGui will maintain those fields. Forward compatibility not guaranteed! //------------------------------------------------------------------ ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) @@ -1598,12 +1590,6 @@ namespace ImGui static inline bool IsAnyWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_AnyWindow); } static inline bool IsAnyWindowHovered() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); } static inline ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = 0.f) { IM_UNUSED(on_edge); IM_UNUSED(outward); IM_ASSERT(0); return pos; } - // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) - static inline void ShowTestWindow() { return ShowDemoWindow(); } - static inline bool IsRootWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootWindow); } - static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } - static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); } - static inline float GetItemsLineHeightWithSpacing() { return GetFrameHeightWithSpacing(); } } typedef ImGuiInputTextCallback ImGuiTextEditCallback; // OBSOLETED in 1.63 (from Aug 2018): made the names consistent typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c9f9c73a..af2e46cc 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -115,10 +115,6 @@ Index of this file: // [SECTION] Forward Declarations, Helpers //----------------------------------------------------------------------------- -#if !defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) && defined(IMGUI_DISABLE_TEST_WINDOWS) && !defined(IMGUI_DISABLE_DEMO_WINDOWS) // Obsolete name since 1.53, TEST->DEMO -#define IMGUI_DISABLE_DEMO_WINDOWS -#endif - #if !defined(IMGUI_DISABLE_DEMO_WINDOWS) // Forward Declarations From 0e741036599a1d53b8b4e6f954567f1b3e5cf949 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Mon, 9 Dec 2019 15:13:24 +0900 Subject: [PATCH 176/384] ImDrawList: Add AddNgon(), AddNgonFilled() API. --- docs/CHANGELOG.txt | 4 ++++ imgui.h | 2 ++ imgui_demo.cpp | 6 ++++-- imgui_draw.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5cd00a75..0c43b000 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -60,6 +60,10 @@ Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. + In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as + we will rework the circle rendering functions to use textures and automatic segment count + selection, those new api can fill a gap. [@ShironekoBen] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking diff --git a/imgui.h b/imgui.h index 0eef98d9..f77adb4a 100644 --- a/imgui.h +++ b/imgui.h @@ -1934,6 +1934,8 @@ struct ImDrawList IMGUI_API void AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col); IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12); + IMGUI_API void AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness = 1.0f); + IMGUI_API void AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments); IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, bool closed, float thickness); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index af2e46cc..c15b5a63 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4440,9 +4440,11 @@ static void ShowExampleAppCustomRendering(bool* p_open) { static float sz = 36.0f; static float thickness = 3.0f; + static int ngon_sides = 6; static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f"); ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); + ImGui::SliderInt("n-gon sides", &ngon_sides, 3, 12); ImGui::ColorEdit4("Color", &colf.x); const ImVec2 p = ImGui::GetCursorScreenPos(); const ImU32 col = ImColor(colf); @@ -4455,7 +4457,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) { // First line uses a thickness of 1.0f, second line uses the configurable thickness float th = (n == 0) ? 1.0f : thickness; - draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 6, th); x += sz + spacing; // Hexagon + draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // n-gon draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 20, th); x += sz + spacing; // Circle draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners @@ -4469,7 +4471,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) x = p.x + 4; y += sz + spacing; } - draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 6); x += sz + spacing; // Hexagon + draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // n-gon draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 32); x += sz + spacing; // Circle draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 18029f4d..9efb4731 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1104,6 +1104,30 @@ void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, PathFillConvex(col); } +// Guaranteed to honor 'num_segments' +void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) +{ + if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) + return; + + // Because we are filling a closed shape we remove 1 from the count of segments/points + const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; + PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1); + PathStroke(col, true, thickness); +} + +// Guaranteed to honor 'num_segments' +void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) +{ + if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) + return; + + // Because we are filling a closed shape we remove 1 from the count of segments/points + const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; + PathArcTo(center, radius, 0.0f, a_max, num_segments - 1); + PathFillConvex(col); +} + void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments) { if ((col & IM_COL32_A_MASK) == 0) From 6fdde67be2b606f0ef86d93d4e2074e4fa9f660c Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 10 Dec 2019 13:37:29 +0100 Subject: [PATCH 177/384] Documentation, FAQ, todo tweaks --- docs/FAQ.md | 25 +++++++++++++++++-------- docs/README.md | 2 +- docs/TODO.txt | 30 ++++++++++++++++++------------ imgui.cpp | 30 +++++++++++++++++------------- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index c777d87f..a56b7967 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -21,7 +21,8 @@ or view this file with any Markdown viewer. | [Why using C++ (as opposed to C)?](#q-why-using-c-as-opposed-to-c) | | **Q&A: Integration** | | [How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?](#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application) | -| [How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)](#q-how-can-i-use-this-without-a-mouse-without-a-keyboard-or-without-a-screen-gamepad-input-share-remote-display) | +| [How can I enable keyboard or gamepad controls?](#q-how-can-i-enable-keyboard-or-gamepad-controls) | +| [How can I use this on a machine without mouse, keyboard or screen? (input share, remote display)](#q-how-can-i-use-this-on-a-machine-without-mouse-keyboard-or-screen-input-share-remote-display) | | [I integrated Dear ImGui in my engine and the text or lines are blurry..](#q-i-integrated-dear-imgui-in-my-engine-and-the-text-or-lines-are-blurry) | | [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) | | **Q&A: Usage** | @@ -48,6 +49,7 @@ or view this file with any Markdown viewer. - See demo code in [imgui_demo.cpp](https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp) and particularly the `ImGui::ShowDemoWindow()` function. The demo covers most features of Dear ImGui, so you can read the code and see its output. - See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h). - The [Wiki](https://github.com/ocornut/imgui/wiki) has many resources and links. +- The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful. - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. --- @@ -65,7 +67,7 @@ Many projects are using this branch and it is kept in sync with master regularly ### Q: Why the names "Dear ImGui" vs "ImGui"? -**TL;DR: Please try to refer to this library as "Dear ImGui".** +**TL;DR: Please refer to this library as "Dear ImGui".** The library started its life as "ImGui" due to the fact that I didn't give it a proper name when when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. @@ -127,16 +129,23 @@ e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` --- -### Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) -- You can control Dear ImGui with a gamepad. Read about navigation in "Using gamepad/keyboard navigation controls". -(short version: map gamepad inputs into the io.NavInputs[] array + set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad`). -- See navigation [control sheets for gamepads](http://www.dearimgui.org/controls_sheets) (for PS4, XB1, Switch gamepads). -- You can share your computer mouse seamlessly with your console/tablet/phone using [Synergy](https://symless.com/synergy) +### Q: How can I enable keyboard or gamepad controls? +- The gamepad/keyboard navigation is fairly functional and keeps being improved. The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. Gamepad support is particularly useful to use Dear ImGui on a game console (e.g. PS4, Switch, XB1) without a mouse connected! +- Keyboard: set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard` to enable. +- Gamepad: set `io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad` to enable (with a supporting back-end). +- See [Control Sheets for Gamepads](http://www.dearimgui.org/controls_sheets) (reference PNG/PSD for for PS4, XB1, Switch gamepads). +- See `USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS` section of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) for more details. + +--- + +### Q: How can I use this on a machine without mouse, keyboard or screen? (input share, remote display) +- You can share your computer mouse seamlessly with your console/tablet/phone using solutions such as [Synergy](https://symless.com/synergy) This is the preferred solution for developer productivity. In particular, the [micro-synergy-client repository](https://github.com/symless/micro-synergy-client) has simple and portable source code (uSynergy.c/.h) for a small embeddable client that you can use on any platform to connect to your host computer, based on the Synergy 1.x protocol. Make sure you download the Synergy 1 server on your computer. Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-like protocols. +- Game console users: consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. - You may also use a third party solution such as [Remote ImGui](https://github.com/JordiRos/remoteimgui) or [imgui-ws](https://github.com/ggerganov/imgui-ws) which sends the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. See [Wiki](https://github.com/ocornut/imgui/wiki) index for most details. - For touch inputs, you can increase the hit box of widgets (via the `style.TouchPadding` setting) to accommodate for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing @@ -536,4 +545,4 @@ You may post screenshot or links in the [gallery threads](https://github.com/oco - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete PR. ##### [Return to Index](#index) - + diff --git a/docs/README.md b/docs/README.md index c78cddb9..8d44b5d8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -126,7 +126,7 @@ Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. ### Upcoming Changes -Some of the goals for 2019+ are: +Some of the goals for 2019-2020 are: - Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787)) diff --git a/docs/TODO.txt b/docs/TODO.txt index e37af88a..7a977f72 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -8,6 +8,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - doc/test: add a proper documentation+regression testing system (#435) - doc/test: checklist app to verify binding/integration of imgui (test inputs, rendering, callback, etc.). - doc/tips: tips of the day: website? applet in imgui_club? + - doc/wiki: work on the wiki https://github.com/ocornut/imgui/wiki - window: preserve/restore relative focus ordering (persistent or not) (#2304) -> also see docking reference to same #. - window: calling SetNextWindowSize() every frame with <= 0 doesn't do anything, may be useful to allow (particularly when used for a single axis). (#690) @@ -27,6 +28,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: GetWindowSize() returns (0,0) when not calculated? (#1045) - window: investigate better auto-positioning for new windows. - window: top most window flag? (#2574) + - window: the size_on_first_use path of Begin() can probably be removed - window/opt: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. -> this may require enforcing that it is illegal to submit contents if Begin returns false. - window/child: the first draw command of a child window could be moved into the current draw command of the parent window (unless child+tooltip?). - window/child: border could be emitted in parent as well. @@ -58,7 +60,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - main: find a way to preserve relative orders of multiple reappearing windows (so an app toggling between "modes" e.g. fullscreen vs all tools) won't lose relative ordering. - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - - main: rename the main "Debug" window to avoid ID collision with user who may want to use "Debug" with specific flags. - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395) - widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h. @@ -273,7 +274,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - drag and drop: (#143) "both an in-process pointer and a promise to generate a serialized version, for whether the drag ends inside or outside the same process" - drag and drop: feedback when hovering a region blocked by modal (mouse cursor "NO"?) - - node/graph editor (#306) + - node/graph editors (#306) (also see https://github.com/ocornut/imgui/wiki#node-editors) - pie menus patterns (#434) - markup: simple markup language for color change? (#902) @@ -301,12 +302,15 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font: add support for kerning, probably optional. A) perhaps default to (32..128)^2 matrix ~ 9K entries = 36KB, then hash for non-ascii?. B) or sparse lookup into per-char list? - font: add a simpler CalcTextSizeA() api? current one ok but not welcome if user needs to call it directly (without going through ImGui::CalcTextSize) - font: fix AddRemapChar() to work before atlas has been built. - - font: what would it take to support codepoint higher than 0xFFFF? (smileys, etc.) (#2538, #2541) + - font: support for unicode codepoints higher than 0xFFFF? (pr #2815) - font: (api breaking) remove "TTF" from symbol names. also because it now supports OTF. - font/opt: Considering storing standalone AdvanceX table as 16-bit fixed point integer? - font/opt: Glyph currently 40 bytes (2+9*4). Consider storing UV as 16 bits integer? (->32 bytes). X0/Y0/X1/Y1 as 16 fixed-point integers? Or X0/Y0 as float and X1/Y1 as fixed8_8? - nav: some features such as PageUp/Down/Home/End should probably work without ImGuiConfigFlags_NavEnableKeyboard? (where do we draw the line?) + ! nav: never clear NavId on some setup (e.g. gamepad centric) + - nav: restore NavId on reappearing non-child window. + - nav: code to focus child-window on restoring NavId appears to have issue (to investigate) - nav: configuration flag to disable global shortcuts (currently only CTRL-Tab) ? - nav: Home/End behavior when navigable item is not fully visible at the edge of scrolling? should be backtrack to keep item into view? - nav: NavScrollToBringItemIntoView() with item bigger than view should focus top-right? Repro: using Nav in "About Window" @@ -352,9 +356,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - misc: possible compile-time support for string view/range instead of char* would e.g. facilitate usage with Rust (#683) - misc: possible compile-time support for wchar_t instead of char*? - - backend: bgfx? https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 - - emscriptem: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42) - - remote: make a system like RemoteImGui first-class citizen/project (#75) - demo: find a way to demonstrate textures in the examples application, as it such a common issue for new users. @@ -363,14 +364,19 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - demo: add virtual scrolling example? - demo: demonstrate Plot offset - demo: window size constraint: square demo is broken when resizing from edges (#1975), would need to rework the callback system to solve this + - examples: window minimize, maximize (#583) - examples: provide a zero frame-rate/idle example. - - examples: apple: example_apple should be using modern GL3. - - examples: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) - - examples: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900) - - examples: opengl: could use a single vertex buffer and glBufferSubData for uploads? - - examples: opengl: explicitly disable GL_STENCIL_TEST in bindings. - - examples: vulkan: viewport: support for synchronized swapping of multiple swap chains. + - backends: apple: example_apple should be using modern GL3. + - backends: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) + - backends: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900) + - backends: opengl: could use a single vertex buffer and glBufferSubData for uploads? + - backends: opengl: explicitly disable GL_STENCIL_TEST in bindings. + - backends: opengl: consider gl_lite loader https://github.com/ApoorvaJ/Papaya/blob/3808e39b0f45d4ca4972621c847586e4060c042a/src/libs/gl_lite.h + - backends: vulkan: viewport: support for synchronized swapping of multiple swap chains. + - backends: bgfx: https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 + - backends: mscriptem: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42) + - optimization: replace vsnprintf with stb_printf? or enable the defines/infrastructure to allow it (#1038) - optimization: add clipping for multi-component widgets (SliderFloatX, ColorEditX, etc.). one problem is that nav branch can't easily clip parent group when there is a move request. - optimization: add a flag to disable most of rendering, for the case where the user expect to skip it (#335) diff --git a/imgui.cpp b/imgui.cpp index 44792232..95ce9ea7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -310,9 +310,18 @@ CODE USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS ------------------------------------------ - The gamepad/keyboard navigation is fairly functional and keeps being improved. - - Gamepad support is particularly useful to use dear imgui on a console system (e.g. PS4, Switch, XB1) without a mouse! + - Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PS4, Switch, XB1) without a mouse! - You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787 - The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. + - Keyboard: + - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. + NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. + - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), the io.WantCaptureKeyboard flag + will be set. For more advanced uses, you may want to read from: + - io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set. + - io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used). + - or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions. + Please reach out if you think the game vs navigation input sharing could be improved. - Gamepad: - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + fill the io.NavInputs[] fields before calling NewFrame(). @@ -324,15 +333,6 @@ CODE - You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://goo.gl/9LgVZW. - If you need to share inputs between your game and the imgui parts, the easiest approach is to go all-or-nothing, with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved. - - Keyboard: - - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. - NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. - - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), the io.WantCaptureKeyboard flag - will be set. For more advanced uses, you may want to read from: - - io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set. - - io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used). - - or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions. - Please reach out if you think the game vs navigation input sharing could be improved. - Mouse: - PS4 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. - Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + uSynergy.c (on your console/tablet/phone app) to share your PC mouse/keyboard. @@ -587,13 +587,16 @@ CODE - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. - The demo covers most features of Dear ImGui, so you can read the code and see its output. - See documentation and comments at the top of imgui.cpp + effectively imgui.h. - - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ - folder to explain how to integrate Dear ImGui with your own engine/application. + - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the + examples/ folder to explain how to integrate Dear ImGui with your own engine/application. + - The Wiki (https://github.com/ocornut/imgui/wiki) has many resources and links. + - The Glossary (https://github.com/ocornut/imgui/wiki/Glossary) page also may be useful. - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. Q: Which version should I get? Q: Why the names "Dear ImGui" vs "ImGui"? + >> This library is called "Dear ImGui", please don't call it "ImGui" :) >> See https://www.dearimgui.org/faq Q&A: Concerns @@ -623,6 +626,7 @@ CODE have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) + Q. How can I enable keyboard controls? Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. @@ -4629,7 +4633,7 @@ void ImGui::EndChild() ImGuiWindow* window = g.CurrentWindow; IM_ASSERT(g.WithinEndChild == false); - IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() callss + IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() calls g.WithinEndChild = true; if (window->BeginCount > 1) From 43bd80a40d0fd11a454eb5e70c234df98204c64d Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 12 Dec 2019 19:56:29 +0100 Subject: [PATCH 178/384] Internals: Breaking: ImRect() default constructor initializes all fields with 0.0f Instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). Previous behavior was designed for adding into a bounding box but rarely relied on and not worth it. --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 3 ++- imgui_internal.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0c43b000..13e3cec7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -55,6 +55,9 @@ Breaking Changes: documented (can only unreserve from the last reserve call). If you suspect you ever used that feature before, #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing calls. [@ShironekoBen] +- imgui_internal.h: changed ImRect() default constructor initializes all fields to 0.0f instead + of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by + adding multiple points into it, you may need to fix your initial value. Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). diff --git a/imgui.cpp b/imgui.cpp index 95ce9ea7..c32b64c1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,6 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/12/13 (1.75) - [imgui_internal.h] changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding multiple points into it, you may need to fix your initial value. - 2019/12/08 (1.75) - removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017): - ShowTestWindow() -> use ShowDemoWindow() - IsRootWindowFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootWindow) @@ -9810,7 +9811,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (show_drawcmd_details && fg_draw_list && ImGui::IsItemHovered()) { ImRect clip_rect = pcmd->ClipRect; - ImRect vtxs_rect; + ImRect vtxs_rect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); for (unsigned int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255,0,255,255)); diff --git a/imgui_internal.h b/imgui_internal.h index 013d5dca..ec35468f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -644,7 +644,7 @@ struct IMGUI_API ImRect ImVec2 Min; // Upper-left ImVec2 Max; // Lower-right - ImRect() : Min(FLT_MAX,FLT_MAX), Max(-FLT_MAX,-FLT_MAX) {} + ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} From 3a800f2dc9f1be1aac4c1148983b80556d6ce727 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 13 Dec 2019 11:56:51 +0100 Subject: [PATCH 179/384] DragFloat: Mention usage of FLT_MAX, INT_MAX etc. explicitly. (#2931) --- imgui.h | 1 + imgui_demo.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index f77adb4a..13150f14 100644 --- a/imgui.h +++ b/imgui.h @@ -434,6 +434,7 @@ namespace ImGui // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. // - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision). // - Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits. + // - Use v_max = FLT_MAX / INT_MAX etc to avoid clamping to a maximum, same with v_min = -FLT_MAX / INT_MIN to avoid clamping to a minimum. // - Use v_min > v_max to lock edits. IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c15b5a63..030ed0da 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2201,10 +2201,10 @@ static void ShowDemoWindowLayout() ImGui::SameLine(140); enable_track |= ImGui::DragInt("##item", &track_item, 0.25f, 0, 99, "Item = %d"); bool scroll_to_off = ImGui::Button("Scroll Offset"); - ImGui::SameLine(140); scroll_to_off |= ImGui::DragFloat("##off", &scroll_to_off_px, 1.00f, 0, 9999, "+%.0f px"); + ImGui::SameLine(140); scroll_to_off |= ImGui::DragFloat("##off", &scroll_to_off_px, 1.00f, 0, FLT_MAX, "+%.0f px"); bool scroll_to_pos = ImGui::Button("Scroll To Pos"); - ImGui::SameLine(140); scroll_to_pos |= ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, 9999, "X/Y = %.0f px"); + ImGui::SameLine(140); scroll_to_pos |= ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, FLT_MAX, "X/Y = %.0f px"); ImGui::PopItemWidth(); if (scroll_to_off || scroll_to_pos) From 10fdc03a46921c71356d1e5c932a6f2ea1250f38 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Dec 2019 13:19:36 +0100 Subject: [PATCH 180/384] Clarification about Im helpers + moving GetColorXXX functions outside of that block. --- imgui.cpp | 66 ++++++++++++++++++++++++------------------------ imgui_internal.h | 2 ++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c32b64c1..30957849 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1726,38 +1726,6 @@ void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& } } -ImU32 ImGui::GetColorU32(ImGuiCol idx, float alpha_mul) -{ - ImGuiStyle& style = GImGui->Style; - ImVec4 c = style.Colors[idx]; - c.w *= style.Alpha * alpha_mul; - return ColorConvertFloat4ToU32(c); -} - -ImU32 ImGui::GetColorU32(const ImVec4& col) -{ - ImGuiStyle& style = GImGui->Style; - ImVec4 c = col; - c.w *= style.Alpha; - return ColorConvertFloat4ToU32(c); -} - -const ImVec4& ImGui::GetStyleColorVec4(ImGuiCol idx) -{ - ImGuiStyle& style = GImGui->Style; - return style.Colors[idx]; -} - -ImU32 ImGui::GetColorU32(ImU32 col) -{ - float style_alpha = GImGui->Style.Alpha; - if (style_alpha >= 1.0f) - return col; - ImU32 a = (col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT; - a = (ImU32)(a * style_alpha); // We don't need to clamp 0..255 because Style.Alpha is in 0..1 range. - return (col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT); -} - //----------------------------------------------------------------------------- // [SECTION] ImGuiStorage // Helper: Key->value storage @@ -2215,10 +2183,42 @@ bool ImGuiListClipper::Step() //----------------------------------------------------------------------------- // [SECTION] RENDER HELPERS -// Those (internal) functions are currently quite a legacy mess - their signature and behavior will change. +// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change. // Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state. //----------------------------------------------------------------------------- +ImU32 ImGui::GetColorU32(ImGuiCol idx, float alpha_mul) +{ + ImGuiStyle& style = GImGui->Style; + ImVec4 c = style.Colors[idx]; + c.w *= style.Alpha * alpha_mul; + return ColorConvertFloat4ToU32(c); +} + +ImU32 ImGui::GetColorU32(const ImVec4& col) +{ + ImGuiStyle& style = GImGui->Style; + ImVec4 c = col; + c.w *= style.Alpha; + return ColorConvertFloat4ToU32(c); +} + +const ImVec4& ImGui::GetStyleColorVec4(ImGuiCol idx) +{ + ImGuiStyle& style = GImGui->Style; + return style.Colors[idx]; +} + +ImU32 ImGui::GetColorU32(ImU32 col) +{ + ImGuiStyle& style = GImGui->Style; + if (style.Alpha >= 1.0f) + return col; + ImU32 a = (col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT; + a = (ImU32)(a * style.Alpha); // We don't need to clamp 0..255 because Style.Alpha is in 0..1 range. + return (col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT); +} + const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end) { const char* text_display_end = text; diff --git a/imgui_internal.h b/imgui_internal.h index ec35468f..07fb2882 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -192,6 +192,8 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer //----------------------------------------------------------------------------- // Generic helpers +// Note that the ImXXX helpers functions are lower-level than ImGui functions. +// ImGui functions or the ImGui context are never called/used from other ImXXX functions. //----------------------------------------------------------------------------- // - Helpers: Misc // - Helpers: Bit manipulation From 9d444062f974b21f1fc09b7e85479fff3e0789c2 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Dec 2019 13:25:46 +0100 Subject: [PATCH 181/384] Limiting Columns()/BeginColumns() api to 64 columns (#125) While the current code technically supports it, future code may not so we're putting the restriction ahead. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 1 + imgui.h | 1 + imgui_widgets.cpp | 4 ++-- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 13e3cec7..c9ff9b2d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -55,6 +55,8 @@ Breaking Changes: documented (can only unreserve from the last reserve call). If you suspect you ever used that feature before, #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing calls. [@ShironekoBen] +- Limiting Columns()/BeginColumns() api to 64 columns with an assert. While the current code + technically supports it, future code may not so we're putting the restriction ahead. - imgui_internal.h: changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding multiple points into it, you may need to fix your initial value. diff --git a/imgui.cpp b/imgui.cpp index 30957849..dff12b62 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -353,6 +353,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2019/12/17 (1.75) - made Columns() limited to 64 columns by asserting above that limit. While the current code technically supports it, future code may not so we're putting the restriction ahead. - 2019/12/13 (1.75) - [imgui_internal.h] changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding multiple points into it, you may need to fix your initial value. - 2019/12/08 (1.75) - removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017): - ShowTestWindow() -> use ShowDemoWindow() diff --git a/imgui.h b/imgui.h index 13150f14..704a7211 100644 --- a/imgui.h +++ b/imgui.h @@ -584,6 +584,7 @@ namespace ImGui // Columns // - You can also use SameLine(pos_x) to mimic simplified columns. // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) + // - There is a maximum of 64 columns. // - By end of the 2019 we will expose a new 'Table' api which will replace columns. IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d605e2d7..684dbe55 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7411,8 +7411,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - IM_ASSERT(columns_count >= 1); - IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported + IM_ASSERT(columns_count >= 1 && columns_count <= 64); // Maximum 64 columns + IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported // Acquire storage for the columns set ImGuiID id = GetColumnsID(str_id, columns_count); From 78ff147181919f3f3595d90b571bd0863c0c4aa4 Mon Sep 17 00:00:00 2001 From: NeroBurner-tux Date: Tue, 24 Sep 2019 19:44:29 +0200 Subject: [PATCH 182/384] SDL: On wayland use SDL_GetMouseState (#2802) When the SDL Video backend is set to wayland the function `SDL_GetGlobalMouseState` does not work. Most probably a security measure for programs to not grab everything the user does https://wiki.libsdl.org/SDL_GetGlobalMouseState using SDL_GetMouseState https://wiki.libsdl.org/SDL_GetMouseState works on wayland --- examples/imgui_impl_sdl.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 05498c09..ac4f55fc 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -17,6 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2019-12-17: Inputs: Use SDL_GetMouseState, because there is no global mouse state on Wayland. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application). @@ -60,6 +61,7 @@ static Uint64 g_Time = 0; static bool g_MousePressed[3] = { false, false, false }; static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; +static bool g_VideoDriverIsWayland = false; static const char* ImGui_ImplSDL2_GetClipboardText(void*) { @@ -124,6 +126,9 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) { g_Window = window; + // Check and store if we are on Wayland to not check on every frame. + g_VideoDriverIsWayland = strncmp(SDL_GetCurrentVideoDriver(), "wayland", 7) == 0; + // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) @@ -238,13 +243,17 @@ static void ImGui_ImplSDL2_UpdateMousePosAndButtons() SDL_Window* focused_window = SDL_GetKeyboardFocus(); if (g_Window == focused_window) { - // SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?) - // The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally. - int wx, wy; - SDL_GetWindowPosition(focused_window, &wx, &wy); - SDL_GetGlobalMouseState(&mx, &my); - mx -= wx; - my -= wy; + if (!g_VideoDriverIsWayland) + { + // SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?) + // The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally. + // Won't use this workaround when on Wayland, as there is no global mouse position. + int wx, wy; + SDL_GetWindowPosition(focused_window, &wx, &wy); + SDL_GetGlobalMouseState(&mx, &my); + mx -= wx; + my -= wy; + } io.MousePos = ImVec2((float)mx, (float)my); } From 0f7105e15608b7198980864c1a92b07c124c7c0d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Dec 2019 14:34:18 +0100 Subject: [PATCH 183/384] Backends: SDL: Wayland: Use SDL_GetMouseState (amend 78ff147) (#2800, 2802) --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_sdl.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c9ff9b2d..0eecd414 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -71,6 +71,8 @@ Other Changes: selection, those new api can fill a gap. [@ShironekoBen] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] +- Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available + on Wayland). (#2800, #2802) [@NeroBurner] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the opengl3 backend might automatically use it). [#2919, #2798] diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index ac4f55fc..8a295aaa 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -17,7 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2019-12-17: Inputs: Use SDL_GetMouseState, because there is no global mouse state on Wayland. +// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state). // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. // 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application). @@ -61,7 +61,7 @@ static Uint64 g_Time = 0; static bool g_MousePressed[3] = { false, false, false }; static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; -static bool g_VideoDriverIsWayland = false; +static bool g_MouseCanUseGlobalState = true; static const char* ImGui_ImplSDL2_GetClipboardText(void*) { @@ -126,9 +126,6 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) { g_Window = window; - // Check and store if we are on Wayland to not check on every frame. - g_VideoDriverIsWayland = strncmp(SDL_GetCurrentVideoDriver(), "wayland", 7) == 0; - // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional) @@ -163,6 +160,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText; io.ClipboardUserData = NULL; + // Load mouse cursors g_MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); g_MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); g_MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL); @@ -173,6 +171,9 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) g_MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); g_MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); + // Check and store if we are on Wayland + g_MouseCanUseGlobalState = strncmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0; + #ifdef _WIN32 SDL_SysWMinfo wmInfo; SDL_VERSION(&wmInfo.version); @@ -243,7 +244,7 @@ static void ImGui_ImplSDL2_UpdateMousePosAndButtons() SDL_Window* focused_window = SDL_GetKeyboardFocus(); if (g_Window == focused_window) { - if (!g_VideoDriverIsWayland) + if (g_MouseCanUseGlobalState) { // SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?) // The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally. From 3831d50ab96c33d24cec3e048d9c7839d2d64074 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 17 Dec 2019 16:29:12 +0200 Subject: [PATCH 184/384] Add ImBezierClosestPoint() function which returns a point on bezier curve which is closed to a specified point. --- imgui.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ imgui_draw.cpp | 21 ++++++++------- imgui_internal.h | 3 +++ 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index dff12b62..d114f9ef 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1109,6 +1109,72 @@ void ImGuiIO::ClearInputCharacters() // [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions) //----------------------------------------------------------------------------- +ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments) +{ + IM_ASSERT(num_segments > 0); + ImVec2 p_last = p1; + ImVec2 p_closest; + float p_closest_dist2 = FLT_MAX; + float t_step = 1.0f / (float)num_segments; + for (int i_step = 1; i_step <= num_segments; i_step++) + { + ImVec2 p_current = ImBezierCalc(p1, p2, p3, p4, t_step * i_step); + ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p); + float dist2 = ImLengthSqr(p - p_line); + if (dist2 < p_closest_dist2) + { + p_closest = p_line; + p_closest_dist2 = dist2; + } + p_last = p_current; + } + return p_closest; +} + +// Closely mimics PathBezierToCasteljau() in imgui_draw.cpp +static void ClosestPointBezierCasteljau(const ImVec2& p, ImVec2& p_closest, ImVec2& p_last, float& p_closest_dist2, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) +{ + float dx = x4 - x1; + float dy = y4 - y1; + float d2 = ((x2 - x4) * dy - (y2 - y4) * dx); + float d3 = ((x3 - x4) * dy - (y3 - y4) * dx); + d2 = (d2 >= 0) ? d2 : -d2; + d3 = (d3 >= 0) ? d3 : -d3; + if ((d2+d3) * (d2+d3) < tess_tol * (dx*dx + dy*dy)) + { + ImVec2 p_current(x4, y4); + ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p); + float dist2 = ImLengthSqr(p - p_line); + if (dist2 < p_closest_dist2) + { + p_closest = p_line; + p_closest_dist2 = dist2; + } + p_last = p_current; + } + else if (level < 10) + { + float x12 = (x1+x2)*0.5f, y12 = (y1+y2)*0.5f; + float x23 = (x2+x3)*0.5f, y23 = (y2+y3)*0.5f; + float x34 = (x3+x4)*0.5f, y34 = (y3+y4)*0.5f; + float x123 = (x12+x23)*0.5f, y123 = (y12+y23)*0.5f; + float x234 = (x23+x34)*0.5f, y234 = (y23+y34)*0.5f; + float x1234 = (x123+x234)*0.5f, y1234 = (y123+y234)*0.5f; + ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1); + ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1); + } +} + +ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float tess_tol) +{ + IM_ASSERT(tess_tol > 0.0f); + ImVec2 p_last = p1; + ImVec2 p_closest; + float p_closest_dist2 = FLT_MAX; + ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, tess_tol, 0); + return p_closest; +} + ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p) { ImVec2 ap = p - a; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 9efb4731..8f913dc0 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -907,6 +907,17 @@ void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, floa } } +ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t) +{ + float u = 1.0f - t; + float w1 = u*u*u; + float w2 = 3*u*u*t; + float w3 = 3*u*t*t; + float w4 = t*t*t; + return ImVec2(w1*p1.x + w2*p2.x + w3*p3.x + w4*p4.x, w1*p1.y + w2*p2.y + w3*p3.y + w4*p4.y); +} + +// Closely mimicked by ClosestPointBezierCasteljau() in imgui.cpp static void PathBezierToCasteljau(ImVector* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) { float dx = x4 - x1; @@ -945,15 +956,7 @@ void ImDrawList::PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImV { float t_step = 1.0f / (float)num_segments; for (int i_step = 1; i_step <= num_segments; i_step++) - { - float t = t_step * i_step; - float u = 1.0f - t; - float w1 = u*u*u; - float w2 = 3*u*u*t; - float w3 = 3*u*t*t; - float w4 = t*t*t; - _Path.push_back(ImVec2(w1*p1.x + w2*p2.x + w3*p3.x + w4*p4.x, w1*p1.y + w2*p2.y + w3*p3.y + w4*p4.y)); - } + _Path.push_back(ImBezierCalc(p1, p2, p3, p4, t_step * i_step)); } } diff --git a/imgui_internal.h b/imgui_internal.h index 07fb2882..bf594bc5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -340,6 +340,9 @@ static inline float ImLinearSweep(float current, float target, float speed) static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } // Helpers: Geometry +IMGUI_API ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t); +IMGUI_API ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments); // For curves with explicit number of segments +IMGUI_API ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float tess_tol); // For auto-tesselated curves, tess_tol = style.CurveTessellationTol IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); From a610f1da52273cac7f4a90cbfd8cb0fb642d5a07 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Dec 2019 16:24:50 +0100 Subject: [PATCH 185/384] Bezier Tweaks, fixed parameter order of 3831d50 --- imgui.cpp | 25 ++++++++++++++++--------- imgui.h | 4 ++-- imgui_draw.cpp | 13 ++++++------- imgui_internal.h | 6 +++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d114f9ef..c81ff318 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -45,7 +45,8 @@ CODE // [SECTION] FORWARD DECLARATIONS // [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) -// [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (Geometry functions) +// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions) // [SECTION] MISC HELPERS/UTILITIES (File functions) // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) // [SECTION] MISC HELPERS/UTILITIES (Color functions) @@ -1106,12 +1107,12 @@ void ImGuiIO::ClearInputCharacters() } //----------------------------------------------------------------------------- -// [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions) +// [SECTION] MISC HELPERS/UTILITIES (Geometry functions) //----------------------------------------------------------------------------- -ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments) +ImVec2 ImBezierClosestPoint(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, int num_segments) { - IM_ASSERT(num_segments > 0); + IM_ASSERT(num_segments > 0); // Use ImBezierClosestPointCasteljau() ImVec2 p_last = p1; ImVec2 p_closest; float p_closest_dist2 = FLT_MAX; @@ -1132,7 +1133,7 @@ ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, } // Closely mimics PathBezierToCasteljau() in imgui_draw.cpp -static void ClosestPointBezierCasteljau(const ImVec2& p, ImVec2& p_closest, ImVec2& p_last, float& p_closest_dist2, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) +static void BezierClosestPointCasteljauStep(const ImVec2& p, ImVec2& p_closest, ImVec2& p_last, float& p_closest_dist2, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) { float dx = x4 - x1; float dy = y4 - y1; @@ -1160,18 +1161,20 @@ static void ClosestPointBezierCasteljau(const ImVec2& p, ImVec2& p_closest, ImVe float x123 = (x12+x23)*0.5f, y123 = (y12+y23)*0.5f; float x234 = (x23+x34)*0.5f, y234 = (y23+y34)*0.5f; float x1234 = (x123+x234)*0.5f, y1234 = (y123+y234)*0.5f; - ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1); - ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1); + BezierClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1); + BezierClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1); } } -ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float tess_tol) +// tess_tol is generally the same value you would find in ImGui::GetStyle().CurveTessellationTol +// Because those ImXXX functions are lower-level than ImGui:: we cannot access this value automatically. +ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, float tess_tol) { IM_ASSERT(tess_tol > 0.0f); ImVec2 p_last = p1; ImVec2 p_closest; float p_closest_dist2 = FLT_MAX; - ClosestPointBezierCasteljau(p, p_closest, p_last, p_closest_dist2, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, tess_tol, 0); + BezierClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, tess_tol, 0); return p_closest; } @@ -1223,6 +1226,10 @@ ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, return proj_ca; } +//----------------------------------------------------------------------------- +// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions) +//----------------------------------------------------------------------------- + // Consider using _stricmp/_strnicmp under Windows or strcasecmp/strncasecmp. We don't actually use either ImStricmp/ImStrnicmp in the codebase any more. int ImStricmp(const char* str1, const char* str2) { diff --git a/imgui.h b/imgui.h index 704a7211..83bb2558 100644 --- a/imgui.h +++ b/imgui.h @@ -1942,7 +1942,7 @@ struct ImDrawList IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, bool closed, float thickness); IMGUI_API void AddConvexPolyFilled(const ImVec2* points, int num_points, ImU32 col); // Note: Anti-aliased filling requires points to be in clockwise order. - IMGUI_API void AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments = 0); + IMGUI_API void AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0); // Image primitives // - Read FAQ to understand what ImTextureID is. @@ -1960,7 +1960,7 @@ struct ImDrawList inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness); _Path.Size = 0; } IMGUI_API void PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments = 10); IMGUI_API void PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle - IMGUI_API void PathBezierCurveTo(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, int num_segments = 0); + IMGUI_API void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0); IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All); // Advanced diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 8f913dc0..58acacf5 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -917,7 +917,7 @@ ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const return ImVec2(w1*p1.x + w2*p2.x + w3*p3.x + w4*p4.x, w1*p1.y + w2*p2.y + w3*p3.y + w4*p4.y); } -// Closely mimicked by ClosestPointBezierCasteljau() in imgui.cpp +// Closely mimics BezierClosestPointCasteljauStep() in imgui.cpp static void PathBezierToCasteljau(ImVector* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) { float dx = x4 - x1; @@ -938,7 +938,6 @@ static void PathBezierToCasteljau(ImVector* path, float x1, float y1, fl float x123 = (x12+x23)*0.5f, y123 = (y12+y23)*0.5f; float x234 = (x23+x34)*0.5f, y234 = (y23+y34)*0.5f; float x1234 = (x123+x234)*0.5f, y1234 = (y123+y234)*0.5f; - PathBezierToCasteljau(path, x1,y1, x12,y12, x123,y123, x1234,y1234, tess_tol, level+1); PathBezierToCasteljau(path, x1234,y1234, x234,y234, x34,y34, x4,y4, tess_tol, level+1); } @@ -949,8 +948,7 @@ void ImDrawList::PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImV ImVec2 p1 = _Path.back(); if (num_segments == 0) { - // Auto-tessellated - PathBezierToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); + PathBezierToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); // Auto-tessellated } else { @@ -1131,13 +1129,14 @@ void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, in PathFillConvex(col); } -void ImDrawList::AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments) +// Cubic Bezier takes 4 controls points +void ImDrawList::AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments) { if ((col & IM_COL32_A_MASK) == 0) return; - PathLineTo(pos0); - PathBezierCurveTo(cp0, cp1, pos1, num_segments); + PathLineTo(p1); + PathBezierCurveTo(p2, p3, p4, num_segments); PathStroke(col, false, thickness); } diff --git a/imgui_internal.h b/imgui_internal.h index bf594bc5..ea58b65c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -340,9 +340,9 @@ static inline float ImLinearSweep(float current, float target, float speed) static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } // Helpers: Geometry -IMGUI_API ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t); -IMGUI_API ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments); // For curves with explicit number of segments -IMGUI_API ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float tess_tol); // For auto-tesselated curves, tess_tol = style.CurveTessellationTol +IMGUI_API ImVec2 ImBezierCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t); // Cubic Bezier +IMGUI_API ImVec2 ImBezierClosestPoint(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, int num_segments); // For curves with explicit number of segments +IMGUI_API ImVec2 ImBezierClosestPointCasteljau(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, float tess_tol);// For auto-tessellated curves you can use tess_tol = style.CurveTessellationTol IMGUI_API ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p); IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p); From e01fb5462d4fc8b30cf7e23229ee5be4b8d7b3e9 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Dec 2019 18:26:28 +0100 Subject: [PATCH 186/384] Internals: Separator: Simplify duplicated code. --- imgui_widgets.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 684dbe55..135715ff 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1259,21 +1259,14 @@ void ImGui::SeparatorEx(ImGuiSeparatorFlags flags) // We don't provide our width to the layout so that it doesn't get feed back into AutoFit const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y + thickness_draw)); ItemSize(ImVec2(0.0f, thickness_layout)); - if (!ItemAdd(bb, 0)) + const bool item_visible = ItemAdd(bb, 0); + if (item_visible) { - if (columns) - { - PopColumnsBackground(); - columns->LineMinY = window->DC.CursorPos.y; - } - return; + // Draw + window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x, bb.Min.y), GetColorU32(ImGuiCol_Separator)); + if (g.LogEnabled) + LogRenderedText(&bb.Min, "--------------------------------"); } - - // Draw - window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x, bb.Min.y), GetColorU32(ImGuiCol_Separator)); - if (g.LogEnabled) - LogRenderedText(&bb.Min, "--------------------------------"); - if (columns) { PopColumnsBackground(); From f70204f2f4149c8b32e2824cc4cc846376c63078 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Dec 2019 15:02:55 +0100 Subject: [PATCH 187/384] Minor bits, placeholder aimed at facilitating merging of Tables branch into Docking --- imgui.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++-------- imgui_draw.cpp | 2 +- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c81ff318..5d58f2fa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3875,6 +3875,21 @@ void ImGui::Initialize(ImGuiContext* context) ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; g.SettingsHandlers.push_back(ini_handler); } + +#if 0 // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. + + // Add .ini handle for ImGuiTable type + { + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Table"; + ini_handler.TypeHash = ImHashStr("Table"); + ini_handler.ReadOpenFn = TableSettingsHandler_ReadOpen; + ini_handler.ReadLineFn = TableSettingsHandler_ReadLine; + ini_handler.WriteAllFn = TableSettingsHandler_WriteAll; + g.SettingsHandlers.push_back(ini_handler); + } + +#endif g.Initialized = true; } @@ -9806,12 +9821,18 @@ void ImGui::ShowMetricsWindow(bool* p_open) return; } - // State + // Debugging enums enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentRegionRect" }; + enum { TRT_OuterRect, TRT_WorkRect, TRT_HostClipRect, TRT_InnerClipRect, TRT_BackgroundClipRect, TRT_ColumnsRect, TRT_ColumnsClipRect, TRT_ColumnsContentHeadersUsed, TRT_ColumnsContentHeadersDesired, TRT_ColumnsContentRowsFrozen, TRT_ColumnsContentRowsUnfrozen, TRT_Count }; // Tables Rect Type + const char* trt_rects_names[TRT_Count] = { "OuterRect", "WorkRect", "HostClipRect", "InnerClipRect", "BackgroundClipRect", "ColumnsRect", "ColumnsClipRect", "ColumnsContentHeadersUsed", "ColumnsContentHeadersDesired", "ColumnsContentRowsFrozen", "ColumnsContentRowsUnfrozen" }; + + // State static bool show_windows_rects = false; static int show_windows_rect_type = WRT_WorkRect; static bool show_windows_begin_order = false; + static bool show_tables_rects = false; + static int show_tables_rect_type = TRT_WorkRect; static bool show_drawcmd_details = true; // Basic info @@ -9825,11 +9846,12 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::Separator(); // Helper functions to display common structures: - // - NodeDrawList - // - NodeColumns - // - NodeWindow - // - NodeWindows - // - NodeTabBar + // - NodeDrawList() + // - NodeColumns() + // - NodeWindow() + // - NodeWindows() + // - NodeTabBar() + // - NodeStorage() struct Funcs { static ImRect GetWindowRect(ImGuiWindow* window, int rect_type) @@ -10057,6 +10079,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for Popups if (ImGui::TreeNode("Popups", "Popups (%d)", g.OpenPopupStack.Size)) { for (int i = 0; i < g.OpenPopupStack.Size; i++) @@ -10067,6 +10090,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for TabBars if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetSize())) { for (int n = 0; n < g.TabBars.GetSize(); n++) @@ -10074,20 +10098,26 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for Tables + IM_UNUSED(trt_rects_names); + IM_UNUSED(show_tables_rects); + IM_UNUSED(show_tables_rect_type); #if 0 - if (ImGui::TreeNode("Docking")) + if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) { ImGui::TreePop(); } #endif + // Details for Docking #if 0 - if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) + if (ImGui::TreeNode("Docking")) { ImGui::TreePop(); } #endif - + + // Misc Details if (ImGui::TreeNode("Internal state")) { const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT); @@ -10108,6 +10138,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Tools if (ImGui::TreeNode("Tools")) { // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. @@ -10120,7 +10151,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::Checkbox("Show windows rectangles", &show_windows_rects); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12); - show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count); + show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count); if (show_windows_rects && g.NavWindow) { ImGui::BulletText("'%s':", g.NavWindow->Name); @@ -10136,7 +10167,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } - // Tool: Display windows Rectangles and Begin Order + // Overlay: Display windows Rectangles and Begin Order if (show_windows_rects || show_windows_begin_order) { for (int n = 0; n < g.Windows.Size; n++) @@ -10160,6 +10191,27 @@ void ImGui::ShowMetricsWindow(bool* p_open) } } } + + // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. +#if 0 + // Overlay: Display Tables Rectangles + if (show_tables_rects) + { + for (int table_n = 0; table_n < g.Tables.GetSize(); table_n++) + { + ImGuiTable* table = g.Tables.GetByIndex(table_n); + } + } +#endif + + // FIXME-WIP: This is a placeholder to facilitate merging of Docking branch into multiple branches. +#if 0 + // Overlay: Display Docking info + if (show_docking_nodes && g.IO.KeyCtrl) + { + } +#endif + ImGui::End(); } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 58acacf5..5a8477fc 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1315,7 +1315,7 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list) // Merge previous channel last draw command with current channel first draw command if matching. last_cmd->ElemCount += ch._CmdBuffer[0].ElemCount; idx_offset += ch._CmdBuffer[0].ElemCount; - ch._CmdBuffer.erase(ch._CmdBuffer.Data); + ch._CmdBuffer.erase(ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges. } if (ch._CmdBuffer.Size > 0) last_cmd = &ch._CmdBuffer.back(); From 4c108d22f08f236f4b11d0f55944148f88f1df74 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Dec 2019 15:02:55 +0100 Subject: [PATCH 188/384] Minor bits, placeholder aimed at facilitating merging of Tables branch into Docking # Conflicts: # imgui.cpp --- imgui.cpp | 81 ++++++++++++++++++++++++++++++++++++++------------ imgui_draw.cpp | 2 +- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7d3c050a..eec03a86 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4106,6 +4106,21 @@ void ImGui::Initialize(ImGuiContext* context) ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; g.SettingsHandlers.push_back(ini_handler); } + +#if 0 // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. + + // Add .ini handle for ImGuiTable type + { + ImGuiSettingsHandler ini_handler; + ini_handler.TypeName = "Table"; + ini_handler.TypeHash = ImHashStr("Table"); + ini_handler.ReadOpenFn = TableSettingsHandler_ReadOpen; + ini_handler.ReadLineFn = TableSettingsHandler_ReadLine; + ini_handler.WriteAllFn = TableSettingsHandler_WriteAll; + g.SettingsHandlers.push_back(ini_handler); + } + +#endif // Create default viewport ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); @@ -14909,12 +14924,18 @@ void ImGui::ShowMetricsWindow(bool* p_open) return; } - // State + // Debugging enums enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentRegionRect" }; + enum { TRT_OuterRect, TRT_WorkRect, TRT_HostClipRect, TRT_InnerClipRect, TRT_BackgroundClipRect, TRT_ColumnsRect, TRT_ColumnsClipRect, TRT_ColumnsContentHeadersUsed, TRT_ColumnsContentHeadersDesired, TRT_ColumnsContentRowsFrozen, TRT_ColumnsContentRowsUnfrozen, TRT_Count }; // Tables Rect Type + const char* trt_rects_names[TRT_Count] = { "OuterRect", "WorkRect", "HostClipRect", "InnerClipRect", "BackgroundClipRect", "ColumnsRect", "ColumnsClipRect", "ColumnsContentHeadersUsed", "ColumnsContentHeadersDesired", "ColumnsContentRowsFrozen", "ColumnsContentRowsUnfrozen" }; + + // State static bool show_windows_rects = false; static int show_windows_rect_type = WRT_WorkRect; static bool show_windows_begin_order = false; + static bool show_tables_rects = false; + static int show_tables_rect_type = TRT_WorkRect; static bool show_drawcmd_details = true; static bool show_docking_nodes = false; @@ -14929,13 +14950,14 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::Separator(); // Helper functions to display common structures: - // - NodeDrawList - // - NodeColumns - // - NodeWindow - // - NodeWindows - // - NodeViewport - // - NodeDockNode - // - NodeTabBar + // - NodeDrawList() + // - NodeColumns() + // - NodeWindow() + // - NodeWindows() + // - NodeViewport() + // - NodeDockNode() + // - NodeTabBar() + // - NodeStorage() struct Funcs { static ImRect GetWindowRect(ImGuiWindow* window, int rect_type) @@ -15255,6 +15277,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for Popups if (ImGui::TreeNode("Popups", "Popups (%d)", g.OpenPopupStack.Size)) { for (int i = 0; i < g.OpenPopupStack.Size; i++) @@ -15265,6 +15288,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for TabBars if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetSize())) { for (int n = 0; n < g.TabBars.GetSize(); n++) @@ -15272,6 +15296,18 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Details for Tables + IM_UNUSED(trt_rects_names); + IM_UNUSED(show_tables_rects); + IM_UNUSED(show_tables_rect_type); +#if 0 + if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) + { + ImGui::TreePop(); + } +#endif + + // Details for Docking if (ImGui::TreeNode("Docking")) { ImGuiDockContext* dc = g.DockContext; @@ -15318,17 +15354,10 @@ void ImGui::ShowMetricsWindow(bool* p_open) } ImGui::TreePop(); } - - ImGui::TreePop(); - } - -#if 0 - if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) - { ImGui::TreePop(); } -#endif - + + // Misc Details if (ImGui::TreeNode("Internal state")) { const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT); @@ -15351,6 +15380,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } + // Tools if (ImGui::TreeNode("Tools")) { // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. @@ -15363,7 +15393,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::Checkbox("Show windows rectangles", &show_windows_rects); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12); - show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count); + show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count); if (show_windows_rects && g.NavWindow) { ImGui::BulletText("'%s':", g.NavWindow->Name); @@ -15379,7 +15409,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } - // Tool: Display windows Rectangles and Begin Order + // Overlay: Display windows Rectangles and Begin Order if (show_windows_rects || show_windows_begin_order) { for (int n = 0; n < g.Windows.Size; n++) @@ -15404,6 +15434,19 @@ void ImGui::ShowMetricsWindow(bool* p_open) } } + // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. +#if 0 + // Overlay: Display Tables Rectangles + if (show_tables_rects) + { + for (int table_n = 0; table_n < g.Tables.GetSize(); table_n++) + { + ImGuiTable* table = g.Tables.GetByIndex(table_n); + } + } +#endif + + // Overlay: Display Docking info if (show_docking_nodes && g.IO.KeyCtrl) { for (int n = 0; n < g.DockContext->Nodes.Data.Size; n++) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index aa956ce7..e2d08774 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1321,7 +1321,7 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list) // Merge previous channel last draw command with current channel first draw command if matching. last_cmd->ElemCount += ch._CmdBuffer[0].ElemCount; idx_offset += ch._CmdBuffer[0].ElemCount; - ch._CmdBuffer.erase(ch._CmdBuffer.Data); + ch._CmdBuffer.erase(ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges. } if (ch._CmdBuffer.Size > 0) last_cmd = &ch._CmdBuffer.back(); From 061650bd2ae21bfb085628fde781fe11df528b59 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Dec 2019 22:14:28 +0100 Subject: [PATCH 189/384] Update Readme --- docs/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8d44b5d8..e84bd768 100644 --- a/docs/README.md +++ b/docs/README.md @@ -118,7 +118,7 @@ Officially maintained bindings (in repository): - Frameworks: Emscripten, Allegro5, Marmalade. Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): -- Languages: C, C#/.Net, ChaiScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... +- Languages: C, C#/.Net, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... - Frameworks: Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. @@ -201,9 +201,10 @@ Ongoing Dear ImGui development is financially supported by users and private spo *Platinum-chocolate sponsors* - Blizzard Entertainment - Google +- Ubisoft *Double-chocolate sponsors* -- Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn. +- Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Aiden Koss, Kylotonn. *Salty caramel supporters* - Remedy Entertainment, Next Level Games, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. From 854fc081949b0a373f039a5b092d7065c5c36cdb Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 20 Dec 2019 16:19:34 +0100 Subject: [PATCH 190/384] Amend f70204f2 to facilitate merges. --- imgui.cpp | 31 +++++++++++++++---------------- imgui_internal.h | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5d58f2fa..144fdd25 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -880,8 +880,6 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y); namespace ImGui { -static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags); - // Navigation static void NavUpdate(); static void NavUpdateWindowing(); @@ -3876,8 +3874,7 @@ void ImGui::Initialize(ImGuiContext* context) g.SettingsHandlers.push_back(ini_handler); } -#if 0 // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. - +#ifdef IMGUI_HAS_TABLE // Add .ini handle for ImGuiTable type { ImGuiSettingsHandler ini_handler; @@ -3888,8 +3885,10 @@ void ImGui::Initialize(ImGuiContext* context) ini_handler.WriteAllFn = TableSettingsHandler_WriteAll; g.SettingsHandlers.push_back(ini_handler); } +#endif // #ifdef IMGUI_HAS_TABLE -#endif +#ifdef IMGUI_HAS_DOCK +#endif // #ifdef IMGUI_HAS_DOCK g.Initialized = true; } @@ -4654,7 +4653,7 @@ static ImRect GetViewportRect() return ImRect(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); } -static bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags) +bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* parent_window = g.CurrentWindow; @@ -10102,20 +10101,22 @@ void ImGui::ShowMetricsWindow(bool* p_open) IM_UNUSED(trt_rects_names); IM_UNUSED(show_tables_rects); IM_UNUSED(show_tables_rect_type); -#if 0 +#ifdef IMGUI_HAS_TABLE if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize())) { + for (int n = 0; n < g.Tables.GetSize(); n++) + Funcs::NodeTable(g.Tables.GetByIndex(n)); ImGui::TreePop(); } -#endif +#endif // #define IMGUI_HAS_TABLE // Details for Docking -#if 0 +#ifdef IMGUI_HAS_DOCK if (ImGui::TreeNode("Docking")) { ImGui::TreePop(); } -#endif +#endif // #define IMGUI_HAS_DOCK // Misc Details if (ImGui::TreeNode("Internal state")) @@ -10192,8 +10193,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) } } - // FIXME-WIP: This is a placeholder to facilitate merging of Tables branch into multiple branches. -#if 0 +#ifdef IMGUI_HAS_TABLE // Overlay: Display Tables Rectangles if (show_tables_rects) { @@ -10202,15 +10202,14 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGuiTable* table = g.Tables.GetByIndex(table_n); } } -#endif +#endif // #define IMGUI_HAS_TABLE - // FIXME-WIP: This is a placeholder to facilitate merging of Docking branch into multiple branches. -#if 0 +#ifdef IMGUI_HAS_DOCK // Overlay: Display Docking info if (show_docking_nodes && g.IO.KeyCtrl) { } -#endif +#endif // #define IMGUI_HAS_DOCK ImGui::End(); } diff --git a/imgui_internal.h b/imgui_internal.h index ea58b65c..cf55e53c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1668,6 +1668,7 @@ namespace ImGui IMGUI_API void LogToBuffer(int auto_open_depth = -1); // Start logging/capturing to internal buffer // Popups, Modals, Tooltips + IMGUI_API bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags flags); IMGUI_API void OpenPopupEx(ImGuiID id); IMGUI_API void ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup); IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup); From dc66f83db8462e7837aec60fef86c025ac4c485b Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 25 Dec 2019 17:46:35 +0100 Subject: [PATCH 191/384] Additional duplicated comments about usage of std::string and input text resize callback (#2006, #1443, #1008) --- imgui.h | 2 +- imgui_demo.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/imgui.h b/imgui.h index 83bb2558..b6931cce 100644 --- a/imgui.h +++ b/imgui.h @@ -468,7 +468,7 @@ namespace ImGui IMGUI_API bool VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format = NULL, float power = 1.0f); // Widgets: Input with Keyboard - // - If you want to use InputText() with a dynamic string type such as std::string or your own, see misc/cpp/imgui_stdlib.h + // - If you want to use InputText() with std::string or any custom dynamic string type, see misc/cpp/imgui_stdlib.h and comments in imgui_demo.cpp. // - Most of the ImGuiInputTextFlags flags are only useful for InputText() and not for InputFloatX, InputIntX, InputDouble etc. IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); IMGUI_API bool InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size = ImVec2(0,0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 030ed0da..6704c20b 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -514,6 +514,8 @@ static void ShowDemoWindowWidgets() } { + // To wire InputText() with std::string or any other custom string type, + // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. static char str0[128] = "Hello, world!"; ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0)); ImGui::SameLine(); HelpMarker("USER:\nHold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\nPROGRAMMER:\nYou can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated in imgui_demo.cpp)."); @@ -989,6 +991,8 @@ static void ShowDemoWindowWidgets() ImGui::TreePop(); } + // To wire InputText() with std::string or any other custom string type, + // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. if (ImGui::TreeNode("Text Input")) { if (ImGui::TreeNode("Multi-line Text Input")) @@ -1008,7 +1012,7 @@ static void ShowDemoWindowWidgets() "\tlock cmpxchg8b eax\n"; static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput; - HelpMarker("You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp)"); + HelpMarker("You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp because we don't want to include in here)"); ImGui::CheckboxFlags("ImGuiInputTextFlags_ReadOnly", (unsigned int*)&flags, ImGuiInputTextFlags_ReadOnly); ImGui::CheckboxFlags("ImGuiInputTextFlags_AllowTabInput", (unsigned int*)&flags, ImGuiInputTextFlags_AllowTabInput); ImGui::CheckboxFlags("ImGuiInputTextFlags_CtrlEnterForNewLine", (unsigned int*)&flags, ImGuiInputTextFlags_CtrlEnterForNewLine); @@ -1037,8 +1041,9 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("Resize Callback")) { - // If you have a custom string type you would typically create a ImGui::InputText() wrapper than takes your type as input. - // See misc/cpp/imgui_stdlib.h and .cpp for an implementation of this using std::string. + // To wire InputText() with std::string or any other custom string type, + // you can use the ImGuiInputTextFlags_CallbackResize flag + create a custom ImGui::InputText() wrapper using your prefered type. + // See misc/cpp/imgui_stdlib.h for an implementation of this using std::string. HelpMarker("Demonstrate using ImGuiInputTextFlags_CallbackResize to wire your resizable string type to InputText().\n\nSee misc/cpp/imgui_stdlib.h for an implementation of this for std::string."); struct Funcs { From c163b856d718f3c6648b7f248c65da5befb30ef1 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Jan 2020 21:54:23 +0100 Subject: [PATCH 192/384] Docking: Fix for IMGUI_DEBUG_INI_SETTINGS=1, comments --- imgui.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b4b9ba4c..84b9ed6b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6761,7 +6761,7 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind if (window != ignore_window && window->WasActive && !(window->Flags & ImGuiWindowFlags_ChildWindow)) if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) { - // FIXME-DOCKING: This is failing (lagging by one frame) for docked windows. + // FIXME-DOCK: This is failing (lagging by one frame) for docked windows. // If A and B are docked into window and B disappear, at the NewFrame() call site window->NavLastChildNavWindow will still point to B. // We might leverage the tab order implicitly stored in window->DockNodeAsHost->TabBar (essentially the 'most_recently_selected_tab' code in tab bar will do that but on next update) // to tell which is the "previous" window. Or we may leverage 'LastFrameFocused/LastFrameJustFocused' and have this function handle child window itself? @@ -11534,7 +11534,7 @@ static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx) { // Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used) - // FIXME-OPT FIXME-DOCKING: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster. + // FIXME-OPT FIXME-DOCK: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster. ImGuiID id = 0x0001; while (DockContextFindNodeByID(ctx, id) != NULL) id++; @@ -11862,7 +11862,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) if (node->IsCentralNode()) { // Central node property needs to be moved to a leaf node, pick the last focused one. - // FIXME-DOCKING: If we had to transfer other flags here, what would the policy be? + // FIXME-DOCK: If we had to transfer other flags here, what would the policy be? ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeID); IM_ASSERT(last_focused_node != NULL); ImGuiDockNode* last_focused_root_node = DockNodeGetRootNode(last_focused_node); @@ -12775,7 +12775,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w const bool has_close_button = (node_flags & ImGuiDockNodeFlags_NoCloseButton) == 0; // In a dock node, the Collapse Button turns into the Window Menu button. - // FIXME-DOCK FIXME-OPT: Could we recycle popups id accross multiple dock nodes? + // FIXME-DOCK FIXME-OPT: Could we recycle popups id across multiple dock nodes? if (has_window_menu_button && IsPopupOpen("#WindowMenu")) { if (ImGuiID tab_id = DockNodeUpdateWindowMenu(node, tab_bar)) @@ -12818,7 +12818,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w int tabs_unsorted_start = tab_bar->Tabs.Size; for (int tab_n = tab_bar->Tabs.Size - 1; tab_n >= 0 && (tab_bar->Tabs[tab_n].Flags & ImGuiTabItemFlags_Unsorted); tab_n--) { - // FIXME-DOCKING: Consider only clearing the flag after the tab has been alive for a few consecutive frames, allowing late comers to not break sorting? + // FIXME-DOCK: Consider only clearing the flag after the tab has been alive for a few consecutive frames, allowing late comers to not break sorting? tab_bar->Tabs[tab_n].Flags &= ~ImGuiTabItemFlags_Unsorted; tabs_unsorted_start = tab_n; } @@ -13747,7 +13747,7 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags fla SetNextWindowSize(node->Size); g.NextWindowData.PosUndock = false; - // FIXME-DOCKING: Why do we need a child window to host a dockspace, could we host it in the existing window? + // FIXME-DOCK Why do we need a child window to host a dockspace, could we host it in the existing window? ImGuiWindowFlags window_flags = ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_DockNodeHost; window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar; window_flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; @@ -14674,13 +14674,14 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings buf->appendf("%*s", ImMax(2, (line_start_pos + 92) - buf->size()), ""); // Align everything if (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) buf->appendf(" ; in '%s'", node->HostWindow->ParentWindow->Name); + // Iterate settings so we can give info about windows that didn't exist during the session. int contains_window = 0; - for (int window_n = 0; window_n < ctx->SettingsWindows.Size; window_n++) // Iterate settings so we can give info about windows that didn't exist during the session. - if (ctx->SettingsWindows[window_n].DockId == node_settings->ID) + for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) + if (settings->DockId == node_settings->ID) { if (contains_window++ == 0) buf->appendf(" ; contains "); - buf->appendf("'%s' ", ctx->SettingsWindows[window_n].Name); + buf->appendf("'%s' ", settings->GetName()); } } #endif From 3b1b5266e54fa6daba32cdf0da95b8d709312d1b Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Jan 2020 22:50:56 +0100 Subject: [PATCH 193/384] Docking: Fixed a bug where the tab bar of a hidden dockspace would keep requesting focus. (#2960) --- imgui.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 84b9ed6b..74863074 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13703,6 +13703,12 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags fla if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) return; + // Early out if parent window is hidden/collapsed + // This is faster but also DockNodeUpdateTabBar() relies on TabBarLayout() running (which won't if SkipItems=true) to set NextSelectedTabId = 0). See #2960. + // If for whichever reason this is causing problem we would need to ensure that DockNodeUpdateTabBar() ends up clearing NextSelectedTabId even if SkipItems=true. + if (window->SkipItems) + flags |= ImGuiDockNodeFlags_KeepAliveOnly; + IM_ASSERT((flags & ImGuiDockNodeFlags_DockSpace) == 0); ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); if (!node) From 2b10e06555fdffa33a8035ad6e2b285324d40aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zlatan=20Vasovi=C4=87?= Date: Sat, 4 Jan 2020 17:29:51 +0100 Subject: [PATCH 194/384] Fix a typo --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index e84bd768..18bab4d7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -85,7 +85,7 @@ ImGui::End(); Result:
![sample code output](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/code_sample_03_color.gif) -Dear ImGui allows you **create elaborate tools** as well as very short-lived ones. On the extreme side of short-liveness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. +Dear ImGui allows you **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. ### How it works From 0dd02dd90d3d928816151d2a7c1340ba9ebca9bd Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Jan 2020 12:41:37 +0100 Subject: [PATCH 195/384] Happy new year! Comments, Replaced pictures, Removed Patreon --- LICENSE.txt | 2 +- docs/FAQ.md | 14 +++++++------- docs/README.md | 20 ++++++-------------- docs/TODO.txt | 4 ++++ imgui.h | 10 +++++++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 3b439aa4..d8763995 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2019 Omar Cornut +Copyright (c) 2014-2020 Omar Cornut Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/FAQ.md b/docs/FAQ.md index a56b7967..11e81824 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -371,23 +371,23 @@ Finally, you may call ImGui::ShowMetricsWindow() to explore/visualize/understand ### Q: How can I use my own math types instead of ImVec2/ImVec4? -You can edit [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) and setup the IM_VEC2_CLASS_EXTRA/IM_VEC4_CLASS_EXTRA macros to add implicit type conversions. -This way you'll be able to use your own types everywhere, e.g. passing MyVector2 or glm::vec2 to ImGui functions instead of ImVec2. +You can edit [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) and setup the `IM_VEC2_CLASS_EXTRA`/`IM_VEC4_CLASS_EXTRA` macros to add implicit type conversions. +This way you'll be able to use your own types everywhere, e.g. passing `MyVector2` or `glm::vec2` to ImGui functions instead of `ImVec2`. --- ### Q: How can I interact with standard C++ types (such as std::string and std::vector)? - Being highly portable (bindings for several languages, frameworks, programming style, obscure or older platforms/compilers), and aiming for compatibility & performance suitable for every modern real-time game engines, dear imgui does not use any of std C++ types. We use raw types (e.g. char* instead of std::string) because they adapt to more use cases. - To use ImGui::InputText() with a std::string or any resizable string class, see [misc/cpp/imgui_stdlib.h](https://github.com/ocornut/imgui/blob/master/misc/cpp/imgui_stdlib.h). -- To use combo boxes and list boxes with std::vector or any other data structure: the BeginCombo()/EndCombo() API -lets you iterate and submit items yourself, so does the ListBoxHeader()/ListBoxFooter() API. -Prefer using them over the old and awkward Combo()/ListBox() api. +- To use combo boxes and list boxes with `std::vector` or any other data structure: the `BeginCombo()/EndCombo()` API +lets you iterate and submit items yourself, so does the `ListBoxHeader()/ListBoxFooter()` API. +Prefer using them over the old and awkward `Combo()/ListBox()` api. - Generally for most high-level types you should be able to access the underlying data type. You may write your own one-liner wrappers to facilitate user code (tip: add new functions in ImGui:: namespace from your code). - Dear ImGui applications often need to make intensive use of strings. It is expected that many of the strings you will pass to the API are raw literals (free in C/C++) or allocated in a manner that won't incur a large cost on your application. -Please bear in mind that using std::string on applications with large amount of UI may incur unsatisfactory performances. -Modern implementations of std::string often include small-string optimization (which is often a local buffer) but those +Please bear in mind that using `std::string` on applications with large amount of UI may incur unsatisfactory performances. +Modern implementations of `std::string` often include small-string optimization (which is often a local buffer) but those are not configurable and not the same across implementations. - If you are finding your UI traversal cost to be too large, make sure your string usage is not leading to excessive amount of heap allocations. Consider using literals, statically sized buffers and your own helper functions. A common pattern diff --git a/docs/README.md b/docs/README.md index 18bab4d7..ce4e5bc5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,16 +3,12 @@ dear imgui [![Build Status](https://github.com/ocornut/imgui/workflows/build/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=build) [![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) -(This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.) +(This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out.) Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ -Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: -
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) - -Individuals/hobbyists: support continued maintenance and development via PayPal: -
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) +Individuals: support continued maintenance and development via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) donations. ---- @@ -29,7 +25,7 @@ Dear ImGui is particularly suited to integration in games engine (for tooling), ### Usage -**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily copy and compile into your application/engine. They are all the files in the root folder of the repository (imgui.cpp, imgui.h, imgui_demo.cpp, imgui_draw.cpp etc.). +**The core of Dear ImGui is self-contained within a few platform-agnostic files** which you can easily compile in your application/engine. They are all the files in the root folder of the repository (imgui.cpp, imgui.h, imgui_demo.cpp, imgui_draw.cpp etc.). **No specific build process is required**. You can add the .cpp files to your existing project. @@ -48,7 +44,7 @@ ImGui::InputText("string", buf, IM_ARRAYSIZE(buf)); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ``` Result: -
![sample code output](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/code_sample_02.png) +
![sample code output (dark)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v175/capture_readme_styles_0001.png) ![sample code output (light)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v175/capture_readme_styles_0002.png)
_(settings: Dark style (left), Light style (right) / Font: Roboto-Medium, 16px / Rounding: 5)_ Code: @@ -183,16 +179,12 @@ How to help **How can I help financing further development of Dear ImGui?** -Your contributions are keeping this project alive. The library is available under a free and permissive license, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you! +Your contributions are keeping this project alive. The library is available under a free and permissive license, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. Thank you! Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ -Individuals/hobbyists: support continued maintenance and development via the monthly Patreon: -
  [![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_02.png)](http://www.patreon.com/imgui) - -Individuals/hobbyists: support continued maintenance and development via PayPal: -
  [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) +Individuals: support continued maintenance and development via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) donations. ### Sponsors diff --git a/docs/TODO.txt b/docs/TODO.txt index 7a977f72..57680c1e 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -29,6 +29,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: investigate better auto-positioning for new windows. - window: top most window flag? (#2574) - window: the size_on_first_use path of Begin() can probably be removed + - window/size: manually triggered auto-fit (double-click on grip) shouldn't resize window down to viewport size? - window/opt: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. -> this may require enforcing that it is illegal to submit contents if Begin returns false. - window/child: the first draw command of a child window could be moved into the current draw command of the parent window (unless child+tooltip?). - window/child: border could be emitted in parent as well. @@ -38,6 +39,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i ! scrolling: exposing horizontal scrolling with Shift+Wheel even when scrollbar is disabled expose lots of issues (#2424, #1463) - scrolling: while holding down a scrollbar, try to keep the same contents visible (at least while not moving mouse) - scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. + - scrolling: forward mouse wheel scrolling to parent window when at the edge of scrolling limits? (useful for listbox,tables?) - scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro) - scrolling/style: shadows on scrollable areas to denote that there is more contents @@ -159,6 +161,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing. - tabs: persistent order/focus in BeginTabBar() api (#261, #351) + - tabs: TabItem could honor SetNextItemWidth()? - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? @@ -349,6 +352,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - misc: idle: expose "woken up" boolean (set by inputs) and/or animation time (for cursor blink) for back-end to be able stop refreshing easily. - misc: idle: if cursor blink if the _only_ visible animation, core imgui could rewrite vertex alpha to avoid CPU pass on ImGui:: calls. - misc: idle: if cursor blink if the _only_ visible animation, could even expose a dirty rectangle that optionally can be leverage by some app to render in a smaller viewport, getting rid of much pixel shading cost. + - misc: no way to run a root-most GetID() with ImGui:: api since there's always a Debug window in the stack. (mentioned in #2960) - misc: make the ImGuiCond values linear (non-power-of-two). internal storage for ImGuiWindow can use integers to combine into flags (Why?) - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL) - misc: PushItemFlag(): add a flag to disable keyboard capture when used with mouse? (#1682) diff --git a/imgui.h b/imgui.h index b6931cce..7e722e8a 100644 --- a/imgui.h +++ b/imgui.h @@ -1210,7 +1210,7 @@ enum ImGuiMouseCursor_ #endif }; -// Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextItem***() functions +// Enumeration for ImGui::SetWindow***(), SetNextWindow***(), SetNextItem***() functions // Represent a condition. // Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always. enum ImGuiCond_ @@ -1723,9 +1723,13 @@ struct ImGuiStorage // - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop. struct ImGuiListClipper { - float StartPosY; + int DisplayStart, DisplayEnd; + int ItemsCount; + + // [Internal] + int StepNo; float ItemsHeight; - int ItemsCount, StepNo, DisplayStart, DisplayEnd; + float StartPosY; // items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step). // items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing(). From 22d7f26e06299bc5492f734b8c18bf7288390c60 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Jan 2020 12:55:01 +0100 Subject: [PATCH 196/384] Tweak wording Remove Patreon --- docs/FAQ.md | 6 +++--- imgui.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 11e81824..68b43f73 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -537,10 +537,10 @@ the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft # Q&A: Community ### Q: How can I help? +- Businesses: please reach out to `contact AT dearimgui.org` if you work in a place using Dear ImGui! We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts. This is among the most useful thing you can do for Dear ImGui. With increased funding we can hire more people working on this project. +- Individuals: you can support continued maintenance and development via PayPal donations. See [README](https://github.com/ocornut/imgui/blob/master/docs/README.md). - If you are experienced with Dear ImGui and C++, look at the [GitHub Issues](https://github.com/ocornut/imgui/issues), look at the [Wiki](https://github.com/ocornut/imgui/wiki), read [docs/TODO.txt](https://github.com/ocornut/imgui/blob/master/docs/TODO.txt) and see how you want to help and can help! -- Businesses: convince your company to fund development via support contracts/sponsoring! This is among the most useful thing you can do for Dear ImGui. With increased funding we will be able to hire more people working on this project. -- Individuals: you can also become a [Patron](http://www.patreon.com/imgui) or donate on PayPal! See README. -- Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. +- Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. Disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete PR. diff --git a/imgui.cpp b/imgui.cpp index 144fdd25..b8b4139a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11,8 +11,8 @@ // Developed by Omar Cornut and every direct or indirect contributors to the GitHub. // See LICENSE.txt for copyright and licensing details (standard MIT License). // This library is free but I need your support to sustain development and maintenance. -// Businesses: you can support continued maintenance and development via support contracts or sponsoring, see docs/README. -// Individuals: you can support continued maintenance and development via donations or Patreon https://www.patreon.com/imgui. +// Businesses: you can support continued development via invoiced technical support, maintenance and sponsoring contracts. Please reach out to "contact AT dearimgui.org". +// Individuals: you can support continued development via donations. See docs/README or web page. // It is recommended that you don't modify imgui.cpp! It will become difficult for you to update the library. // Note that 'ImGui::' being a namespace, you can add functions into the namespace from your own source files, without @@ -775,11 +775,13 @@ CODE ============== Q: How can I help? - A: - If you are experienced with Dear ImGui and C++, look at the github issues, look at the Wiki, read docs/TODO.txt + A: - Businesses: please reach out to "contact AT dearimgui.org" if you work in a place using Dear ImGui! + We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts. + This is among the most useful thing you can do for Dear ImGui. With increased funding we can hire more people working on this project. + - Individuals: you can support continued development via PayPal donations. See README. + - If you are experienced with Dear ImGui and C++, look at the github issues, look at the Wiki, read docs/TODO.txt and see how you want to help and can help! - - Businesses: convince your company to fund development via support contracts/sponsoring! This is among the most useful thing you can do for dear imgui. - - Individuals: you can also become a Patron (http://www.patreon.com/imgui) or donate on PayPal! See README. - - Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. + - Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues (on github or privately). From d5819393871f5ae6157437ed3f2c1e4a5894ab57 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Jan 2020 15:21:33 +0100 Subject: [PATCH 197/384] Removed trailing spaces. --- examples/imgui_impl_opengl3.cpp | 2 +- imgui.cpp | 16 ++++++++-------- imgui.h | 4 ++-- imgui_demo.cpp | 6 +++--- imgui_draw.cpp | 2 +- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 4f3334b2..3a6d889c 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -157,7 +157,7 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. #endif - // Store GLSL version string so we can refer to it later in case we recreate shaders. + // Store GLSL version string so we can refer to it later in case we recreate shaders. // Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. #if defined(IMGUI_IMPL_OPENGL_ES2) if (glsl_version == NULL) diff --git a/imgui.cpp b/imgui.cpp index b8b4139a..b8163e62 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -495,7 +495,7 @@ CODE - 2016/07/30 (1.50) - SameLine(x) with x>0.0f is now relative to left of column/group if any, and not always to left of window. This was sort of always the intent and hopefully breakage should be minimal. - 2016/05/12 (1.49) - title bar (using ImGuiCol_TitleBg/ImGuiCol_TitleBgActive colors) isn't rendered over a window background (ImGuiCol_WindowBg color) anymore. If your TitleBg/TitleBgActive alpha was 1.0f or you are using the default theme it will not affect you, otherwise if <1.0f you need tweak your custom theme to readjust for the fact that we don't draw a WindowBg background behind the title bar. - This helper function will convert an old TitleBg/TitleBgActive color into a new one with the same visual output, given the OLD color and the OLD WindowBg color: + This helper function will convert an old TitleBg/TitleBgActive color into a new one with the same visual output, given the OLD color and the OLD WindowBg color: ImVec4 ConvertTitleBgCol(const ImVec4& win_bg_col, const ImVec4& title_bg_col) { float new_a = 1.0f - ((1.0f - win_bg_col.w) * (1.0f - title_bg_col.w)), k = title_bg_col.w / new_a; return ImVec4((win_bg_col.x * win_bg_col.w + title_bg_col.x) * k, (win_bg_col.y * win_bg_col.w + title_bg_col.y) * k, (win_bg_col.z * win_bg_col.w + title_bg_col.z) * k, new_a); } If this is confusing, pick the RGB value from title bar from an old screenshot and apply this as TitleBg/TitleBgActive. Or you may just create TitleBgActive from a tweaked TitleBg color. - 2016/05/07 (1.49) - removed confusing set of GetInternalState(), GetInternalStateSize(), SetInternalState() functions. Now using CreateContext(), DestroyContext(), GetCurrentContext(), SetCurrentContext(). @@ -775,8 +775,8 @@ CODE ============== Q: How can I help? - A: - Businesses: please reach out to "contact AT dearimgui.org" if you work in a place using Dear ImGui! - We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts. + A: - Businesses: please reach out to "contact AT dearimgui.org" if you work in a place using Dear ImGui! + We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts. This is among the most useful thing you can do for Dear ImGui. With increased funding we can hire more people working on this project. - Individuals: you can support continued development via PayPal donations. See README. - If you are experienced with Dear ImGui and C++, look at the github issues, look at the Wiki, read docs/TODO.txt @@ -1354,8 +1354,8 @@ const char* ImStrSkipBlank(const char* str) #ifndef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // We support stb_sprintf which is much faster (see: https://github.com/nothings/stb/blob/master/stb_sprintf.h) -// You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS -// and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are +// You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +// and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are // designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.) //#define IMGUI_USE_STB_SPRINTF #ifdef IMGUI_USE_STB_SPRINTF @@ -1480,7 +1480,7 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) - // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. + // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; ImVector buf; @@ -3875,7 +3875,7 @@ void ImGui::Initialize(ImGuiContext* context) ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; g.SettingsHandlers.push_back(ini_handler); } - + #ifdef IMGUI_HAS_TABLE // Add .ini handle for ImGuiTable type { @@ -10119,7 +10119,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } #endif // #define IMGUI_HAS_DOCK - + // Misc Details if (ImGui::TreeNode("Internal state")) { diff --git a/imgui.h b/imgui.h index 7e722e8a..6ed2fb5b 100644 --- a/imgui.h +++ b/imgui.h @@ -677,7 +677,7 @@ namespace ImGui // - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[]. // - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index. IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key] - IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. + IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down)? IMGUI_API int GetKeyPressedAmount(int key_index, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate @@ -1178,7 +1178,7 @@ enum ImGuiColorEditFlags_ #endif }; -// Identify a mouse button. +// Identify a mouse button. // Those values are guaranteed to be stable and we frequently use 0/1 directly. Named enums provided for convenience. enum ImGuiMouseButton_ { diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 6704c20b..1f0a1b19 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -514,7 +514,7 @@ static void ShowDemoWindowWidgets() } { - // To wire InputText() with std::string or any other custom string type, + // To wire InputText() with std::string or any other custom string type, // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. static char str0[128] = "Hello, world!"; ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0)); @@ -991,7 +991,7 @@ static void ShowDemoWindowWidgets() ImGui::TreePop(); } - // To wire InputText() with std::string or any other custom string type, + // To wire InputText() with std::string or any other custom string type, // see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file. if (ImGui::TreeNode("Text Input")) { @@ -1041,7 +1041,7 @@ static void ShowDemoWindowWidgets() if (ImGui::TreeNode("Resize Callback")) { - // To wire InputText() with std::string or any other custom string type, + // To wire InputText() with std::string or any other custom string type, // you can use the ImGuiInputTextFlags_CallbackResize flag + create a custom ImGui::InputText() wrapper using your prefered type. // See misc/cpp/imgui_stdlib.h for an implementation of this using std::string. HelpMarker("Demonstrate using ImGuiInputTextFlags_CallbackResize to wire your resizable string type to InputText().\n\nSee misc/cpp/imgui_stdlib.h for an implementation of this for std::string."); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 5a8477fc..62cf2691 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -517,7 +517,7 @@ void ImDrawList::PopTextureID() } // Reserve space for a number of vertices and indices. -// You must finish filling your reserved data before calling PrimReserve() again, as it may reallocate or +// You must finish filling your reserved data before calling PrimReserve() again, as it may reallocate or // submit the intermediate results. PrimUnreserve() can be used to release unused allocations. void ImDrawList::PrimReserve(int idx_count, int vtx_count) { diff --git a/imgui_internal.h b/imgui_internal.h index cf55e53c..d77a63cd 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -161,7 +161,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #ifdef IMGUI_DEBUG_PARANOID #define IM_ASSERT_PARANOID(_EXPR) IM_ASSERT(_EXPR) #else -#define IM_ASSERT_PARANOID(_EXPR) +#define IM_ASSERT_PARANOID(_EXPR) #endif // Error handling @@ -506,7 +506,7 @@ enum ImGuiItemStatusFlags_ ImGuiItemStatusFlags_HasDisplayRect = 1 << 1, ImGuiItemStatusFlags_Edited = 1 << 2, // Value exposed by item was edited in the current frame (should match the bool return value of most widgets) ImGuiItemStatusFlags_ToggledSelection = 1 << 3, // Set when Selectable(), TreeNode() reports toggling a selection. We can't report "Selected" because reporting the change allows us to handle clipping with less issues. - ImGuiItemStatusFlags_ToggledOpen = 1 << 4, // Set when TreeNode() reports toggling their open state. + ImGuiItemStatusFlags_ToggledOpen = 1 << 4, // Set when TreeNode() reports toggling their open state. ImGuiItemStatusFlags_HasDeactivated = 1 << 5, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. ImGuiItemStatusFlags_Deactivated = 1 << 6 // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 135715ff..95022802 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5274,7 +5274,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l if (!is_leaf) button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; - // We allow clicking on the arrow section with keyboard modifiers held, in order to easily + // We allow clicking on the arrow section with keyboard modifiers held, in order to easily // allow browsing a tree while preserving selection with code implementing multi-selection patterns. // When clicking on the rest of the tree node we always disallow keyboard modifiers. const float hit_padding_x = style.TouchExtraPadding.x; @@ -5282,7 +5282,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x; if (window != g.HoveredWindow || !(g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2)) button_flags |= ImGuiButtonFlags_NoKeyModifiers; - + bool selected = (flags & ImGuiTreeNodeFlags_Selected) != 0; const bool was_selected = selected; From e254167afd3936ac730560c6b85ce4937525f496 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 6 Jan 2020 16:51:48 +0200 Subject: [PATCH 198/384] ColorEdit: Fix label alignment when using ImGuiColorEditFlags_NoInputs. (#2955) --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0eecd414..2acf6304 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,7 @@ Breaking Changes: Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. +- ColorEdit: Fix label alignment when using ImGuiColorEditFlags_NoInputs. (#2955) [@rokups] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 95022802..f11f44be 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4340,7 +4340,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel)) { - window->DC.CursorPos = ImVec2(pos.x + w_full + style.ItemInnerSpacing.x, pos.y + style.FramePadding.y); + const float text_offset_x = (flags & ImGuiColorEditFlags_NoInputs) ? w_button : w_full + style.ItemInnerSpacing.x; + window->DC.CursorPos = ImVec2(pos.x + text_offset_x, pos.y + style.FramePadding.y); TextEx(label, label_display_end); } From 5e2329b98e6562c9e7883e92dcf878e969d81878 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 7 Jan 2020 15:32:34 +0200 Subject: [PATCH 199/384] Backends: GL3: Implement glbinding opengl loader support. (#2870) --- docs/CHANGELOG.txt | 1 + examples/README.txt | 4 ++-- examples/example_glfw_opengl3/main.cpp | 8 ++++++++ examples/example_sdl_opengl3/main.cpp | 7 +++++++ examples/imgui_impl_opengl3.cpp | 9 +++++++++ examples/imgui_impl_opengl3.h | 3 +++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2acf6304..dc5d43f2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -79,6 +79,7 @@ Other Changes: automatically use it). [#2919, #2798] - Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed even if underlying system event loop gets paused due to app nap (#2910, #2917). [@bear24rw] +- Examples: Added support for glbindings OpenGL loader. ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index cf92f41b..f52c90bc 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -198,7 +198,7 @@ example_glfw_opengl2/ GLFW + OpenGL2 example (legacy, fixed pipeline). = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp **DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** - **Prefer using OPENGL3 code (with gl3w/glew/glad, you can replace the OpenGL function loader)** + **Prefer using OPENGL3 code (with gl3w/glew/glad/glbindings, you can replace the OpenGL function loader)** This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to make things more complicated, will require your code to reset many OpenGL attributes to their initial @@ -243,7 +243,7 @@ example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp **DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** - **Prefer using OPENGL3 code (with gl3w/glew/glad, you can replace the OpenGL function loader)** + **Prefer using OPENGL3 code (with gl3w/glew/glad/glbindings, you can replace the OpenGL function loader)** This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to make things more complicated, will require your code to reset many OpenGL attributes to their initial diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index a658ec86..ef7ddfed 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -17,6 +17,11 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Initialize with glbinding::initialize() +#include +using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif @@ -74,6 +79,9 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) + bool err = false; + glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)glfwGetProcAddress(name); }); #else bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. #endif diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 2220537d..a0cfe240 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -19,6 +19,10 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#include // Initialize with glbinding::initialize() +#include +using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif @@ -69,6 +73,9 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) + bool err = false; + glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)SDL_GL_GetProcAddress(name); }); #else bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires some form of initialization. #endif diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 3a6d889c..9289913e 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-01-07: OpenGL: Added support for glbindings OpenGL loader. // 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders. // 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility. // 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call. @@ -85,12 +86,14 @@ #undef IMGUI_IMPL_OPENGL_LOADER_GL3W #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #elif defined(__EMSCRIPTEN__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" #undef IMGUI_IMPL_OPENGL_LOADER_GL3W #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif #endif @@ -115,6 +118,10 @@ #include // Needs to be initialized with glewInit() in user's code #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Needs to be initialized with gladLoadGL() in user's code +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#include // Initialize with glbinding::initialize() +#include +using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif @@ -186,6 +193,8 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) gl_loader = "GLEW"; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) gl_loader = "GLAD"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) + gl_loader = "glbinding"; #else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM gl_loader = "Custom"; #endif diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 4c72ec47..98cefe7d 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -46,6 +46,7 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) #if defined(__has_include) #if __has_include() @@ -54,6 +55,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); #define IMGUI_IMPL_OPENGL_LOADER_GLAD #elif __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GL3W + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING #else #error "Cannot detect OpenGL loader!" #endif From f6951bb67d5a463e9deddac0ca0db2a132901924 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 6 Jan 2020 09:49:36 +0200 Subject: [PATCH 200/384] Viewports: SDL2: Honor NoTaskBarIcon flag under non Win32 OS. (#2117) --- examples/imgui_impl_sdl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index d78db88d..12b8ebfd 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -467,6 +467,10 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) sdl_flags |= SDL_WINDOW_HIDDEN; sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0; sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE; +#if !defined(_WIN32) + // See SDL hack in ImGui_ImplSDL2_ShowWindow(). + sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) ? SDL_WINDOW_SKIP_TASKBAR : 0; +#endif #if SDL_HAS_ALWAYS_ON_TOP sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0; #endif From 32c33c6659902e3472aadbb624518f0037d4f5ab Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 6 Jan 2020 16:15:59 +0200 Subject: [PATCH 201/384] ColorEdit: Preserve last saturation value when V=0. Disable Hue editing lock. This workaround is no longer necessary because preserving hue value prevents it from resetting when it is edited in said condition. --- imgui_internal.h | 1 + imgui_widgets.cpp | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index d77a63cd..4ea85076 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1121,6 +1121,7 @@ struct ImGuiContext ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets float ColorEditLastHue; // Backup of last Hue associated to LastColor[3], so we can restore Hue in lossy RGB<>HSV round trips + float ColorEditLastSaturation; // Backup of last Saturation associated to LastColor[3], so we can restore Saturation in lossy RGB<>HSV round trips float ColorEditLastColor[3]; ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. bool DragCurrentAccumDirty; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f11f44be..fcaaa369 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4222,8 +4222,13 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag { // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. ColorConvertRGBtoHSV(f[0], f[1], f[2], f[0], f[1], f[2]); - if (f[1] == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) - f[0] = g.ColorEditLastHue; + if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) + { + if (f[1] == 0) + f[0] = g.ColorEditLastHue; + if (f[2] == 0) + f[1] = g.ColorEditLastSaturation; + } } int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; @@ -4262,16 +4267,15 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag SameLine(0, style.ItemInnerSpacing.x); SetNextItemWidth((n + 1 < components) ? w_item_one : w_item_last); - // Disable Hue edit when Saturation is zero - const bool disable_hue_edit = (n == 0 && (flags & ImGuiColorEditFlags_DisplayHSV) && i[1] == 0); + // FIXME: When ImGuiColorEditFlags_HDR flag is passed HS values snap in weird ways when SV values go below 0. if (flags & ImGuiColorEditFlags_Float) { - value_changed |= DragFloat(ids[n], &f[n], 1.0f/255.0f, disable_hue_edit ? +FLT_MAX : 0.0f, disable_hue_edit ? -FLT_MAX : hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]); + value_changed |= DragFloat(ids[n], &f[n], 1.0f/255.0f, 0.0f, hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]); value_changed_as_float |= value_changed; } else { - value_changed |= DragInt(ids[n], &i[n], 1.0f, disable_hue_edit ? INT_MAX : 0, disable_hue_edit ? INT_MIN : hdr ? 0 : 255, fmt_table_int[fmt_idx][n]); + value_changed |= DragInt(ids[n], &i[n], 1.0f, 0, hdr ? 0 : 255, fmt_table_int[fmt_idx][n]); } if (!(flags & ImGuiColorEditFlags_NoOptions)) OpenPopupOnItemClick("context"); @@ -4354,6 +4358,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB)) { g.ColorEditLastHue = f[0]; + g.ColorEditLastSaturation = f[1]; ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); memcpy(g.ColorEditLastColor, f, sizeof(float) * 3); } @@ -4536,8 +4541,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { // Hue is lost when converting from greyscale rgb (saturation=0). Restore it. ColorConvertRGBtoHSV(R, G, B, H, S, V); - if (S == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) - H = g.ColorEditLastHue; + if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) + { + if (S == 0) + H = g.ColorEditLastHue; + if (V == 0) + S = g.ColorEditLastSaturation; + } } else if (flags & ImGuiColorEditFlags_InputHSV) { @@ -4665,6 +4675,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); g.ColorEditLastHue = H; + g.ColorEditLastSaturation = S; memcpy(g.ColorEditLastColor, col, sizeof(float) * 3); } else if (flags & ImGuiColorEditFlags_InputHSV) @@ -4719,8 +4730,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl G = col[1]; B = col[2]; ColorConvertRGBtoHSV(R, G, B, H, S, V); - if (S == 0 && memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) // Fix local Hue as display below will use it immediately. - H = g.ColorEditLastHue; + if (memcmp(g.ColorEditLastColor, col, sizeof(float) * 3) == 0) // Fix local Hue as display below will use it immediately. + { + if (S == 0) + H = g.ColorEditLastHue; + if (V == 0) + S = g.ColorEditLastSaturation; + } } else if (flags & ImGuiColorEditFlags_InputHSV) { From 1db78b8ca77f4590d68d1e30b2c6a55599248b96 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Jan 2020 21:25:42 +0100 Subject: [PATCH 202/384] Renaming + missing initialization + missing Changelog update. --- docs/CHANGELOG.txt | 13 ++++++++----- imgui_internal.h | 4 ++-- imgui_widgets.cpp | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index dc5d43f2..2575da17 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -65,6 +65,9 @@ Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. - ColorEdit: Fix label alignment when using ImGuiColorEditFlags_NoInputs. (#2955) [@rokups] +- ColorEdit: In HSV display of a RGB stored value, attempt to locally preserve Saturation + when Value==0.0 (similar to changes done in 1.73 for Hue). Removed Hue editing lock since + those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as @@ -75,11 +78,11 @@ Other Changes: - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available on Wayland). (#2800, #2802) [@NeroBurner] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking - settings (otherwise if another loader such as Glew is accessible, the opengl3 backend might - automatically use it). [#2919, #2798] + settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might + automatically use it). (#2919, #2798) - Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed - even if underlying system event loop gets paused due to app nap (#2910, #2917). [@bear24rw] -- Examples: Added support for glbindings OpenGL loader. + even if underlying system event loop gets paused due to app nap. (#2910, #2917) [@bear24rw] +- Examples: Added support for glbindings OpenGL loader. (#2870) [@rokups] ----------------------------------------------------------------------- @@ -164,7 +167,7 @@ Other Changes: - Nav, Scrolling: Added support for Home/End key. (#787) - ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around. - ColorEdit, ColorPicker: In HSV display of a RGB stored value, attempt to locally preserve Hue - when Saturation==0, which reduces accidentally lossy interactions. (#2722, 2770) [@rokups] + when Saturation==0, which reduces accidentally lossy interactions. (#2722, #2770) [@rokups] - ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711) Note that some elements won't accurately fade down with the same intensity, and the color wheel when enabled will have small overlap glitches with (style.Alpha < 1.0). diff --git a/imgui_internal.h b/imgui_internal.h index 4ea85076..a618b3dc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1121,7 +1121,7 @@ struct ImGuiContext ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets float ColorEditLastHue; // Backup of last Hue associated to LastColor[3], so we can restore Hue in lossy RGB<>HSV round trips - float ColorEditLastSaturation; // Backup of last Saturation associated to LastColor[3], so we can restore Saturation in lossy RGB<>HSV round trips + float ColorEditLastSat; // Backup of last Saturation associated to LastColor[3], so we can restore Saturation in lossy RGB<>HSV round trips float ColorEditLastColor[3]; ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. bool DragCurrentAccumDirty; @@ -1266,7 +1266,7 @@ struct ImGuiContext LastValidMousePos = ImVec2(0.0f, 0.0f); TempInputTextId = 0; ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; - ColorEditLastHue = 0.0f; + ColorEditLastHue = ColorEditLastSat = 0.0f; ColorEditLastColor[0] = ColorEditLastColor[1] = ColorEditLastColor[2] = FLT_MAX; DragCurrentAccumDirty = false; DragCurrentAccum = 0.0f; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index fcaaa369..1f28f464 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4227,7 +4227,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (f[1] == 0) f[0] = g.ColorEditLastHue; if (f[2] == 0) - f[1] = g.ColorEditLastSaturation; + f[1] = g.ColorEditLastSat; } } int i[4] = { IM_F32_TO_INT8_UNBOUND(f[0]), IM_F32_TO_INT8_UNBOUND(f[1]), IM_F32_TO_INT8_UNBOUND(f[2]), IM_F32_TO_INT8_UNBOUND(f[3]) }; @@ -4358,7 +4358,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB)) { g.ColorEditLastHue = f[0]; - g.ColorEditLastSaturation = f[1]; + g.ColorEditLastSat = f[1]; ColorConvertHSVtoRGB(f[0], f[1], f[2], f[0], f[1], f[2]); memcpy(g.ColorEditLastColor, f, sizeof(float) * 3); } @@ -4546,7 +4546,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl if (S == 0) H = g.ColorEditLastHue; if (V == 0) - S = g.ColorEditLastSaturation; + S = g.ColorEditLastSat; } } else if (flags & ImGuiColorEditFlags_InputHSV) @@ -4675,7 +4675,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]); g.ColorEditLastHue = H; - g.ColorEditLastSaturation = S; + g.ColorEditLastSat = S; memcpy(g.ColorEditLastColor, col, sizeof(float) * 3); } else if (flags & ImGuiColorEditFlags_InputHSV) @@ -4735,7 +4735,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl if (S == 0) H = g.ColorEditLastHue; if (V == 0) - S = g.ColorEditLastSaturation; + S = g.ColorEditLastSat; } } else if (flags & ImGuiColorEditFlags_InputHSV) From f9630e60c599f3b97ac31f96d6c13e4d30a502d7 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Jan 2020 21:32:00 +0100 Subject: [PATCH 203/384] Metrics: Fix not being able to expand "ParentWindow" when parent window is same as root window. --- imgui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index b8163e62..549ee75e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9992,7 +9992,11 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (!ImGui::TreeNode(label, "%s (%d)", label, windows.Size)) return; for (int i = 0; i < windows.Size; i++) + { + ImGui::PushID(windows[i]); Funcs::NodeWindow(windows[i], "Window"); + ImGui::PopID(); + } ImGui::TreePop(); } @@ -10003,7 +10007,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::BulletText("%s: NULL", label); return; } - bool open = ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, (window->Active || window->WasActive), window); + bool open = ImGui::TreeNode(label, "%s '%s', %d @ 0x%p", label, window->Name, (window->Active || window->WasActive), window); if (ImGui::IsItemHovered() && window->WasActive) ImGui::GetForegroundDrawList()->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255)); if (!open) From 00c515f51afeafbd6b88d866bf430e42c3658b29 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 9 Jan 2020 15:39:02 +0200 Subject: [PATCH 204/384] Add glbinding build sample to Makefiles of GL3 examples. (#2870) --- examples/example_glfw_opengl3/Makefile | 4 ++++ examples/example_sdl_opengl3/Makefile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index f72f4669..f0160b19 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -41,6 +41,10 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W # SOURCES += ../libs/glad/src/glad.c # CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD +## Using OpenGL loader: glbinding +## (This assumes a system-wide installation) +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING + ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM ##--------------------------------------------------------------------- diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 12d8b57c..77140b5e 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -41,6 +41,10 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W # SOURCES += ../libs/glad/src/glad.c # CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD +## Using OpenGL loader: glbinding +## (This assumes a system-wide installation) +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING + ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM ##--------------------------------------------------------------------- From 1eb71fc72b4c83c91d2f3d0b91996bf958370ac9 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 10 Jan 2020 14:34:15 +0100 Subject: [PATCH 205/384] ButtonBehavior: Added ImGuiButtonFlags_PressedOnClickReleaseAnywhere behavior (#2971) Rearranged flags. Added tests in 'widgets_button_press' --- imgui_internal.h | 30 ++++++++++++++++-------------- imgui_widgets.cpp | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index a618b3dc..29864f82 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -418,20 +418,22 @@ enum ImGuiButtonFlags_ { ImGuiButtonFlags_None = 0, ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat - ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // [Default] return true on click + release on same item - ImGuiButtonFlags_PressedOnClick = 1 << 2, // return true on click (default requires click+release) - ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return true on release (default requires click+release) - ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return true on double-click (default requires click+release) - ImGuiButtonFlags_FlattenChildren = 1 << 5, // allow interactions even if a child window is overlapping - ImGuiButtonFlags_AllowItemOverlap = 1 << 6, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() - ImGuiButtonFlags_DontClosePopups = 1 << 7, // disable automatically closing parent popup on press // [UNUSED] - ImGuiButtonFlags_Disabled = 1 << 8, // disable interactions - ImGuiButtonFlags_AlignTextBaseLine = 1 << 9, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine - ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable mouse interaction if a key modifier is held - ImGuiButtonFlags_NoHoldingActiveID = 1 << 11, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) - ImGuiButtonFlags_PressedOnDragDropHold = 1 << 12, // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) - ImGuiButtonFlags_NoNavFocus = 1 << 13, // don't override navigation focus when activated - ImGuiButtonFlags_NoHoveredOnNav = 1 << 14 // don't report as hovered when navigated on + ImGuiButtonFlags_PressedOnClick = 1 << 1, // return true on click (mouse down event) + ImGuiButtonFlags_PressedOnClickRelease = 1 << 2, // [Default] return true on click + release on same item <-- this is what the majority of Button are using + ImGuiButtonFlags_PressedOnClickReleaseAnywhere = 1 << 3, // return true on click + release even if the release event is not done while hovering the item + ImGuiButtonFlags_PressedOnRelease = 1 << 4, // return true on release (default requires click+release) + ImGuiButtonFlags_PressedOnDoubleClick = 1 << 5, // return true on double-click (default requires click+release) + ImGuiButtonFlags_PressedOnDragDropHold = 1 << 6, // return true when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers) + ImGuiButtonFlags_FlattenChildren = 1 << 7, // allow interactions even if a child window is overlapping + ImGuiButtonFlags_AllowItemOverlap = 1 << 8, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() + ImGuiButtonFlags_DontClosePopups = 1 << 9, // disable automatically closing parent popup on press // [UNUSED] + ImGuiButtonFlags_Disabled = 1 << 10, // disable interactions + ImGuiButtonFlags_AlignTextBaseLine = 1 << 11, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine + ImGuiButtonFlags_NoKeyModifiers = 1 << 12, // disable mouse interaction if a key modifier is held + ImGuiButtonFlags_NoHoldingActiveID = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) + ImGuiButtonFlags_NoNavFocus = 1 << 14, // don't override navigation focus when activated + ImGuiButtonFlags_NoHoveredOnNav = 1 << 15, // don't report as hovered when navigated on + ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold }; enum ImGuiSliderFlags_ diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1f28f464..0afa50b5 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -462,7 +462,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } // Default behavior requires click+release on same spot - if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick)) == 0) + if ((flags & (ImGuiButtonFlags_PressedOnMask_ & ~ImGuiButtonFlags_PressedOnDragDropHold)) == 0) flags |= ImGuiButtonFlags_PressedOnClickRelease; ImGuiWindow* backup_hovered_window = g.HoveredWindow; @@ -507,7 +507,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool { if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { - if ((flags & ImGuiButtonFlags_PressedOnClickRelease) && g.IO.MouseClicked[0]) + if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere)) && g.IO.MouseClicked[0]) { SetActiveID(id, window); if (!(flags & ImGuiButtonFlags_NoNavFocus)) @@ -577,7 +577,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } else { - if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) && !g.DragDropActive) + const bool release_in = hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) != 0; + const bool release_anywhere = (flags & ImGuiButtonFlags_PressedOnClickReleaseAnywhere) != 0; + if ((release_in || release_anywhere) && !g.DragDropActive) { bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDownWasDoubleClick[0]; bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay; // Repeat mode trumps @@ -5573,12 +5575,12 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries ImGuiButtonFlags button_flags = 0; - if (flags & ImGuiSelectableFlags_NoHoldingActiveID) button_flags |= ImGuiButtonFlags_NoHoldingActiveID; - if (flags & ImGuiSelectableFlags_PressedOnClick) button_flags |= ImGuiButtonFlags_PressedOnClick; - if (flags & ImGuiSelectableFlags_PressedOnRelease) button_flags |= ImGuiButtonFlags_PressedOnRelease; - if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; - if (flags & ImGuiSelectableFlags_AllowDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; - if (flags & ImGuiSelectableFlags_AllowItemOverlap) button_flags |= ImGuiButtonFlags_AllowItemOverlap; + if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveID; } + if (flags & ImGuiSelectableFlags_PressedOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } + if (flags & ImGuiSelectableFlags_PressedOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } + if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; } + if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; } + if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; } if (flags & ImGuiSelectableFlags_Disabled) selected = false; From 4ee7aa72e9fe86c3254f705829686438b5eebeef Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 10 Jan 2020 14:35:03 +0100 Subject: [PATCH 206/384] ButtonBehavior: Default assignment of pressed behavior now also test for ImGuiButtonFlags_PressedOnDragDropHold which wasn't the case before. --- imgui_widgets.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0afa50b5..c7d142cb 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -462,7 +462,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } // Default behavior requires click+release on same spot - if ((flags & (ImGuiButtonFlags_PressedOnMask_ & ~ImGuiButtonFlags_PressedOnDragDropHold)) == 0) + if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0) flags |= ImGuiButtonFlags_PressedOnClickRelease; ImGuiWindow* backup_hovered_window = g.HoveredWindow; @@ -5290,6 +5290,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l button_flags |= ImGuiButtonFlags_AllowItemOverlap; if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnDoubleClick | ((flags & ImGuiTreeNodeFlags_OpenOnArrow) ? ImGuiButtonFlags_PressedOnClickRelease : 0); + else + button_flags |= ImGuiButtonFlags_PressedOnClickRelease; if (!is_leaf) button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; From ae1e3619f6f81a45a7162d70cba65118fd36c0ec Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 9 Jan 2020 13:47:42 +0200 Subject: [PATCH 207/384] Disable some PVS studio warnings. V1048: While they are technically correct we want to emphasize assigned values must remain same. --- imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 549ee75e..f659123e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4197,7 +4197,7 @@ void ImGui::Render() g.FrameCountRendered = g.FrameCount; // Gather ImDrawList to render (for each active window) - g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsRenderWindows = 0; + g.IO.MetricsRenderWindows = 0; g.DrawDataBuilder.Clear(); if (!g.BackgroundDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.BackgroundDrawList); @@ -8363,7 +8363,7 @@ static void ImGui::NavUpdate() IM_ASSERT(child_window->ChildId != 0); FocusWindow(parent_window); SetNavID(child_window->ChildId, 0); - g.NavIdIsAlive = false; + g.NavIdIsAlive = false; // -V1048: Reassigning with same value, we're being explicit here. if (g.NavDisableMouseHover) g.NavMousePosDirty = true; } @@ -8453,7 +8453,7 @@ static void ImGui::NavUpdate() { //IMGUI_DEBUG_LOG("[Nav] NavInitRequest from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer); g.NavInitRequest = g.NavInitRequestFromMove = true; - g.NavInitResultId = 0; + g.NavInitResultId = 0; // -V1048: Reassigning with same value, we're being explicit here. g.NavDisableHighlight = false; } NavUpdateAnyRequestFlag(); From 97a8dc6514db70112678c4f1972ee65a6ab0281d Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 10 Jan 2020 17:37:54 +0200 Subject: [PATCH 208/384] CI: Added PVS-Studio static analysis on the continuous-integration server. --- .github/workflows/build.yml | 35 +++++++++++++++++++++++++++++++++++ docs/CHANGELOG.txt | 1 + imgui.cpp | 6 ++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 265c400d..856e29f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -265,3 +265,38 @@ jobs: run: | source emsdk-master/emsdk_env.sh make -C examples/example_emscripten + + Static-Analysis: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Install Dependencies + env: + PVS_STUDIO_LICENSE: ${{ secrets.PVS_STUDIO_LICENSE }} + run: | + if [[ "$PVS_STUDIO_LICENSE" != "" ]]; + then + echo "$PVS_STUDIO_LICENSE" > pvs-studio.lic + wget -q https://files.viva64.com/etc/pubkey.txt + sudo apt-key add pubkey.txt + sudo wget -O /etc/apt/sources.list.d/viva64.list https://files.viva64.com/etc/viva64.list + sudo apt-get update + sudo apt-get install -y pvs-studio + fi + + - name: PVS-Studio static analysis + run: | + if [[ ! -f pvs-studio.lic ]]; + then + echo "PVS Studio license is missing. No analysis will be performed." + echo "If you have a PVS Studio license please create a project secret named PVS_STUDIO_LICENSE with your license." + echo "You may use a free license. More information at https://www.viva64.com/en/b/0457/" + exit 0 + fi + cd examples/example_null + pvs-studio-analyzer trace -- make EXTRA_WARNINGS=1 + pvs-studio-analyzer analyze -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log + plog-converter -a 'GA:1,2;OP:1' -t errorfile -w pvs-studio.log diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2575da17..36d10732 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,6 +77,7 @@ Other Changes: - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available on Wayland). (#2800, #2802) [@NeroBurner] +- CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might automatically use it). (#2919, #2798) diff --git a/imgui.cpp b/imgui.cpp index f659123e..ed6da44d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8363,7 +8363,8 @@ static void ImGui::NavUpdate() IM_ASSERT(child_window->ChildId != 0); FocusWindow(parent_window); SetNavID(child_window->ChildId, 0); - g.NavIdIsAlive = false; // -V1048: Reassigning with same value, we're being explicit here. + // Reassigning with same value, we're being explicit here. + g.NavIdIsAlive = false; // -V1048 if (g.NavDisableMouseHover) g.NavMousePosDirty = true; } @@ -8453,7 +8454,8 @@ static void ImGui::NavUpdate() { //IMGUI_DEBUG_LOG("[Nav] NavInitRequest from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer); g.NavInitRequest = g.NavInitRequestFromMove = true; - g.NavInitResultId = 0; // -V1048: Reassigning with same value, we're being explicit here. + // Reassigning with same value, we're being explicit here. + g.NavInitResultId = 0; // -V1048 g.NavDisableHighlight = false; } NavUpdateAnyRequestFlag(); From f03c00bc89c4ba9b45f4e216d943e1d890dfbac0 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 10 Jan 2020 19:36:26 +0200 Subject: [PATCH 209/384] Added imgui_single_file.h, We use this to validate compiling all *.cpp in same compilation unit. Removed Unity builds stuff from example_null/. CI builds a temporary .cpp file. --- .github/workflows/build.yml | 25 +++++++++++++++++++------ docs/CHANGELOG.txt | 5 ++++- examples/example_null/Makefile | 9 ++------- examples/example_null/unity_build.cpp | 6 ------ misc/single_file/imgui_single_file.h | 17 +++++++++++++++++ 5 files changed, 42 insertions(+), 20 deletions(-) delete mode 100644 examples/example_null/unity_build.cpp create mode 100644 misc/single_file/imgui_single_file.h diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 856e29f5..04f8f6dc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,8 +44,13 @@ jobs: - name: Build example_null (extra warnings) run: mingw32-make -C examples/example_null EXTRA_WARNINGS=1 - - name: Build example_null (unity build) - run: mingw32-make -C examples/example_null UNITY_BUILD=1 + - name: Build example_null (single file build) + shell: bash + run: | + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp - name: Build Win32 example_glfw_opengl2 shell: cmd @@ -176,8 +181,12 @@ jobs: make -C examples/example_null clean CXXFLAGS="$CXXFLAGS -m64" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 - - name: Build example_null (unity build) - run: make -C examples/example_null UNITY_BUILD=1 + - name: Build example_null (single file build) + run: | + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 @@ -208,8 +217,12 @@ jobs: - name: Build example_null (extra warnings) run: make -C examples/example_null EXTRA_WARNINGS=1 - - name: Build example_null (unity build) - run: make -C examples/example_null UNITY_BUILD=1 + - name: Build example_null (single file build) + run: | + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + clang++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 36d10732..5f6d16d6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,11 +68,14 @@ Other Changes: - ColorEdit: In HSV display of a RGB stored value, attempt to locally preserve Saturation when Value==0.0 (similar to changes done in 1.73 for Hue). Removed Hue editing lock since those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] -- Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as we will rework the circle rendering functions to use textures and automatic segment count selection, those new api can fill a gap. [@ShironekoBen] +- Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- Misc: Added misc/single_file/imgui_single_file.h, We use this to validate compiling all *.cpp + files in a same compilation unit. Actual users of that technique (also called "Unity builds") + can generally provide this themselves, so we don't really recommend you use this. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 3930eb27..7d39e824 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -5,13 +5,8 @@ EXE = example_null EXTRA_WARNINGS ?= 0 -UNITY_BUILD ?= 0 -ifeq ($(UNITY_BUILD), 1) - SOURCES = unity_build.cpp -else - SOURCES = main.cpp - SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp -endif +SOURCES = main.cpp +SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) diff --git a/examples/example_null/unity_build.cpp b/examples/example_null/unity_build.cpp deleted file mode 100644 index c6040016..00000000 --- a/examples/example_null/unity_build.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Unity build test - build this example as a single compilation unit. -#include "main.cpp" -#include "../../imgui.cpp" -#include "../../imgui_demo.cpp" -#include "../../imgui_draw.cpp" -#include "../../imgui_widgets.cpp" diff --git a/misc/single_file/imgui_single_file.h b/misc/single_file/imgui_single_file.h new file mode 100644 index 00000000..a556931c --- /dev/null +++ b/misc/single_file/imgui_single_file.h @@ -0,0 +1,17 @@ +// imgui_single_file.h +// We use this to validate compiling all *.cpp files in a same compilation unit. +// Users of that technique (also called "Unity builds") can generally provide this themselves, +// so we don't really recommend you use this in your projects. + +// Do this: +// #define IMGUI_IMPLEMENTATION +// Before you include this file in *one* C++ file to create the implementation. +// Using this in your project will leak the contents of imgui_internal.h and ImVec2 operators in this compilation unit. +#include "../../imgui.h" + +#ifdef IMGUI_IMPLEMENTATION +#include "../../imgui.cpp" +#include "../../imgui_demo.cpp" +#include "../../imgui_draw.cpp" +#include "../../imgui_widgets.cpp" +#endif From 4b3c5ff5f158de53c67d966b6f65c03bfca2c23f Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 11 Jan 2020 15:35:39 +0100 Subject: [PATCH 210/384] Comments + minor moving --- imgui_demo.cpp | 14 +++++++------- imgui_internal.h | 18 +++++++++--------- misc/README.txt | 6 ++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 1f0a1b19..b0e0d347 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -7,11 +7,11 @@ // your game/app! Removing this file from your project is hindering access to documentation for everyone in your team, // likely leading you to poorer usage of the library. // Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow(). -// If you want to link core Dear ImGui in your shipped builds but want an easy guarantee that the demo will not be linked, +// If you want to link core Dear ImGui in your shipped builds but want a thorough guarantee that the demo will not be linked, // you can setup your imconfig.h with #define IMGUI_DISABLE_DEMO_WINDOWS and those functions will be empty. // In other situation, whenever you have Dear ImGui available you probably want this to be available for reference. // Thank you, -// -Your beloved friend, imgui_demo.cpp (that you won't delete) +// -Your beloved friend, imgui_demo.cpp (which you won't delete) // Message to beginner C/C++ programmers about the meaning of the 'static' keyword: // In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is @@ -21,13 +21,13 @@ // reentrant or used in multiple threads. This might be a pattern you will want to use in your code, but most of the real data // you would be editing is likely going to be stored outside your functions. -// The Demo code is this file is designed to be easy to copy-and-paste in into your application! +// The Demo code in this file is designed to be easy to copy-and-paste in into your application! // Because of this: // - We never omit the ImGui:: namespace when calling functions, even though most of our code is already in the same namespace. // - We try to declare static variables in the local scope, as close as possible to the code using them. -// - We never use any of the helpers/facilities used internally by dear imgui, unless it has been exposed in the public API (imgui.h). -// - We never use maths operators on ImVec2/ImVec4. For other imgui sources files, they are provided by imgui_internal.h w/ IMGUI_DEFINE_MATH_OPERATORS, -// for your own sources file they are optional and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h. +// - We never use any of the helpers/facilities used internally by Dear ImGui, unless it has been exposed in the public API (imgui.h). +// - We never use maths operators on ImVec2/ImVec4. For other of our sources files, they are provided by imgui_internal.h w/ IMGUI_DEFINE_MATH_OPERATORS. +// For your own sources file they are optional and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h. // Because we don't want to assume anything about your support of maths operators, we don't use them in imgui_demo.cpp. /* @@ -97,7 +97,7 @@ Index of this file: #pragma GCC diagnostic ignored "-Wmisleading-indentation" // [__GNUC__ >= 6] warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub. #endif -// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n. +// Play it nice with Windows users (Update: since 2018-05, Notepad finally appears to support Unix-style carriage returns!) #ifdef _WIN32 #define IM_NEWLINE "\r\n" #else diff --git a/imgui_internal.h b/imgui_internal.h index 29864f82..96ff585f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -920,7 +920,7 @@ struct ImGuiNextWindowData ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } - inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } + inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } // Also cleared by ItemAdd() }; enum ImGuiNextItemDataFlags_ @@ -1035,7 +1035,7 @@ struct ImGuiContext ImVectorOpenPopupStack; // Which popups are open (persistent) ImVectorBeginPopupStack; // Which level of BeginPopup() we are in (reset every frame) - // Navigation data (for gamepad/keyboard) + // Gamepad/keyboard Navigation ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' ImGuiID NavId; // Focused item for navigation ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() @@ -1076,7 +1076,7 @@ struct ImGuiContext ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag) ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag) - // Tabbing system (older than Nav, active even if Nav is disabled. FIXME-NAV: This needs a redesign!) + // Legacy Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!) ImGuiWindow* FocusRequestCurrWindow; // ImGuiWindow* FocusRequestNextWindow; // int FocusRequestCurrCounterAll; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch) @@ -1085,6 +1085,10 @@ struct ImGuiContext int FocusRequestNextCounterTab; // " bool FocusTabPressed; // + // Range-Select/Multi-Select + // [This is unused in this branch, but left here to facilitate merging/syncing multiple branches] + ImGuiID MultiSelectScopeId; + // Render ImDrawData DrawData; // Main ImDrawData instance to pass render information to the user ImDrawDataBuilder DrawDataBuilder; @@ -1133,10 +1137,6 @@ struct ImGuiContext int TooltipOverrideCount; ImVector PrivateClipboard; // If no custom clipboard handler is defined - // Range-Select/Multi-Select - // [This is unused in this branch, but left here to facilitate merging/syncing multiple branches] - ImGuiID MultiSelectScopeId; - // Platform support ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor ImVec2 PlatformImeLastPos; @@ -1247,6 +1247,8 @@ struct ImGuiContext FocusRequestNextCounterAll = FocusRequestNextCounterTab = INT_MAX; FocusTabPressed = false; + MultiSelectScopeId = 0; + DimBgRatio = 0.0f; BackgroundDrawList._OwnerName = "##Background"; // Give it a name for debugging ForegroundDrawList._OwnerName = "##Foreground"; // Give it a name for debugging @@ -1276,8 +1278,6 @@ struct ImGuiContext ScrollbarClickDeltaToGrabCenter = 0.0f; TooltipOverrideCount = 0; - MultiSelectScopeId = 0; - PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX); SettingsLoaded = false; diff --git a/misc/README.txt b/misc/README.txt index be3af5ae..86900089 100644 --- a/misc/README.txt +++ b/misc/README.txt @@ -16,3 +16,9 @@ misc/natvis/ Natvis file to describe dear imgui types in the Visual Studio debugger. With this, types like ImVector<> will be displayed nicely in the debugger. You can include this file a Visual Studio project file, or install it in Visual Studio folder. + +misc/single_file/ + Single-file header stub. + We use this to validate compiling all *.cpp files in a same compilation unit. + Users of that technique (also called "Unity builds") can generally provide this themselves, + so we don't really recommend you use this in your projects. From ff5299e0e030b9b769ff3b069a924001c6a84feb Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 12 Jan 2020 21:51:40 +0100 Subject: [PATCH 211/384] Docs: FAQ, Comments. --- docs/CHANGELOG.txt | 32 +++++++++++++ docs/FAQ.md | 107 +++++++++++++++++++++++--------------------- examples/README.txt | 2 + imgui.cpp | 59 ++++++++++++------------ imgui.h | 18 ++++++-- imgui_demo.cpp | 7 +++ 6 files changed, 139 insertions(+), 86 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5f6d16d6..cf9c1327 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -93,6 +93,8 @@ Other Changes: VERSION 1.74 (Released 2019-11-25) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.74 + Breaking Changes: - Removed redirecting functions/enums names that were marked obsolete in 1.52 (October 2017): - Begin() [old 5 args version] -> use Begin() [3 args], use SetNextWindowSize() SetNextWindowBgAlpha() if needed @@ -166,6 +168,8 @@ Other Changes: VERSION 1.73 (Released 2019-09-24) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.73 + Other Changes: - Nav, Scrolling: Added support for Home/End key. (#787) @@ -226,6 +230,8 @@ Other Changes: VERSION 1.72b (Released 2019-07-31) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.72b + Other Changes: - Nav, Scrolling: Fixed programmatic scroll leading to a slightly incorrect scroll offset when @@ -241,6 +247,8 @@ Other Changes: VERSION 1.72 (Released 2019-07-27) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.72 + Breaking Changes: - Removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): - ImGuiCol_Column*, ImGuiSetCond_* enums. @@ -322,6 +330,8 @@ Other Changes: VERSION 1.71 (Released 2019-06-12) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.71 + Breaking Changes: - IO: changed AddInputCharacter(unsigned short c) signature to AddInputCharacter(unsigned int c). - Renamed SetNextTreeNodeOpen() to SetNextItemOpen(). Kept inline redirection function (will obsolete). @@ -402,6 +412,8 @@ Other Changes: VERSION 1.70 (Released 2019-05-06) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.70 + Breaking Changes: - ImDrawList: Improved algorithm for mitre joints on thick lines, preserving correct thickness up to 90 degrees angles (e.g. rectangles). If you have custom rendering using thick lines, @@ -489,6 +501,8 @@ Other Changes: VERSION 1.69 (Released 2019-03-13) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.69 + Breaking Changes: - Renamed ColorEdit/ColorPicker's ImGuiColorEditFlags_RGB/_HSV/_HEX flags to respectively @@ -565,6 +579,8 @@ Other Changes: VERSION 1.68 (Released 2019-02-19) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.68 + Breaking Changes: - Removed io.DisplayVisibleMin/DisplayVisibleMax (which were marked obsolete and removed from viewport/docking branch already). @@ -633,6 +649,8 @@ Other Changes: VERSION 1.67 (Released 2019-01-14) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.67 + Breaking Changes: - Made it illegal to call Begin("") with an empty string. This somehow half-worked before but had various undesirable @@ -696,6 +714,8 @@ Other Changes: VERSION 1.66b (Released 2018-12-01) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.66b + Other Changes: - Fixed a text rendering/clipping bug introduced in 1.66 (on 2018-10-12, commit ede3a3b9) that affect single ImDrawList::AddText() @@ -713,6 +733,8 @@ Other Changes: VERSION 1.66 (Released 2018-11-22) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.66 + Breaking Changes: - Renamed SetScrollHere() to SetScrollHereY(). Kept redirection function (will obsolete). @@ -772,6 +794,8 @@ Other Changes: VERSION 1.65 (Released 2018-09-06) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.65 + Breaking Changes: - Renamed stb_truetype.h to imstb_truetype.h, stb_textedit.h to imstb_textedit.h, and @@ -796,6 +820,8 @@ Other Changes: VERSION 1.64 (Released 2018-08-31) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.64 + Changes: - Moved README, CHANGELOG and TODO files to the docs/ folder. @@ -818,6 +844,8 @@ Changes: VERSION 1.63 (Released 2018-08-29) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.63 + Breaking Changes: - Style: Renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. @@ -910,6 +938,8 @@ Other Changes: VERSION 1.62 (Released 2018-06-22) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.62 + Breaking Changes: - TreeNodeEx(): The helper ImGuiTreeNodeFlags_CollapsingHeader flag now include ImGuiTreeNodeFlags_NoTreePushOnOpen. @@ -989,6 +1019,8 @@ Other Changes: VERSION 1.61 (Released 2018-05-14) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.61 + Breaking Changes: - DragInt(): The default compile-time format string has been changed from "%.0f" to "%d", as we are not using integers internally diff --git a/docs/FAQ.md b/docs/FAQ.md index 68b43f73..3216a524 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -12,21 +12,16 @@ or view this file with any Markdown viewer. | **Q&A: Basics** | :---------------------------------------------------------- | | [Where is the documentation?](#q-where-is-the-documentation) | +| [What is this library called?](#q-what-is-this-library-called) | | [Which version should I get?](#q-which-version-should-i-get) | -| [Why the names "Dear ImGui" vs "ImGui"?](#q-why-the-names-dear-imgui-vs-imgui) | -| **Q&A: Concerns** | -| [Who uses Dear ImGui?](#q-who-uses-dear-imgui) | -| [Can you create elaborate/serious tools with Dear ImGui?](#q-can-you-create-elaborateserious-tools-with-dear-imgui) | -| [Can you reskin the look of Dear ImGui?](#q-can-you-reskin-the-look-of-dear-imgui) | -| [Why using C++ (as opposed to C)?](#q-why-using-c-as-opposed-to-c) | | **Q&A: Integration** | -| [How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?](#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application) | +| **[How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?](#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application)** | | [How can I enable keyboard or gamepad controls?](#q-how-can-i-enable-keyboard-or-gamepad-controls) | | [How can I use this on a machine without mouse, keyboard or screen? (input share, remote display)](#q-how-can-i-use-this-on-a-machine-without-mouse-keyboard-or-screen-input-share-remote-display) | | [I integrated Dear ImGui in my engine and the text or lines are blurry..](#q-i-integrated-dear-imgui-in-my-engine-and-the-text-or-lines-are-blurry) | | [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) | | **Q&A: Usage** | -| [Why are multiple widgets reacting when I interact with a single one?
How can I have multiple widgets with the same label or with an empty label?](#q-why-are-multiple-widgets-reacting-when-i-interact-with-a-single-one-q-how-can-i-have-multiple-widgets-with-the-same-label-or-with-an-empty-label) | +| **[Why are multiple widgets reacting when I interact with a single one?
How can I have multiple widgets with the same label or with an empty label?](#q-why-are-multiple-widgets-reacting-when-i-interact-with-a-single-one-q-how-can-i-have-multiple-widgets-with-the-same-label-or-with-an-empty-label)** | | [How can I display an image? What is ImTextureID, how does it work?](#q-how-can-i-display-an-image-what-is-imtextureid-how-does-it-work)| | [How can I use my own math types instead of ImVec2/ImVec4?](#q-how-can-i-use-my-own-math-types-instead-of-imvec2imvec4) | | [How can I interact with standard C++ types (such as std::string and std::vector)?](#q-how-can-i-interact-with-standard-c-types-such-as-stdstring-and-stdvector) | @@ -36,6 +31,11 @@ or view this file with any Markdown viewer. | [How can I easily use icons in my application?](#q-how-can-i-easily-use-icons-in-my-application) | | [How can I load multiple fonts?](#q-how-can-i-load-multiple-fonts) | | [How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?](#q-how-can-i-display-and-input-non-latin-characters-such-as-chinese-japanese-korean-cyrillic) | +| **Q&A: Concerns** | +| [Who uses Dear ImGui?](#q-who-uses-dear-imgui) | +| [Can you create elaborate/serious tools with Dear ImGui?](#q-can-you-create-elaborateserious-tools-with-dear-imgui) | +| [Can you reskin the look of Dear ImGui?](#q-can-you-reskin-the-look-of-dear-imgui) | +| [Why using C++ (as opposed to C)?](#q-why-using-c-as-opposed-to-c) | | **Q&A: Community** | | [How can I help?](#q-how-can-i-help) | @@ -50,60 +50,30 @@ or view this file with any Markdown viewer. - See documentation and comments at the top of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) + general API comments in [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h). - The [Wiki](https://github.com/ocornut/imgui/wiki) has many resources and links. - The [Glossary](https://github.com/ocornut/imgui/wiki/Glossary) page may be useful. +- The [Issues](https://github.com/ocornut/imgui/issues) section can be searched for past questions and issues. - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. +- The `ImGui::ShowMetricsWindow()` function exposes lots of internal information and tools. Although it is primary designed as a debugging tool, having access to that information tends to help understands concepts. --- -### Q: Which version should I get? -I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. +### Q. What is this library called? -You may also peak at the [docking](https://github.com/ocornut/imgui/tree/docking) branch which includes: -- [Docking/Merging features](https://github.com/ocornut/imgui/issues/2109) -- [Multi-viewport features](https://github.com/ocornut/imgui/issues/1542) +**This library is called Dear ImGui**. Please refer to it as Dear ImGui (not ImGui, not IMGUI). -Many projects are using this branch and it is kept in sync with master regularly. +(The library misleadingly started its life in 2014 as "ImGui" due to the fact that I didn't give it a proper name when when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations e.g. Unity uses it own implementation of the IMGUI paradigm. To reduce the ambiguity without affecting existing code bases, I have decided in December 2015 a fully qualified name "Dear ImGui" for this library. --- -### Q: Why the names "Dear ImGui" vs "ImGui"? - -**TL;DR: Please refer to this library as "Dear ImGui".** - -The library started its life as "ImGui" due to the fact that I didn't give it a proper name when when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce the ambiguity without affecting existing code bases, I have decided on an alternate, longer name "Dear ImGui" that people can use to refer to this specific library. - -##### [Return to Index](#index) - - -# Q&A: Concerns - -### Q: Who uses Dear ImGui? - -You may take a look at: - -- [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) -- [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) -- [Gallery](https://github.com/ocornut/imgui/issues/2847) - -### Q: Can you create elaborate/serious tools with Dear ImGui? - -Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. - -Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. - -Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. - -### Q: Can you reskin the look of Dear ImGui? - -Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. - -A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) -![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) +### Q: Which version should I get? +I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported. -### Q: Why using C++ (as opposed to C)? +You may use the [docking](https://github.com/ocornut/imgui/tree/docking) branch which includes: +- [Docking features](https://github.com/ocornut/imgui/issues/2109) +- [Multi-viewport features](https://github.com/ocornut/imgui/issues/1542) -Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. +Many projects are using this branch and it is kept in sync with master regularly. -There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. +--- ##### [Return to Index](#index) @@ -365,7 +335,7 @@ void* my_void_ptr; my_void_ptr = (void*)my_dx11_srv; // cast a ID3D11ShaderResourceView* into an opaque void* my_dx11_srv = (ID3D11ShaderResourceView*)my_void_ptr; // cast a void* into a ID3D11ShaderResourceView* ``` -Finally, you may call ImGui::ShowMetricsWindow() to explore/visualize/understand how the ImDrawList are generated. +Finally, you may call `ImGui::ShowMetricsWindow()` to explore/visualize/understand how the ImDrawList are generated. --- @@ -534,6 +504,41 @@ the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft ##### [Return to Index](#index) + +# Q&A: Concerns + +### Q: Who uses Dear ImGui? + +You may take a look at: + +- [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) +- [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) +- [Gallery](https://github.com/ocornut/imgui/issues/2847) + +### Q: Can you create elaborate/serious tools with Dear ImGui? + +Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. + +Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might require you to readjust some habits before you can realize its full potential. Dear ImGui is about making things that are simple, efficient and powerful. + +Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. + +### Q: Can you reskin the look of Dear ImGui? + +Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. + +A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) +![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) + +### Q: Why using C++ (as opposed to C)? + +Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. + +There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings. + +##### [Return to Index](#index) + + # Q&A: Community ### Q: How can I help? diff --git a/examples/README.txt b/examples/README.txt index f52c90bc..a2655da6 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -35,6 +35,8 @@ You can find binaries of some of those example applications at: MISC COMMENTS AND SUGGESTIONS --------------------------------------- + - Read FAQ at http://dearimgui.org/faq + - Please read 'PROGRAMMER GUIDE' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. Please read the comments and instruction at the top of each file. diff --git a/imgui.cpp b/imgui.cpp index ed6da44d..c9ca32a3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,12 +1,19 @@ // dear imgui, v1.75 WIP // (main code and documentation) -// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. -// Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. -// Get latest version at https://github.com/ocornut/imgui -// Releases change-log at https://github.com/ocornut/imgui/releases -// Technical Support for Getting Started https://github.com/ocornut/imgui/wiki -// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2847 +// Help: +// - Read FAQ at http://dearimgui.org/faq +// - Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. +// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that. + +// Resources: +// - FAQ http://dearimgui.org/faq +// - Homepage & latest https://github.com/ocornut/imgui +// - Releases & changelog https://github.com/ocornut/imgui/releases +// - Gallery https://github.com/ocornut/imgui/issues/2847 (please post your screenshots/video there!) +// - Glossary https://github.com/ocornut/imgui/wiki/Glossary +// - Wiki https://github.com/ocornut/imgui/wiki +// - Issues & support https://github.com/ocornut/imgui/issues // Developed by Omar Cornut and every direct or indirect contributors to the GitHub. // See LICENSE.txt for copyright and licensing details (standard MIT License). @@ -155,8 +162,9 @@ CODE GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE --------------------------------------------------------------- - Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library. + - In the majority of cases you should be able to use unmodified back-ends files available in the examples/ folder. - Add the Dear ImGui source files to your projects or using your preferred build system. - It is recommended you build and statically link the .cpp files as part of your project and not as shared library (DLL). + It is recommended you build and statically link the .cpp files as part of your project and NOT as shared library (DLL). - You can later customize the imconfig.h file to tweak some compile-time behavior, such as integrating Dear ImGui types with your own maths types. - When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them. - Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide. @@ -176,7 +184,7 @@ CODE // TODO: Fill optional fields of the io structure later. // TODO: Load TTF/OTF fonts if you don't want to use the default font. - // Initialize helper Platform and Renderer bindings (here we are using imgui_impl_win32 and imgui_impl_dx11) + // Initialize helper Platform and Renderer bindings (here we are using imgui_impl_win32.cpp and imgui_impl_dx11.cpp) ImGui_ImplWin32_Init(hwnd); ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); @@ -597,37 +605,17 @@ CODE - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. + Q: What is this library called? Q: Which version should I get? - Q: Why the names "Dear ImGui" vs "ImGui"? >> This library is called "Dear ImGui", please don't call it "ImGui" :) >> See https://www.dearimgui.org/faq - Q&A: Concerns - ============= - - Q: Who uses Dear ImGui? - Q: Can you create elaborate/serious tools with Dear ImGui? - Q: Can you reskin the look of Dear ImGui? - Q: Why using C++ (as opposed to C)? - >> See https://www.dearimgui.org/faq - Q&A: Integration ================ Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application? - A: You can read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags from the ImGuiIO structure (e.g. if (ImGui::GetIO().WantCaptureMouse) { ... } ) - - When 'io.WantCaptureMouse' is set, imgui wants to use your mouse state, and you may want to discard/hide the inputs from the rest of your application. - - When 'io.WantCaptureKeyboard' is set, imgui wants to use your keyboard state, and you may want to discard/hide the inputs from the rest of your application. - - When 'io.WantTextInput' is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console OS). - Note: you should always pass your mouse/keyboard inputs to imgui, even when the io.WantCaptureXXX flag are set false. - This is because imgui needs to detect that you clicked in the void to unfocus its own windows. - Note: The 'io.WantCaptureMouse' is more accurate that any attempt to "check if the mouse is hovering a window" (don't do that!). - It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs. - Those flags are updated by ImGui::NewFrame(). Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also - perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you might find use for an early call to UpdateHoveredWindowAndCaptureFlags(). - Note: Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically - have 'io.WantCaptureKeyboard=false'. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs - were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) + A: You should read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags! + >> See https://www.dearimgui.org/faq for fully detailed answer. You really want to read this. Q. How can I enable keyboard controls? Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display) @@ -771,6 +759,15 @@ CODE Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? >> See https://www.dearimgui.org/faq and docs/FONTS.txt + Q&A: Concerns + ============= + + Q: Who uses Dear ImGui? + Q: Can you create elaborate/serious tools with Dear ImGui? + Q: Can you reskin the look of Dear ImGui? + Q: Why using C++ (as opposed to C)? + >> See https://www.dearimgui.org/faq + Q&A: Community ============== diff --git a/imgui.h b/imgui.h index 6ed2fb5b..57d0511c 100644 --- a/imgui.h +++ b/imgui.h @@ -1,10 +1,20 @@ // dear imgui, v1.75 WIP // (headers) -// See imgui.cpp file for documentation. -// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. -// Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. -// Get latest version at https://github.com/ocornut/imgui +// Help: +// - Read FAQ at http://dearimgui.org/faq +// - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. +// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that. +// Read imgui.cpp for more details, documentation and comments. + +// Resources: +// - FAQ http://dearimgui.org/faq +// - Homepage & latest https://github.com/ocornut/imgui +// - Releases & changelog https://github.com/ocornut/imgui/releases +// - Gallery https://github.com/ocornut/imgui/issues/2847 (please post your screenshots/video there!) +// - Glossary https://github.com/ocornut/imgui/wiki/Glossary +// - Wiki https://github.com/ocornut/imgui/wiki +// - Issues & support https://github.com/ocornut/imgui/issues /* diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b0e0d347..5ccebef2 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,6 +1,13 @@ // dear imgui, v1.75 WIP // (demo code) +// Help: +// - Read FAQ at http://dearimgui.org/faq +// - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. +// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that. +// Read imgui.cpp for more details, documentation and comments. +// Get latest version at https://github.com/ocornut/imgui + // Message to the person tempted to delete this file when integrating Dear ImGui into their code base: // Do NOT remove this file from your project! Think again! It is the most useful reference code that you and other coders // will want to refer to and call. Have the ImGui::ShowDemoWindow() function wired in an always-available debug menu of From f56962cb9a371d8b124a145cee8e20d74da175f4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 13 Jan 2020 14:09:42 +0100 Subject: [PATCH 212/384] ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x' + both with/without alpha when available. --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index cf9c1327..782f5be2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,8 @@ Other Changes: - ColorEdit: In HSV display of a RGB stored value, attempt to locally preserve Saturation when Value==0.0 (similar to changes done in 1.73 for Hue). Removed Hue editing lock since those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] +- ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. +- ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as we will rework the circle rendering functions to use textures and automatic segment count diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index c7d142cb..4f3c6fa7 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5022,12 +5022,15 @@ void ImGui::ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags) ImFormatString(buf, IM_ARRAYSIZE(buf), "(%d,%d,%d,%d)", cr, cg, cb, ca); if (Selectable(buf)) SetClipboardText(buf); - if (flags & ImGuiColorEditFlags_NoAlpha) - ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X", cr, cg, cb); - else - ImFormatString(buf, IM_ARRAYSIZE(buf), "0x%02X%02X%02X%02X", cr, cg, cb, ca); + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", cr, cg, cb); if (Selectable(buf)) SetClipboardText(buf); + if (!(flags & ImGuiColorEditFlags_NoAlpha)) + { + ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", cr, cg, cb, ca); + if (Selectable(buf)) + SetClipboardText(buf); + } EndPopup(); } From 52334ad8df3325d01a7597c4306d8b4cc8016a4f Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 13 Jan 2020 15:04:28 +0100 Subject: [PATCH 213/384] Internals: Minor ordering/comments of ImGuiWindowTempData. --- imgui.cpp | 2 +- imgui_internal.h | 37 +++++++++++++++++++++++-------------- imgui_widgets.cpp | 6 +++--- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c9ca32a3..8e6527a2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5859,7 +5859,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.TextWrapPosStack.resize(0); window->DC.CurrentColumns = NULL; window->DC.TreeDepth = 0; - window->DC.TreeMayJumpToParentOnPopMask = 0x00; + window->DC.TreeJumpToParentOnPopMask = 0x00; window->DC.StateStorage = &window->StateStorage; window->DC.GroupStack.resize(0); window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); diff --git a/imgui_internal.h b/imgui_internal.h index 96ff585f..4e5b35bc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1310,6 +1310,7 @@ struct ImGuiContext // FIXME: That's theory, in practice the delimitation between ImGuiWindow and ImGuiWindowTempData is quite tenuous and could be reconsidered. struct IMGUI_API ImGuiWindowTempData { + // Layout ImVec2 CursorPos; // Current emitting position, in absolute coordinates. ImVec2 CursorPosPrevLine; ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding. @@ -1318,27 +1319,38 @@ struct IMGUI_API ImGuiWindowTempData ImVec2 PrevLineSize; float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added). float PrevLineTextBaseOffset; - int TreeDepth; // Current tree depth. - ImU32 TreeMayJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. + ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) + ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. + ImVec1 GroupOffset; + + // Last item status ImGuiID LastItemId; // ID for last item ImGuiItemStatusFlags LastItemStatusFlags; // Status flags for last item (see ImGuiItemStatusFlags_) ImRect LastItemRect; // Interaction rect for last item ImRect LastItemDisplayRect; // End-user display rect for last item (only valid if LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) + + // Keyboard/Gamepad navigation ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping. int NavLayerActiveMask; // Which layer have been written to (result from previous frame) int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame) bool NavHideHighlightOneFrame; bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) + + // Miscellaneous bool MenuBarAppending; // FIXME: Remove this ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs. + int TreeDepth; // Current tree depth. + ImU32 TreeJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. ImVector ChildWindows; ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state) + ImGuiColumns* CurrentColumns; // Current columns set ImGuiLayoutType LayoutType; ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() int FocusCounterAll; // Counter for focus/tabbing system. Start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) int FocusCounterTab; // (same, but only count widgets which you can Tab through) + // Local parameters stacks // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings. ImGuiItemFlags ItemFlags; // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default] float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window @@ -1349,29 +1361,31 @@ struct IMGUI_API ImGuiWindowTempData ImVectorGroupStack; short StackSizesBackup[6]; // Store size of various stacks for asserting - ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) - ImVec1 GroupOffset; - ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. - ImGuiColumns* CurrentColumns; // Current columns set - ImGuiWindowTempData() { CursorPos = CursorPosPrevLine = CursorStartPos = CursorMaxPos = ImVec2(0.0f, 0.0f); CurrLineSize = PrevLineSize = ImVec2(0.0f, 0.0f); CurrLineTextBaseOffset = PrevLineTextBaseOffset = 0.0f; - TreeDepth = 0; - TreeMayJumpToParentOnPopMask = 0x00; + Indent = ImVec1(0.0f); + ColumnsOffset = ImVec1(0.0f); + GroupOffset = ImVec1(0.0f); + LastItemId = 0; LastItemStatusFlags = 0; LastItemRect = LastItemDisplayRect = ImRect(); + NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; NavLayerCurrent = ImGuiNavLayer_Main; NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); NavHideHighlightOneFrame = false; NavHasScroll = false; + MenuBarAppending = false; MenuBarOffset = ImVec2(0.0f, 0.0f); + TreeDepth = 0; + TreeJumpToParentOnPopMask = 0x00; StateStorage = NULL; + CurrentColumns = NULL; LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical; FocusCounterAll = FocusCounterTab = -1; @@ -1379,11 +1393,6 @@ struct IMGUI_API ImGuiWindowTempData ItemWidth = 0.0f; TextWrapPos = -1.0f; memset(StackSizesBackup, 0, sizeof(StackSizesBackup)); - - Indent = ImVec1(0.0f); - GroupOffset = ImVec1(0.0f); - ColumnsOffset = ImVec1(0.0f); - CurrentColumns = NULL; } }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 4f3c6fa7..3c0a5d8e 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5269,7 +5269,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; bool is_open = TreeNodeBehaviorIsOpen(id, flags); if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) - window->DC.TreeMayJumpToParentOnPopMask |= (1 << window->DC.TreeDepth); + window->DC.TreeJumpToParentOnPopMask |= (1 << window->DC.TreeDepth); bool item_add = ItemAdd(interact_bb, id); window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HasDisplayRect; @@ -5442,12 +5442,12 @@ void ImGui::TreePop() // Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled) if (g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet()) - if (g.NavIdIsAlive && (window->DC.TreeMayJumpToParentOnPopMask & tree_depth_mask)) + if (g.NavIdIsAlive && (window->DC.TreeJumpToParentOnPopMask & tree_depth_mask)) { SetNavID(window->IDStack.back(), g.NavLayer); NavMoveRequestCancel(); } - window->DC.TreeMayJumpToParentOnPopMask &= tree_depth_mask - 1; + window->DC.TreeJumpToParentOnPopMask &= tree_depth_mask - 1; IM_ASSERT(window->IDStack.Size > 1); // There should always be 1 element in the IDStack (pushed during window creation). If this triggers you called TreePop/PopID too much. PopID(); From 02c2d18aa3be3be2a7762a90c3c6d275e7ea51c3 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 13 Jan 2020 15:21:37 +0100 Subject: [PATCH 214/384] Internals: Renaming and marking of legacy focus/tabbing system --- imgui.cpp | 40 ++++++++++++++++++++-------------------- imgui_internal.h | 20 ++++++++++---------- imgui_widgets.cpp | 2 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8e6527a2..8146459e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3080,24 +3080,24 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id) // Increment counters const bool is_tab_stop = (window->DC.ItemFlags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0; - window->DC.FocusCounterAll++; + window->DC.FocusCounterRegular++; if (is_tab_stop) - window->DC.FocusCounterTab++; + window->DC.FocusCounterTabStop++; // Process TAB/Shift-TAB to tab *OUT* of the currently focused item. // (Note that we can always TAB out of a widget that doesn't allow tabbing in) if (g.ActiveId == id && g.FocusTabPressed && !IsActiveIdUsingKey(ImGuiKey_Tab) && g.FocusRequestNextWindow == NULL) { g.FocusRequestNextWindow = window; - g.FocusRequestNextCounterTab = window->DC.FocusCounterTab + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items. + g.FocusRequestNextCounterTabStop = window->DC.FocusCounterTabStop + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items. } // Handle focus requests if (g.FocusRequestCurrWindow == window) { - if (window->DC.FocusCounterAll == g.FocusRequestCurrCounterAll) + if (window->DC.FocusCounterRegular == g.FocusRequestCurrCounterRegular) return true; - if (is_tab_stop && window->DC.FocusCounterTab == g.FocusRequestCurrCounterTab) + if (is_tab_stop && window->DC.FocusCounterTabStop == g.FocusRequestCurrCounterTabStop) { g.NavJustTabbedId = id; return true; @@ -3113,8 +3113,8 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id) void ImGui::FocusableItemUnregister(ImGuiWindow* window) { - window->DC.FocusCounterAll--; - window->DC.FocusCounterTab--; + window->DC.FocusCounterRegular--; + window->DC.FocusCounterTabStop--; } float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x) @@ -3767,26 +3767,26 @@ void ImGui::NewFrame() // Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also // manipulate the Next fields even, even though they will be turned into Curr fields by the code below. g.FocusRequestNextWindow = g.NavWindow; - g.FocusRequestNextCounterAll = INT_MAX; + g.FocusRequestNextCounterRegular = INT_MAX; if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX) - g.FocusRequestNextCounterTab = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1); + g.FocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1); else - g.FocusRequestNextCounterTab = g.IO.KeyShift ? -1 : 0; + g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0; } // Turn queued focus request into current one g.FocusRequestCurrWindow = NULL; - g.FocusRequestCurrCounterAll = g.FocusRequestCurrCounterTab = INT_MAX; + g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX; if (g.FocusRequestNextWindow != NULL) { ImGuiWindow* window = g.FocusRequestNextWindow; g.FocusRequestCurrWindow = window; - if (g.FocusRequestNextCounterAll != INT_MAX && window->DC.FocusCounterAll != -1) - g.FocusRequestCurrCounterAll = ImModPositive(g.FocusRequestNextCounterAll, window->DC.FocusCounterAll + 1); - if (g.FocusRequestNextCounterTab != INT_MAX && window->DC.FocusCounterTab != -1) - g.FocusRequestCurrCounterTab = ImModPositive(g.FocusRequestNextCounterTab, window->DC.FocusCounterTab + 1); + if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1) + g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1); + if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1) + g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1); g.FocusRequestNextWindow = NULL; - g.FocusRequestNextCounterAll = g.FocusRequestNextCounterTab = INT_MAX; + g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX; } g.NavIdTabCounter = INT_MAX; @@ -5850,7 +5850,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.ChildWindows.resize(0); window->DC.LayoutType = ImGuiLayoutType_Vertical; window->DC.ParentLayoutType = parent_window ? parent_window->DC.LayoutType : ImGuiLayoutType_Vertical; - window->DC.FocusCounterAll = window->DC.FocusCounterTab = -1; + window->DC.FocusCounterRegular = window->DC.FocusCounterTabStop = -1; window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_; window->DC.ItemWidth = window->ItemWidthDefault; window->DC.TextWrapPos = -1.0f; // disabled @@ -6904,8 +6904,8 @@ void ImGui::SetKeyboardFocusHere(int offset) ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; g.FocusRequestNextWindow = window; - g.FocusRequestNextCounterAll = window->DC.FocusCounterAll + 1 + offset; - g.FocusRequestNextCounterTab = INT_MAX; + g.FocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset; + g.FocusRequestNextCounterTabStop = INT_MAX; } void ImGui::SetItemDefaultFocus() @@ -8059,7 +8059,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window. g.NavLayer = window->DC.NavLayerCurrent; g.NavIdIsAlive = true; - g.NavIdTabCounter = window->DC.FocusCounterTab; + g.NavIdTabCounter = window->DC.FocusCounterTabStop; window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel; // Store item bounding box (relative to window position) } } diff --git a/imgui_internal.h b/imgui_internal.h index 4e5b35bc..50565382 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1076,13 +1076,13 @@ struct ImGuiContext ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag) ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag) - // Legacy Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!) + // Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!) ImGuiWindow* FocusRequestCurrWindow; // ImGuiWindow* FocusRequestNextWindow; // - int FocusRequestCurrCounterAll; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch) - int FocusRequestCurrCounterTab; // Tab item being requested for focus, stored as an index - int FocusRequestNextCounterAll; // Stored for next frame - int FocusRequestNextCounterTab; // " + int FocusRequestCurrCounterRegular; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch) + int FocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index + int FocusRequestNextCounterRegular; // Stored for next frame + int FocusRequestNextCounterTabStop; // " bool FocusTabPressed; // // Range-Select/Multi-Select @@ -1243,8 +1243,8 @@ struct ImGuiContext NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None; FocusRequestCurrWindow = FocusRequestNextWindow = NULL; - FocusRequestCurrCounterAll = FocusRequestCurrCounterTab = INT_MAX; - FocusRequestNextCounterAll = FocusRequestNextCounterTab = INT_MAX; + FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX; + FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX; FocusTabPressed = false; MultiSelectScopeId = 0; @@ -1347,8 +1347,8 @@ struct IMGUI_API ImGuiWindowTempData ImGuiColumns* CurrentColumns; // Current columns set ImGuiLayoutType LayoutType; ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() - int FocusCounterAll; // Counter for focus/tabbing system. Start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) - int FocusCounterTab; // (same, but only count widgets which you can Tab through) + int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign) + int FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through. // Local parameters stacks // We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings. @@ -1387,7 +1387,7 @@ struct IMGUI_API ImGuiWindowTempData StateStorage = NULL; CurrentColumns = NULL; LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical; - FocusCounterAll = FocusCounterTab = -1; + FocusCounterRegular = FocusCounterTabStop = -1; ItemFlags = ImGuiItemFlags_Default_; ItemWidth = 0.0f; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3c0a5d8e..5453d84c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3458,7 +3458,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state = &g.InputTextState; const bool focus_requested = FocusableItemRegister(window, id); - const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterAll == window->DC.FocusCounterAll); + const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterRegular == window->DC.FocusCounterRegular); const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code; const bool user_clicked = hovered && io.MouseClicked[0]; From e2eb0b4bc48b7644e09fb2ce9d569255a3553e93 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 13 Jan 2020 15:36:24 +0100 Subject: [PATCH 215/384] Internals: Begin tries to setup WindowTemp/DC members in same order as their declaration. Readme: remove Coverity banner (PVS is better) --- docs/README.md | 1 - imgui.cpp | 23 ++++++++++++++--------- imgui_internal.h | 2 +- imgui_widgets.cpp | 10 +++++----- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index ce4e5bc5..97b7812c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,6 @@ dear imgui ===== [![Build Status](https://github.com/ocornut/imgui/workflows/build/badge.svg)](https://github.com/ocornut/imgui/actions?workflow=build) -[![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720) (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out.) diff --git a/imgui.cpp b/imgui.cpp index 8146459e..7fcaea29 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5533,8 +5533,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->WindowPadding = style.WindowPadding; if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f) window->WindowPadding = ImVec2(0.0f, (flags & ImGuiWindowFlags_MenuBar) ? style.WindowPadding.y : 0.0f); - window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); - window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y; // Collapse window by double-clicking on title bar // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing @@ -5842,27 +5840,34 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.CursorMaxPos = window->DC.CursorStartPos; window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f); window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; - window->DC.NavHideHighlightOneFrame = false; - window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); + + window->DC.NavLayerCurrent = ImGuiNavLayer_Main; + window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; + window->DC.NavHideHighlightOneFrame = false; + window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); + window->DC.MenuBarAppending = false; + window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); + window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y; + window->DC.MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); + window->DC.TreeDepth = 0; + window->DC.TreeJumpToParentOnPopMask = 0x00; window->DC.ChildWindows.resize(0); + window->DC.StateStorage = &window->StateStorage; + window->DC.CurrentColumns = NULL; window->DC.LayoutType = ImGuiLayoutType_Vertical; window->DC.ParentLayoutType = parent_window ? parent_window->DC.LayoutType : ImGuiLayoutType_Vertical; window->DC.FocusCounterRegular = window->DC.FocusCounterTabStop = -1; + window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_; window->DC.ItemWidth = window->ItemWidthDefault; window->DC.TextWrapPos = -1.0f; // disabled window->DC.ItemFlagsStack.resize(0); window->DC.ItemWidthStack.resize(0); window->DC.TextWrapPosStack.resize(0); - window->DC.CurrentColumns = NULL; - window->DC.TreeDepth = 0; - window->DC.TreeJumpToParentOnPopMask = 0x00; - window->DC.StateStorage = &window->StateStorage; window->DC.GroupStack.resize(0); - window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); if ((flags & ImGuiWindowFlags_ChildWindow) && (window->DC.ItemFlags != parent_window->DC.ItemFlags)) { diff --git a/imgui_internal.h b/imgui_internal.h index 50565382..d3cfabe7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1340,6 +1340,7 @@ struct IMGUI_API ImGuiWindowTempData // Miscellaneous bool MenuBarAppending; // FIXME: Remove this ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs. + ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items measurement int TreeDepth; // Current tree depth. ImU32 TreeJumpToParentOnPopMask; // Store a copy of !g.NavIdIsAlive for TreeDepth 0..31.. Could be turned into a ImU64 if necessary. ImVector ChildWindows; @@ -1460,7 +1461,6 @@ struct IMGUI_API ImGuiWindow int LastFrameActive; // Last frame number the window was Active. float LastTimeActive; // Last timestamp the window was Active (using float as we don't need high precision there) float ItemWidthDefault; - ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items ImGuiStorage StateStorage; ImVector ColumnsStorage; float FontWindowScale; // User scale multiplier per-window, via SetWindowFontScale() diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5453d84c..a6d1dfd2 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6172,11 +6172,11 @@ bool ImGui::BeginMenu(const char* label, bool enabled) { // Menu inside a menu popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); - float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame + float w = window->DC.MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled); - RenderArrow(window->DrawList, pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right); + RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right); } const bool hovered = enabled && ItemHoverable(window->DC.LastItemRect, id); @@ -6320,17 +6320,17 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo else { ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); - float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame + float w = window->DC.MenuColumns.DeclColumns(label_size.x, shortcut_size.x, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f)); if (shortcut_size.x > 0.0f) { PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); - RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); + RenderText(pos + ImVec2(window->DC.MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); PopStyleColor(); } if (selected) - RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); + RenderCheckMark(pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); } IMGUI_TEST_ENGINE_ITEM_INFO(window->DC.LastItemId, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0)); From 4f7bf7e96a83030000e76fdcd281fa1e2619115d Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Jan 2020 14:58:32 +0100 Subject: [PATCH 216/384] Backends: Win32: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD and IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. (#2716) --- docs/CHANGELOG.txt | 4 ++++ examples/imgui_impl_win32.cpp | 21 +++++++++++++++------ examples/imgui_impl_win32.h | 8 ++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 782f5be2..ae128853 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -82,6 +82,10 @@ Other Changes: - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available on Wayland). (#2800, #2802) [@NeroBurner] +- Backends: Win32: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD to disable all + XInput using code, and IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT to disable linking with XInput, + the later may be problematic if compiling with recent Windows SDK and you want your app to run + on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) - CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index ffe1e8bf..140e1e4b 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -13,11 +13,22 @@ #define WIN32_LEAN_AND_MEAN #endif #include -#include #include +// Using XInput library for gamepad (with recent Windows SDK this may leads to executables which won't run on Windows 7) +#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD +#include +#else +#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT +#endif +#if defined(_MSC_VER) && !defined(IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT) +#pragma comment(lib, "xinput") +//#pragma comment(lib, "Xinput9_1_0") +#endif + // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). // 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent. @@ -40,7 +51,7 @@ // 2016-11-12: Inputs: Only call Win32 ::SetCursor(NULL) when io.MouseDrawCursor is set. // Win32 Data -static HWND g_hWnd = 0; +static HWND g_hWnd = NULL; static INT64 g_Time = 0; static INT64 g_TicksPerSecond = 0; static ImGuiMouseCursor g_LastMouseCursor = ImGuiMouseCursor_COUNT; @@ -149,13 +160,10 @@ static void ImGui_ImplWin32_UpdateMousePos() io.MousePos = ImVec2((float)pos.x, (float)pos.y); } -#ifdef _MSC_VER -#pragma comment(lib, "xinput") -#endif - // Gamepad navigation mapping static void ImGui_ImplWin32_UpdateGamepads() { +#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD ImGuiIO& io = ImGui::GetIO(); memset(io.NavInputs, 0, sizeof(io.NavInputs)); if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) @@ -198,6 +206,7 @@ static void ImGui_ImplWin32_UpdateGamepads() #undef MAP_BUTTON #undef MAP_ANALOG } +#endif // #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD } void ImGui_ImplWin32_NewFrame() diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index 76161860..93dc75a0 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -13,9 +13,13 @@ IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); +// Configuration: Disable gamepad support or linking with xinput.lib +//#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD +//#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT + // Handler for Win32 messages, update mouse/keyboard data. // You may or not need this for your implementation, but it can serve as reference for handling inputs. // Intentionally commented out to avoid dragging dependencies on types. You can COPY this line into your .cpp code instead. -/* +#if 0 IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -*/ +#endif From 2ebe08be40da88eada47a8c2a5ba6f6c93e91acb Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Jan 2020 19:23:50 +0100 Subject: [PATCH 217/384] Focus, Nav: Merged bits from RangeSelect features to enable early manipulation of focus scope for styling purpose. FocusScopeId is tracked by nav scoring/request and stored in result. It's all rather WIP and we should reorganize the SetNavIDXXX functions fiasco at some point (soon?). Didn't separate FocusScope from SelectionScope for now, will re-investigate this later, this is the minimum commit to be able to do some styling. --- imgui.cpp | 51 ++++++++++++++++++++++++++++------------------- imgui_internal.h | 45 ++++++++++++++++++++--------------------- imgui_widgets.cpp | 8 ++++---- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7fcaea29..c7e7a3c6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2752,19 +2752,21 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) window->MemoryDrawListIdxCapacity = window->MemoryDrawListVtxCapacity = 0; } -void ImGui::SetNavID(ImGuiID id, int nav_layer) +// FIXME-NAV: Refactor those functions into a single, more explicit one. +void ImGui::SetNavID(ImGuiID id, int nav_layer, int focus_scope_id) { ImGuiContext& g = *GImGui; IM_ASSERT(g.NavWindow); IM_ASSERT(nav_layer == 0 || nav_layer == 1); g.NavId = id; + g.NavFocusScopeId = focus_scope_id; g.NavWindow->NavLastIds[nav_layer] = id; } -void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel) +void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel) { ImGuiContext& g = *GImGui; - SetNavID(id, nav_layer); + SetNavID(id, nav_layer, focus_scope_id); g.NavWindow->NavRectRel[nav_layer] = rect_rel; g.NavMousePosDirty = true; g.NavDisableHighlight = false; @@ -2809,13 +2811,15 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; IM_ASSERT(id != 0); - // Assume that SetFocusID() is called in the context where its NavLayer is the current layer, which is the case everywhere we call it. + // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and window->DC.NavFocusScopeIdCurrent are valid. + // Note that window may be != g.CurrentWindow (e.g. SetFocusID call in InputTextEx for multi-line text) const ImGuiNavLayer nav_layer = window->DC.NavLayerCurrent; if (g.NavWindow != window) g.NavInitRequest = false; - g.NavId = id; g.NavWindow = window; + g.NavId = id; g.NavLayer = nav_layer; + g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; window->NavLastIds[nav_layer] = id; if (window->DC.LastItemId == id) window->NavRectRel[nav_layer] = ImRect(window->DC.LastItemRect.Min - window->Pos, window->DC.LastItemRect.Max - window->Pos); @@ -5845,6 +5849,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; + window->DC.NavFocusScopeIdCurrent = 0; window->DC.NavHideHighlightOneFrame = false; window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); @@ -6047,6 +6052,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) g.NavMousePosDirty = true; g.NavInitRequest = false; g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId + g.NavFocusScopeId = 0; g.NavIdIsAlive = false; g.NavLayer = ImGuiNavLayer_Main; //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL); @@ -8039,21 +8045,22 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con #endif if (new_best) { - result->ID = id; - result->SelectScopeId = g.MultiSelectScopeId; result->Window = window; + result->ID = id; + result->FocusScopeId = window->DC.NavFocusScopeIdCurrent; result->RectRel = nav_bb_rel; } + // Features like PageUp/PageDown need to maintain a separate score for the visible set of items. const float VISIBLE_RATIO = 0.70f; if ((g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb)) if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO) if (NavScoreItem(&g.NavMoveResultLocalVisibleSet, nav_bb)) { result = &g.NavMoveResultLocalVisibleSet; - result->ID = id; - result->SelectScopeId = g.MultiSelectScopeId; result->Window = window; + result->ID = id; + result->FocusScopeId = window->DC.NavFocusScopeIdCurrent; result->RectRel = nav_bb_rel; } } @@ -8063,6 +8070,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con { g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window. g.NavLayer = window->DC.NavLayerCurrent; + g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; g.NavIdIsAlive = true; g.NavIdTabCounter = window->DC.FocusCounterTabStop; window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel; // Store item bounding box (relative to window position) @@ -8153,10 +8161,11 @@ static void NavRestoreLayer(ImGuiNavLayer layer) g.NavLayer = layer; if (layer == 0) g.NavWindow = ImGui::NavRestoreLastChildNavWindow(g.NavWindow); - if (layer == 0 && g.NavWindow->NavLastIds[0] != 0) - ImGui::SetNavIDWithRectRel(g.NavWindow->NavLastIds[0], layer, g.NavWindow->NavRectRel[0]); + ImGuiWindow* window = g.NavWindow; + if (layer == 0 && window->NavLastIds[0] != 0) + ImGui::SetNavIDWithRectRel(window->NavLastIds[0], layer, 0, window->NavRectRel[0]); else - ImGui::NavInitWindow(g.NavWindow, true); + ImGui::NavInitWindow(window, true); } static inline void ImGui::NavUpdateAnyRequestFlag() @@ -8179,7 +8188,7 @@ void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) //IMGUI_DEBUG_LOG("[Nav] NavInitWindow() init_for_nav=%d, window=\"%s\", layer=%d\n", init_for_nav, window->Name, g.NavLayer); if (init_for_nav) { - SetNavID(0, g.NavLayer); + SetNavID(0, g.NavLayer, 0); g.NavInitRequest = true; g.NavInitRequestFromMove = false; g.NavInitResultId = 0; @@ -8189,6 +8198,7 @@ void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) else { g.NavId = window->NavLastIds[0]; + g.NavFocusScopeId = 0; } } @@ -8295,9 +8305,9 @@ static void ImGui::NavUpdate() // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called) //IMGUI_DEBUG_LOG("[Nav] Apply NavInitRequest result: 0x%08X Layer %d in \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name); if (g.NavInitRequestFromMove) - SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel); + SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, 0, g.NavInitResultRectRel); else - SetNavID(g.NavInitResultId, g.NavLayer); + SetNavID(g.NavInitResultId, g.NavLayer, 0); g.NavWindow->NavRectRel[g.NavLayer] = g.NavInitResultRectRel; } g.NavInitRequest = false; @@ -8364,7 +8374,7 @@ static void ImGui::NavUpdate() ImGuiWindow* parent_window = g.NavWindow->ParentWindow; IM_ASSERT(child_window->ChildId != 0); FocusWindow(parent_window); - SetNavID(child_window->ChildId, 0); + SetNavID(child_window->ChildId, 0, 0); // Reassigning with same value, we're being explicit here. g.NavIdIsAlive = false; // -V1048 if (g.NavDisableMouseHover) @@ -8386,7 +8396,7 @@ static void ImGui::NavUpdate() // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow))) g.NavWindow->NavLastIds[0] = 0; - g.NavId = 0; + g.NavId = g.NavFocusScopeId = 0; } } @@ -8506,7 +8516,7 @@ static void ImGui::NavUpdate() float pad = window->CalcFontSize() * 0.5f; window_rect_rel.Expand(ImVec2(-ImMin(window_rect_rel.GetWidth(), pad), -ImMin(window_rect_rel.GetHeight(), pad))); // Terrible approximation for the intent of starting navigation from first fully visible item window->NavRectRel[g.NavLayer].ClipWith(window_rect_rel); - g.NavId = 0; + g.NavId = g.NavFocusScopeId = 0; } g.NavMoveFromClampedRefRect = false; } @@ -8586,9 +8596,10 @@ static void ImGui::NavUpdateMoveResult() { // Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId) g.NavJustMovedToId = result->ID; - g.NavJustMovedToMultiSelectScopeId = result->SelectScopeId; + g.NavJustMovedToFocusScopeId = result->FocusScopeId; + } - SetNavIDWithRectRel(result->ID, g.NavLayer, result->RectRel); + SetNavIDWithRectRel(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel); g.NavMoveFromClampedRefRect = false; } diff --git a/imgui_internal.h b/imgui_internal.h index d3cfabe7..894519b2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -877,16 +877,16 @@ struct ImDrawDataBuilder struct ImGuiNavMoveResult { - ImGuiID ID; // Best candidate - ImGuiID SelectScopeId;// Best candidate window current selectable group ID - ImGuiWindow* Window; // Best candidate window - float DistBox; // Best candidate box distance to current NavId - float DistCenter; // Best candidate center distance to current NavId - float DistAxial; - ImRect RectRel; // Best candidate bounding box in window relative space + ImGuiWindow* Window; // Best candidate window + ImGuiID ID; // Best candidate ID + ImGuiID FocusScopeId; // Best candidate focus scope ID + float DistBox; // Best candidate box distance to current NavId + float DistCenter; // Best candidate center distance to current NavId + float DistAxial; + ImRect RectRel; // Best candidate bounding box in window relative space ImGuiNavMoveResult() { Clear(); } - void Clear() { ID = SelectScopeId = 0; Window = NULL; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); } + void Clear() { Window = NULL; ID = FocusScopeId = 0; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); } }; enum ImGuiNextWindowDataFlags_ @@ -920,7 +920,7 @@ struct ImGuiNextWindowData ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } - inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } // Also cleared by ItemAdd() + inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } }; enum ImGuiNextItemDataFlags_ @@ -933,12 +933,13 @@ enum ImGuiNextItemDataFlags_ struct ImGuiNextItemData { ImGuiNextItemDataFlags Flags; - float Width; // Set by SetNextItemWidth(). - bool OpenVal; // Set by SetNextItemOpen() function. + float Width; // Set by SetNextItemWidth() + ImGuiID FocusScopeId; // Set by SetNextItemMultiSelectData() (!= 0 signify value has been set, so it's an alternate version of HasSelectionData, we don't use Flags for this because they are cleared too early. This is mostly used for debugging) ImGuiCond OpenCond; + bool OpenVal; // Set by SetNextItemOpen() ImGuiNextItemData() { memset(this, 0, sizeof(*this)); } - inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; } + inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; } // Also cleared manually by ItemAdd()! }; //----------------------------------------------------------------------------- @@ -1038,13 +1039,15 @@ struct ImGuiContext // Gamepad/keyboard Navigation ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' ImGuiID NavId; // Focused item for navigation + ImGuiID NavFocusScopeId; ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0 ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0 ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0 ImGuiID NavJustTabbedId; // Just tabbed to this id. ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). - ImGuiID NavJustMovedToMultiSelectScopeId; // Just navigated to this select scope id (result of a successfully MoveRequest). + ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). + ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. @@ -1085,10 +1088,6 @@ struct ImGuiContext int FocusRequestNextCounterTabStop; // " bool FocusTabPressed; // - // Range-Select/Multi-Select - // [This is unused in this branch, but left here to facilitate merging/syncing multiple branches] - ImGuiID MultiSelectScopeId; - // Render ImDrawData DrawData; // Main ImDrawData instance to pass render information to the user ImDrawDataBuilder DrawDataBuilder; @@ -1218,8 +1217,8 @@ struct ImGuiContext LastActiveIdTimer = 0.0f; NavWindow = NULL; - NavId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; - NavJustTabbedId = NavJustMovedToId = NavJustMovedToMultiSelectScopeId = NavNextActivateId = 0; + NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; + NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; NavInputSource = ImGuiInputSource_None; NavScoringRectScreen = ImRect(); NavScoringCount = 0; @@ -1247,8 +1246,6 @@ struct ImGuiContext FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX; FocusTabPressed = false; - MultiSelectScopeId = 0; - DimBgRatio = 0.0f; BackgroundDrawList._OwnerName = "##Background"; // Give it a name for debugging ForegroundDrawList._OwnerName = "##Foreground"; // Give it a name for debugging @@ -1334,6 +1331,7 @@ struct IMGUI_API ImGuiWindowTempData int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping. int NavLayerActiveMask; // Which layer have been written to (result from previous frame) int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame) + ImGuiID NavFocusScopeIdCurrent; // Current focus scope ID while appending bool NavHideHighlightOneFrame; bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) @@ -1378,6 +1376,7 @@ struct IMGUI_API ImGuiWindowTempData NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; NavLayerCurrent = ImGuiNavLayer_Main; NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); + NavFocusScopeIdCurrent = 0; NavHideHighlightOneFrame = false; NavHasScroll = false; @@ -1701,8 +1700,8 @@ namespace ImGui IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. - IMGUI_API void SetNavID(ImGuiID id, int nav_layer); - IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel); + IMGUI_API void SetNavID(ImGuiID id, int nav_layer, int focus_scope_id); + IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel); // Inputs // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a6d1dfd2..95483e2f 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5312,9 +5312,9 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l bool hovered, held; bool pressed = ButtonBehavior(interact_bb, id, &hovered, &held, button_flags); + bool toggled = false; if (!is_leaf) { - bool toggled = false; if (pressed) { if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) @@ -5444,7 +5444,7 @@ void ImGui::TreePop() if (g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet()) if (g.NavIdIsAlive && (window->DC.TreeJumpToParentOnPopMask & tree_depth_mask)) { - SetNavID(window->IDStack.back(), g.NavLayer); + SetNavID(window->IDStack.back(), g.NavLayer, 0); NavMoveRequestCancel(); } window->DC.TreeJumpToParentOnPopMask &= tree_depth_mask - 1; @@ -5600,7 +5600,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) { g.NavDisableHighlight = true; - SetNavID(id, window->DC.NavLayerCurrent); + SetNavID(id, window->DC.NavLayerCurrent, window->DC.NavFocusScopeIdCurrent); } } if (pressed) @@ -6077,7 +6077,7 @@ void ImGui::EndMenuBar() const ImGuiNavLayer layer = ImGuiNavLayer_Menu; IM_ASSERT(window->DC.NavLayerActiveMaskNext & (1 << layer)); // Sanity check FocusWindow(window); - SetNavIDWithRectRel(window->NavLastIds[layer], layer, window->NavRectRel[layer]); + SetNavIDWithRectRel(window->NavLastIds[layer], layer, 0, window->NavRectRel[layer]); g.NavLayer = layer; g.NavDisableHighlight = true; // Hide highlight for the current frame so we don't see the intermediary selection. g.NavMoveRequestForward = ImGuiNavForward_ForwardQueued; From f6d6880a61c3a3139fabcb63541b0339f8fa432b Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Jan 2020 20:34:26 +0100 Subject: [PATCH 218/384] Internals: Nav: PushFocusScope, PopFocusScope, GetFocusScopeID() helpers --- imgui.cpp | 16 ++++++++++++++++ imgui_internal.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index c7e7a3c6..50cdf4ee 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6909,6 +6909,22 @@ void ImGui::ActivateItem(ImGuiID id) g.NavNextActivateId = id; } +void ImGui::PushFocusScope(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent); + window->DC.NavFocusScopeIdCurrent = id; +} + +void ImGui::PopFocusScope() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DC.NavFocusScopeIdCurrent = window->IDStack.back(); + window->IDStack.pop_back(); +} + void ImGui::SetKeyboardFocusHere(int offset) { IM_ASSERT(offset >= -1); // -1 is allowed but not below diff --git a/imgui_internal.h b/imgui_internal.h index 894519b2..a19c1811 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1703,6 +1703,11 @@ namespace ImGui IMGUI_API void SetNavID(ImGuiID id, int nav_layer, int focus_scope_id); IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel); + // Focus scope (WIP) + IMGUI_API void PushFocusScope(ImGuiID id); // Note: this is storing in same stack as IDStack, so Push/Pop mismatch will be reported there. + IMGUI_API void PopFocusScope(); + inline ImGuiID GetFocusScopeID() { ImGuiContext& g = *GImGui; return g.NavFocusScopeId; } + // Inputs // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } From 9ad4c5da7e2806f47fb08cbfa050b1ed3e768fbe Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 15 Jan 2020 17:23:05 +0100 Subject: [PATCH 219/384] Fix zealous warnings + Internals: Renamed members from XxxxID to XxxxxId to be more consistent with rest of the codebase (still some inconsistency left that are harder to fix) --- imgui.cpp | 14 +++++++------- imgui.h | 2 +- imgui_demo.cpp | 5 +++-- imgui_internal.h | 10 +++++----- imgui_widgets.cpp | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 50cdf4ee..a9e2dd7a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2753,7 +2753,7 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) } // FIXME-NAV: Refactor those functions into a single, more explicit one. -void ImGui::SetNavID(ImGuiID id, int nav_layer, int focus_scope_id) +void ImGui::SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id) { ImGuiContext& g = *GImGui; IM_ASSERT(g.NavWindow); @@ -2763,7 +2763,7 @@ void ImGui::SetNavID(ImGuiID id, int nav_layer, int focus_scope_id) g.NavWindow->NavLastIds[nav_layer] = id; } -void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel) +void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) { ImGuiContext& g = *GImGui; SetNavID(id, nav_layer, focus_scope_id); @@ -2958,10 +2958,10 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg) // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd() #ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX - if (id == g.DebugItemPickerBreakID) + if (id == g.DebugItemPickerBreakId) { IM_DEBUG_BREAK(); - g.DebugItemPickerBreakID = 0; + g.DebugItemPickerBreakId = 0; } #endif } @@ -3060,7 +3060,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) // #define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX in imconfig.h if you want this check to also be performed in ItemAdd(). if (g.DebugItemPickerActive && g.HoveredIdPreviousFrame == id) GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 255, 0, 255)); - if (g.DebugItemPickerBreakID == id) + if (g.DebugItemPickerBreakId == id) IM_DEBUG_BREAK(); return true; @@ -3840,7 +3840,7 @@ void ImGui::NewFrame() void ImGui::UpdateDebugToolItemPicker() { ImGuiContext& g = *GImGui; - g.DebugItemPickerBreakID = 0; + g.DebugItemPickerBreakId = 0; if (g.DebugItemPickerActive) { const ImGuiID hovered_id = g.HoveredIdPreviousFrame; @@ -3849,7 +3849,7 @@ void ImGui::UpdateDebugToolItemPicker() g.DebugItemPickerActive = false; if (ImGui::IsMouseClicked(0) && hovered_id) { - g.DebugItemPickerBreakID = hovered_id; + g.DebugItemPickerBreakId = hovered_id; g.DebugItemPickerActive = false; } ImGui::SetNextWindowBgAlpha(0.60f); diff --git a/imgui.h b/imgui.h index 57d0511c..c2cde0d2 100644 --- a/imgui.h +++ b/imgui.h @@ -2228,10 +2228,10 @@ struct ImFont short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont. ImWchar FallbackChar; // 2 // in // = '?' // Replacement character if a glyph isn't found. Only set via SetFallbackChar() ImWchar EllipsisChar; // 2 // out // = -1 // Character used for ellipsis rendering. + bool DirtyLookupTables; // 1 // out // float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) - bool DirtyLookupTables; // 1 // out // // Methods IMGUI_API ImFont(); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5ccebef2..8e9137e7 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3431,8 +3431,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface); ImGui::Text("Texture Area: about %d px ~%dx%d px", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt); for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) - if (const ImFontConfig* cfg = &font->ConfigData[config_i]) - ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH); + if (font->ConfigData) + if (const ImFontConfig* cfg = &font->ConfigData[config_i]) + ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH); if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) { // Display all glyphs of the fonts in separate pages of 256 characters diff --git a/imgui_internal.h b/imgui_internal.h index a19c1811..ea5accfc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -430,7 +430,7 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_Disabled = 1 << 10, // disable interactions ImGuiButtonFlags_AlignTextBaseLine = 1 << 11, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine ImGuiButtonFlags_NoKeyModifiers = 1 << 12, // disable mouse interaction if a key modifier is held - ImGuiButtonFlags_NoHoldingActiveID = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) + ImGuiButtonFlags_NoHoldingActiveId = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_NoNavFocus = 1 << 14, // don't override navigation focus when activated ImGuiButtonFlags_NoHoveredOnNav = 1 << 15, // don't report as hovered when navigated on ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold @@ -1160,7 +1160,7 @@ struct ImGuiContext // Debug Tools bool DebugItemPickerActive; - ImGuiID DebugItemPickerBreakID; // Will call IM_DEBUG_BREAK() when encountering this id + ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this id // Misc float FramerateSecPerFrame[120]; // Calculate estimate of framerate for user over the last 2 seconds. @@ -1289,7 +1289,7 @@ struct ImGuiContext LogDepthToExpand = LogDepthToExpandDefault = 2; DebugItemPickerActive = false; - DebugItemPickerBreakID = 0; + DebugItemPickerBreakId = 0; memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); FramerateSecPerFrameIdx = 0; @@ -1700,8 +1700,8 @@ namespace ImGui IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. - IMGUI_API void SetNavID(ImGuiID id, int nav_layer, int focus_scope_id); - IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel); + IMGUI_API void SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id); + IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel); // Focus scope (WIP) IMGUI_API void PushFocusScope(ImGuiID id); // Note: this is storing in same stack as IDStack, so Push/Pop mismatch will be reported there. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 95483e2f..cf437c7e 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -517,7 +517,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) { pressed = true; - if (flags & ImGuiButtonFlags_NoHoldingActiveID) + if (flags & ImGuiButtonFlags_NoHoldingActiveId) ClearActiveID(); else SetActiveID(id, window); // Hold on ID @@ -5580,7 +5580,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries ImGuiButtonFlags button_flags = 0; - if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveID; } + if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; } if (flags & ImGuiSelectableFlags_PressedOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } if (flags & ImGuiSelectableFlags_PressedOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; } From aa34681652c557ce7cbeb6b9e9067d7af3062454 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 17 Jan 2020 11:36:56 +0100 Subject: [PATCH 220/384] Backends: GLFW: inhibit error callback when creating cursors because X11 setups may be missing them + comment (#2980) --- examples/imgui_impl_glfw.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 142b6409..2182efb8 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -15,6 +15,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors. // 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor). // 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. @@ -175,6 +176,11 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw io.ImeWindowHandle = (void*)glfwGetWin32Window(g_Window); #endif + // Create mouse cursors + // (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist, + // GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting. + // Missing cursors will return NULL and our _UpdateMouseCursor() function will use the Arrow cursor instead.) + GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL); g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR); @@ -191,6 +197,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); #endif + glfwSetErrorCallback(prev_error_callback); // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. g_PrevUserCallbackMousebutton = NULL; From 6c00d1916e854d6605dd4474a188ad3393117504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Sun, 29 Dec 2019 15:39:49 +0100 Subject: [PATCH 221/384] Disable format checks when using stb_sprintf.h STB sprintf allows extra formats like %b or %$d. If ImGui is configured to use STB sprintf, it generates warnings with GCC and clang when using such formats because it keeps applying default printf-style warnings. This commit disables printf-style warnings when using STB sprintf. Since the printf-style warnings are defined in imgui.h based on the compiler, IMGUI_USE_STB_SPRINTF can't just be defined in the cpp file anymore and it's been moved as a proper config in imconfig.h. --- docs/CHANGELOG.txt | 2 ++ imconfig.h | 4 ++++ imgui.cpp | 1 - imgui.h | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ae128853..11e4fdf0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,8 @@ Other Changes: we will rework the circle rendering functions to use textures and automatic segment count selection, those new api can fill a gap. [@ShironekoBen] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- Misc: Disable format checks when using stb_printf, to allow using extra formats. + Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari] - Misc: Added misc/single_file/imgui_single_file.h, We use this to validate compiling all *.cpp files in a same compilation unit. Actual users of that technique (also called "Unity builds") can generally provide this themselves, so we don't really recommend you use this. [@rokups] diff --git a/imconfig.h b/imconfig.h index c4f7891e..6724e40f 100644 --- a/imconfig.h +++ b/imconfig.h @@ -53,6 +53,10 @@ //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +//---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library. +// Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf. +// #define IMGUI_USE_STB_SPRINTF + //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. // This will be inlined as part of ImVec2 and ImVec4 class declarations. /* diff --git a/imgui.cpp b/imgui.cpp index a9e2dd7a..09a315cc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1354,7 +1354,6 @@ const char* ImStrSkipBlank(const char* str) // You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are // designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.) -//#define IMGUI_USE_STB_SPRINTF #ifdef IMGUI_USE_STB_SPRINTF #define STB_SPRINTF_IMPLEMENTATION #include "stb_sprintf.h" diff --git a/imgui.h b/imgui.h index c2cde0d2..1245ab1b 100644 --- a/imgui.h +++ b/imgui.h @@ -76,7 +76,7 @@ Index of this file: #include #define IM_ASSERT(_EXPR) assert(_EXPR) // You can override the default assert handler by editing imconfig.h #endif -#if defined(__clang__) || defined(__GNUC__) +#if !defined(IMGUI_USE_STB_SPRINTF) && (defined(__clang__) || defined(__GNUC__)) #define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) // To apply printf-style warnings to our functions. #define IM_FMTLIST(FMT) __attribute__((format(printf, FMT, 0))) #else From 2478dbfdb7a3b5d10738f16128e5a7afd5d429e1 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 17 Jan 2020 14:18:16 +0100 Subject: [PATCH 222/384] Disable warning C5054 introduced in VS 2019 16.2 (#2983) --- imgui.cpp | 3 +++ imgui_widgets.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 09a315cc..6ef20da8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -812,6 +812,9 @@ CODE #ifdef _MSC_VER #pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later +#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types +#endif #endif // Clang/GCC warnings with -Weverything diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index cf437c7e..124594db 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -47,8 +47,11 @@ Index of this file: // Visual Studio warnings #ifdef _MSC_VER -#pragma warning (disable: 4127) // condition expression is constant -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#pragma warning (disable: 4127) // condition expression is constant +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later +#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types +#endif #endif // Clang/GCC warnings with -Weverything From e499497ec547616e70c0cfdd59f3a1c681d503e2 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 17 Jan 2020 14:56:56 +0100 Subject: [PATCH 223/384] Backends: Win32: Added support for io.KeySuper (Windows key) for consistency with other backends. (#2976) Even if realistically it is difficult to make good use of under Windows. + Style editor: Use a more explicit form of RadioButton() to avoid being depending on underlying flags type. (#2983) --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_win32.cpp | 3 ++- imgui_demo.cpp | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 11e4fdf0..a3e03316 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -88,6 +88,8 @@ Other Changes: XInput using code, and IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT to disable linking with XInput, the later may be problematic if compiling with recent Windows SDK and you want your app to run on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) +- Backends: Win32: Added support for io.KeySuper (Windows key) for consistency with other backends, + even if realistically it is difficult to make good use of under Windows. - CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 140e1e4b..189f6d3b 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -28,6 +28,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-01-17: Inputs: Added support for io.KeySuper (Windows key) for consistency with other backends, even if realistically it is difficult to make good use of under Windows. // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). @@ -229,7 +230,7 @@ void ImGui_ImplWin32_NewFrame() io.KeyCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; io.KeyShift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; io.KeyAlt = (::GetKeyState(VK_MENU) & 0x8000) != 0; - io.KeySuper = false; + io.KeySuper = ((::GetKeyState(VK_LWIN) | ::GetKeyState(VK_RWIN)) & 0x8000) != 0; // io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the WndProc handler below. // Update OS mouse position diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8e9137e7..ec8c142f 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3374,9 +3374,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) filter.Draw("Filter colors", ImGui::GetFontSize() * 16); static ImGuiColorEditFlags alpha_flags = 0; - ImGui::RadioButton("Opaque", &alpha_flags, 0); ImGui::SameLine(); - ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine(); - ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf); ImGui::SameLine(); + if (ImGui::RadioButton("Opaque", alpha_flags == 0)) { alpha_flags = 0; } ImGui::SameLine(); + if (ImGui::RadioButton("Alpha", alpha_flags == ImGuiColorEditFlags_AlphaPreview)) { alpha_flags = ImGuiColorEditFlags_AlphaPreview; } ImGui::SameLine(); + if (ImGui::RadioButton("Both", alpha_flags == ImGuiColorEditFlags_AlphaPreviewHalf)) { alpha_flags = ImGuiColorEditFlags_AlphaPreviewHalf; } ImGui::SameLine(); HelpMarker("In the color list:\nLeft-click on colored square to open color picker,\nRight-click to open edit options menu."); ImGui::BeginChild("##colors", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened); From 8bcac7d95caa7e3b960b7bf7c3bcda4ecfe4541f Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 17 Jan 2020 15:18:33 +0100 Subject: [PATCH 224/384] Backends: GLFW, SDL: report Windows key (io.KeySuper) as always released. Neither GLFW nor SDL can correctly report the key release in every cases (e.g. when using Win+V) causing problems with some widgets. The next release of GLFW (3.4+) will have a fix for it. However since it is both difficult and discouraged to make use of this key for Windows application anyway, we just hide it. (#2976) --- docs/CHANGELOG.txt | 6 ++++-- examples/imgui_impl_glfw.cpp | 4 ++++ examples/imgui_impl_sdl.cpp | 4 ++++ examples/imgui_impl_win32.cpp | 3 +-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a3e03316..11afd5e4 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -84,12 +84,14 @@ Other Changes: - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available on Wayland). (#2800, #2802) [@NeroBurner] +- Backends: GLFW, SDL: report Windows key (io.KeySuper) as always released. Neither GLFW nor SDL can + correctly report the key release in every cases (e.g. when using Win+V) causing problems with some + widgets. The next release of GLFW (3.4+) will have a fix for it. However since it is both difficult + and discouraged to make use of this key for Windows application anyway, we just hide it. (#2976) - Backends: Win32: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD to disable all XInput using code, and IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT to disable linking with XInput, the later may be problematic if compiling with recent Windows SDK and you want your app to run on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) -- Backends: Win32: Added support for io.KeySuper (Windows key) for consistency with other backends, - even if realistically it is difficult to make good use of under Windows. - CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 2182efb8..c496232c 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -122,7 +122,11 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int a io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; +#ifdef _WIN32 + io.KeySuper = false; +#else io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; +#endif } void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 8a295aaa..32722bf6 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -115,7 +115,11 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0); io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0); +#ifdef _WIN32 + io.KeySuper = false; +#else io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0); +#endif return true; } } diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 189f6d3b..140e1e4b 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -28,7 +28,6 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2020-01-17: Inputs: Added support for io.KeySuper (Windows key) for consistency with other backends, even if realistically it is difficult to make good use of under Windows. // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). @@ -230,7 +229,7 @@ void ImGui_ImplWin32_NewFrame() io.KeyCtrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; io.KeyShift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; io.KeyAlt = (::GetKeyState(VK_MENU) & 0x8000) != 0; - io.KeySuper = ((::GetKeyState(VK_LWIN) | ::GetKeyState(VK_RWIN)) & 0x8000) != 0; + io.KeySuper = false; // io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the WndProc handler below. // Update OS mouse position From 15c6abe4bea4da14900fe53fa13ea2eb9133df32 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 20 Jan 2020 11:48:17 +0100 Subject: [PATCH 225/384] Internals: Standard math functions default redirection uses a define instead of an extraneous inline function call --- imgui_internal.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index ea5accfc..80453c95 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -297,22 +297,21 @@ IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* // Helpers: Maths // - Wrapper for standard libs functions. (Note that imgui_demo.cpp does _not_ use them to keep the code easy to copy) #ifndef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS -static inline float ImFabs(float x) { return fabsf(x); } -static inline float ImSqrt(float x) { return sqrtf(x); } -static inline float ImPow(float x, float y) { return powf(x, y); } -static inline double ImPow(double x, double y) { return pow(x, y); } -static inline float ImFmod(float x, float y) { return fmodf(x, y); } -static inline double ImFmod(double x, double y) { return fmod(x, y); } -static inline float ImCos(float x) { return cosf(x); } -static inline float ImSin(float x) { return sinf(x); } -static inline float ImAcos(float x) { return acosf(x); } -static inline float ImAtan2(float y, float x) { return atan2f(y, x); } -static inline double ImAtof(const char* s) { return atof(s); } -static inline float ImFloorStd(float x) { return floorf(x); } // we already uses our own ImFloor() { return (float)(int)v } internally so the standard one wrapper is named differently (it's used by stb_truetype) -static inline float ImCeil(float x) { return ceilf(x); } +#define ImFabs(X) fabsf(X) +#define ImSqrt(X) sqrtf(X) +#define ImFmod(X, Y) fmodf((X), (Y)) +#define ImCos(X) cosf(X) +#define ImSin(X) sinf(X) +#define ImAcos(X) acosf(X) +#define ImAtan2(Y, X) atan2f((Y), (X)) +#define ImAtof(STR) atof(STR) +#define ImFloorStd(X) floorf(X) // We already uses our own ImFloor() { return (float)(int)v } internally so the standard one wrapper is named differently (it's used by e.g. stb_truetype) +#define ImCeil(X) ceilf(X) +static inline float ImPow(float x, float y) { return powf(x, y); } // DragBehaviorT/SliderBehaviorT uses ImPow with either float/double and need the precision +static inline double ImPow(double x, double y) { return pow(x, y); } #endif -// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double -// (Exceptionally using templates here but we could also redefine them for variety of types) +// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support variety of types: signed/unsigned int/long long float/double +// (Exceptionally using templates here but we could also redefine them for those types) template static inline T ImMin(T lhs, T rhs) { return lhs < rhs ? lhs : rhs; } template static inline T ImMax(T lhs, T rhs) { return lhs >= rhs ? lhs : rhs; } template static inline T ImClamp(T v, T mn, T mx) { return (v < mn) ? mn : (v > mx) ? mx : v; } From 0a3df4b2cebfdd3ead550e51718d90565feaf64c Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 20 Jan 2020 14:28:01 +0100 Subject: [PATCH 226/384] Update FAQ.md --- docs/FAQ.md | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 3216a524..571c94c7 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -54,6 +54,8 @@ or view this file with any Markdown viewer. - Your programming IDE is your friend, find the type or function declaration to find comments associated to it. - The `ImGui::ShowMetricsWindow()` function exposes lots of internal information and tools. Although it is primary designed as a debugging tool, having access to that information tends to help understands concepts. +##### [Return to Index](#index) + --- ### Q. What is this library called? @@ -62,6 +64,8 @@ or view this file with any Markdown viewer. (The library misleadingly started its life in 2014 as "ImGui" due to the fact that I didn't give it a proper name when when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations e.g. Unity uses it own implementation of the IMGUI paradigm. To reduce the ambiguity without affecting existing code bases, I have decided in December 2015 a fully qualified name "Dear ImGui" for this library. +##### [Return to Index](#index) + --- ### Q: Which version should I get? @@ -73,10 +77,9 @@ You may use the [docking](https://github.com/ocornut/imgui/tree/docking) branch Many projects are using this branch and it is kept in sync with master regularly. ---- - ##### [Return to Index](#index) +---- # Q&A: Integration @@ -97,6 +100,8 @@ e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` **Note:** Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have `io.WantCaptureKeyboard == false`. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) +##### [Return to Index](#index) + --- ### Q: How can I enable keyboard or gamepad controls? @@ -106,6 +111,8 @@ e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` - See [Control Sheets for Gamepads](http://www.dearimgui.org/controls_sheets) (reference PNG/PSD for for PS4, XB1, Switch gamepads). - See `USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS` section of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) for more details. +##### [Return to Index](#index) + --- ### Q: How can I use this on a machine without mouse, keyboard or screen? (input share, remote display) @@ -117,9 +124,9 @@ to your host computer, based on the Synergy 1.x protocol. Make sure you download Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-like protocols. - Game console users: consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. - You may also use a third party solution such as [Remote ImGui](https://github.com/JordiRos/remoteimgui) or [imgui-ws](https://github.com/ggerganov/imgui-ws) which sends the vertices to render over the local network, allowing you to use Dear ImGui even on a screen-less machine. See [Wiki](https://github.com/ocornut/imgui/wiki) index for most details. -- For touch inputs, you can increase the hit box of widgets (via the `style.TouchPadding` setting) to accommodate -for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing -for screen real-estate and precision. +- For touch inputs, you can increase the hit box of widgets (via the `style.TouchPadding` setting) to accommodate for the lack of precision of touch inputs, but it is recommended you use a mouse or gamepad to allow optimizing for screen real-estate and precision. + +##### [Return to Index](#index) --- @@ -127,6 +134,8 @@ for screen real-estate and precision. In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). Also make sure your orthographic projection matrix and io.DisplaySize matches your actual framebuffer dimension. +##### [Return to Index](#index) + --- ### Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around.. @@ -138,6 +147,7 @@ and **NOT** as ##### [Return to Index](#index) +--- # Q&A: Usage @@ -257,6 +267,8 @@ will preserve your node open/closed state when the targeted object change. e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. See what makes more sense in your situation! +##### [Return to Index](#index) + --- ### Q: How can I display an image? What is ImTextureID, how does it work? @@ -337,6 +349,8 @@ my_dx11_srv = (ID3D11ShaderResourceView*)my_void_ptr; // cast a void* into a I ``` Finally, you may call `ImGui::ShowMetricsWindow()` to explore/visualize/understand how the ImDrawList are generated. +##### [Return to Index](#index) + --- ### Q: How can I use my own math types instead of ImVec2/ImVec4? @@ -344,6 +358,8 @@ Finally, you may call `ImGui::ShowMetricsWindow()` to explore/visualize/understa You can edit [imconfig.h](https://github.com/ocornut/imgui/blob/master/imconfig.h) and setup the `IM_VEC2_CLASS_EXTRA`/`IM_VEC4_CLASS_EXTRA` macros to add implicit type conversions. This way you'll be able to use your own types everywhere, e.g. passing `MyVector2` or `glm::vec2` to ImGui functions instead of `ImVec2`. +##### [Return to Index](#index) + --- ### Q: How can I interact with standard C++ types (such as std::string and std::vector)? @@ -366,6 +382,8 @@ One possible implementation of a helper to facilitate printf-style building of s This is a small helper where you can instance strings with configurable local buffers length. Many game engines will provide similar or better string helpers. +##### [Return to Index](#index) + --- ### Q: How can I display custom shapes? (using low-level ImDrawList API) @@ -402,6 +420,7 @@ ImGui::End(); ##### [Return to Index](#index) +--- # Q&A: Fonts, Text @@ -429,6 +448,8 @@ io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size; // CORRECT io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT ``` +##### [Return to Index](#index) + --- ### Q: How can I easily use icons in my application? @@ -439,6 +460,8 @@ You may want to see `ImFontConfig::GlyphMinAdvanceX` to make your icon look mono With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas, and copying your own graphics data into it. See docs/FONTS.txt about using the AddCustomRectFontGlyph API. +##### [Return to Index](#index) + --- ### Q: How can I load multiple fonts? @@ -471,6 +494,8 @@ io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs ``` +##### [Return to Index](#index) + --- ### Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic? @@ -504,6 +529,7 @@ the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft ##### [Return to Index](#index) +--- # Q&A: Concerns @@ -515,6 +541,10 @@ You may take a look at: - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) - [Gallery](https://github.com/ocornut/imgui/issues/2847) +##### [Return to Index](#index) + +--- + ### Q: Can you create elaborate/serious tools with Dear ImGui? Yes. People have written game editors, data browsers, debuggers, profilers and all sort of non-trivial tools with the library. In my experience the simplicity of the API is very empowering. Your UI runs close to your live data. Make the tools always-on and everybody in the team will be inclined to create new tools (as opposed to more "offline" UI toolkits where only a fraction of your team effectively creates tools). The list of sponsors below is also an indicator that serious game teams have been using the library. @@ -523,6 +553,10 @@ Dear ImGui is very programmer centric and the immediate-mode GUI paradigm might Dear ImGui is built to be efficient and scalable toward the needs for AAA-quality applications running all day. The IMGUI paradigm offers different opportunities for optimization that the more typical RMGUI paradigm. +##### [Return to Index](#index) + +--- + ### Q: Can you reskin the look of Dear ImGui? Somehow. You can alter the look of the interface to some degree: changing colors, sizes, padding, rounding, fonts. However, as Dear ImGui is designed and optimized to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. Dear ImGui is NOT designed to create user interface for games, although with ingenious use of the low-level API you can do it. @@ -530,6 +564,10 @@ Somehow. You can alter the look of the interface to some degree: changing colors A reasonably skinned application may look like (screenshot from [#2529](https://github.com/ocornut/imgui/issues/2529#issuecomment-524281119)) ![minipars](https://user-images.githubusercontent.com/314805/63589441-d9794f00-c5b1-11e9-8d96-cfc1b93702f7.png) +##### [Return to Index](#index) + +--- + ### Q: Why using C++ (as opposed to C)? Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience. @@ -538,6 +576,7 @@ There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/ci ##### [Return to Index](#index) +--- # Q&A: Community From 3fe6ae97323ddfa9cce73831b930af63c34d287b Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 20 Jan 2020 18:09:59 +0100 Subject: [PATCH 227/384] Internals: Move some Nav functions and members around (no functional change) + Misc comments --- docs/README.md | 6 +- examples/README.txt | 2 +- examples/example_glut_opengl2/main.cpp | 2 +- examples/imgui_impl_glut.cpp | 2 +- examples/imgui_impl_glut.h | 2 +- imgui.cpp | 116 ++++++++++++------------- imgui.h | 2 +- imgui_internal.h | 22 ++--- 8 files changed, 78 insertions(+), 76 deletions(-) diff --git a/docs/README.md b/docs/README.md index 97b7812c..2bad5cae 100644 --- a/docs/README.md +++ b/docs/README.md @@ -114,19 +114,19 @@ Officially maintained bindings (in repository): Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): - Languages: C, C#/.Net, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- Frameworks: Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/GameMakerStudio2, Irrlicht, Ogre, OpenFrameworks, OpenSceneGraph/OSG, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +- Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, Irrlicht, Ogre, OpenFrameworks, OSG/OpenSceneGraph, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. ### Upcoming Changes -Some of the goals for 2019-2020 are: +Some of the goals for 2020 are: - Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback) - Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787)) +- Finish work on new Tables API (to replace Columns). (see [#2957](https://github.com/ocornut/imgui/issues/2957)) - Add an automation and testing system, both to test the library and end-user apps. (see [#435](https://github.com/ocornut/imgui/issues/435)) -- Make Columns better. They are currently pretty terrible! New Tables API coming Q4 2019! - Make the examples look better, improve styles, improve font support, make the examples hi-DPI and multi-DPI aware. ### Gallery diff --git a/examples/README.txt b/examples/README.txt index a2655da6..da05b056 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -106,7 +106,7 @@ List of Platforms Bindings in this repository: imgui_impl_osx.mm ; macOS native API (not as feature complete as glfw/sdl back-ends) imgui_impl_sdl.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org imgui_impl_win32.cpp ; Win32 native API (Windows) - imgui_impl_glut.cpp ; GLUT/FreeGLUT (absolutely not recommended in 2019) + imgui_impl_glut.cpp ; GLUT/FreeGLUT (absolutely not recommended in 2020!) List of Renderer Bindings in this repository: diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 34c26dbe..03db3fce 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -2,7 +2,7 @@ // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. // !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!! -// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!! +// !!! If someone or something is teaching you GLUT in 2020, you are being abused. Please show some resistance. !!! // !!! Nowadays, prefer using GLFW or SDL instead! #include "imgui.h" diff --git a/examples/imgui_impl_glut.cpp b/examples/imgui_impl_glut.cpp index 56d8c553..fe519d9c 100644 --- a/examples/imgui_impl_glut.cpp +++ b/examples/imgui_impl_glut.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Renderer (e.g. OpenGL2) // !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!! -// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!! +// !!! If someone or something is teaching you GLUT in 2020, you are being abused. Please show some resistance. !!! // !!! Nowadays, prefer using GLFW or SDL instead! // Issues: diff --git a/examples/imgui_impl_glut.h b/examples/imgui_impl_glut.h index 506c3867..0c561207 100644 --- a/examples/imgui_impl_glut.h +++ b/examples/imgui_impl_glut.h @@ -2,7 +2,7 @@ // This needs to be used along with a Renderer (e.g. OpenGL2) // !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!! -// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!! +// !!! If someone or something is teaching you GLUT in 2020, you are being abused. Please show some resistance. !!! // !!! Nowadays, prefer using GLFW or SDL instead! // Issues: diff --git a/imgui.cpp b/imgui.cpp index 6ef20da8..bb94bddf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2754,27 +2754,6 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) window->MemoryDrawListIdxCapacity = window->MemoryDrawListVtxCapacity = 0; } -// FIXME-NAV: Refactor those functions into a single, more explicit one. -void ImGui::SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(g.NavWindow); - IM_ASSERT(nav_layer == 0 || nav_layer == 1); - g.NavId = id; - g.NavFocusScopeId = focus_scope_id; - g.NavWindow->NavLastIds[nav_layer] = id; -} - -void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) -{ - ImGuiContext& g = *GImGui; - SetNavID(id, nav_layer, focus_scope_id); - g.NavWindow->NavRectRel[nav_layer] = rect_rel; - g.NavMousePosDirty = true; - g.NavDisableHighlight = false; - g.NavDisableMouseHover = true; -} - void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; @@ -2807,31 +2786,6 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) g.ActiveIdUsingKeyInputMask = 0x00; } -// FIXME-NAV: The existence of SetNavID/SetNavIDWithRectRel/SetFocusID is incredibly messy and confusing and needs some explanation or refactoring. -void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(id != 0); - - // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and window->DC.NavFocusScopeIdCurrent are valid. - // Note that window may be != g.CurrentWindow (e.g. SetFocusID call in InputTextEx for multi-line text) - const ImGuiNavLayer nav_layer = window->DC.NavLayerCurrent; - if (g.NavWindow != window) - g.NavInitRequest = false; - g.NavWindow = window; - g.NavId = id; - g.NavLayer = nav_layer; - g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; - window->NavLastIds[nav_layer] = id; - if (window->DC.LastItemId == id) - window->NavRectRel[nav_layer] = ImRect(window->DC.LastItemRect.Min - window->Pos, window->DC.LastItemRect.Max - window->Pos); - - if (g.ActiveIdSource == ImGuiInputSource_Nav) - g.NavDisableMouseHover = true; - else - g.NavDisableHighlight = true; -} - void ImGui::ClearActiveID() { SetActiveID(0, NULL); @@ -2879,18 +2833,18 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla // An active popup disable hovering on other windows (apart from its own children) // FIXME-OPT: This could be cached/stored within the window. ImGuiContext& g = *GImGui; - if (g.NavWindow) - if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) - if (focused_root_window->WasActive && focused_root_window != window->RootWindow) - { - // For the purpose of those flags we differentiate "standard popup" from "modal popup" - // NB: The order of those two tests is important because Modal windows are also Popups. - if (focused_root_window->Flags & ImGuiWindowFlags_Modal) - return false; - if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) - return false; - } - + if (!g.NavWindow) + return false; + if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) + if (focused_root_window->WasActive && focused_root_window != window->RootWindow) + { + // For the purpose of those flags we differentiate "standard popup" from "modal popup" + // NB: The order of those two tests is important because Modal windows are also Popups. + if (focused_root_window->Flags & ImGuiWindowFlags_Modal) + return false; + if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + return false; + } return true; } @@ -7860,6 +7814,52 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) // [SECTION] KEYBOARD/GAMEPAD NAVIGATION //----------------------------------------------------------------------------- +// FIXME-NAV: The existance of SetNavID vs SetNavIDWithRectRel vs SetFocusID is incredibly messy and confusing, +// and needs some explanation or serious refactoring. +void ImGui::SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.NavWindow); + IM_ASSERT(nav_layer == 0 || nav_layer == 1); + g.NavId = id; + g.NavFocusScopeId = focus_scope_id; + g.NavWindow->NavLastIds[nav_layer] = id; +} + +void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) +{ + ImGuiContext& g = *GImGui; + SetNavID(id, nav_layer, focus_scope_id); + g.NavWindow->NavRectRel[nav_layer] = rect_rel; + g.NavMousePosDirty = true; + g.NavDisableHighlight = false; + g.NavDisableMouseHover = true; +} + +void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(id != 0); + + // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and window->DC.NavFocusScopeIdCurrent are valid. + // Note that window may be != g.CurrentWindow (e.g. SetFocusID call in InputTextEx for multi-line text) + const ImGuiNavLayer nav_layer = window->DC.NavLayerCurrent; + if (g.NavWindow != window) + g.NavInitRequest = false; + g.NavWindow = window; + g.NavId = id; + g.NavLayer = nav_layer; + g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; + window->NavLastIds[nav_layer] = id; + if (window->DC.LastItemId == id) + window->NavRectRel[nav_layer] = ImRect(window->DC.LastItemRect.Min - window->Pos, window->DC.LastItemRect.Max - window->Pos); + + if (g.ActiveIdSource == ImGuiInputSource_Nav) + g.NavDisableMouseHover = true; + else + g.NavDisableHighlight = true; +} + ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy) { if (ImFabs(dx) > ImFabs(dy)) diff --git a/imgui.h b/imgui.h index 1245ab1b..32468168 100644 --- a/imgui.h +++ b/imgui.h @@ -595,7 +595,7 @@ namespace ImGui // - You can also use SameLine(pos_x) to mimic simplified columns. // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) // - There is a maximum of 64 columns. - // - By end of the 2019 we will expose a new 'Table' api which will replace columns. + // - Currently working on new 'Tables' api which will replace columns (see GitHub #2957) IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished IMGUI_API int GetColumnIndex(); // get current column index diff --git a/imgui_internal.h b/imgui_internal.h index 80453c95..e9c39d8e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1046,17 +1046,10 @@ struct ImGuiContext ImGuiID NavJustTabbedId; // Just tabbed to this id. ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). - ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. int NavScoringCount; // Metrics for debugging - ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed top-most. - ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f - ImGuiWindow* NavWindowingList; - float NavWindowingTimer; - float NavWindowingHighlightAlpha; - bool NavWindowingToggleLayer; ImGuiNavLayer NavLayer; // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later. int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRefRectRel is valid @@ -1078,6 +1071,14 @@ struct ImGuiContext ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag) ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag) + // Navigation: Windowing (CTRL+TAB, holding Menu button + directional pads to move/resize) + ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed top-most. + ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f + ImGuiWindow* NavWindowingList; + float NavWindowingTimer; + float NavWindowingHighlightAlpha; + bool NavWindowingToggleLayer; + // Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!) ImGuiWindow* FocusRequestCurrWindow; // ImGuiWindow* FocusRequestNextWindow; // @@ -1221,9 +1222,6 @@ struct ImGuiContext NavInputSource = ImGuiInputSource_None; NavScoringRectScreen = ImRect(); NavScoringCount = 0; - NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL; - NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; - NavWindowingToggleLayer = false; NavLayer = ImGuiNavLayer_Main; NavIdTabCounter = INT_MAX; NavIdIsAlive = false; @@ -1240,6 +1238,10 @@ struct ImGuiContext NavMoveRequestForward = ImGuiNavForward_None; NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None; + NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL; + NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; + NavWindowingToggleLayer = false; + FocusRequestCurrWindow = FocusRequestNextWindow = NULL; FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX; FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX; From 7e068da2bdf15cc3af63d49d1422091b5a4c3932 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 20 Jan 2020 19:29:25 +0100 Subject: [PATCH 228/384] Docking: Internals: Renamed members from XxxxID to XxxxxId to be more consistent with rest of the codebase (still some inconsistency left that are harder to fix) --- imgui.cpp | 124 +++++++++++++++++++++++------------------------ imgui_internal.h | 6 +-- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 80a3a162..a58b6faf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11310,16 +11310,16 @@ struct ImGuiDockPreviewData struct ImGuiDockNodeSettings { ImGuiID ID; - ImGuiID ParentNodeID; - ImGuiID ParentWindowID; - ImGuiID SelectedWindowID; + ImGuiID ParentNodeId; + ImGuiID ParentWindowId; + ImGuiID SelectedWindowId; signed char SplitAxis; char Depth; ImGuiDockNodeFlags Flags; // NB: We save individual flags one by one in ascii format (ImGuiDockNodeFlags_SavedFlagsMask_) ImVec2ih Pos; ImVec2ih Size; ImVec2ih SizeRef; - ImGuiDockNodeSettings() { ID = ParentNodeID = ParentWindowID = SelectedWindowID = 0; SplitAxis = ImGuiAxis_None; Depth = 0; Flags = ImGuiDockNodeFlags_None; } + ImGuiDockNodeSettings() { ID = ParentNodeId = ParentWindowId = SelectedWindowId = 0; SplitAxis = ImGuiAxis_None; Depth = 0; Flags = ImGuiDockNodeFlags_None; } }; struct ImGuiDockContext @@ -11615,8 +11615,8 @@ static int IMGUI_CDECL DockNodeComparerDepthMostFirst(const void* lhs, const voi struct ImGuiDockContextPruneNodeData { int CountWindows, CountChildWindows, CountChildNodes; - ImGuiID RootID; - ImGuiDockContextPruneNodeData() { CountWindows = CountChildWindows = CountChildNodes = 0; RootID = 0; } + ImGuiID RootId; + ImGuiDockContextPruneNodeData() { CountWindows = CountChildWindows = CountChildNodes = 0; RootId = 0; } }; // Garbage collect unused nodes (run once at init time) @@ -11633,10 +11633,10 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++) { ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n]; - ImGuiDockContextPruneNodeData* parent_data = settings->ParentNodeID ? pool.GetByKey(settings->ParentNodeID) : 0; - pool.GetOrAddByKey(settings->ID)->RootID = parent_data ? parent_data->RootID : settings->ID; - if (settings->ParentNodeID) - pool.GetOrAddByKey(settings->ParentNodeID)->CountChildNodes++; + ImGuiDockContextPruneNodeData* parent_data = settings->ParentNodeId ? pool.GetByKey(settings->ParentNodeId) : 0; + pool.GetOrAddByKey(settings->ID)->RootId = parent_data ? parent_data->RootId : settings->ID; + if (settings->ParentNodeId) + pool.GetOrAddByKey(settings->ParentNodeId)->CountChildNodes++; } // Count reference to dock ids from dockspaces @@ -11644,8 +11644,8 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++) { ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n]; - if (settings->ParentWindowID != 0) - if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->ParentWindowID)) + if (settings->ParentWindowId != 0) + if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->ParentWindowId)) if (window_settings->DockId) if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(window_settings->DockId)) data->CountChildNodes++; @@ -11658,7 +11658,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(dock_id)) { data->CountWindows++; - if (ImGuiDockContextPruneNodeData* data_root = (data->RootID == dock_id) ? data : pool.GetByKey(data->RootID)) + if (ImGuiDockContextPruneNodeData* data_root = (data->RootId == dock_id) ? data : pool.GetByKey(data->RootId)) data_root->CountChildWindows++; } @@ -11669,11 +11669,11 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) ImGuiDockContextPruneNodeData* data = pool.GetByKey(settings->ID); if (data->CountWindows > 1) continue; - ImGuiDockContextPruneNodeData* data_root = (data->RootID == settings->ID) ? data : pool.GetByKey(data->RootID); + ImGuiDockContextPruneNodeData* data_root = (data->RootId == settings->ID) ? data : pool.GetByKey(data->RootId); bool remove = false; - remove |= (data->CountWindows == 1 && settings->ParentNodeID == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window - remove |= (data->CountWindows == 0 && settings->ParentNodeID == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window + remove |= (data->CountWindows == 1 && settings->ParentNodeId == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window + remove |= (data->CountWindows == 0 && settings->ParentNodeId == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window remove |= (data_root->CountChildWindows == 0); if (remove) { @@ -11693,7 +11693,7 @@ static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDoc if (settings->ID == 0) continue; ImGuiDockNode* node = DockContextAddNode(ctx, settings->ID); - node->ParentNode = settings->ParentNodeID ? DockContextFindNodeByID(ctx, settings->ParentNodeID) : NULL; + node->ParentNode = settings->ParentNodeId ? DockContextFindNodeByID(ctx, settings->ParentNodeId) : NULL; node->Pos = ImVec2(settings->Pos.x, settings->Pos.y); node->Size = ImVec2(settings->Size.x, settings->Size.y); node->SizeRef = ImVec2(settings->SizeRef.x, settings->SizeRef.y); @@ -11702,7 +11702,7 @@ static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDoc node->ParentNode->ChildNodes[0] = node; else if (node->ParentNode && node->ParentNode->ChildNodes[1] == NULL) node->ParentNode->ChildNodes[1] = node; - node->SelectedTabID = settings->SelectedWindowID; + node->SelectedTabId = settings->SelectedWindowId; node->SplitAxis = settings->SplitAxis; node->LocalFlags |= (settings->Flags & ImGuiDockNodeFlags_SavedFlagsMask_); @@ -11880,7 +11880,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) { // Central node property needs to be moved to a leaf node, pick the last focused one. // FIXME-DOCK: If we had to transfer other flags here, what would the policy be? - ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeID); + ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeId); IM_ASSERT(last_focused_node != NULL); ImGuiDockNode* last_focused_root_node = DockNodeGetRootNode(last_focused_node); IM_ASSERT(last_focused_root_node == DockNodeGetRootNode(payload_node)); @@ -12026,9 +12026,9 @@ ImGuiDockNode::ImGuiDockNode(ImGuiID id) HostWindow = VisibleWindow = NULL; CentralNode = OnlyNodeWithWindows = NULL; LastFrameAlive = LastFrameActive = LastFrameFocused = -1; - LastFocusedNodeID = 0; - SelectedTabID = 0; - WantCloseTabID = 0; + LastFocusedNodeId = 0; + SelectedTabId = 0; + WantCloseTabId = 0; AuthorityForPos = AuthorityForSize = ImGuiDataAuthority_DockNode; AuthorityForViewport = ImGuiDataAuthority_Auto; IsVisible = true; @@ -12098,7 +12098,7 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, b if (node->TabBar == NULL) { DockNodeAddTabBar(node); - node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabID; + node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabId; // Add existing windows for (int n = 0; n < node->Windows.Size - 1; n++) @@ -12321,7 +12321,7 @@ static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* nod bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount); bool remove = false; remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount); - remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabID == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame + remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame remove |= (window->DockTabWantClose); if (remove) { @@ -12387,8 +12387,8 @@ static void ImGui::DockNodeUpdateForRootNode(ImGuiDockNode* node) DockNodeFindInfo(node, &results); node->CentralNode = results.CentralNode; node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL; - if (node->LastFocusedNodeID == 0 && results.FirstNodeWithWindows != NULL) - node->LastFocusedNodeID = results.FirstNodeWithWindows->ID; + if (node->LastFocusedNodeId == 0 && results.FirstNodeWithWindows != NULL) + node->LastFocusedNodeId = results.FirstNodeWithWindows->ID; // Copy the window class from of our first window so it can be used for proper dock filtering. // When node has mixed windows, prioritize the class with the most constraint (DockingAllowUnclassed = false) as the reference to copy. @@ -12453,7 +12453,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) DockNodeHideHostWindow(node); node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow; node->WantCloseAll = false; - node->WantCloseTabID = 0; + node->WantCloseTabId = 0; node->HasCloseButton = node->HasWindowMenuButton = node->EnableCloseButton = false; node->LastFrameActive = g.FrameCount; @@ -12476,8 +12476,8 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) { IM_ASSERT(node->Windows.Size > 0); ImGuiWindow* ref_window = NULL; - if (node->SelectedTabID != 0) // Note that we prune single-window-node settings on .ini loading, so this is generally 0 for them! - ref_window = DockNodeFindWindowByID(node, node->SelectedTabID); + if (node->SelectedTabId != 0) // Note that we prune single-window-node settings on .ini loading, so this is generally 0 for them! + ref_window = DockNodeFindWindowByID(node, node->SelectedTabId); if (ref_window == NULL) ref_window = node->Windows[0]; if (ref_window->AutoFitFramesX > 0 || ref_window->AutoFitFramesY > 0) @@ -12585,7 +12585,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) IM_ASSERT(node->TabBar == NULL); if (node->IsRootNode()) if (g.NavWindow && g.NavWindow->RootWindowDockStop->DockNode && g.NavWindow->RootWindowDockStop->ParentWindow == host_window) - node->LastFocusedNodeID = g.NavWindow->RootWindowDockStop->DockNode->ID; + node->LastFocusedNodeId = g.NavWindow->RootWindowDockStop->DockNode->ID; // We need to draw a background at the root level if requested by ImGuiDockNodeFlags_PassthruCentralNode, but we will only know the correct pos/size after // processing the resizing splitters. So we are using the DrawList channel splitting facility to submit drawing primitives out of order! @@ -12647,13 +12647,13 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) else { node->WantCloseAll = false; - node->WantCloseTabID = 0; + node->WantCloseTabId = 0; node->IsFocused = false; } if (node->TabBar && node->TabBar->SelectedTabId) - node->SelectedTabID = node->TabBar->SelectedTabId; + node->SelectedTabId = node->TabBar->SelectedTabId; else if (node->Windows.Size > 0) - node->SelectedTabID = node->Windows[0]->ID; + node->SelectedTabId = node->Windows[0]->ID; // Draw payload drop target if (host_window && node->IsVisible) @@ -12733,16 +12733,16 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w const bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount); const bool closed_all = node->WantCloseAll && node_was_active; - const ImGuiID closed_one = node->WantCloseTabID && node_was_active; + const ImGuiID closed_one = node->WantCloseTabId && node_was_active; node->WantCloseAll = false; - node->WantCloseTabID = 0; + node->WantCloseTabId = 0; // Decide if we should use a focused title bar color bool is_focused = false; ImGuiDockNode* root_node = DockNodeGetRootNode(node); if (g.NavWindowingTarget) is_focused = (g.NavWindowingTarget->DockNode == node); - else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindow && root_node->LastFocusedNodeID == node->ID) + else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindow && root_node->LastFocusedNodeId == node->ID) is_focused = true; // Hidden tab bar will show a triangle on the upper-left (in Begin) @@ -12849,8 +12849,8 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w } // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated - if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabID) != NULL) - tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabID; + if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL) + tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId; else if (tab_bar->Tabs.Size > tabs_count_old) tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID; @@ -12880,7 +12880,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w bool tab_open = true; TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window); if (!tab_open) - node->WantCloseTabID = window->ID; + node->WantCloseTabId = window->ID; if (tab_bar->VisibleTabId == window->ID) node->VisibleWindow = window; @@ -12912,7 +12912,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w if (CloseButton(host_window->GetID("#CLOSE"), title_bar_rect.GetTR() + ImVec2(-style.FramePadding.x * 2.0f - button_sz, 0.0f))) if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->VisibleTabId)) { - node->WantCloseTabID = tab->ID; + node->WantCloseTabId = tab->ID; TabBarCloseTab(tab_bar, tab); } //if (IsItemActive()) @@ -13697,7 +13697,7 @@ void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond) } else { - dock_id = new_node->LastFocusedNodeID; + dock_id = new_node->LastFocusedNodeId; } } @@ -14416,7 +14416,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) if (node->TabBar && node->TabBar->CurrFrameVisible != -1) window->DockOrder = (short)DockNodeGetTabOrder(window); - if ((node->WantCloseAll || node->WantCloseTabID == window->ID) && p_open != NULL) + if ((node->WantCloseAll || node->WantCloseTabId == window->ID) && p_open != NULL) *p_open = false; // Update ChildId to allow returning from Child to Parent with Escape @@ -14588,9 +14588,9 @@ static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettings else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.Flags |= ImGuiDockNodeFlags_DockSpace; } else return; if (sscanf(line, "ID=0x%08X%n", &node.ID, &r) == 1) { line += r; } else return; - if (sscanf(line, " Parent=0x%08X%n", &node.ParentNodeID, &r) == 1) { line += r; if (node.ParentNodeID == 0) return; } - if (sscanf(line, " Window=0x%08X%n", &node.ParentWindowID, &r) ==1) { line += r; if (node.ParentWindowID == 0) return; } - if (node.ParentNodeID == 0) + if (sscanf(line, " Parent=0x%08X%n", &node.ParentNodeId, &r) == 1) { line += r; if (node.ParentNodeId == 0) return; } + if (sscanf(line, " Window=0x%08X%n", &node.ParentWindowId, &r) ==1) { line += r; if (node.ParentWindowId == 0) return; } + if (node.ParentNodeId == 0) { if (sscanf(line, " Pos=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Pos = ImVec2ih((short)x, (short)y); } else return; if (sscanf(line, " Size=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Size = ImVec2ih((short)x, (short)y); } else return; @@ -14606,10 +14606,10 @@ static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettings if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_HiddenTabBar; } if (sscanf(line, " NoWindowMenuButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoWindowMenuButton; } if (sscanf(line, " NoCloseButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoCloseButton; } - if (sscanf(line, " Selected=0x%08X%n", &node.SelectedWindowID,&r) == 1) { line += r; } + if (sscanf(line, " Selected=0x%08X%n", &node.SelectedWindowId,&r) == 1) { line += r; } ImGuiDockContext* dc = ctx->DockContext; - if (node.ParentNodeID != 0) - if (ImGuiDockNodeSettings* parent_settings = DockSettingsFindNodeSettings(ctx, node.ParentNodeID)) + if (node.ParentNodeId != 0) + if (ImGuiDockNodeSettings* parent_settings = DockSettingsFindNodeSettings(ctx, node.ParentNodeId)) node.Depth = parent_settings->Depth + 1; dc->SettingsNodes.push_back(node); } @@ -14619,9 +14619,9 @@ static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDo ImGuiDockNodeSettings node_settings; IM_ASSERT(depth < (1 << (sizeof(node_settings.Depth) << 3))); node_settings.ID = node->ID; - node_settings.ParentNodeID = node->ParentNode ? node->ParentNode->ID : 0; - node_settings.ParentWindowID = (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) ? node->HostWindow->ParentWindow->ID : 0; - node_settings.SelectedWindowID = node->SelectedTabID; + node_settings.ParentNodeId = node->ParentNode ? node->ParentNode->ID : 0; + node_settings.ParentWindowId = (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) ? node->HostWindow->ParentWindow->ID : 0; + node_settings.SelectedWindowId = node->SelectedTabId; node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None; node_settings.Depth = (char)depth; node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_); @@ -14663,14 +14663,14 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n]; buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", (node_settings->Flags & ImGuiDockNodeFlags_DockSpace) ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file buf->appendf(" ID=0x%08X", node_settings->ID); - if (node_settings->ParentNodeID) + if (node_settings->ParentNodeId) { - buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentNodeID, node_settings->SizeRef.x, node_settings->SizeRef.y); + buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentNodeId, node_settings->SizeRef.x, node_settings->SizeRef.y); } else { - if (node_settings->ParentWindowID) - buf->appendf(" Window=0x%08X", node_settings->ParentWindowID); + if (node_settings->ParentWindowId) + buf->appendf(" Window=0x%08X", node_settings->ParentWindowId); buf->appendf(" Pos=%d,%d Size=%d,%d", node_settings->Pos.x, node_settings->Pos.y, node_settings->Size.x, node_settings->Size.y); } if (node_settings->SplitAxis != ImGuiAxis_None) @@ -14687,8 +14687,8 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings buf->appendf(" NoWindowMenuButton=1"); if (node_settings->Flags & ImGuiDockNodeFlags_NoCloseButton) buf->appendf(" NoCloseButton=1"); - if (node_settings->SelectedWindowID) - buf->appendf(" Selected=0x%08X", node_settings->SelectedWindowID); + if (node_settings->SelectedWindowId) + buf->appendf(" Selected=0x%08X", node_settings->SelectedWindowId); #if IMGUI_DEBUG_INI_SETTINGS // [DEBUG] Include comments in the .ini file to ease debugging @@ -15211,7 +15211,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y); NodeWindow(node->HostWindow, "HostWindow"); NodeWindow(node->VisibleWindow, "VisibleWindow"); - ImGui::BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabID, node->LastFocusedNodeID); + ImGui::BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabId, node->LastFocusedNodeId); ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : ""); if (ImGui::TreeNode("flags", "LocalFlags: 0x%04X SharedFlags: 0x%04X", node->LocalFlags, node->SharedFlags)) { @@ -15372,14 +15372,14 @@ void ImGui::ShowMetricsWindow(bool* p_open) { ImGuiDockNodeSettings* settings = &dc->SettingsNodes[n]; const char* selected_tab_name = NULL; - if (settings->SelectedWindowID) + if (settings->SelectedWindowId) { - if (ImGuiWindow* window = FindWindowByID(settings->SelectedWindowID)) + if (ImGuiWindow* window = FindWindowByID(settings->SelectedWindowId)) selected_tab_name = window->Name; - else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedWindowID)) + else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedWindowId)) selected_tab_name = window_settings->GetName(); } - ImGui::BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeID, settings->SelectedWindowID, selected_tab_name ? selected_tab_name : settings->SelectedWindowID ? "N/A" : ""); + ImGui::BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeId, settings->SelectedWindowId, selected_tab_name ? selected_tab_name : settings->SelectedWindowId ? "N/A" : ""); } ImGui::TreePop(); } diff --git a/imgui_internal.h b/imgui_internal.h index 7a316e89..e4a4cab9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1072,9 +1072,9 @@ struct ImGuiDockNode int LastFrameAlive; // Last frame number the node was updated or kept alive explicitly with DockSpace() + ImGuiDockNodeFlags_KeepAliveOnly int LastFrameActive; // Last frame number the node was updated. int LastFrameFocused; // Last frame number the node was focused. - ImGuiID LastFocusedNodeID; // [Root node only] Which of our child docking node (any ancestor in the hierarchy) was last focused. - ImGuiID SelectedTabID; // [Leaf node only] Which of our tab/window is selected. - ImGuiID WantCloseTabID; // [Leaf node only] Set when closing a specific tab/window. + ImGuiID LastFocusedNodeId; // [Root node only] Which of our child docking node (any ancestor in the hierarchy) was last focused. + ImGuiID SelectedTabId; // [Leaf node only] Which of our tab/window is selected. + ImGuiID WantCloseTabId; // [Leaf node only] Set when closing a specific tab/window. ImGuiDataAuthority AuthorityForPos :3; ImGuiDataAuthority AuthorityForSize :3; ImGuiDataAuthority AuthorityForViewport :3; From f1b5c742ff33a44f9a70dfec8f4b6072288fb685 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 20 Jan 2020 19:33:46 +0100 Subject: [PATCH 229/384] Viewports: Add various comments --- examples/imgui_impl_dx10.cpp | 1 + examples/imgui_impl_dx11.cpp | 1 + examples/imgui_impl_dx12.cpp | 1 + examples/imgui_impl_dx9.cpp | 1 + examples/imgui_impl_glfw.cpp | 8 +++++--- examples/imgui_impl_sdl.cpp | 2 ++ examples/imgui_impl_vulkan.cpp | 3 ++- examples/imgui_impl_win32.cpp | 2 ++ imgui.cpp | 2 +- imgui.h | 6 +++--- 10 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 021be31d..95dc6fd2 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -544,6 +544,7 @@ void ImGui_ImplDX10_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataDx10 { IDXGISwapChain* SwapChain; diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index f03177f2..ffd05625 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -560,6 +560,7 @@ void ImGui_ImplDX11_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataDx11 { IDXGISwapChain* SwapChain; diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 5beadf0d..3ead29c5 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -66,6 +66,7 @@ struct FrameContext D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetCpuDescriptors; }; +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataDx12 { ID3D12CommandQueue* CommandQueue; diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 2dd0ee8c..ab1b6578 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -310,6 +310,7 @@ void ImGui_ImplDX9_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataDx9 { IDirect3DSwapChain9* SwapChain; diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index ed03aece..388942c6 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -428,6 +428,7 @@ void ImGui_ImplGlfw_NewFrame() // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataGlfw { GLFWwindow* Window; @@ -496,7 +497,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport) #endif glfwSetWindowPos(data->Window, (int)viewport->Pos.x, (int)viewport->Pos.y); - // Install callbacks for secondary viewports + // Install GLFW callbacks for secondary viewports glfwSetMouseButtonCallback(data->Window, ImGui_ImplGlfw_MouseButtonCallback); glfwSetScrollCallback(data->Window, ImGui_ImplGlfw_ScrollCallback); glfwSetKeyCallback(data->Window, ImGui_ImplGlfw_KeyCallback); @@ -529,7 +530,8 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport) viewport->PlatformUserData = viewport->PlatformHandle = NULL; } -// FIXME-VIEWPORT: Implement same work-around for Linux/OSX in the meanwhile. +// We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs". +// In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!) #if defined(_WIN32) && GLFW_HAS_GLFW_HOVERED static WNDPROC g_GlfwWndProc = NULL; static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -733,7 +735,6 @@ static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst } #endif // GLFW_HAS_VULKAN -// FIXME-PLATFORM: GLFW doesn't export monitor work area (see https://github.com/glfw/glfw/pull/989) static void ImGui_ImplGlfw_UpdateMonitors() { ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); @@ -805,6 +806,7 @@ static void ImGui_ImplGlfw_InitPlatformInterface() glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); // Register main window handle (which is owned by the main application, not by us) + // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGuiViewportDataGlfw* data = IM_NEW(ImGuiViewportDataGlfw)(); data->Window = g_Window; diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 63021d39..ebb1ff15 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -432,6 +432,7 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window) // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataSDL2 { SDL_Window* Window; @@ -685,6 +686,7 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g ImGui_ImplSDL2_UpdateMonitors(); // Register main window handle (which is owned by the main application, not by us) + // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)(); data->Window = window; diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index a503703e..3d0ad9a1 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -70,7 +70,8 @@ struct ImGui_ImplVulkanH_WindowRenderBuffers ImGui_ImplVulkanH_FrameRenderBuffers* FrameRenderBuffers; }; -// For multi-viewport support +// For multi-viewport support: +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataVulkan { bool WindowOwned; diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 61750145..cc190093 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -511,6 +511,7 @@ static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos) // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- +// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataWin32 { HWND Hwnd; @@ -831,6 +832,7 @@ static void ImGui_ImplWin32_InitPlatformInterface() #endif // Register main window handle (which is owned by the main application, not by us) + // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport* main_viewport = ImGui::GetMainViewport(); ImGuiViewportDataWin32* data = IM_NEW(ImGuiViewportDataWin32)(); data->Hwnd = g_hWnd; diff --git a/imgui.cpp b/imgui.cpp index a58b6faf..82d8eee0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3326,7 +3326,7 @@ static ImDrawList* GetViewportDrawList(ImGuiViewportP* viewport, size_t drawlist { // Create the draw list on demand, because they are not frequently used for all viewports ImGuiContext& g = *GImGui; - IM_ASSERT(drawlist_no >= 0 && drawlist_no < IM_ARRAYSIZE(viewport->DrawLists)); + IM_ASSERT(drawlist_no < IM_ARRAYSIZE(viewport->DrawLists)); ImDrawList* draw_list = viewport->DrawLists[drawlist_no]; if (draw_list == NULL) { diff --git a/imgui.h b/imgui.h index c74fc7ca..cee80e35 100644 --- a/imgui.h +++ b/imgui.h @@ -1159,7 +1159,7 @@ enum ImGuiCol_ ImGuiCol_TabActive, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive, - ImGuiCol_DockingPreview, + ImGuiCol_DockingPreview, // Preview overlay color when about to docking something ImGuiCol_DockingEmptyBg, // Background color for empty node (e.g. CentralNode with no window docked into it) ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, @@ -2463,8 +2463,8 @@ struct ImGuiViewport ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows. - void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.) - void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context) + void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this. + void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this. void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) void* PlatformHandleRaw; // void* to hold low-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) From 7a22767483c4c6d0ea4d782c0bca4dbe0fc94776 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 20 Jan 2020 15:57:39 +0200 Subject: [PATCH 230/384] CI: Add MSVC extra warnings build and correct labels of other extra warnings builds. --- .github/workflows/build.yml | 11 +++++++++-- examples/example_null/build_win32.bat | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04f8f6dc..a874bfff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ jobs: Windows: runs-on: windows-2019 env: + VS_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\ MSBUILD_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ # Until gh-actions allow us to use env variables inside other env variables (because we need %GITHUB_WORKSPACE%) we have to use relative path to imgui/examples/example_name directory. SDL2_DIR: ..\..\SDL2-devel-2.0.10-VC\SDL2-2.0.10\ @@ -41,9 +42,15 @@ jobs: } # Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long. - - name: Build example_null (extra warnings) + - name: Build example_null (extra warnings, mingw 64-bit) run: mingw32-make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (extra warnings, msvc 64-bit) + shell: cmd + run: | + cd examples\example_null + "%VS_PATH%\VC\Auxiliary\Build\vcvarsall.bat" x64 && .\build_win32.bat /W4 + - name: Build example_null (single file build) shell: bash run: | @@ -214,7 +221,7 @@ jobs: brew install glfw3 brew install sdl2 - - name: Build example_null (extra warnings) + - name: Build example_null (extra warnings, clang 64-bit) run: make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (single file build) diff --git a/examples/example_null/build_win32.bat b/examples/example_null/build_win32.bat index 12cb70ab..38e79148 100644 --- a/examples/example_null/build_win32.bat +++ b/examples/example_null/build_win32.bat @@ -1,3 +1,3 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. mkdir Debug -cl /nologo /Zi /MD /I ..\.. *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib +cl /nologo /Zi /MD /I ..\.. %* *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib From 2eda3585e7a46fbdb97db6bcd232bde7ecd19fd6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 22 Jan 2020 14:20:56 +0100 Subject: [PATCH 231/384] Fixed hoverable/focus bug introduced in 3fe6ae97 (#2997) + ArrowButtonEx() internal bits. --- imgui.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bb94bddf..86bbd146 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2834,7 +2834,7 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla // FIXME-OPT: This could be cached/stored within the window. ImGuiContext& g = *GImGui; if (!g.NavWindow) - return false; + return true; if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) if (focused_root_window->WasActive && focused_root_window != window->RootWindow) { diff --git a/imgui_internal.h b/imgui_internal.h index e9c39d8e..5065255c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1780,7 +1780,7 @@ namespace ImGui IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos); IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos); - IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags); + IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); IMGUI_API void Scrollbar(ImGuiAxis axis); IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawCornerFlags rounding_corners); IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 124594db..dc9b0530 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -720,7 +720,7 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir) { float sz = GetFrameHeight(); - return ArrowButtonEx(str_id, dir, ImVec2(sz, sz), 0); + return ArrowButtonEx(str_id, dir, ImVec2(sz, sz), ImGuiButtonFlags_None); } // Button to close a window From 051ce0765ef8569729c9ae9b3d466132f9010b89 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Mon, 9 Dec 2019 15:57:24 +0900 Subject: [PATCH 232/384] AddCircle, AddCircleFilled: Add auto-calculation of circle segment counts --- imgui.cpp | 7 +++++++ imgui.h | 9 +++++---- imgui_demo.cpp | 5 +++-- imgui_draw.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- imgui_internal.h | 8 ++++++++ 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 86bbd146..75b95ba5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -988,6 +988,7 @@ ImGuiStyle::ImGuiStyle() AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU. AntiAliasedFill = true; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. + CircleSegmentMaxError = 0.75f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. // Default theme ImGui::StyleColorsDark(this); @@ -3560,6 +3561,7 @@ static void NewFrameSanityChecks() IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!"); + IM_ASSERT(g.Style.CircleSegmentMaxError > 0.0f && "Invalid style setting!"); IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!"); IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."); IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); @@ -3622,6 +3624,7 @@ void ImGui::NewFrame() IM_ASSERT(g.Font->IsLoaded()); g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; + g.DrawListSharedData.CircleSegmentMaxError = g.Style.CircleSegmentMaxError; g.DrawListSharedData.InitialFlags = ImDrawListFlags_None; if (g.Style.AntiAliasedLines) g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedLines; @@ -3630,6 +3633,10 @@ void ImGui::NewFrame() if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset; + // Recalculate circle segment counts if the segment error has changed + if (g.DrawListSharedData.CircleSegmentMaxError != g.DrawListSharedData.CircleSegmentCountsMaxCircleSegmentError) + g.DrawListSharedData.RecalculateCircleSegmentCounts(); + g.BackgroundDrawList.Clear(); g.BackgroundDrawList.PushTextureID(g.IO.Fonts->TexID); g.BackgroundDrawList.PushClipRectFullScreen(); diff --git a/imgui.h b/imgui.h index 32468168..7582aafc 100644 --- a/imgui.h +++ b/imgui.h @@ -1359,6 +1359,7 @@ struct ImGuiStyle bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. bool AntiAliasedFill; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. + float CircleSegmentMaxError; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. ImVec4 Colors[ImGuiCol_COUNT]; IMGUI_API ImGuiStyle(); @@ -1948,10 +1949,10 @@ struct ImDrawList IMGUI_API void AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col); IMGUI_API void AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness = 1.0f); IMGUI_API void AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col); - IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); - IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12); - IMGUI_API void AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness = 1.0f); - IMGUI_API void AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments); + IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); // Draw a circle - use num_segments <= 0 to automatically calculate tessellation (preferred). Use AddNgon() instead if you need a specific segment count. + IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12); // Draw a filled circle - use num_segments <= 0 to automatically calculate tessellation (preferred). Use AddNgonFilled() instead if you need a specific segment count. + IMGUI_API void AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness = 1.0f); // Draw an n-gon with a specific number of sides. Use AddCircle() instead if you want an actual circle and don't care about the exact side count. + IMGUI_API void AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments); // Draw a filled n-gon with a specific number of sides. Use AddCircleFilled() instead if you want an actual circle and don't care about the exact side count. IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, bool closed, float thickness); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index ec8c142f..8ce91784 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3502,6 +3502,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::PushItemWidth(100); ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, FLT_MAX, "%.2f", 2.0f); if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f; + ImGui::DragFloat("Max circle segment error", &style.CircleSegmentMaxError, 0.01f, 0.1f, 10.0f, "%.2f", 1.0f); ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. ImGui::PopItemWidth(); @@ -4471,7 +4472,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) // First line uses a thickness of 1.0f, second line uses the configurable thickness float th = (n == 0) ? 1.0f : thickness; draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // n-gon - draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 20, th); x += sz + spacing; // Circle + draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0, th); x += sz + spacing; // Circle draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners @@ -4485,7 +4486,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) y += sz + spacing; } draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // n-gon - draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 32); x += sz + spacing; // Circle + draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0); x += sz + spacing; // Circle draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 62cf2691..435e689b 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -348,6 +348,8 @@ ImDrawListSharedData::ImDrawListSharedData() Font = NULL; FontSize = 0.0f; CurveTessellationTol = 0.0f; + CircleSegmentMaxError = 0.0f; + CircleSegmentCountsMaxCircleSegmentError = -FLT_MIN; // Impossible value to force recalculation ClipRectFullscreen = ImVec4(-8192.0f, -8192.0f, +8192.0f, +8192.0f); InitialFlags = ImDrawListFlags_None; @@ -1083,11 +1085,34 @@ void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImV PathFillConvex(col); } +void ImDrawListSharedData::RecalculateCircleSegmentCounts() +{ + for (int i = 0; i < NumCircleSegmentCounts; i++) + { + const float radius = i + 1.0f; + CircleSegmentCounts[i] = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - CircleSegmentMaxError) / radius)), 3, 10000); + } + + CircleSegmentCountsMaxCircleSegmentError = CircleSegmentMaxError; +} + void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) { - if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) + if ((col & IM_COL32_A_MASK) == 0 || (radius <= 0.0f)) return; + // Calculate number of segments if required + if (num_segments <= 0) + { + int radius_int = (int)radius; + if (radius_int <= ImDrawListSharedData::NumCircleSegmentCounts) + num_segments = _Data->CircleSegmentCounts[radius_int - 1]; // Use cached value + else + num_segments = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - _Data->CircleSegmentMaxError) / radius)), 3, 10000); + } + else + num_segments = ImClamp(num_segments, 3, 10000); // Clamp to avoid drawing insanely tessellated shapes + // Because we are filling a closed shape we remove 1 from the count of segments/points const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1); @@ -1096,9 +1121,21 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) { - if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) + if ((col & IM_COL32_A_MASK) == 0 || (radius <= 0.0f)) return; + // Calculate number of segments if required + if (num_segments <= 0) + { + int radius_int = (int)radius; + if (radius_int <= ImDrawListSharedData::NumCircleSegmentCounts) + num_segments = _Data->CircleSegmentCounts[radius_int - 1]; // Use cached value + else + num_segments = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - _Data->CircleSegmentMaxError) / radius)), 3, 10000); + } + else + num_segments = ImClamp(num_segments, 3, 10000); // Clamp to avoid drawing insanely tessellated shapes + // Because we are filling a closed shape we remove 1 from the count of segments/points const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; PathArcTo(center, radius, 0.0f, a_max, num_segments - 1); diff --git a/imgui_internal.h b/imgui_internal.h index 5065255c..6679219d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -855,6 +855,7 @@ struct IMGUI_API ImDrawListSharedData ImFont* Font; // Current/default font (optional, for simplified AddText overload) float FontSize; // Current/default font size (optional, for simplified AddText overload) float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() + float CircleSegmentMaxError; // Number of circle segments to use per pixel of radius for AddCircle() etc ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) @@ -862,6 +863,13 @@ struct IMGUI_API ImDrawListSharedData // FIXME: Bake rounded corners fill/borders in atlas ImVec2 CircleVtx12[12]; + // Cached circle segment counts for the first radii (to avoid calculation overhead) + static const int NumCircleSegmentCounts = 64;// Number of circle segment counts to cache (i.e. the maximum radius before we calculate dynamically) + int CircleSegmentCounts[NumCircleSegmentCounts]; // The segment count for radius (array index + 1) + float CircleSegmentCountsMaxCircleSegmentError; // The MaxCircleSegmentError used to calculate these counts + + void RecalculateCircleSegmentCounts(); // Recalculate circle segment counts based on the current MaxCircleSegmentError + ImDrawListSharedData(); }; From 5363af7f47573c8a9231bc44bc6252188affea08 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 8 Jan 2020 00:10:18 +0100 Subject: [PATCH 233/384] AddCircle, AddCircleFilled: Add auto-calculation of circle segment counts (amends) Tweak default max error value, Changelog, comments, path-fast for 12 segments circles, made LUT store ImU8 --- docs/CHANGELOG.txt | 3 ++ imgui.cpp | 9 ++---- imgui.h | 11 ++++--- imgui_demo.cpp | 31 ++++++++++++------- imgui_draw.cpp | 76 ++++++++++++++++++++++++++++------------------ imgui_internal.h | 20 ++++++------ 6 files changed, 89 insertions(+), 61 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 11afd5e4..f7c903f2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -55,6 +55,7 @@ Breaking Changes: documented (can only unreserve from the last reserve call). If you suspect you ever used that feature before, #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing calls. [@ShironekoBen] +- ImDrawList::AddCircle()/AddCircleFilled() functions don't accept negative radius. - Limiting Columns()/BeginColumns() api to 64 columns with an assert. While the current code technically supports it, future code may not so we're putting the restriction ahead. - imgui_internal.h: changed ImRect() default constructor initializes all fields to 0.0f instead @@ -70,6 +71,8 @@ Other Changes: those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] - ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. +- ImDrawList: AddCircle(), AddCircleFilled() API can now auto-tessellate when provided a segment + count of zero. Alter tessellation quality with 'style.CircleSegmentMaxError'. [@ShironekoBen] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as we will rework the circle rendering functions to use textures and automatic segment count diff --git a/imgui.cpp b/imgui.cpp index 75b95ba5..6ec427e5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -362,6 +362,7 @@ CODE When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2020/01/22 (1.75) - ImDrawList::AddCircle()/AddCircleFilled() functions don't accept negative radius any more. - 2019/12/17 (1.75) - made Columns() limited to 64 columns by asserting above that limit. While the current code technically supports it, future code may not so we're putting the restriction ahead. - 2019/12/13 (1.75) - [imgui_internal.h] changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding multiple points into it, you may need to fix your initial value. - 2019/12/08 (1.75) - removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017): @@ -988,7 +989,7 @@ ImGuiStyle::ImGuiStyle() AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU. AntiAliasedFill = true; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. - CircleSegmentMaxError = 0.75f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. + CircleSegmentMaxError = 1.60f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. // Default theme ImGui::StyleColorsDark(this); @@ -3624,7 +3625,7 @@ void ImGui::NewFrame() IM_ASSERT(g.Font->IsLoaded()); g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; - g.DrawListSharedData.CircleSegmentMaxError = g.Style.CircleSegmentMaxError; + g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError); g.DrawListSharedData.InitialFlags = ImDrawListFlags_None; if (g.Style.AntiAliasedLines) g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedLines; @@ -3633,10 +3634,6 @@ void ImGui::NewFrame() if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset; - // Recalculate circle segment counts if the segment error has changed - if (g.DrawListSharedData.CircleSegmentMaxError != g.DrawListSharedData.CircleSegmentCountsMaxCircleSegmentError) - g.DrawListSharedData.RecalculateCircleSegmentCounts(); - g.BackgroundDrawList.Clear(); g.BackgroundDrawList.PushTextureID(g.IO.Fonts->TexID); g.BackgroundDrawList.PushClipRectFullScreen(); diff --git a/imgui.h b/imgui.h index 7582aafc..5fab99dc 100644 --- a/imgui.h +++ b/imgui.h @@ -1941,6 +1941,9 @@ struct ImDrawList // Primitives // - For rectangular primitives, "p_min" and "p_max" represent the upper-left and lower-right corners. + // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). + // In future versions we will use textures to provide cheaper and higher-quality circles. + // Use AddNgon() and AddNgonFilled() functions if you need to guaranteed a specific number of sides. IMGUI_API void AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness = 1.0f); IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size), rounding_corners_flags: 4 bits corresponding to which corner to round IMGUI_API void AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All); // a: upper-left, b: lower-right (== upper-left + size) @@ -1949,10 +1952,10 @@ struct ImDrawList IMGUI_API void AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col); IMGUI_API void AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness = 1.0f); IMGUI_API void AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col); - IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); // Draw a circle - use num_segments <= 0 to automatically calculate tessellation (preferred). Use AddNgon() instead if you need a specific segment count. - IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12); // Draw a filled circle - use num_segments <= 0 to automatically calculate tessellation (preferred). Use AddNgonFilled() instead if you need a specific segment count. - IMGUI_API void AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness = 1.0f); // Draw an n-gon with a specific number of sides. Use AddCircle() instead if you want an actual circle and don't care about the exact side count. - IMGUI_API void AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments); // Draw a filled n-gon with a specific number of sides. Use AddCircleFilled() instead if you want an actual circle and don't care about the exact side count. + IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f); + IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12); + IMGUI_API void AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness = 1.0f); + IMGUI_API void AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments); IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, bool closed, float thickness); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 8ce91784..05051913 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3500,9 +3500,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); HelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well."); ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill); ImGui::PushItemWidth(100); - ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, FLT_MAX, "%.2f", 2.0f); + ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f"); if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f; - ImGui::DragFloat("Max circle segment error", &style.CircleSegmentMaxError, 0.01f, 0.1f, 10.0f, "%.2f", 1.0f); + ImGui::DragFloat("Circle segment Max Error", &style.CircleSegmentMaxError, 0.01f, 0.10f, 10.0f, "%.2f"); ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. ImGui::PopItemWidth(); @@ -4455,24 +4455,33 @@ static void ShowExampleAppCustomRendering(bool* p_open) static float sz = 36.0f; static float thickness = 3.0f; static int ngon_sides = 6; + static bool circle_segments_override = false; + static int circle_segments_override_v = 12; static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); + ImGui::PushItemWidth(-ImGui::GetFontSize() * 10); ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f"); ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); - ImGui::SliderInt("n-gon sides", &ngon_sides, 3, 12); + ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); + ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override); + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); + if (ImGui::SliderInt("Circle segments", &circle_segments_override_v, 3, 40)) + circle_segments_override = true; ImGui::ColorEdit4("Color", &colf.x); + ImGui::PopItemWidth(); const ImVec2 p = ImGui::GetCursorScreenPos(); const ImU32 col = ImColor(colf); + const float spacing = 10.0f; + const ImDrawCornerFlags corners_none = 0; + const ImDrawCornerFlags corners_all = ImDrawCornerFlags_All; + const ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight; + const int circle_segments = circle_segments_override ? circle_segments_override_v : 0; float x = p.x + 4.0f, y = p.y + 4.0f; - float spacing = 10.0f; - ImDrawCornerFlags corners_none = 0; - ImDrawCornerFlags corners_all = ImDrawCornerFlags_All; - ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight; for (int n = 0; n < 2; n++) { // First line uses a thickness of 1.0f, second line uses the configurable thickness float th = (n == 0) ? 1.0f : thickness; - draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // n-gon - draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0, th); x += sz + spacing; // Circle + draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // N-gon + draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th); x += sz + spacing; // Circle draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners @@ -4485,8 +4494,8 @@ static void ShowExampleAppCustomRendering(bool* p_open) x = p.x + 4; y += sz + spacing; } - draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // n-gon - draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0); x += sz + spacing; // Circle + draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // N-gon + draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments);x += sz + spacing; // Circle draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 435e689b..2f3370e0 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -349,16 +349,29 @@ ImDrawListSharedData::ImDrawListSharedData() FontSize = 0.0f; CurveTessellationTol = 0.0f; CircleSegmentMaxError = 0.0f; - CircleSegmentCountsMaxCircleSegmentError = -FLT_MIN; // Impossible value to force recalculation ClipRectFullscreen = ImVec4(-8192.0f, -8192.0f, +8192.0f, +8192.0f); InitialFlags = ImDrawListFlags_None; - // Const data + // Lookup tables for (int i = 0; i < IM_ARRAYSIZE(CircleVtx12); i++) { const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(CircleVtx12); CircleVtx12[i] = ImVec2(ImCos(a), ImSin(a)); } + memset(CircleSegmentCounts, 0, sizeof(CircleSegmentCounts)); // This will be set by +} + +void ImDrawListSharedData::SetCircleSegmentMaxError(float max_error) +{ + if (CircleSegmentMaxError == max_error) + return; + CircleSegmentMaxError = max_error; + for (int i = 0; i < IM_ARRAYSIZE(CircleSegmentCounts); i++) + { + const float radius = i + 1.0f; + const int segment_count = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, CircleSegmentMaxError); + CircleSegmentCounts[i] = (ImU8)ImMin(segment_count, 255); + } } void ImDrawList::Clear() @@ -1085,60 +1098,63 @@ void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImV PathFillConvex(col); } -void ImDrawListSharedData::RecalculateCircleSegmentCounts() -{ - for (int i = 0; i < NumCircleSegmentCounts; i++) - { - const float radius = i + 1.0f; - CircleSegmentCounts[i] = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - CircleSegmentMaxError) / radius)), 3, 10000); - } - - CircleSegmentCountsMaxCircleSegmentError = CircleSegmentMaxError; -} - void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) { - if ((col & IM_COL32_A_MASK) == 0 || (radius <= 0.0f)) + if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) return; - // Calculate number of segments if required + // Obtain segment count if (num_segments <= 0) { - int radius_int = (int)radius; - if (radius_int <= ImDrawListSharedData::NumCircleSegmentCounts) - num_segments = _Data->CircleSegmentCounts[radius_int - 1]; // Use cached value + // Automatic segment count + const int radius_idx = (int)radius - 1; + if (radius_idx < IM_ARRAYSIZE(_Data->CircleSegmentCounts)) + num_segments = _Data->CircleSegmentCounts[radius_idx]; // Use cached value else - num_segments = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - _Data->CircleSegmentMaxError) / radius)), 3, 10000); + num_segments = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, _Data->CircleSegmentMaxError); + } + else + { + // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) + num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); } - else - num_segments = ImClamp(num_segments, 3, 10000); // Clamp to avoid drawing insanely tessellated shapes // Because we are filling a closed shape we remove 1 from the count of segments/points const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; - PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1); + if (num_segments == 12) + PathArcToFast(center, radius - 0.5f, 0, 12); + else + PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1); PathStroke(col, true, thickness); } void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) { - if ((col & IM_COL32_A_MASK) == 0 || (radius <= 0.0f)) + if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) return; - // Calculate number of segments if required + // Obtain segment count if (num_segments <= 0) { - int radius_int = (int)radius; - if (radius_int <= ImDrawListSharedData::NumCircleSegmentCounts) - num_segments = _Data->CircleSegmentCounts[radius_int - 1]; // Use cached value + // Automatic segment count + const int radius_idx = (int)radius - 1; + if (radius_idx < IM_ARRAYSIZE(_Data->CircleSegmentCounts)) + num_segments = _Data->CircleSegmentCounts[radius_idx]; // Use cached value else - num_segments = ImClamp((int)((IM_PI * 2.0f) / ImAcos((radius - _Data->CircleSegmentMaxError) / radius)), 3, 10000); + num_segments = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, _Data->CircleSegmentMaxError); } else - num_segments = ImClamp(num_segments, 3, 10000); // Clamp to avoid drawing insanely tessellated shapes + { + // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) + num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); + } // Because we are filling a closed shape we remove 1 from the count of segments/points const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; - PathArcTo(center, radius, 0.0f, a_max, num_segments - 1); + if (num_segments == 12) + PathArcToFast(center, radius, 0, 12); + else + PathArcTo(center, radius, 0.0f, a_max, num_segments - 1); PathFillConvex(col); } diff --git a/imgui_internal.h b/imgui_internal.h index 6679219d..e1279c05 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -848,7 +848,13 @@ struct ImGuiColumns } }; +// Helper function to calculate a circle's segment count given its radius and a "maximum error" value. +#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN 12 +#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX 512 +#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(_RAD,_MAXERROR) ImClamp((int)((IM_PI * 2.0f) / ImAcos((_RAD - _MAXERROR) / _RAD)), IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX) + // Data shared between all ImDrawList instances +// You may want to create your own instance of this if you want to use ImDrawList completely without ImGui. In that case, watch out for future changes to this structure. struct IMGUI_API ImDrawListSharedData { ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas @@ -859,18 +865,12 @@ struct IMGUI_API ImDrawListSharedData ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen() ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) - // Const data - // FIXME: Bake rounded corners fill/borders in atlas - ImVec2 CircleVtx12[12]; - - // Cached circle segment counts for the first radii (to avoid calculation overhead) - static const int NumCircleSegmentCounts = 64;// Number of circle segment counts to cache (i.e. the maximum radius before we calculate dynamically) - int CircleSegmentCounts[NumCircleSegmentCounts]; // The segment count for radius (array index + 1) - float CircleSegmentCountsMaxCircleSegmentError; // The MaxCircleSegmentError used to calculate these counts - - void RecalculateCircleSegmentCounts(); // Recalculate circle segment counts based on the current MaxCircleSegmentError + // [Internal] Lookup tables + ImVec2 CircleVtx12[12]; // FIXME: Bake rounded corners fill/borders in atlas + ImU8 CircleSegmentCounts[64]; // Precomputed segment count for given radius (array index + 1) before we calculate it dynamically (to avoid calculation overhead) ImDrawListSharedData(); + void SetCircleSegmentMaxError(float max_error); }; struct ImDrawDataBuilder From f6da5000bfaf3a035e8d8a7db9b5150644f4630b Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 23 Jan 2020 16:20:10 +0100 Subject: [PATCH 234/384] Backends: OpenGL2: Explicitly backup, setup and restore GL_TEXTURE_ENV to increase compatibility with legacy OpenGL applications. (#3000) --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_opengl2.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f7c903f2..28b792ff 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -171,6 +171,8 @@ Other Changes: - Examples: DX12: Using IDXGIDebug1::ReportLiveObjects() when DX12_ENABLE_DEBUG_LAYER is enabled. - Examples: Emscripten: Removed BINARYEN_TRAP_MODE=clamp from Makefile which was removed in Emscripten 1.39.0 but required prior to 1.39.0, making life easier for absolutely no-one. (#2877, #2878) [@podsvirov] +- Backends: OpenGL2: Explicitly backup, setup and restore GL_TEXTURE_ENV to increase compatibility with + legacy OpenGL applications. (#3000) - Backends: OpenGL3: Fix building with pre-3.2 GL loaders which do not expose glDrawElementsBaseVertex(), using runtime GL version to decide if we set ImGuiBackendFlags_RendererHasVtxOffset. (#2866, #2852) [@dpilawa] - Backends: OSX: Fix using Backspace key. (#2578, #2817, #2818) [@DiligentGraphics] diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index de4b128c..b062697b 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -18,6 +18,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-01-23: OpenGL: Explicitly backup, setup and restore GL_TEXTURE_ENV to increase compatibility with legacy OpenGL applications. // 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. // 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display. // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. @@ -89,6 +90,7 @@ static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_wid glEnableClientState(GL_COLOR_ARRAY); glEnable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), // you may need to backup/reset/restore current shader using the lines below. DO NOT MODIFY THIS FILE! Add the code in your calling function: @@ -126,6 +128,7 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data) GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); + GLint last_tex_env_mode; glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_tex_env_mode); glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); // Setup desired GL state @@ -193,6 +196,7 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data) glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_tex_env_mode); } bool ImGui_ImplOpenGL2_CreateFontsTexture() From f68075b333b017520e2d98a5c9901f04b3c2745c Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 28 Nov 2019 22:42:13 +0100 Subject: [PATCH 235/384] Docking: Added DockNodeFlagsOverrideSet/DockNodeFlagsOverrideClear (experimental) --- imgui.cpp | 10 ++++++++++ imgui.h | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 82d8eee0..642ebed9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12313,6 +12313,7 @@ static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* nod DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[1]); // Remove inactive windows + // Merge node flags overrides stored in windows for (int window_n = 0; window_n < node->Windows.Size; window_n++) { ImGuiWindow* window = node->Windows[window_n]; @@ -12336,6 +12337,11 @@ static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* nod DockNodeRemoveWindow(node, window, node->ID); window_n--; } + else + { + node->LocalFlags &= ~window->WindowClass.DockNodeFlagsOverrideClear; + node->LocalFlags |= window->WindowClass.DockNodeFlagsOverrideSet; + } } // Auto-hide tab bar option @@ -12344,6 +12350,10 @@ static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* nod node->WantHiddenTabBarToggle = true; node->WantHiddenTabBarUpdate = false; + // Cancel toggling if we know our tab bar is enforced to be hidden at all times + if (node->WantHiddenTabBarToggle && node->VisibleWindow && (node->VisibleWindow->WindowClass.DockNodeFlagsOverrideSet & ImGuiDockNodeFlags_HiddenTabBar)) + node->WantHiddenTabBarToggle = false; + // Apply toggles at a single point of the frame (here!) if (node->Windows.Size > 1) node->LocalFlags &= ~ImGuiDockNodeFlags_HiddenTabBar; diff --git a/imgui.h b/imgui.h index cee80e35..7d9c4750 100644 --- a/imgui.h +++ b/imgui.h @@ -1646,10 +1646,12 @@ struct ImGuiWindowClass ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not. ImGuiViewportFlags ViewportFlagsOverrideSet; // Viewport flags to set when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. ImGuiViewportFlags ViewportFlagsOverrideClear; // Viewport flags to clear when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. + ImGuiDockNodeFlags DockNodeFlagsOverrideSet; // [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!) + ImGuiDockNodeFlags DockNodeFlagsOverrideClear; // [EXPERIMENTAL] bool DockingAlwaysTabBar; // Set to true to enforce single floating windows of this class always having their own docking node (equivalent of setting the global io.ConfigDockingAlwaysTabBar) bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window. - ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideSet = ViewportFlagsOverrideClear = 0x00; DockingAlwaysTabBar = false; DockingAllowUnclassed = true; } + ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideSet = ViewportFlagsOverrideClear = 0x00; DockNodeFlagsOverrideSet = DockNodeFlagsOverrideClear = 0x00; DockingAlwaysTabBar = false; DockingAllowUnclassed = true; } }; // Data payload for Drag and Drop operations: AcceptDragDropPayload(), GetDragDropPayload() From b887259974cf1b6587e86f7c9ca7086119303520 Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Mon, 27 Jan 2020 14:11:29 +0300 Subject: [PATCH 236/384] Bindings: Improved FreeGLUT support for MinGW (#3004) --- examples/example_glut_opengl2/Makefile | 8 +++++++- examples/example_glut_opengl2/main.cpp | 4 ++-- examples/imgui_impl_glut.cpp | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/example_glut_opengl2/Makefile b/examples/example_glut_opengl2/Makefile index c381c0c9..70576b8f 100644 --- a/examples/example_glut_opengl2/Makefile +++ b/examples/example_glut_opengl2/Makefile @@ -41,7 +41,13 @@ endif ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) ECHO_MESSAGE = "MinGW" - LIBS += -lgdi32 -lopengl32 -limm32 -lglut + LIBS += -lgdi32 -lopengl32 -limm32 +ifeq ($(shell pkg-config freeglut --exists 2> /dev/null && echo yes || echo no),yes) + CXXFLAGS += $(shell pkg-config freeglut --cflags) + LIBS += $(shell pkg-config freeglut --libs) +else + LIBS += -lglut +endif CFLAGS = $(CXXFLAGS) endif diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 03db3fce..d36c1f84 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -6,8 +6,8 @@ // !!! Nowadays, prefer using GLFW or SDL instead! #include "imgui.h" -#include "../imgui_impl_glut.h" -#include "../imgui_impl_opengl2.h" +#include "imgui_impl_glut.h" +#include "imgui_impl_opengl2.h" #ifdef __APPLE__ #include #else diff --git a/examples/imgui_impl_glut.cpp b/examples/imgui_impl_glut.cpp index fe519d9c..3c17bbfc 100644 --- a/examples/imgui_impl_glut.cpp +++ b/examples/imgui_impl_glut.cpp @@ -39,7 +39,12 @@ static int g_Time = 0; // Current time, in milliseconds bool ImGui_ImplGLUT_Init() { ImGuiIO& io = ImGui::GetIO(); + +#ifdef FREEGLUT + io.BackendPlatformName ="imgui_impl_glut (freeglut)"; +#else io.BackendPlatformName ="imgui_impl_glut"; +#endif g_Time = 0; From 4d4e3b97f4c9950ccb92986c8f201b2923a8ec61 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 24 Jan 2020 15:25:47 +0100 Subject: [PATCH 237/384] TODO, Readme (dropped TreeNode_NoIndent flag from todo, as it feels unnecessary) --- docs/CHANGELOG.txt | 1 + docs/README.md | 4 ++-- docs/TODO.txt | 33 +++++++++++++++++---------------- examples/README.txt | 16 ++++++---------- imgui_internal.h | 2 +- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 28b792ff..d05ae4df 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -95,6 +95,7 @@ Other Changes: XInput using code, and IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT to disable linking with XInput, the later may be problematic if compiling with recent Windows SDK and you want your app to run on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) +- Backends: Glut: Improved FreeGLUT support for MinGW. (#3004) [@podsvirov] - CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might diff --git a/docs/README.md b/docs/README.md index 2bad5cae..37952f06 100644 --- a/docs/README.md +++ b/docs/README.md @@ -113,8 +113,8 @@ Officially maintained bindings (in repository): - Frameworks: Emscripten, Allegro5, Marmalade. Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): -- Languages: C, C#/.Net, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, Irrlicht, Ogre, OpenFrameworks, OSG/OpenSceneGraph, ORX, px_render, LÖVE+Lua, Magnum, NanoRT, Qt, QtDirect3D, SFML, Software Rasterizers, Unreal Engine 4... +- Languages: C, C#/.Net, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... +- Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, Nim Game Lib, Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, px_render, Qt/QtDirect3D, SFML, Sokol, Unreal Engine 4, vtk, Win32 GDI. - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. diff --git a/docs/TODO.txt b/docs/TODO.txt index 57680c1e..1184ce50 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -218,21 +218,11 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - menus: hovering from menu to menu on a menu-bar has 1 frame without any menu, which is a little annoying. ideally either 0 either longer. - menus: could merge draw call in most cases (how about storing an optional aabb in ImDrawCmd to move the burden of merging in a single spot). - - text: selectable text (for copy) as a generic feature (ItemFlags?) - - text: proper alignment options in imgui_internal.h - - text: it's currently impossible to have a window title with "##". perhaps an official workaround would be nice. \ style inhibitor? non-visible ascii code to insert between #? - - text: provided a framed text helper, e.g. https://pastebin.com/1Laxy8bT - - text: refactor TextUnformatted (or underlying function) to more explicitly request if we need width measurement or not - - text link/url button: underlined. should api expose an ID or use text contents as ID? which colors enum to use? - - text/wrapped: should be a more first-class citizen, e.g. wrapped text within a Selectable with known width - - text/wrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (#249) - - tree node: add treenode/treepush int variants? not there because (void*) cast from int warns on some platforms/settings? - tree node: try to apply scrolling at time of TreePop() if node was just opened and end of node is past scrolling limits? - tree node / selectable render mismatch which is visible if you use them both next to each other (e.g. cf. property viewer) - tree node: tweak color scheme to distinguish headers from selected tree node (#581) - tree node: leaf/non-leaf highlight mismatch. - - tree node: _NoIndentOnOpen flag? would require to store a per-depth bit mask to store info for pop (or whatever is cheaper) - tree node/opt: could avoid formatting when clipped (flag assuming we don't care about width/height, assume single line height?) - settings: write more decent code to allow saving/loading new fields: columns, selected tree nodes? @@ -281,6 +271,17 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - pie menus patterns (#434) - markup: simple markup language for color change? (#902) + - text: selectable text (for copy) as a generic feature (ItemFlags?) + - text: proper alignment options in imgui_internal.h + - text: it's currently impossible to have a window title with "##". perhaps an official workaround would be nice. \ style inhibitor? non-visible ascii code to insert between #? + - text: provided a framed text helper, e.g. https://pastebin.com/1Laxy8bT + - text: refactor TextUnformatted (or underlying function) to more explicitly request if we need width measurement or not + - text link/url button: underlined. should api expose an ID or use text contents as ID? which colors enum to use? + - text/wrapped: should be a more first-class citizen, e.g. wrapped text within a Selectable with known width. + - text/wrapped: custom separator for text wrapping. (#3002) + - text/wrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (#249) + + - font: arbitrary line spacing. (#2945) - font: MergeMode: flags to select overwriting or not (this is now very easy with refactored ImFontAtlasBuildWithStbTruetype) - font: free the Alpha buffer if user only requested RGBA. !- font: better CalcTextSizeA() API, at least for simple use cases. current one is horrible (perhaps have simple vs extended versions). @@ -312,8 +313,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - nav: some features such as PageUp/Down/Home/End should probably work without ImGuiConfigFlags_NavEnableKeyboard? (where do we draw the line?) ! nav: never clear NavId on some setup (e.g. gamepad centric) - - nav: restore NavId on reappearing non-child window. - - nav: code to focus child-window on restoring NavId appears to have issue (to investigate) + - nav: code to focus child-window on restoring NavId appears to have issue: e.g. when focus change is implicit because of window closure. - nav: configuration flag to disable global shortcuts (currently only CTRL-Tab) ? - nav: Home/End behavior when navigable item is not fully visible at the edge of scrolling? should be backtrack to keep item into view? - nav: NavScrollToBringItemIntoView() with item bigger than view should focus top-right? Repro: using Nav in "About Window" @@ -321,20 +321,21 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - nav: patterns to make it possible for arrows key to update selection - nav: restore/find nearest NavId when current one disappear (e.g. pressed a button that disappear, or perhaps auto restoring when current button change name) - nav: SetItemDefaultFocus() level of priority, so widget like Selectable when inside a popup could claim a low-priority default focus on the first selected iem - - nav: ESC within a menu of a child window seems to exit the child window. - nav: NavFlattened: ESC on a flattened child should select something. - nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child. - nav: NavFlattened: init request doesn't select items that are part of a NavFlattened child - nav: NavFlattened: cannot access menu-bar of a flattened child window with Alt/menu key (not a very common use case..). - - nav: Left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?) + - nav/treenode: Left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?) - nav/menus: pressing left-right on a vertically clipped menu bar tends to jump to the collapse/close buttons. - nav/menus: allow pressing Menu to leave a sub-menu. - - nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB) + - nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB) or last focused window menu bar? - nav/menus: when using the main menu bar, even though we restore focus after, the underlying window loses its title bar highlight during menu manipulation. could we prevent it? - nav/menus: main menu bar currently cannot restore a NULL focus. Could save NavWindow at the time of being focused, similarly to what popup do? + - nav/menus: Alt,Up could open the first menu (e.g. "File") currently it tends to nav into the window/collapse menu. Do do that we would need custom transition? + - nav/windowing: configure fade-in/fade-out delay on Ctrl+Tab? + - nav/windowing: when CTRL-Tab/windowing is active, the HoveredWindow detection doesn't take account of the window display re-ordering. - nav: simulate right-click or context activation? (SHIFT+F10) - nav: tabs should go through most/all widgets (in submission order?). - - nav: when CTRL-Tab/windowing is active, the HoveredWindow detection doesn't take account of the window display re-ordering. - nav: esc/enter default behavior for popups, e.g. be able to mark an "ok" or "cancel" button that would get triggered by those keys. - nav: when activating a button that changes label (without a static ID) or disappear, can we somehow automatically recover into a nearest highlight item? - nav: there's currently no way to completely clear focus with the keyboard. depending on patterns used by the application to dispatch inputs, it may be desirable. diff --git a/examples/README.txt b/examples/README.txt index da05b056..5f45fad9 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -131,22 +131,18 @@ Third-party framework, graphics API and languages bindings are listed at: https://github.com/ocornut/imgui/wiki/Bindings - Languages: - C, C#, ChaiScript, CovScript, D, Go, Haxe/hxcpp, Java, JavaScript, Julia, Lua, Nim, - Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... +Including backends for: - Frameworks: - Amethyst, bsf, Cinder, Cocoa2d-x, Diligent Engine, Flexium, GML/GameMaker Studio, - GTK3 + OpenGL, Irrlicht, Ogre, OpenSceneGraph/OSG, openFrameworks, Orx, LÖVE+LUA, - Magnum, NanoRT, Nim Game Lib, px_render, Qt, Qt3d, SFML, Sokol, Unreal Engine 4, vtk... - - Miscellaneous: Software Renderer, RemoteImgui, imgui-ws, etc. + AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, + GML/Game Maker Studio2, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, Nim Game Lib, + Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, px_render, Qt/QtDirect3D, SFML, Sokol, + Unreal Engine 4, vtk, Win32 GDI, etc. Not sure which to use? Recommended platform/frameworks: GLFW https://github.com/glfw/glfw Use imgui_impl_glfw.cpp - SDL2 https://www.libsdl.org Use imgui_impl_sdl.cp + SDL2 https://www.libsdl.org Use imgui_impl_sdl.cpp Sokol https://github.com/floooh/sokol Use util/sokol_imgui.h in Sokol repository. Those will allow you to create portable applications and will solve and abstract away many issues. diff --git a/imgui_internal.h b/imgui_internal.h index e1279c05..f5c5f384 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1664,7 +1664,7 @@ namespace ImGui IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id); IMGUI_API void MarkItemEdited(ImGuiID id); - IMGUI_API void PushOverrideID(ImGuiID id); + IMGUI_API void PushOverrideID(ImGuiID id); // Push given value at the top of the ID stack (whereas PushID combines old and new hashes) // Basic Helpers for widget code IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = -1.0f); From 377f7300546e2a43e225d38c724a7f28da0ed6f2 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 27 Jan 2020 17:57:07 +0100 Subject: [PATCH 238/384] Fix resizing viewport-owning windows when mouse pos is outside the InnerClipRect (can happen with OS decoration on). (#1542) --- imgui.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index a9615907..b0f350bc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5403,9 +5403,12 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au ImRect resize_rect(corner - grip.InnerDir * grip_hover_outer_size, corner + grip.InnerDir * grip_hover_inner_size); if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); + ImVec2 resize_rect_ref_min = resize_rect.Min; resize_rect.ClipWith(clip_viewport_rect); bool hovered, held; ButtonBehavior(resize_rect, window->GetID(resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); + if (held && g.ActiveIdIsJustActivated) + g.ActiveIdClickOffset = g.IO.MousePos - resize_rect_ref_min; // Override our reference click offset as viewport clipping may be moved it. //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); if (hovered || held) g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; @@ -5431,8 +5434,11 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au { bool hovered, held; ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); + ImVec2 border_rect_ref_min = border_rect.Min; border_rect.ClipWith(clip_viewport_rect); ButtonBehavior(border_rect, window->GetID(border_n + 4), &hovered, &held, ImGuiButtonFlags_FlattenChildren); + if (held && g.ActiveIdIsJustActivated) + g.ActiveIdClickOffset = g.IO.MousePos - border_rect_ref_min; // Override our reference click offset as viewport clipping may be moved it. //GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held) { From 6c1a73774dabd2be64f85543b1286e44632d1905 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 27 Jan 2020 19:02:54 +0100 Subject: [PATCH 239/384] Tooltip: Testing DragDropWithinSourceOrTarget in BeginTooltipEx() instead of just BeginTooltip() - feel this was an overlook. Added tooltip flags instead of using bool. --- docs/TODO.txt | 3 ++- imgui.cpp | 25 +++++++++---------------- imgui_internal.h | 15 +++++++++++---- imgui_widgets.cpp | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 1184ce50..f0d5c90b 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -203,10 +203,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - popups: clicking outside (to close popup) and holding shouldn't drag window below. - popups: add variant using global identifier similar to Begin/End (#402) - popups: border options. richer api like BeginChild() perhaps? (#197) + - tooltip: drag and drop with tooltip near monitor edges lose/changes its last direction instead of locking one. The drag and drop tooltip should always follow without changing direction. - tooltip: tooltip that doesn't fit in entire screen seems to lose their "last preferred direction" and may teleport when moving mouse. - tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic. - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed): IsItemHovered() with timer + implicit aabb-id for items with no ID. (#1485) + - tooltip: drag tooltip hovering over source widget with IsItemHovered/SetTooltip flickers. - menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207) - menus: menu bars inside modal windows are acting weird. @@ -252,7 +254,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - filters: handle wild-cards (with implicit leading/trailing *), reg-exprs - filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb) - - drag and drop: drag tooltip hovering over source widget with IsItemHovered/SetTooltip flickers. - drag and drop: fix/support/options for overlapping drag sources. - drag and drop: releasing a drop shows the "..." tooltip for one frame - since e13e598 (#1725) - drag and drop: drag source on a group object (would need e.g. an invisible button covering group in EndGroup) https://twitter.com/paniq/status/1121446364909535233 diff --git a/imgui.cpp b/imgui.cpp index 6ec427e5..9a908940 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7340,8 +7340,14 @@ void ImGui::SetScrollHereY(float center_y_ratio) //----------------------------------------------------------------------------- void ImGui::BeginTooltip() +{ + BeginTooltipEx(ImGuiWindowFlags_None, ImGuiTooltipFlags_None); +} + +void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags) { ImGuiContext& g = *GImGui; + if (g.DragDropWithinSourceOrTarget) { // The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor) @@ -7352,21 +7358,12 @@ void ImGui::BeginTooltip() SetNextWindowPos(tooltip_pos); SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f); //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :( - BeginTooltipEx(0, true); - } - else - { - BeginTooltipEx(0, false); + tooltip_flags |= ImGuiTooltipFlags_OverridePreviousTooltip; } -} -// Not exposed publicly as BeginTooltip() because bool parameters are evil. Let's see if other needs arise first. -void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip) -{ - ImGuiContext& g = *GImGui; char window_name[16]; ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", g.TooltipOverrideCount); - if (override_previous_tooltip) + if (tooltip_flags & ImGuiTooltipFlags_OverridePreviousTooltip) if (ImGuiWindow* window = FindWindowByName(window_name)) if (window->Active) { @@ -7387,11 +7384,7 @@ void ImGui::EndTooltip() void ImGui::SetTooltipV(const char* fmt, va_list args) { - ImGuiContext& g = *GImGui; - if (g.DragDropWithinSourceOrTarget) - BeginTooltip(); - else - BeginTooltipEx(0, true); + BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip); TextV(fmt, args); EndTooltip(); } diff --git a/imgui_internal.h b/imgui_internal.h index f5c5f384..dee16628 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -112,6 +112,7 @@ typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// F typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for SeparatorEx() typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for SliderBehavior() typedef int ImGuiTextFlags; // -> enum ImGuiTextFlags_ // Flags: for TextEx() +typedef int ImGuiTooltipFlags; // -> enum ImGuiTooltipFlags_ // Flags: for BeginTooltipEx() //------------------------------------------------------------------------- // STB libraries includes @@ -526,6 +527,12 @@ enum ImGuiTextFlags_ ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0 }; +enum ImGuiTooltipFlags_ +{ + ImGuiTooltipFlags_None = 0, + ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0 // Override will clear/ignore previously submitted tooltip (defaults to append) +}; + // FIXME: this is in development, not exposed/functional as a generic feature yet. // Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2 enum ImGuiLayoutType_ @@ -1106,19 +1113,19 @@ struct ImGuiContext // Drag and Drop bool DragDropActive; - bool DragDropWithinSourceOrTarget; + bool DragDropWithinSourceOrTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block. ImGuiDragDropFlags DragDropSourceFlags; int DragDropSourceFrameCount; int DragDropMouseButton; ImGuiPayload DragDropPayload; - ImRect DragDropTargetRect; + ImRect DragDropTargetRect; // Store rectangle of current target candidate (we favor small targets when overlapping) ImGuiID DragDropTargetId; ImGuiDragDropFlags DragDropAcceptFlags; float DragDropAcceptIdCurrRectSurface; // Target item surface (we resolve overlapping targets by prioritizing the smaller surface) ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source - ImVector DragDropPayloadBufHeap; // We don't expose the ImVector<> directly + ImVector DragDropPayloadBufHeap; // We don't expose the ImVector<> directly, ImGuiPayload only holds pointer+size unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads // Tab bars @@ -1694,7 +1701,7 @@ namespace ImGui IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup); IMGUI_API bool IsPopupOpen(ImGuiID id); // Test for id within current popup stack level (currently begin-ed into); this doesn't scan the whole popup stack! IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); - IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_tooltip = true); + IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags); IMGUI_API ImGuiWindow* GetTopMostPopupModal(); IMGUI_API ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window); IMGUI_API ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy = ImGuiPopupPositionPolicy_Default); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index dc9b0530..3aa9f13d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4960,7 +4960,7 @@ void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags { ImGuiContext& g = *GImGui; - BeginTooltipEx(0, true); + BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip); const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text; if (text_end > text) { From 5f4dfad5b7ca2d56b54f1e6aefa4601b7b439698 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Jan 2020 20:06:34 +0100 Subject: [PATCH 240/384] Merge misc/shallow changes from Docking to reduce drift. Most are comments. Fix menu bar clipping: 07ff47bf1b7fb3dced2dc91ca39efedaff34e337 --- docs/CHANGELOG.txt | 1 + imgui.cpp | 104 ++++++++++++++++++++++++--------------------- imgui_demo.cpp | 3 +- imgui_internal.h | 12 +++--- imgui_widgets.cpp | 8 +--- 5 files changed, 67 insertions(+), 61 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d05ae4df..75cceb63 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -71,6 +71,7 @@ Other Changes: those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] - ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. +- MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. - ImDrawList: AddCircle(), AddCircleFilled() API can now auto-tessellate when provided a segment count of zero. Alter tessellation quality with 'style.CircleSegmentMaxError'. [@ShironekoBen] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. diff --git a/imgui.cpp b/imgui.cpp index 9a908940..4637aa72 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -807,7 +807,7 @@ CODE // Debug options #define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL #define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window -#define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file +#define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file (particularly helps for Docking, but makes saving slower) // Visual Studio warnings #ifdef _MSC_VER @@ -983,7 +983,7 @@ ImGuiStyle::ImGuiStyle() ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text. SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text when button is larger than text. - DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area by at least this amount. Only applies to regular windows. + DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU. @@ -2621,6 +2621,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) SkipItems = false; Appearing = false; Hidden = false; + IsFallbackWindow = false; HasCloseButton = false; ResizeBorderHeld = -1; BeginCount = 0; @@ -2835,18 +2836,17 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla // An active popup disable hovering on other windows (apart from its own children) // FIXME-OPT: This could be cached/stored within the window. ImGuiContext& g = *GImGui; - if (!g.NavWindow) - return true; - if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) - if (focused_root_window->WasActive && focused_root_window != window->RootWindow) - { - // For the purpose of those flags we differentiate "standard popup" from "modal popup" - // NB: The order of those two tests is important because Modal windows are also Popups. - if (focused_root_window->Flags & ImGuiWindowFlags_Modal) - return false; - if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) - return false; - } + if (g.NavWindow) + if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) + if (focused_root_window->WasActive && focused_root_window != window->RootWindow) + { + // For the purpose of those flags we differentiate "standard popup" from "modal popup" + // NB: The order of those two tests is important because Modal windows are also Popups. + if (focused_root_window->Flags & ImGuiWindowFlags_Modal) + return false; + if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) + return false; + } return true; } @@ -3290,10 +3290,10 @@ void ImGui::UpdateMouseMovingWindowNewFrame() } } -// Initiate moving window, handle left-click and right-click focus +// Initiate moving window when clicking on empty space or title bar. +// Handle left-click and right-click focus. void ImGui::UpdateMouseMovingWindowEndFrame() { - // Initiate moving window ImGuiContext& g = *GImGui; if (g.ActiveId != 0 || g.HoveredId != 0) return; @@ -3787,9 +3787,10 @@ void ImGui::NewFrame() // Create implicit/fallback window - which we will only render it if the user has added something to it. // We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags. // This fallback is particularly important as it avoid ImGui:: calls from crashing. + g.WithinFrameScopeWithImplicitWindow = true; SetNextWindowSize(ImVec2(400,400), ImGuiCond_FirstUseEver); Begin("Debug##Default"); - g.WithinFrameScopeWithImplicitWindow = true; + IM_ASSERT(g.CurrentWindow->IsFallbackWindow == true); #ifdef IMGUI_ENABLE_TEST_ENGINE ImGuiTestEngineHook_PostNewFrame(&g); @@ -4014,10 +4015,8 @@ static void AddWindowToDrawData(ImVector* out_render_list, ImGuiWin static void AddRootWindowToDrawData(ImGuiWindow* window) { ImGuiContext& g = *GImGui; - if (window->Flags & ImGuiWindowFlags_Tooltip) - AddWindowToDrawData(&g.DrawDataBuilder.Layers[1], window); - else - AddWindowToDrawData(&g.DrawDataBuilder.Layers[0], window); + int layer = (window->Flags & ImGuiWindowFlags_Tooltip) ? 1 : 0; + AddWindowToDrawData(&g.DrawDataBuilder.Layers[layer], window); } void ImDrawDataBuilder::FlattenIntoSingleLayer() @@ -4156,16 +4155,17 @@ void ImGui::Render() if (g.FrameCountEnded != g.FrameCount) EndFrame(); g.FrameCountRendered = g.FrameCount; - - // Gather ImDrawList to render (for each active window) g.IO.MetricsRenderWindows = 0; g.DrawDataBuilder.Clear(); + + // Add background ImDrawList if (!g.BackgroundDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.BackgroundDrawList); + // Add ImDrawList to render ImGuiWindow* windows_to_render_top_most[2]; windows_to_render_top_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL; - windows_to_render_top_most[1] = g.NavWindowingTarget ? g.NavWindowingList : NULL; + windows_to_render_top_most[1] = (g.NavWindowingTarget ? g.NavWindowingList : NULL); for (int n = 0; n != g.Windows.Size; n++) { ImGuiWindow* window = g.Windows[n]; @@ -4181,6 +4181,7 @@ void ImGui::Render() if (g.IO.MouseDrawCursor) RenderMouseCursor(&g.ForegroundDrawList, g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); + // Add foreground ImDrawList if (!g.ForegroundDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.ForegroundDrawList); @@ -4837,8 +4838,9 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size // Minimum size if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize))) { + ImGuiWindow* window_for_height = window; new_size = ImMax(new_size, g.Style.WindowMinSize); - new_size.y = ImMax(new_size.y, window->TitleBarHeight() + window->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows + new_size.y = ImMax(new_size.y, window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight() + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows } return new_size; } @@ -5045,6 +5047,10 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au } PopID(); + // Restore nav layer + window->DC.NavLayerCurrent = ImGuiNavLayer_Main; + window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); + // Navigation resize (keyboard/gamepad) if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window) { @@ -5077,10 +5083,6 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au MarkIniSettingsDirty(window); } - // Resize nav layer - window->DC.NavLayerCurrent = ImGuiNavLayer_Main; - window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); - window->Size = window->SizeFull; return ret_auto_fit; } @@ -5129,6 +5131,8 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window) } } +// Draw background and borders +// Draw and handle scrollbars void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size) { ImGuiContext& g = *GImGui; @@ -5340,6 +5344,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const int current_frame = g.FrameCount; const bool first_begin_of_the_frame = (window->LastFrameActive != current_frame); + window->IsFallbackWindow = (g.CurrentWindowStack.Size == 0 && g.WithinFrameScopeWithImplicitWindow); // Update the Appearing flag bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on @@ -5485,6 +5490,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } } + // SELECT VIEWPORT // FIXME-VIEWPORT: In the docking/viewport branch, this is the point where we select the current viewport (which may affect the style) SetCurrentWindow(window); @@ -5595,14 +5601,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->Pos = FindBestWindowPosForPopup(window); // Clamp position/size so window stays visible within its viewport or monitor - // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. ImRect viewport_rect(GetViewportRect()); if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) { - if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. + ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); + if (viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f) { - ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); ClampWindowRect(window, viewport_rect, clamp_padding); } } @@ -5739,20 +5744,22 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping child. // We also disabled this when we have dimming overlay behind this specific one child. // FIXME: More code may rely on explicit sorting of overlapping child window and would need to disable this somehow. Please get in contact if you are affected. - bool render_decorations_in_parent = false; - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) - if (window->DrawList->CmdBuffer.back().ElemCount == 0 && parent_window->DrawList->VtxBuffer.Size > 0) - render_decorations_in_parent = true; - if (render_decorations_in_parent) - window->DrawList = parent_window->DrawList; + { + bool render_decorations_in_parent = false; + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) + if (window->DrawList->CmdBuffer.back().ElemCount == 0 && parent_window->DrawList->VtxBuffer.Size > 0) + render_decorations_in_parent = true; + if (render_decorations_in_parent) + window->DrawList = parent_window->DrawList; - // Handle title bar, scrollbar, resize grips and resize borders - const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow; - const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight); - RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, resize_grip_count, resize_grip_col, resize_grip_draw_size); + // Handle title bar, scrollbar, resize grips and resize borders + const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow; + const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight); + RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, resize_grip_count, resize_grip_col, resize_grip_draw_size); - if (render_decorations_in_parent) - window->DrawList = &window->DrawListInst; + if (render_decorations_in_parent) + window->DrawList = &window->DrawListInst; + } // Draw navigation selection/windowing rectangle border if (g.NavWindowingTargetAnim == window) @@ -7568,7 +7575,7 @@ void ImGui::CloseCurrentPopup() window->DC.NavHideHighlightOneFrame = true; } -bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) +bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags) { ImGuiContext& g = *GImGui; if (!IsPopupOpen(id)) @@ -7578,12 +7585,13 @@ bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags) } char name[20]; - if (extra_flags & ImGuiWindowFlags_ChildMenu) + if (flags & ImGuiWindowFlags_ChildMenu) ImFormatString(name, IM_ARRAYSIZE(name), "##Menu_%02d", g.BeginPopupStack.Size); // Recycle windows based on depth else ImFormatString(name, IM_ARRAYSIZE(name), "##Popup_%08x", id); // Not recycling, so we can close/open during the same frame - bool is_open = Begin(name, NULL, extra_flags | ImGuiWindowFlags_Popup); + flags |= ImGuiWindowFlags_Popup; + bool is_open = Begin(name, NULL, flags); if (!is_open) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display) EndPopup(); @@ -10077,7 +10085,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) char buf[256]; char* p = buf; const char* buf_end = buf + IM_ARRAYSIZE(buf); - ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s", tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : ""); + p += ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s", tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : ""); if (ImGui::TreeNode(tab_bar, "%s", buf)) { for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 05051913..6bee207b 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4685,7 +4685,8 @@ void ShowExampleAppDocuments(bool* p_open) static bool opt_reorderable = true; static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; - if (!ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar)) + bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar); + if (!window_contents_visible) { ImGui::End(); return; diff --git a/imgui_internal.h b/imgui_internal.h index dee16628..a6a40120 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -646,8 +646,9 @@ struct ImVec1 struct ImVec2ih { short x, y; - ImVec2ih() { x = y = 0; } - ImVec2ih(short _x, short _y) { x = _x; y = _y; } + ImVec2ih() { x = y = 0; } + ImVec2ih(short _x, short _y) { x = _x; y = _y; } + explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; } }; // 2D axis aligned bounding-box @@ -976,7 +977,7 @@ struct ImGuiPtrOrIndex }; //----------------------------------------------------------------------------- -// Main imgui context +// Main Dear ImGui context //----------------------------------------------------------------------------- struct ImGuiContext @@ -1416,7 +1417,7 @@ struct IMGUI_API ImGuiWindowTempData struct IMGUI_API ImGuiWindow { char* Name; - ImGuiID ID; // == ImHash(Name) + ImGuiID ID; // == ImHashStr(Name) ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ ImVec2 Pos; // Position (always rounded-up to nearest pixel) ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) @@ -1443,6 +1444,7 @@ struct IMGUI_API ImGuiWindow bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) bool Appearing; // Set during the frame where the window is appearing (or re-appearing) bool Hidden; // Do not display (== (HiddenFrames*** > 0)) + bool IsFallbackWindow; // Set on the "Debug##Default" window. bool HasCloseButton; // Set when the window has a close button (p_open != NULL) signed char ResizeBorderHeld; // Current border being held for resize (-1: none, otherwise 0-3) short BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) @@ -1568,7 +1570,7 @@ struct ImGuiTabBar { ImVector Tabs; ImGuiID ID; // Zero for tab-bars used by docking - ImGuiID SelectedTabId; // Selected tab + ImGuiID SelectedTabId; // Selected tab/window ImGuiID NextSelectedTabId; ImGuiID VisibleTabId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for CTRL+TAB preview) int CurrFrameVisible; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3aa9f13d..eb64ab19 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6047,7 +6047,7 @@ bool ImGui::BeginMenuBar() // We don't clip with current 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 and small windows don't tend to display over the lower-right rounded area, which looks particularly glitchy. ImRect bar_rect = window->MenuBarRect(); - ImRect clip_rect(IM_ROUND(bar_rect.Min.x), IM_ROUND(bar_rect.Min.y + window->WindowBorderSize), IM_ROUND(ImMax(bar_rect.Min.x, bar_rect.Max.x - window->WindowRounding)), IM_ROUND(bar_rect.Max.y)); + ImRect clip_rect(IM_ROUND(bar_rect.Min.x + window->WindowBorderSize), IM_ROUND(bar_rect.Min.y + window->WindowBorderSize), IM_ROUND(ImMax(bar_rect.Min.x, bar_rect.Max.x - ImMax(window->WindowRounding, window->WindowBorderSize))), IM_ROUND(bar_rect.Max.y)); clip_rect.ClipWith(window->OuterRectClipped); PushClipRect(clip_rect.Min, clip_rect.Max, false); @@ -6354,9 +6354,6 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, //------------------------------------------------------------------------- // [SECTION] Widgets: BeginTabBar, EndTabBar, etc. //------------------------------------------------------------------------- -// [BETA API] API may evolve! This code has been extracted out of the Docking branch, -// and some of the construct which are not used in Master may be left here to facilitate merging. -//------------------------------------------------------------------------- // - BeginTabBar() // - BeginTabBarEx() [Internal] // - EndTabBar() @@ -6871,9 +6868,6 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) //------------------------------------------------------------------------- // [SECTION] Widgets: BeginTabItem, EndTabItem, etc. //------------------------------------------------------------------------- -// [BETA API] API may evolve! This code has been extracted out of the Docking branch, -// and some of the construct which are not used in Master may be left here to facilitate merging. -//------------------------------------------------------------------------- // - BeginTabItem() // - EndTabItem() // - TabItemEx() [Internal] From bbe946fb6c9ba015a5b1a6a938ff7a4b5af03c32 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Jan 2020 20:08:04 +0100 Subject: [PATCH 241/384] Minor fixes/tweaks (some to reduce drift wiih master branch) --- imgui.cpp | 15 ++++++--------- imgui.h | 2 +- imgui_demo.cpp | 2 +- imgui_draw.cpp | 8 ++++---- imgui_internal.h | 10 +++++++--- imgui_widgets.cpp | 4 ---- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b0f350bc..9cdc2f33 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -388,7 +388,6 @@ CODE - IMGUI_DISABLE_TEST_WINDOWS -> use IMGUI_DISABLE_DEMO_WINDOWS - 2019/12/08 (1.75) - obsoleted calling ImDrawList::PrimReserve() with a negative count (which was the vaguely documented and rarely if ever used). Instead we added an explicit PrimUnreserve() API. - 2019/12/06 (1.75) - removed implicit default parameter to IsMouseDragging(int button = 0) to be consistent with other mouse functions (none of the other functions have it). ->>>>>>> refs/heads/master - 2019/11/21 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency. - 2019/11/19 (1.74) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency. @@ -3848,7 +3847,7 @@ void ImGui::NewFrame() ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); for (int n = 0; n < g.Viewports.Size; n++) virtual_space.Add(g.Viewports[n]->GetRect()); - g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y); + g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min, virtual_space.Max); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError); g.DrawListSharedData.InitialFlags = ImDrawListFlags_None; @@ -4500,7 +4499,7 @@ void ImGui::Render() AddRootWindowToDrawData(window); } for (int n = 0; n < IM_ARRAYSIZE(windows_to_render_top_most); n++) - if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the tp-most window + if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the top-most window AddRootWindowToDrawData(windows_to_render_top_most[n]); // Draw software mouse cursor if requested @@ -5459,7 +5458,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au } PopID(); - // Resize nav layer + // Restore nav layer window->DC.NavLayerCurrent = ImGuiNavLayer_Main; window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); @@ -6341,13 +6340,12 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding); } - const bool is_undocked_or_docked_visible = !window->DockIsActive || window->DockTabIsVisible; - // Since 1.71, child window can render their decoration (bg color, border, scrollbars, etc.) within their parent to save a draw call. // When using overlapping child windows, this will break the assumption that child z-order is mapped to submission order. // We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping child. // We also disabled this when we have dimming overlay behind this specific one child. // FIXME: More code may rely on explicit sorting of overlapping child window and would need to disable this somehow. Please get in contact if you are affected. + const bool is_undocked_or_docked_visible = !window->DockIsActive || window->DockTabIsVisible; if (is_undocked_or_docked_visible) { bool render_decorations_in_parent = false; @@ -6464,7 +6462,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) NavInitWindow(window, false); } - // Close from platform window + // Close requested by platform window if (p_open != NULL && window->Viewport->PlatformRequestClose && window->Viewport != GetMainViewport()) { if (!window->DockIsActive || window->DockTabIsVisible) @@ -15280,8 +15278,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) char buf[256]; char* p = buf; const char* buf_end = buf + IM_ARRAYSIZE(buf); - p += ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s", - tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : ""); + p += ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s", tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : ""); if (tab_bar->Flags & ImGuiTabBarFlags_DockNode) { p += ImFormatString(p, buf_end - p, " { "); diff --git a/imgui.h b/imgui.h index 8cd0263a..11b73b87 100644 --- a/imgui.h +++ b/imgui.h @@ -1454,7 +1454,7 @@ struct ImGuiIO ImGuiConfigFlags ConfigFlags; // = 0 // See ImGuiConfigFlags_ enum. Set by user/application. Gamepad/keyboard navigation options, etc. ImGuiBackendFlags BackendFlags; // = 0 // See ImGuiBackendFlags_ enum. Set by back-end (imgui_impl_xxx files or custom back-end) to communicate features supported by the back-end. - ImVec2 DisplaySize; // // Main display size, in pixels. This is for the default viewport. Use BeginViewport() for other viewports. + ImVec2 DisplaySize; // // Main display size, in pixels. This is for the default viewport. float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. float IniSavingRate; // = 5.0f // Minimum time between saving positions/sizes to .ini file, in seconds. const char* IniFilename; // = "imgui.ini" // Path to .ini file. Set NULL to disable automatic .ini loading/saving, if e.g. you want to manually load/save from memory. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 9c321b85..3e2fbef5 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4867,7 +4867,7 @@ void ShowExampleAppDocuments(bool* p_open) Target_DockSpaceAndWindow // Create documents as regular windows, and create an embedded dockspace }; static Target opt_target = Target_Tab; - static bool opt_reorderable = true; + static bool opt_reorderable = true; static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; // When (opt_target == Target_DockSpaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant") diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 627e3e25..228df410 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3153,10 +3153,10 @@ void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, Im pos -= offset; const ImTextureID tex_id = font_atlas->TexID; draw_list->PushTextureID(tex_id); - draw_list->AddImage(tex_id, pos + ImVec2(1, 0)*scale, pos + ImVec2(1, 0)*scale + size*scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos + ImVec2(2, 0)*scale, pos + ImVec2(2, 0)*scale + size*scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos, pos + size*scale, uv[2], uv[3], col_border); - draw_list->AddImage(tex_id, pos, pos + size*scale, uv[0], uv[1], col_fill); + draw_list->AddImage(tex_id, pos + ImVec2(1,0)*scale, pos + ImVec2(1,0)*scale + size*scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos + ImVec2(2,0)*scale, pos + ImVec2(2,0)*scale + size*scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos, pos + size*scale, uv[2], uv[3], col_border); + draw_list->AddImage(tex_id, pos, pos + size*scale, uv[0], uv[1], col_fill); draw_list->PopTextureID(); } } diff --git a/imgui_internal.h b/imgui_internal.h index f17a48d8..65f32217 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1004,7 +1004,7 @@ struct ImGuiNextItemData }; //----------------------------------------------------------------------------- -// Docking, Tabs +// Tabs //----------------------------------------------------------------------------- struct ImGuiShrinkWidthItem @@ -1022,6 +1022,10 @@ struct ImGuiPtrOrIndex ImGuiPtrOrIndex(int index) { Ptr = NULL; Index = index; } }; +//----------------------------------------------------------------------------- +// Docking +//----------------------------------------------------------------------------- + // Extend ImGuiDockNodeFlags_ enum ImGuiDockNodeFlagsPrivate_ { @@ -1113,7 +1117,7 @@ struct ImGuiDockNode }; //----------------------------------------------------------------------------- -// Main imgui context +// Main Dear ImGui context //----------------------------------------------------------------------------- struct ImGuiContext @@ -1610,7 +1614,7 @@ struct IMGUI_API ImGuiWindow bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) bool Appearing; // Set during the frame where the window is appearing (or re-appearing) bool Hidden; // Do not display (== (HiddenFrames*** > 0)) - bool IsFallbackWindow; + bool IsFallbackWindow; // Set on the "Debug##Default" window. bool HasCloseButton; // Set when the window has a close button (p_open != NULL) signed char ResizeBorderHeld; // Current border being held for resize (-1: none, otherwise 0-3) short BeginCount; // Number of Begin() during the current frame (generally 0 or 1, 1+ if appending via multiple Begin/End pairs) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b033ca2d..fb5eb516 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6366,8 +6366,6 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, //------------------------------------------------------------------------- // [SECTION] Widgets: BeginTabBar, EndTabBar, etc. //------------------------------------------------------------------------- -// [BETA API] API may evolve! -//------------------------------------------------------------------------- // - BeginTabBar() // - BeginTabBarEx() [Internal] // - EndTabBar() @@ -6926,8 +6924,6 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) //------------------------------------------------------------------------- // [SECTION] Widgets: BeginTabItem, EndTabItem, etc. //------------------------------------------------------------------------- -// [BETA API] API may evolve! -//------------------------------------------------------------------------- // - BeginTabItem() // - EndTabItem() // - TabItemEx() [Internal] From 3b828e6f96ea8a2fdbf5beda942bcd43a4b1f613 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 28 Jan 2020 20:29:07 +0100 Subject: [PATCH 242/384] Fix following bbe946f (ImRect <> ImVec4) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 9cdc2f33..af9e76f3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3847,7 +3847,7 @@ void ImGui::NewFrame() ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); for (int n = 0; n < g.Viewports.Size; n++) virtual_space.Add(g.Viewports[n]->GetRect()); - g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min, virtual_space.Max); + g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError); g.DrawListSharedData.InitialFlags = ImDrawListFlags_None; From 7794b104c5c6aa0f41680cf527b528f451e7352e Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 29 Jan 2020 11:40:49 +0200 Subject: [PATCH 243/384] Backends: SDL/Viewports: Fix crash when SDL backend is used with DirectX graphics API and system does not support Vulkan. We must pass this flag only when we intend to render using vulkan backend. --- examples/imgui_impl_sdl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 32ac4022..8d52a212 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -74,6 +74,7 @@ static bool g_MousePressed[3] = { false, false, false }; static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; static bool g_MouseCanUseGlobalState = true; +static bool g_UseVulkan = false; // Forward Declarations static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context); @@ -240,6 +241,7 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window) #if !SDL_HAS_VULKAN IM_ASSERT(0 && "Unsupported"); #endif + g_UseVulkan = true; return ImGui_ImplSDL2_Init(window, NULL); } @@ -467,7 +469,7 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) } Uint32 sdl_flags = 0; - sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN; + sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (g_UseVulkan ? SDL_WINDOW_VULKAN : 0); sdl_flags |= SDL_GetWindowFlags(g_Window) & SDL_WINDOW_ALLOW_HIGHDPI; sdl_flags |= SDL_WINDOW_HIDDEN; sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0; From 0e89041997d1e3bd0686edab8d2e43860a47061a Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Jan 2020 16:35:30 +0100 Subject: [PATCH 244/384] Internals: ButtonEx, ButtonBehavior can support multiple mouse buttons. --- imgui_internal.h | 12 ++++++- imgui_widgets.cpp | 81 ++++++++++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index a6a40120..db9aaa18 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -433,7 +433,15 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_NoHoldingActiveId = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_NoNavFocus = 1 << 14, // don't override navigation focus when activated ImGuiButtonFlags_NoHoveredOnNav = 1 << 15, // don't report as hovered when navigated on - ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold + ImGuiButtonFlags_MouseButtonLeft = 1 << 16, // [Default] react on left mouse button + ImGuiButtonFlags_MouseButtonRight = 1 << 17, // react on right mouse button + ImGuiButtonFlags_MouseButtonMiddle = 1 << 18, // react on center mouse button + + ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, + ImGuiButtonFlags_MouseButtonShift_ = 16, + ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, + ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold, + ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease }; enum ImGuiSliderFlags_ @@ -1033,6 +1041,7 @@ struct ImGuiContext ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) + int ActiveIdMouseButton; ImGuiID ActiveIdPreviousFrame; bool ActiveIdPreviousFrameIsAlive; bool ActiveIdPreviousFrameHasBeenEditedBefore; @@ -1225,6 +1234,7 @@ struct ImGuiContext ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = NULL; ActiveIdSource = ImGuiInputSource_None; + ActiveIdMouseButton = 0; ActiveIdPreviousFrame = 0; ActiveIdPreviousFrameIsAlive = false; ActiveIdPreviousFrameHasBeenEditedBefore = false; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index eb64ab19..099673f3 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -464,9 +464,13 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool return false; } - // Default behavior requires click+release on same spot + // Default only reacts to left mouse button + if ((flags & ImGuiButtonFlags_MouseButtonMask_) == 0) + flags |= ImGuiButtonFlags_MouseButtonDefault_; + + // Default behavior requires click + release inside bounding box if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0) - flags |= ImGuiButtonFlags_PressedOnClickRelease; + flags |= ImGuiButtonFlags_PressedOnDefault_; ImGuiWindow* backup_hovered_window = g.HoveredWindow; const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredRootWindow == window; @@ -505,38 +509,55 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (hovered && (flags & ImGuiButtonFlags_AllowItemOverlap) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0)) hovered = false; - // Mouse + // Mouse handling if (hovered) { if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { - if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere)) && g.IO.MouseClicked[0]) - { - SetActiveID(id, window); - if (!(flags & ImGuiButtonFlags_NoNavFocus)) - SetFocusID(id, window); - FocusWindow(window); - } - if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) + // Poll buttons + int mouse_button_clicked = -1; + int mouse_button_released = -1; + if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseClicked[0]) { mouse_button_clicked = 0; } + else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseClicked[1]) { mouse_button_clicked = 1; } + else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseClicked[2]) { mouse_button_clicked = 2; } + if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseReleased[0]) { mouse_button_released = 0; } + else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseReleased[1]) { mouse_button_released = 1; } + else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseReleased[2]) { mouse_button_released = 2; } + + if (mouse_button_clicked != -1 && g.ActiveId != id) { - pressed = true; - if (flags & ImGuiButtonFlags_NoHoldingActiveId) - ClearActiveID(); - else - SetActiveID(id, window); // Hold on ID - FocusWindow(window); + if (flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere)) + { + SetActiveID(id, window); + g.ActiveIdMouseButton = mouse_button_clicked; + if (!(flags & ImGuiButtonFlags_NoNavFocus)) + SetFocusID(id, window); + FocusWindow(window); + } + if ((flags & ImGuiButtonFlags_PressedOnClick) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[mouse_button_clicked])) + { + pressed = true; + if (flags & ImGuiButtonFlags_NoHoldingActiveId) + ClearActiveID(); + else + SetActiveID(id, window); // Hold on ID + g.ActiveIdMouseButton = mouse_button_clicked; + FocusWindow(window); + } } - if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) + if ((flags & ImGuiButtonFlags_PressedOnRelease) && mouse_button_released != -1) { - if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps + // Repeat mode trumps on release behavior + if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button_released] >= g.IO.KeyRepeatDelay)) pressed = true; ClearActiveID(); } // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). // Relies on repeat logic of IsMouseClicked() but we may as well do it ourselves if we end up exposing finer RepeatDelay/RepeatRate settings. - if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && g.IO.MouseDownDuration[0] > 0.0f && IsMouseClicked(0, true)) - pressed = true; + if (g.ActiveId == id && (flags & ImGuiButtonFlags_Repeat)) + if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, true)) + pressed = true; } if (pressed) @@ -548,7 +569,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.NavId == id && !g.NavDisableHighlight && g.NavDisableMouseHover && (g.ActiveId == 0 || g.ActiveId == id || g.ActiveId == window->MoveId)) if (!(flags & ImGuiButtonFlags_NoHoveredOnNav)) hovered = true; - if (g.NavActivateDownId == id) { bool nav_activated_by_code = (g.NavActivateId == id); @@ -568,24 +588,25 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool bool held = false; if (g.ActiveId == id) { - if (pressed) - g.ActiveIdHasBeenPressedBefore = true; if (g.ActiveIdSource == ImGuiInputSource_Mouse) { if (g.ActiveIdIsJustActivated) g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; - if (g.IO.MouseDown[0]) + + const int mouse_button = g.ActiveIdMouseButton; + IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT); + if (g.IO.MouseDown[mouse_button]) { held = true; } else { - const bool release_in = hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) != 0; - const bool release_anywhere = (flags & ImGuiButtonFlags_PressedOnClickReleaseAnywhere) != 0; + bool release_in = hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) != 0; + bool release_anywhere = (flags & ImGuiButtonFlags_PressedOnClickReleaseAnywhere) != 0; if ((release_in || release_anywhere) && !g.DragDropActive) { - bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDownWasDoubleClick[0]; - bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay; // Repeat mode trumps + bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDownWasDoubleClick[mouse_button]; + bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button] >= g.IO.KeyRepeatDelay; // Repeat mode trumps if (!is_double_click_release && !is_repeating_already) pressed = true; } @@ -599,6 +620,8 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.NavActivateDownId != id) ClearActiveID(); } + if (pressed) + g.ActiveIdHasBeenPressedBefore = true; } if (out_hovered) *out_hovered = hovered; From 0a23582718d4b1fe8b32798ded890752e79970ad Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 29 Jan 2020 20:11:42 +0100 Subject: [PATCH 245/384] Examples: VS projects: Removed inconsistent/extraneous explicit linkage to imm32. --- examples/example_sdl_directx11/example_sdl_directx11.vcxproj | 4 ++-- .../example_win32_directx10/example_win32_directx10.vcxproj | 4 ++-- .../example_win32_directx11/example_win32_directx11.vcxproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj index 7af2c9c0..804bd500 100644 --- a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj @@ -129,7 +129,7 @@ true true %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) Console @@ -149,7 +149,7 @@ true true %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) Console diff --git a/examples/example_win32_directx10/example_win32_directx10.vcxproj b/examples/example_win32_directx10/example_win32_directx10.vcxproj index 0f351dde..5c3aa69f 100644 --- a/examples/example_win32_directx10/example_win32_directx10.vcxproj +++ b/examples/example_win32_directx10/example_win32_directx10.vcxproj @@ -121,7 +121,7 @@ true true true - d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) Console @@ -139,7 +139,7 @@ true true true - d3d10.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + d3d10.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) Console diff --git a/examples/example_win32_directx11/example_win32_directx11.vcxproj b/examples/example_win32_directx11/example_win32_directx11.vcxproj index ce2434b0..bcb71bc4 100644 --- a/examples/example_win32_directx11/example_win32_directx11.vcxproj +++ b/examples/example_win32_directx11/example_win32_directx11.vcxproj @@ -120,7 +120,7 @@ true true true - d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) Console @@ -138,7 +138,7 @@ true true true - d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) Console From 6e1f8be07bdbf242f8360f26504871eaf1f59a8e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Jan 2020 15:13:36 +0100 Subject: [PATCH 246/384] Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 6 +++++- imgui.h | 2 +- imgui_internal.h | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 75cceb63..ebd82d44 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -72,6 +72,7 @@ Other Changes: - ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. - MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. +- Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog] - ImDrawList: AddCircle(), AddCircleFilled() API can now auto-tessellate when provided a segment count of zero. Alter tessellation quality with 'style.CircleSegmentMaxError'. [@ShironekoBen] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. diff --git a/imgui.cpp b/imgui.cpp index 4637aa72..899a323b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5161,10 +5161,14 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar if (!(flags & ImGuiWindowFlags_NoBackground)) { ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags)); + bool override_alpha = false; float alpha = 1.0f; if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasBgAlpha) + { alpha = g.NextWindowData.BgAlphaVal; - if (alpha != 1.0f) + override_alpha = true; + } + if (override_alpha) bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT); window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot); } diff --git a/imgui.h b/imgui.h index 5fab99dc..55c9b2bb 100644 --- a/imgui.h +++ b/imgui.h @@ -294,7 +294,7 @@ namespace ImGui IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. set an axis to 0.0f to leave it automatic. call before Begin() IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() IMGUI_API void SetNextWindowFocus(); // set next window to be focused / top-most. call before Begin() - IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg. you may also use ImGuiWindowFlags_NoBackground. + IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily override the Alpha component of ImGuiCol_WindowBg/ChildBg/PopupBg. you may also use ImGuiWindowFlags_NoBackground. IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects. IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 0); // (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0,0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects. IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed(). diff --git a/imgui_internal.h b/imgui_internal.h index db9aaa18..b1eb00d4 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -939,7 +939,7 @@ struct ImGuiNextWindowData ImRect SizeConstraintRect; ImGuiSizeCallback SizeCallback; void* SizeCallbackUserData; - float BgAlphaVal; + float BgAlphaVal; // Override background alpha ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } From 8cbb693f4764f19983588d5f1b9ddd92a7873c8f Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Sat, 25 Jan 2020 23:49:23 +0300 Subject: [PATCH 247/384] Emscripten: Allow filesystem support. (#3005) Filesystem functions perfectly work for Emscripten platform. This changes remove extra changes added by #2734. You can still disable filesystem functions by defining IMGUI_DISABLE_FILE_FUNCTIONS. --- docs/CHANGELOG.txt | 3 ++- imgui_internal.h | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ebd82d44..6f73c077 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -85,6 +85,7 @@ Other Changes: - Misc: Added misc/single_file/imgui_single_file.h, We use this to validate compiling all *.cpp files in a same compilation unit. Actual users of that technique (also called "Unity builds") can generally provide this themselves, so we don't really recommend you use this. [@rokups] +- CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] - Backends: GLFW, SDL, Win32, OSX, Allegro: Added support for ImGuiMouseCursor_NotAllowed. [@rokups] - Backends: GLFW: Added support for the missing mouse cursors newly added in GLFW 3.4+. [@rokups] - Backends: SDL: Wayland: use SDL_GetMouseState (because there is no global mouse state available @@ -98,7 +99,7 @@ Other Changes: the later may be problematic if compiling with recent Windows SDK and you want your app to run on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) - Backends: Glut: Improved FreeGLUT support for MinGW. (#3004) [@podsvirov] -- CI: Added PVS-Studio static analysis on the continuous-integration server. [@rokups] +- Backends: Emscripten: Avoid forcefully setting IMGUI_DISABLE_FILE_FUNCTIONS. (#3005) [@podsvirov] - Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might automatically use it). (#2919, #2798) diff --git a/imgui_internal.h b/imgui_internal.h index b1eb00d4..18b960a4 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -270,9 +270,6 @@ static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) #endif // Helpers: File System -#if defined(__EMSCRIPTEN__) && !defined(IMGUI_DISABLE_FILE_FUNCTIONS) -#define IMGUI_DISABLE_FILE_FUNCTIONS -#endif #ifdef IMGUI_DISABLE_FILE_FUNCTIONS #define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS typedef void* ImFileHandle; From 05a49f0413232d2483e902089d2e9e99b40ce3b2 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 30 Jan 2020 17:15:11 +0100 Subject: [PATCH 248/384] Examples: Emscripten: Demonstrating embedding fonts in Makefile and code. (#2953) [@Oipo] --- docs/CHANGELOG.txt | 5 ++-- examples/example_emscripten/Makefile | 39 +++++++++++++++++++++------- examples/example_emscripten/main.cpp | 13 ++++++---- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6f73c077..9ee78e80 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -100,12 +100,13 @@ Other Changes: on Windows 7. You can instead try linking with Xinput9_1_0.lib instead. (#2716) - Backends: Glut: Improved FreeGLUT support for MinGW. (#3004) [@podsvirov] - Backends: Emscripten: Avoid forcefully setting IMGUI_DISABLE_FILE_FUNCTIONS. (#3005) [@podsvirov] -- Examples: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking +- Examples: OpenGL: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might automatically use it). (#2919, #2798) +- Examples: OpenGL: Added support for glbindings OpenGL loader. (#2870) [@rokups] +- Examples: Emscripten: Demonstrating embedding fonts in Makefile and code. (#2953) [@Oipo] - Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed even if underlying system event loop gets paused due to app nap. (#2910, #2917) [@bear24rw] -- Examples: Added support for glbindings OpenGL loader. (#2870) [@rokups] ----------------------------------------------------------------------- diff --git a/examples/example_emscripten/Makefile b/examples/example_emscripten/Makefile index f5b7369a..9833270e 100644 --- a/examples/example_emscripten/Makefile +++ b/examples/example_emscripten/Makefile @@ -1,8 +1,10 @@ # # Makefile to use with emscripten # See https://emscripten.org/docs/getting_started/downloads.html -# for installation instructions. This Makefile assumes you have -# loaded emscripten's environment. +# for installation instructions. +# +# This Makefile assumes you have loaded emscripten's environment. +# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead) # # Running `make` will produce three files: # - example_emscripten.html @@ -13,7 +15,6 @@ CC = emcc CXX = em++ - EXE = example_emscripten.html SOURCES = main.cpp SOURCES += ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp @@ -21,21 +22,41 @@ SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -EMS = -s USE_SDL=2 -s WASM=1 +##--------------------------------------------------------------------- +## EMSCRIPTEN OPTIONS +##--------------------------------------------------------------------- + +EMS += -s USE_SDL=2 -s WASM=1 EMS += -s ALLOW_MEMORY_GROWTH=1 EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0 EMS += -s ASSERTIONS=1 -EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS -# Uncomment next line to fix possible rendering bugs with emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) + +# Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) #EMS += -s BINARYEN_TRAP_MODE=clamp #EMS += -s SAFE_HEAP=1 ## Adds overhead -CPPFLAGS = -I../ -I../../ +# Emscripten allows preloading a file or folder to be accessible at runtime. +# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts" +# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html +# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.) +USE_FILE_SYSTEM ?= 0 +ifeq ($(USE_FILE_SYSTEM), 0) +EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS +endif +ifeq ($(USE_FILE_SYSTEM), 1) +LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts +endif + +##--------------------------------------------------------------------- +## FINAL BUILD FLAGS +##--------------------------------------------------------------------- + +CPPFLAGS += -I../ -I../../ #CPPFLAGS += -g CPPFLAGS += -Wall -Wformat -Os CPPFLAGS += $(EMS) -LIBS = $(EMS) -LDFLAGS = --shell-file shell_minimal.html +LIBS += $(EMS) +LDFLAGS += --shell-file shell_minimal.html ##--------------------------------------------------------------------- ## BUILD RULES diff --git a/examples/example_emscripten/main.cpp b/examples/example_emscripten/main.cpp index d9a6406d..f0eb3a2b 100644 --- a/examples/example_emscripten/main.cpp +++ b/examples/example_emscripten/main.cpp @@ -83,13 +83,16 @@ int main(int, char**) // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. // - Read 'docs/FONTS.txt' for more instructions and details. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + // - Emscripten allows preloading a file or folder to be accessible at runtime. See Makefile for details. //io.Fonts->AddFontDefault(); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); - //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); - //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); +#ifndef IMGUI_DISABLE_FILE_FUNCTIONS + io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); +#endif // This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them. emscripten_set_main_loop_arg(main_loop, NULL, 0, true); From 9cff4d6e5e76dd18d9c4ee7a1560563da2059a44 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 29 Jan 2020 16:14:58 +0200 Subject: [PATCH 249/384] Columns: ImDrawList::Channels* functions now work inside columns. Use a private splitter in columns, paving way for removal of obsolete ImDrawList::Channels* functions. --- docs/CHANGELOG.txt | 2 ++ imgui.h | 7 +++++-- imgui_draw.cpp | 2 +- imgui_internal.h | 1 + imgui_widgets.cpp | 14 +++++++------- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9ee78e80..1c952838 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -79,6 +79,8 @@ Other Changes: In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as we will rework the circle rendering functions to use textures and automatic segment count selection, those new api can fill a gap. [@ShironekoBen] +- Columns: ImDrawList::Channels* functions now work inside columns. Added extra comments to + suggest using user-owned ImDrawListSplitter instead of ImDrawList functions. [@rokups] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] - Misc: Disable format checks when using stb_printf, to allow using extra formats. Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari] diff --git a/imgui.h b/imgui.h index 55c9b2bb..4cbe196e 100644 --- a/imgui.h +++ b/imgui.h @@ -1987,8 +1987,11 @@ struct ImDrawList IMGUI_API ImDrawList* CloneOutput() const; // Create a clone of the CmdBuffer/IdxBuffer/VtxBuffer. // Advanced: Channels - // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives) - // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end) + // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit FG primitives before BG primitives) + // - Use to minimize draw calls (e.g. if going back-and-forth between multiple clipping rectangles, prefer to append into separate channels then merge at the end) + // - FIXME-OBSOLETE: This API shouldn't have been in ImDrawList in the first place! + // Prefer using your own persistent copy of ImDrawListSplitter as you can stack them. + // Using the ImDrawList::ChannelsXXXX you cannot stack a split over another. inline void ChannelsSplit(int count) { _Splitter.Split(this, count); } inline void ChannelsMerge() { _Splitter.Merge(this); } inline void ChannelsSetCurrent(int n) { _Splitter.SetCurrentChannel(this, n); } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 2f3370e0..b457b532 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1307,7 +1307,7 @@ void ImDrawListSplitter::ClearFreeMemory() void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count) { - IM_ASSERT(_Current == 0 && _Count <= 1); + IM_ASSERT(_Current == 0 && _Count <= 1 && "Nested channel splitting is not supported. Please use separate instances of ImDrawListSplitter."); int old_channels_count = _Channels.Size; if (old_channels_count < channels_count) _Channels.resize(channels_count); diff --git a/imgui_internal.h b/imgui_internal.h index 18b960a4..6df52433 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -843,6 +843,7 @@ struct ImGuiColumns ImRect HostClipRect; // Backup of ClipRect at the time of BeginColumns() ImRect HostWorkRect; // Backup of WorkRect at the time of BeginColumns() ImVector Columns; + ImDrawListSplitter Splitter; ImGuiColumns() { Clear(); } void Clear() diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 099673f3..d5eed2cd 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7400,7 +7400,7 @@ void ImGui::PushColumnsBackground() ImGuiColumns* columns = window->DC.CurrentColumns; if (columns->Count == 1) return; - window->DrawList->ChannelsSetCurrent(0); + columns->Splitter.SetCurrentChannel(window->DrawList, 0); int cmd_size = window->DrawList->CmdBuffer.Size; PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false); IM_UNUSED(cmd_size); @@ -7413,7 +7413,7 @@ void ImGui::PopColumnsBackground() ImGuiColumns* columns = window->DC.CurrentColumns; if (columns->Count == 1) return; - window->DrawList->ChannelsSetCurrent(columns->Current + 1); + columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1); PopClipRect(); } @@ -7504,8 +7504,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag if (columns->Count > 1) { - window->DrawList->ChannelsSplit(1 + columns->Count); - window->DrawList->ChannelsSetCurrent(1); + columns->Splitter.Split(window->DrawList, 1 + columns->Count); + columns->Splitter.SetCurrentChannel(window->DrawList, 1); PushColumnClipRect(0); } @@ -7544,14 +7544,14 @@ void ImGui::NextColumn() // Columns 1+ ignore IndentX (by canceling it out) // FIXME-COLUMNS: Unnecessary, could be locked? window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding; - window->DrawList->ChannelsSetCurrent(columns->Current + 1); + columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1); } else { // New row/line // Column 0 honor IndentX window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); - window->DrawList->ChannelsSetCurrent(1); + columns->Splitter.SetCurrentChannel(window->DrawList, 1); columns->Current = 0; columns->LineMinY = columns->LineMaxY; } @@ -7581,7 +7581,7 @@ void ImGui::EndColumns() if (columns->Count > 1) { PopClipRect(); - window->DrawList->ChannelsMerge(); + columns->Splitter.Merge(window->DrawList); } const ImGuiColumnsFlags flags = columns->Flags; From 47fab0e166fe91966a16855fbcbecffcaaee5fd2 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 12:27:57 +0100 Subject: [PATCH 250/384] Misc renaming, comments. Docs: add missing spacing to Changelog. --- docs/CHANGELOG.txt | 11 +++++++++++ imgui.cpp | 15 ++++++++------- imgui_demo.cpp | 6 +++--- imgui_internal.h | 6 +++--- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1c952838..165e46bb 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -8,6 +8,7 @@ Changes to the examples/bindings are included within the individual .cpp files i RELEASE NOTES: https://github.com/ocornut/imgui/releases REPORT ISSUES, ASK QUESTIONS: https://github.com/ocornut/imgui/issues COMMITS HISTORY: https://github.com/ocornut/imgui/commits/master +FAQ https://www.dearimgui.org/faq/ WHEN TO UPDATE? @@ -34,6 +35,7 @@ HOW TO UPDATE? ----------------------------------------------------------------------- Breaking Changes: + - Removed redirecting functions/enums names that were marked obsolete in 1.53 (December 2017): - ShowTestWindow() -> use ShowDemoWindow() - IsRootWindowFocused() -> use IsWindowFocused(ImGuiFocusedFlags_RootWindow) @@ -63,6 +65,7 @@ Breaking Changes: adding multiple points into it, you may need to fix your initial value. Other Changes: + - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. - ColorEdit: Fix label alignment when using ImGuiColorEditFlags_NoInputs. (#2955) [@rokups] @@ -118,6 +121,7 @@ Other Changes: Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.74 Breaking Changes: + - Removed redirecting functions/enums names that were marked obsolete in 1.52 (October 2017): - Begin() [old 5 args version] -> use Begin() [3 args], use SetNextWindowSize() SetNextWindowBgAlpha() if needed - IsRootWindowOrAnyChildHovered() -> use IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows) @@ -142,6 +146,7 @@ Breaking Changes: The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate] Other Changes: + - InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787) - InputText: Filter out ASCII 127 (DEL) emitted by low-level OSX layer, as we are using the Key value. (#2578) - Layout: Fixed a couple of subtle bounding box vertical positioning issues relating to the handling of text @@ -274,6 +279,7 @@ Other Changes: Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.72 Breaking Changes: + - Removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): - ImGuiCol_Column*, ImGuiSetCond_* enums. - IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow() functions. @@ -285,6 +291,7 @@ Breaking Changes: Kept redirection function (will obsolete). (#581, #324) Other Changes: + - Scrolling: Made mouse-wheel scrolling lock the underlying window until the mouse is moved again or until a short delay expires (~2 seconds). This allow uninterrupted scroll even if child windows are passing under the mouse cursor. (#2604) @@ -357,6 +364,7 @@ Other Changes: Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.71 Breaking Changes: + - IO: changed AddInputCharacter(unsigned short c) signature to AddInputCharacter(unsigned int c). - Renamed SetNextTreeNodeOpen() to SetNextItemOpen(). Kept inline redirection function (will obsolete). - Window: rendering of child windows outer decorations (e.g. bg color, border, scrollbars) is now @@ -367,6 +375,7 @@ Breaking Changes: to the creation of overlapping child windows. Please reach out if you are affected by this change! Other Changes: + - Window: clarified behavior of SetNextWindowContentSize(). Content size is defined as the size available after removal of WindowPadding on each sides. So SetNextWindowContentSize(ImVec2(100,100)) + auto-resize will always allow submitting a 100x100 item without creating a scrollbar, regarding of WindowPadding. @@ -439,6 +448,7 @@ Other Changes: Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.70 Breaking Changes: + - ImDrawList: Improved algorithm for mitre joints on thick lines, preserving correct thickness up to 90 degrees angles (e.g. rectangles). If you have custom rendering using thick lines, they will appear a little thicker now. (#2518) [@rmitton] @@ -451,6 +461,7 @@ Breaking Changes: on them but it is possible you have!). Other Changes: + - ImDrawList: Added ImDrawCallback_ResetRenderState, a special ImDrawList::AddCallback() value to request the renderer back-end to reset its render state. (#2037, #1639, #2452) Examples: Added support for ImDrawCallback_ResetRenderState in all renderer back-ends. Each diff --git a/imgui.cpp b/imgui.cpp index 899a323b..3fa63e0d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3766,7 +3766,7 @@ void ImGui::NewFrame() window->Active = false; window->WriteAccessed = false; - // Garbage collect (this is totally functional but we may need decide if the side-effects are desirable) + // Garbage collect transient buffers of recently unused windows if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time) GcCompactTransientWindowBuffers(window); } @@ -3887,7 +3887,7 @@ void ImGui::Shutdown(ImGuiContext* context) IM_DELETE(g.Windows[i]); g.Windows.clear(); g.WindowsFocusOrder.clear(); - g.WindowsSortBuffer.clear(); + g.WindowsTempSortBuffer.clear(); g.CurrentWindow = NULL; g.CurrentWindowStack.clear(); g.WindowsById.Clear(); @@ -4123,19 +4123,19 @@ void ImGui::EndFrame() // Sort the window list so that all child windows are after their parent // We cannot do that on FocusWindow() because childs may not exist yet - g.WindowsSortBuffer.resize(0); - g.WindowsSortBuffer.reserve(g.Windows.Size); + g.WindowsTempSortBuffer.resize(0); + g.WindowsTempSortBuffer.reserve(g.Windows.Size); for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* window = g.Windows[i]; if (window->Active && (window->Flags & ImGuiWindowFlags_ChildWindow)) // if a child is active its parent will add it continue; - AddWindowToSortBuffer(&g.WindowsSortBuffer, window); + AddWindowToSortBuffer(&g.WindowsTempSortBuffer, window); } // This usually assert if there is a mismatch between the ImGuiWindowFlags_ChildWindow / ParentWindow values and DC.ChildWindows[] in parents, aka we've done something wrong. - IM_ASSERT(g.Windows.Size == g.WindowsSortBuffer.Size); - g.Windows.swap(g.WindowsSortBuffer); + IM_ASSERT(g.Windows.Size == g.WindowsTempSortBuffer.Size); + g.Windows.swap(g.WindowsTempSortBuffer); g.IO.MetricsActiveWindows = g.WindowsActiveCount; // Unlock font atlas @@ -10119,6 +10119,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) }; Funcs::NodeWindows(g.Windows, "Windows"); + //Funcs::NodeWindows(g.WindowsFocusOrder, "WindowsFocusOrder"); if (ImGui::TreeNode("DrawLists", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size)) { for (int i = 0; i < g.DrawDataBuilder.Layers[0].Size; i++) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 6bee207b..54b3a9f6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1790,7 +1790,7 @@ static void ShowDemoWindowLayout() // Child 1: no border, enable horizontal scrollbar { ImGuiWindowFlags window_flags = ImGuiWindowFlags_HorizontalScrollbar | (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0); - ImGui::BeginChild("Child1", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f, 260), false, window_flags); + ImGui::BeginChild("ChildL", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f, 260), false, window_flags); for (int i = 0; i < 100; i++) { ImGui::Text("%04d: scrollable region", i); @@ -1808,7 +1808,7 @@ static void ShowDemoWindowLayout() { ImGuiWindowFlags window_flags = (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0) | (disable_menu ? 0 : ImGuiWindowFlags_MenuBar); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); - ImGui::BeginChild("Child2", ImVec2(0, 260), true, window_flags); + ImGui::BeginChild("ChildR", ImVec2(0, 260), true, window_flags); if (!disable_menu && ImGui::BeginMenuBar()) { if (ImGui::BeginMenu("Menu")) @@ -1841,7 +1841,7 @@ static void ShowDemoWindowLayout() { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10); ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(255, 0, 0, 100)); - ImGui::BeginChild("blah", ImVec2(200, 100), true, ImGuiWindowFlags_None); + ImGui::BeginChild("Red", ImVec2(200, 100), true, ImGuiWindowFlags_None); for (int n = 0; n < 50; n++) ImGui::Text("Some test %d", n); ImGui::EndChild(); diff --git a/imgui_internal.h b/imgui_internal.h index 6df52433..46221159 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1006,8 +1006,8 @@ struct ImGuiContext // Windows state ImVector Windows; // Windows, sorted in display order, back to front - ImVector WindowsFocusOrder; // Windows, sorted in focus order, back to front - ImVector WindowsSortBuffer; + ImVector WindowsFocusOrder; // Windows, sorted in focus order, back to front. (FIXME: We could only store root windows here! Need to sort out the Docking equivalent which is RootWindowDockStop and is unfortunately a little more dynamic) + ImVector WindowsTempSortBuffer; // Temporary buffer used in EndFrame() to reorder windows so parents are kept before their child ImVector CurrentWindowStack; ImGuiStorage WindowsById; // Map window's ImGuiID to ImGuiWindow* int WindowsActiveCount; // Number of unique windows submitted by frame @@ -1424,7 +1424,7 @@ struct IMGUI_API ImGuiWindowTempData // Storage for one window struct IMGUI_API ImGuiWindow { - char* Name; + char* Name; // Window name, owned by the window. ImGuiID ID; // == ImHashStr(Name) ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ ImVec2 Pos; // Position (always rounded-up to nearest pixel) From d19297e2fa930f4bbcfd0d586c6dabea4988154a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 14:10:43 +0100 Subject: [PATCH 251/384] InputTextMultiline: Provide label to BeginChildEx so internal window name hold a little more context. --- imgui_widgets.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d5eed2cd..a5aa86b1 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3458,14 +3458,23 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ EndGroup(); return false; } - if (!BeginChildFrame(id, frame_bb.GetSize())) + + // We reproduce the contents of BeginChildFrame() in order to provide 'label' so our window internal data are easier to read/debug. + PushStyleColor(ImGuiCol_ChildBg, style.Colors[ImGuiCol_FrameBg]); + PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding); + PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize); + PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding); + bool child_visible = BeginChildEx(label, id, frame_bb.GetSize(), true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding); + PopStyleVar(3); + PopStyleColor(); + if (!child_visible) { - EndChildFrame(); + EndChild(); EndGroup(); return false; } draw_window = g.CurrentWindow; // Child window - draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight + draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight so we can "enter" into it. inner_size.x -= draw_window->ScrollbarSizes.x; } else @@ -4151,7 +4160,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (is_multiline) { Dummy(text_size + ImVec2(0.0f, g.FontSize)); // Always add room to scroll an extra line - EndChildFrame(); + EndChild(); EndGroup(); } From d9bca0d8531b8c6fca08cf883781fc0776418222 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 14:17:43 +0100 Subject: [PATCH 252/384] Nav: Fixed a bug where the initial CTRL-Tab press while in a child window sometimes selected the current root window instead of always selecting the previous root window. (#787) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 165e46bb..30a2a780 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,8 @@ Other Changes: - Inputs: Added ImGuiMouseButton enum for convenience (e.g. ImGuiMouseButton_Right=1). We forever guarantee that the existing value will not changes so existing code is free to use 0/1/2. +- Nav: Fixed a bug where the initial CTRL-Tab press while in a child window sometimes selected + the current root window instead of always selecting the previous root window. (#787) - ColorEdit: Fix label alignment when using ImGuiColorEditFlags_NoInputs. (#2955) [@rokups] - ColorEdit: In HSV display of a RGB stored value, attempt to locally preserve Saturation when Value==0.0 (similar to changes done in 1.73 for Hue). Removed Hue editing lock since diff --git a/imgui.cpp b/imgui.cpp index 3fa63e0d..0d13896e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8766,7 +8766,7 @@ static void ImGui::NavUpdateWindowing() if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1)) { - g.NavWindowingTarget = g.NavWindowingTargetAnim = window; + g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow; // FIXME-DOCK: Will need to use RootWindowDockStop g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f; g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true; g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad; From 4b4be11fd2dabc7a72d749c22a5eeeb3647078bc Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 14:57:47 +0100 Subject: [PATCH 253/384] Docking: Clarifying that DockNode!=NULL when DockIsActive. Comments. Cleanup. --- imgui.cpp | 6 ++++-- imgui_internal.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6a55cff7..ca718d74 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5626,7 +5626,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar // Docking: Unhide tab bar (small triangle in the corner), drag from small triangle to quickly undock ImGuiDockNode* node = window->DockNode; - if (node && window->DockIsActive && node->IsHiddenTabBar() && !node->IsNoTabBar()) + if (window->DockIsActive && node->IsHiddenTabBar() && !node->IsNoTabBar()) { float unhide_sz_draw = ImFloor(g.FontSize * 0.70f); float unhide_sz_hit = ImFloor(g.FontSize * 0.55f); @@ -5850,6 +5850,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { BeginDocked(window, p_open); flags = window->Flags; + if (window->DockIsActive) + IM_ASSERT(window->DockNode != NULL); // Docking currently override constraints g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint; @@ -13135,7 +13137,7 @@ bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir //off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h)); hs_w = ImFloor(hs_for_central_nodes * 1.50f); hs_h = ImFloor(hs_for_central_nodes * 0.80f); - off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h)); + off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - hs_h), ImFloor(parent.GetHeight() * 0.5f - hs_h)); } else { diff --git a/imgui_internal.h b/imgui_internal.h index b17ebcc8..4f21d646 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1691,14 +1691,14 @@ struct IMGUI_API ImGuiWindow int MemoryDrawListVtxCapacity; // Docking - ImGuiDockNode* DockNode; // Which node are we docked into + ImGuiDockNode* DockNode; // Which node are we docked into. Important: Prefer testing DockIsActive in many cases as this will still be set when the dock node is hidden. ImGuiDockNode* DockNodeAsHost; // Which node are we owning (for parent windows) - ImGuiID DockId; // Backup of last valid DockNode->Id, so single value remember their dock node id + ImGuiID DockId; // Backup of last valid DockNode->ID, so single window remember their dock node id even when they are not bound any more ImGuiItemStatusFlags DockTabItemStatusFlags; ImRect DockTabItemRect; short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. - bool DockIsActive :1; // =~ (DockNode != NULL) && (DockNode->Windows.Size > 1) - bool DockTabIsVisible :1; // Is the window visible this frame? =~ is the corresponding tab selected? + bool DockIsActive :1; // When docking artifacts are actually visible. When this is set, DockNode is guaranteed to be != NULL. ~~ (DockNode != NULL) && (DockNode->Windows.Size > 1). + bool DockTabIsVisible :1; // Is our window visible this frame? ~~ is the corresponding tab selected? bool DockTabWantClose :1; public: From fb257eef3e63dd589325a1db66478c5dfbe3dbe7 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 17:43:35 +0100 Subject: [PATCH 254/384] Internals: Update ->RootWindow and other links before applying the SetNextWindowXXX stuff. This is so FocusWindow() can always assume that ->RootWindow != NULL. --- imgui.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 0d13896e..fac95013 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5402,6 +5402,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window_just_appearing_after_hidden_for_resize && !(flags & ImGuiWindowFlags_ChildWindow)) window->NavLastIds[0] = 0; + // Update ->RootWindow and others pointers (before any possible call to FocusWindow) + if (first_begin_of_the_frame) + UpdateWindowParentAndRootLinks(window, flags, parent_window); + // Process SetNextWindow***() calls bool window_pos_set_by_api = false; bool window_size_x_set_by_api = false, window_size_y_set_by_api = false; @@ -5443,8 +5447,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { // Initialize const bool window_is_child_tooltip = (flags & ImGuiWindowFlags_ChildWindow) && (flags & ImGuiWindowFlags_Tooltip); // FIXME-WIP: Undocumented behavior of Child+Tooltip for pinned tooltip (#1345) - UpdateWindowParentAndRootLinks(window, flags, parent_window); - window->Active = true; window->HasCloseButton = (p_open != NULL); window->ClipRect = ImVec4(-FLT_MAX,-FLT_MAX,+FLT_MAX,+FLT_MAX); @@ -6037,8 +6039,8 @@ void ImGui::FocusWindow(ImGuiWindow* window) return; // Move the root window to the top of the pile - if (window->RootWindow) - window = window->RootWindow; + IM_ASSERT(window->RootWindow != NULL); + window = window->RootWindow; // Steal focus on active widgets if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. @@ -7823,7 +7825,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) // [SECTION] KEYBOARD/GAMEPAD NAVIGATION //----------------------------------------------------------------------------- -// FIXME-NAV: The existance of SetNavID vs SetNavIDWithRectRel vs SetFocusID is incredibly messy and confusing, +// FIXME-NAV: The existence of SetNavID vs SetNavIDWithRectRel vs SetFocusID is incredibly messy and confusing, // and needs some explanation or serious refactoring. void ImGui::SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id) { @@ -8295,7 +8297,8 @@ static void ImGui::NavUpdate() if (g.NavScoringCount > 0) IMGUI_DEBUG_LOG("NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); #endif - // Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard) + // Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard) + // (do it before we map Keyboard input!) bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; if (nav_gamepad_active) From fc41839cabb173b07897726abb9187061e3a44fa Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 18:27:40 +0100 Subject: [PATCH 255/384] Focus: Reworking FocusWindow() so in Docking branch we can fix CTRL+Tab being out of order on Docked windows because WindowsFocusOreder is poorly maintained. When merging this and d9bca0d8 in Docking we'll replace two ocurrences of RootWindow with RootWindowDockStop. --- imgui.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fac95013..6d44419d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6040,17 +6040,18 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Move the root window to the top of the pile IM_ASSERT(window->RootWindow != NULL); - window = window->RootWindow; + ImGuiWindow* focus_front_window = window->RootWindow; // NB: In docking branch this is window->RootWindowDockStop + ImGuiWindow* display_front_window = window->RootWindow; // Steal focus on active widgets - if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. - if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window) + if (focus_front_window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement may be unnecessary? Need further testing before removing it.. + if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window) ClearActiveID(); // Bring to front - BringWindowToFocusFront(window); - if (!(window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) - BringWindowToDisplayFront(window); + BringWindowToFocusFront(focus_front_window); + if ((display_front_window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) + BringWindowToDisplayFront(display_front_window); } void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window) From fc42528f134a3aec1f6c34daec6f26390e7b29b5 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 Jan 2020 18:28:25 +0100 Subject: [PATCH 256/384] When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we test both the focused/clicked window (which could be a child window) and the root window. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 30a2a780..099f8f08 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -78,6 +78,8 @@ Other Changes: - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. - MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. - Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog] +- Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we + test both the focused/clicked window (which could be a child window) and the root window. - ImDrawList: AddCircle(), AddCircleFilled() API can now auto-tessellate when provided a segment count of zero. Alter tessellation quality with 'style.CircleSegmentMaxError'. [@ShironekoBen] - ImDrawList: Add AddNgon(), AddNgonFilled() API with a guarantee on the explicit segment count. diff --git a/imgui.cpp b/imgui.cpp index 6d44419d..4f2993b4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6050,7 +6050,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Bring to front BringWindowToFocusFront(focus_front_window); - if ((display_front_window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) + if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) BringWindowToDisplayFront(display_front_window); } From 5a437f198ce39b923dc1a04c7fbfe7c64a283e25 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 2 Feb 2020 21:01:22 +0100 Subject: [PATCH 257/384] Internals: GetItemStatusFlags(). Added Comments. --- imgui_internal.h | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 46221159..85dcce20 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1258,7 +1258,7 @@ struct ImGuiContext NavInitResultId = 0; NavMoveFromClampedRefRect = false; NavMoveRequest = false; - NavMoveRequestFlags = 0; + NavMoveRequestFlags = ImGuiNavMoveFlags_None; NavMoveRequestForward = ImGuiNavForward_None; NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None; @@ -1277,11 +1277,11 @@ struct ImGuiContext MouseCursor = ImGuiMouseCursor_Arrow; DragDropActive = DragDropWithinSourceOrTarget = false; - DragDropSourceFlags = 0; + DragDropSourceFlags = ImGuiDragDropFlags_None; DragDropSourceFrameCount = -1; DragDropMouseButton = -1; DragDropTargetId = 0; - DragDropAcceptFlags = 0; + DragDropAcceptFlags = ImGuiDragDropFlags_None; DragDropAcceptIdCurrRectSurface = 0.0f; DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; DragDropAcceptFrameCount = -1; @@ -1395,7 +1395,7 @@ struct IMGUI_API ImGuiWindowTempData GroupOffset = ImVec1(0.0f); LastItemId = 0; - LastItemStatusFlags = 0; + LastItemStatusFlags = ImGuiItemStatusFlags_None; LastItemRect = LastItemDisplayRect = ImRect(); NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; @@ -1570,7 +1570,7 @@ struct ImGuiTabItem float Width; // Width currently displayed float ContentWidth; // Width of actual contents, stored during BeginTabItem() call - ImGuiTabItem() { ID = 0; Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; } + ImGuiTabItem() { ID = 0; Flags = ImGuiTabItemFlags_None; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; } }; // Storage for a tab bar (sizeof() 92~96 bytes) @@ -1617,6 +1617,7 @@ struct ImGuiTabBar namespace ImGui { + // Windows // We should always have a CurrentWindow in the stack (there is an implicit "Debug" window) // If this ever crash because g.CurrentWindow is NULL it means that either // - ImGui::NewFrame() has never been called, which is illegal. @@ -1625,11 +1626,6 @@ namespace ImGui inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id); IMGUI_API ImGuiWindow* FindWindowByName(const char* name); - IMGUI_API void FocusWindow(ImGuiWindow* window); - IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window); - IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window); - IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window); - IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window); IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window); IMGUI_API ImVec2 CalcWindowExpectedSize(ImGuiWindow* window); IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent); @@ -1638,9 +1634,15 @@ namespace ImGui IMGUI_API void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond = 0); IMGUI_API void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond = 0); IMGUI_API void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond = 0); - IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window); - IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window); + // Windows: Display Order and Focus Order + IMGUI_API void FocusWindow(ImGuiWindow* window); + IMGUI_API void FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window); + IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window); + IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window); + IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window); + + // Fonts, drawing IMGUI_API void SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { IM_UNUSED(window); ImGuiContext& g = *GImGui; return &g.ForegroundDrawList; } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. @@ -1672,6 +1674,7 @@ namespace ImGui // Basic Accessors inline ImGuiID GetItemID() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.LastItemId; } + inline ImGuiItemStatusFlags GetItemStatusFlags() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.LastItemStatusFlags; } inline ImGuiID GetActiveID() { ImGuiContext& g = *GImGui; return g.ActiveId; } inline ImGuiID GetFocusID() { ImGuiContext& g = *GImGui; return g.NavId; } IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); @@ -1680,7 +1683,7 @@ namespace ImGui IMGUI_API ImGuiID GetHoveredID(); IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id); - IMGUI_API void MarkItemEdited(ImGuiID id); + IMGUI_API void MarkItemEdited(ImGuiID id); // Mark data associated to given item as "edited", used by IsItemDeactivatedAfterEdit() function. IMGUI_API void PushOverrideID(ImGuiID id); // Push given value at the top of the ID stack (whereas PushID combines old and new hashes) // Basic Helpers for widget code @@ -1749,7 +1752,7 @@ namespace ImGui IMGUI_API void ClearDragDrop(); IMGUI_API bool IsDragDropPayloadBeingAccepted(); - // New Columns API (FIXME-WIP) + // Internal Columns API (this is not exposed because we will encourage transitioning to the Tables api) IMGUI_API void BeginColumns(const char* str_id, int count, ImGuiColumnsFlags flags = 0); // setup number of columns. use an identifier to distinguish multiple column sets. close with EndColumns(). IMGUI_API void EndColumns(); // close columns IMGUI_API void PushColumnClipRect(int column_index); @@ -1852,6 +1855,10 @@ namespace ImGui IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); IMGUI_API void ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp); + // Garbage collection + IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window); + IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window); + // Debug Tools inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max, col); } inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; } From d4fc525614eada62c61b6ba965b08021647d674b Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 2 Feb 2020 21:24:53 +0100 Subject: [PATCH 258/384] Nav, Focus: Fixed messed up Ctrl+Tab order with Docked windows. Amend d9bca0d8531b8c6fca08cf883781fc0776418222, fc41839cabb173b07897726abb9187061e3a44fa, fc42528f134a3aec1f6c34daec6f26390e7b29b5 for docking. --- imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f24d040d..519ec41e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6717,7 +6717,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Move the root window to the top of the pile IM_ASSERT(window->RootWindow != NULL); - ImGuiWindow* focus_front_window = window->RootWindow; // NB: In docking branch this is window->RootWindowDockStop + ImGuiWindow* focus_front_window = window->RootWindowDockStop; ImGuiWindow* display_front_window = window->RootWindow; // Steal focus on active widgets @@ -6727,7 +6727,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Bring to front BringWindowToFocusFront(focus_front_window); - if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) + if (((window->Flags | focus_front_window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) BringWindowToDisplayFront(display_front_window); } @@ -9532,7 +9532,7 @@ static void ImGui::NavUpdateWindowing() if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1)) { - g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow; // FIXME-DOCK: Will need to use RootWindowDockStop + g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindowDockStop; g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f; g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true; g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad; From 365b6399815acf66c65a5afa5d76f7fcea9588d9 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 2 Feb 2020 22:17:04 +0100 Subject: [PATCH 259/384] Nav, Docking: Fixed failing to restore NavId when refocusing a child within a docked window. --- imgui.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 519ec41e..6de7c771 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8928,11 +8928,11 @@ void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags mov // This way we could find the last focused window among our children. It would be much less confusing this way? static void ImGui::NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window) { - ImGuiWindow* parent_window = nav_window; - while (parent_window && (parent_window->Flags & ImGuiWindowFlags_ChildWindow) != 0 && (parent_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0) - parent_window = parent_window->ParentWindow; - if (parent_window && parent_window != nav_window) - parent_window->NavLastChildNavWindow = nav_window; + ImGuiWindow* parent = nav_window; + while (parent && parent->RootWindowDockStop != parent && (parent->Flags & ImGuiWindowFlags_ChildWindow) != 0 && (parent->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0) + parent = parent->ParentWindow; + if (parent && parent != nav_window) + parent->NavLastChildNavWindow = nav_window; } // Restore the last focused child. From 3bde375078db5fe15959f4ba6480fcf4013189d7 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 2 Feb 2020 22:40:56 +0100 Subject: [PATCH 260/384] Nav, Docking: Fixed failing to restore NavId when refocusing due to missing nav window. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 6de7c771..e0c882b5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6746,7 +6746,7 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind { // We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user. ImGuiWindow* window = g.WindowsFocusOrder[i]; - if (window != ignore_window && window->WasActive && !(window->Flags & ImGuiWindowFlags_ChildWindow)) + if (window != ignore_window && window->WasActive && window->RootWindowDockStop == window) if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) { // FIXME-DOCK: This is failing (lagging by one frame) for docked windows. From 83efdcec8d564f9750220a7b5cf034d96b56c834 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 3 Feb 2020 10:29:08 +0200 Subject: [PATCH 261/384] Canceling text input with [esc] key uses stb_textedit facilities to restore original value. This makes restoration undoable using hotkeys. Fixes #3008. --- docs/CHANGELOG.txt | 1 + imgui_widgets.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 099f8f08..9a60ef28 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -76,6 +76,7 @@ Other Changes: those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] - ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. +- InputText: Fix crash when executing undo action after clearing input with ESC (#3008). [@rokups] - MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. - Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog] - Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a5aa86b1..777530bf 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3828,6 +3828,25 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { apply_new_text = state->InitialTextA.Data; apply_new_text_length = state->InitialTextA.Size - 1; + + // Select all text + state->OnKeyPressed(STB_TEXTEDIT_K_TEXTSTART); + state->OnKeyPressed(STB_TEXTEDIT_K_TEXTEND | STB_TEXTEDIT_K_SHIFT); + + // Paste converted text or empty buffer + if (state->InitialTextA.size() > 1) + { + ImVector w_text; + const char* apply_new_text_end = apply_new_text + apply_new_text_length + 1; + w_text.resize(ImTextCountCharsFromUtf8(apply_new_text, apply_new_text_end)); + ImTextStrFromUtf8(w_text.Data, w_text.Size, apply_new_text, apply_new_text_end); + ImStb::stb_textedit_paste(state, &state->Stb, w_text.Data, w_text.Size); + } + else + { + ImWchar empty = 0; + ImStb::stb_textedit_paste(state, &state->Stb, &empty, 0); + } } } From bdbb2b21f5643089329e314fa64e92767f89d709 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 3 Feb 2020 16:37:54 +0100 Subject: [PATCH 262/384] Fix 83efdcec from overflowing buffer + make it a single undo records + comments (#3008) --- docs/CHANGELOG.txt | 3 ++- imgui_widgets.cpp | 40 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9a60ef28..1970a63b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -76,7 +76,8 @@ Other Changes: those improvements in 1.73 makes them unnecessary. (#2722, #2770). [@rokups] - ColorEdit: "Copy As" context-menu tool shows hex values with a '#' prefix instead of '0x'. - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. -- InputText: Fix crash when executing undo action after clearing input with ESC (#3008). [@rokups] +- InputText: Fix corruption or crash when executing undo after clearing input with ESC, as a + byproduct we are allowing to later undo the revert with a CTRL+Z. (#3008). - MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. - Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog] - Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 777530bf..67bba187 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3271,8 +3271,25 @@ static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const Im #define STB_TEXTEDIT_IMPLEMENTATION #include "imstb_textedit.h" +// stb_textedit internally allows for a single undo record to do addition and deletion, but somehow, calling +// the stb_textedit_paste() function creates two separate records, so we perform it manually. (FIXME: Report to nothings/stb?) +static void stb_textedit_replace(STB_TEXTEDIT_STRING* str, STB_TexteditState* state, const STB_TEXTEDIT_CHARTYPE* text, int text_len) +{ + stb_text_makeundo_replace(str, state, 0, str->CurLenW, text_len); + ImStb::STB_TEXTEDIT_DELETECHARS(str, 0, str->CurLenW); + if (text_len <= 0) + return; + if (ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len)) + { + state->cursor = text_len; + state->has_preferred_x = 0; + return; + } + IM_ASSERT(0); // Failed to insert character, normally shouldn't happen because of how we currently use stb_textedit_replace() } +} // namespace ImStb + void ImGuiInputTextState::OnKeyPressed(int key) { stb_textedit_key(this, &Stb, key); @@ -3826,27 +3843,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Restore initial value. Only return true if restoring to the initial value changes the current buffer contents. if (!is_readonly && strcmp(buf, state->InitialTextA.Data) != 0) { + // Push records into the undo stack so we can CTRL+Z the revert operation itself apply_new_text = state->InitialTextA.Data; apply_new_text_length = state->InitialTextA.Size - 1; - - // Select all text - state->OnKeyPressed(STB_TEXTEDIT_K_TEXTSTART); - state->OnKeyPressed(STB_TEXTEDIT_K_TEXTEND | STB_TEXTEDIT_K_SHIFT); - - // Paste converted text or empty buffer - if (state->InitialTextA.size() > 1) - { - ImVector w_text; - const char* apply_new_text_end = apply_new_text + apply_new_text_length + 1; - w_text.resize(ImTextCountCharsFromUtf8(apply_new_text, apply_new_text_end)); - ImTextStrFromUtf8(w_text.Data, w_text.Size, apply_new_text, apply_new_text_end); - ImStb::stb_textedit_paste(state, &state->Stb, w_text.Data, w_text.Size); - } - else + ImVector w_text; + if (apply_new_text_length > 0) { - ImWchar empty = 0; - ImStb::stb_textedit_paste(state, &state->Stb, &empty, 0); + w_text.resize(ImTextCountCharsFromUtf8(apply_new_text, apply_new_text + apply_new_text_length) + 1); + ImTextStrFromUtf8(w_text.Data, w_text.Size, apply_new_text, apply_new_text + apply_new_text_length); } + stb_textedit_replace(state, &state->Stb, w_text.Data, (apply_new_text_length > 0) ? (w_text.Size - 1) : 0); } } From f694244dec94ca67666d767fd5be59faf74686b9 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 4 Feb 2020 15:19:49 +0100 Subject: [PATCH 263/384] InputText: Fix using a combination of _CallbackResize + _EnterReturnsTrue + lack of persisting user storage. (#3009) Amend 24ff25981 (#2006, #1443, #1008) --- docs/CHANGELOG.txt | 4 ++++ imgui_widgets.cpp | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1970a63b..8ea4737f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -78,6 +78,10 @@ Other Changes: - ColorEdit: "Copy As" content-menu tool shows hex values both with/without alpha when available. - InputText: Fix corruption or crash when executing undo after clearing input with ESC, as a byproduct we are allowing to later undo the revert with a CTRL+Z. (#3008). +- InputText: Fix using a combination of _CallbackResize (e.g. for std::string binding), along with the + _EnterReturnsTrue flag along with the rarely used property of using an InputText without persisting + user-side storage. Previously if you had e.g. a local unsaved std::string and reading result back + from the widget, the user string object wouldn't be resized when Enter key was pressed. (#3009) - MenuBar: Fix minor clipping issue where occasionally a menu text can overlap the right-most border. - Window: Fix SetNextWindowBgAlpha(1.0f) failing to override alpha component. (#3007) [@Albog] - Window: When testing for the presence of the ImGuiWindowFlags_NoBringToFrontOnFocus flag we diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 67bba187..5faa31b2 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3857,7 +3857,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. - // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. Also this allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage. + // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. + // This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize). bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); if (apply_edit_back_to_user_buffer) { @@ -3951,8 +3952,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Copy result to user buffer if (apply_new_text) { + // We cannot test for 'backup_current_text_length != apply_new_text_length' here because we have no guarantee that the size + // of our owned buffer matches the size of the string object held by the user, and by design we allow InputText() to be used + // without any storage on user's side. IM_ASSERT(apply_new_text_length >= 0); - if (backup_current_text_length != apply_new_text_length && is_resizable) + if (is_resizable) { ImGuiInputTextCallbackData callback_data; callback_data.EventFlag = ImGuiInputTextFlags_CallbackResize; @@ -3967,6 +3971,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ apply_new_text_length = ImMin(callback_data.BufTextLen, buf_size - 1); IM_ASSERT(apply_new_text_length <= buf_size); } + //IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); // If the underlying buffer resize was denied or not carried to the next frame, apply_new_text_length+1 may be >= buf_size. ImStrncpy(buf, apply_new_text, ImMin(apply_new_text_length + 1, buf_size)); From d37d25470af52d9d2d83ce887e1a50cab9882416 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 9 Feb 2020 17:06:58 +0100 Subject: [PATCH 264/384] Added IMGUI_DISABLE compile-time definition to make all headers and sources empty. --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 1 + imconfig.h | 10 ++++++---- imgui.cpp | 4 ++++ imgui.h | 4 ++++ imgui_demo.cpp | 4 ++++ imgui_draw.cpp | 4 ++++ imgui_internal.h | 3 +++ imgui_widgets.cpp | 4 ++++ 9 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8ea4737f..fb8c0fc5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -95,6 +95,7 @@ Other Changes: - Columns: ImDrawList::Channels* functions now work inside columns. Added extra comments to suggest using user-owned ImDrawListSplitter instead of ImDrawList functions. [@rokups] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- Misc: Added IMGUI_DISABLE compile-time definition to make all headers and sources empty. - Misc: Disable format checks when using stb_printf, to allow using extra formats. Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari] - Misc: Added misc/single_file/imgui_single_file.h, We use this to validate compiling all *.cpp diff --git a/docs/TODO.txt b/docs/TODO.txt index f0d5c90b..9f102d7f 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -80,6 +80,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now and super fragile. - input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541) - input text: expose CursorPos in char filter event (#816) + - input text: try usage idiom of using InputText with data only exposed through get/set accessors, without extraneous copy/alloc. (#3009) - input text: access public fields via a non-callback API e.g. InputTextGetState("xxx") that may return NULL if not active. - input text: flag to disable live update of the user buffer (also applies to float/int text input) (#701) - input text: hover tooltip could show unclamped text diff --git a/imconfig.h b/imconfig.h index 6724e40f..09bfd16c 100644 --- a/imconfig.h +++ b/imconfig.h @@ -14,6 +14,7 @@ #pragma once //---- Define assertion handler. Defaults to calling assert(). +// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts @@ -25,10 +26,11 @@ //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS -//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) -// It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. -//#define IMGUI_DISABLE_DEMO_WINDOWS -//#define IMGUI_DISABLE_METRICS_WINDOW +//---- Disable all of Dear ImGui or don't implement standard windows. +// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. +//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. +//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. +//#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty. //---- Don't implement some functions to reduce linkage requirements. //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. diff --git a/imgui.cpp b/imgui.cpp index 4f2993b4..d1bf2639 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -791,6 +791,8 @@ CODE #endif #include "imgui.h" +#ifndef IMGUI_DISABLE + #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif @@ -10282,3 +10284,5 @@ void ImGui::ShowMetricsWindow(bool*) { } #endif //----------------------------------------------------------------------------- + +#endif // #ifndef IMGUI_DISABLE diff --git a/imgui.h b/imgui.h index 4cbe196e..75a4578b 100644 --- a/imgui.h +++ b/imgui.h @@ -45,6 +45,8 @@ Index of this file: #include "imconfig.h" #endif +#ifndef IMGUI_DISABLE + //----------------------------------------------------------------------------- // Header mess //----------------------------------------------------------------------------- @@ -2275,3 +2277,5 @@ struct ImFont #ifdef IMGUI_INCLUDE_IMGUI_USER_H #include "imgui_user.h" #endif + +#endif // #ifndef IMGUI_DISABLE diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 54b3a9f6..6fef81c4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -65,6 +65,8 @@ Index of this file: #endif #include "imgui.h" +#ifndef IMGUI_DISABLE + #include // toupper #include // INT_MIN, INT_MAX #include // sqrtf, powf, cosf, sinf, floorf, ceilf @@ -4866,3 +4868,5 @@ void ImGui::ShowUserGuide() {} void ImGui::ShowStyleEditor(ImGuiStyle*) {} #endif + +#endif // #ifndef IMGUI_DISABLE diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b457b532..41a7aff8 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -27,6 +27,8 @@ Index of this file: #endif #include "imgui.h" +#ifndef IMGUI_DISABLE + #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif @@ -3458,3 +3460,5 @@ static const char* GetDefaultCompressedFontDataTTFBase85() { return proggy_clean_ttf_compressed_data_base85; } + +#endif // #ifndef IMGUI_DISABLE diff --git a/imgui_internal.h b/imgui_internal.h index 85dcce20..47af16fb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -22,6 +22,7 @@ Index of this file: */ #pragma once +#ifndef IMGUI_DISABLE //----------------------------------------------------------------------------- // Header mess @@ -1912,3 +1913,5 @@ extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const cha #ifdef _MSC_VER #pragma warning (pop) #endif + +#endif // #ifndef IMGUI_DISABLE diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5faa31b2..c5509601 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -33,6 +33,8 @@ Index of this file: #endif #include "imgui.h" +#ifndef IMGUI_DISABLE + #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif @@ -7704,3 +7706,5 @@ void ImGui::Columns(int columns_count, const char* id, bool border) } //------------------------------------------------------------------------- + +#endif // #ifndef IMGUI_DISABLE From 7e2d172ae5c8b53184bbf2982ceb1fefbb99ceba Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 9 Feb 2020 17:31:18 +0100 Subject: [PATCH 265/384] Backends: GLFW, SDL: Platform monitors declared properly even if multi-viewport is not enabled. --- examples/imgui_impl_glfw.cpp | 91 ++++++++++++++++++----------------- examples/imgui_impl_glfw.h | 2 + examples/imgui_impl_sdl.cpp | 62 ++++++++++++------------ examples/imgui_impl_win32.cpp | 54 ++++++++++----------- imgui.cpp | 6 ++- 5 files changed, 112 insertions(+), 103 deletions(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 2d3431e9..bcbee436 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -83,11 +83,12 @@ static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL; static GLFWscrollfun g_PrevUserCallbackScroll = NULL; static GLFWkeyfun g_PrevUserCallbackKey = NULL; static GLFWcharfun g_PrevUserCallbackChar = NULL; +static GLFWmonitorfun g_PrevUserCallbackMonitor = NULL; // Forward Declarations +static void ImGui_ImplGlfw_UpdateMonitors(); static void ImGui_ImplGlfw_InitPlatformInterface(); static void ImGui_ImplGlfw_ShutdownPlatformInterface(); -static void ImGui_ImplGlfw_UpdateMonitors(); static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data) { @@ -149,6 +150,11 @@ void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) io.AddInputCharacter(c); } +void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int) +{ + g_WantUpdateMonitors = true; +} + static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) { g_Window = window; @@ -220,6 +226,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_PrevUserCallbackScroll = NULL; g_PrevUserCallbackKey = NULL; g_PrevUserCallbackChar = NULL; + g_PrevUserCallbackMonitor = NULL; if (install_callbacks) { g_InstalledCallbacks = true; @@ -227,8 +234,13 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw g_PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); g_PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); g_PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); + g_PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); } + // Update monitors the first time (note: monitor callback are broken in GLFW 3.2 and earlier, see github.com/glfw/glfw/issues/784) + ImGui_ImplGlfw_UpdateMonitors(); + glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); + // Our mouse update function expect PlatformHandle to be filled for the main viewport ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = (void*)g_Window; @@ -405,6 +417,40 @@ static void ImGui_ImplGlfw_UpdateGamepads() io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; } +static void ImGui_ImplGlfw_UpdateMonitors() +{ + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + int monitors_count = 0; + GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count); + platform_io.Monitors.resize(0); + for (int n = 0; n < monitors_count; n++) + { + ImGuiPlatformMonitor monitor; + int x, y; + glfwGetMonitorPos(glfw_monitors[n], &x, &y); + const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]); +#if GLFW_HAS_MONITOR_WORK_AREA + monitor.MainPos = ImVec2((float)x, (float)y); + monitor.MainSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); + int w, h; + glfwGetMonitorWorkarea(glfw_monitors[n], &x, &y, &w, &h); + monitor.WorkPos = ImVec2((float)x, (float)y);; + monitor.WorkSize = ImVec2((float)w, (float)h); +#else + monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y); + monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); +#endif +#if GLFW_HAS_PER_MONITOR_DPI + // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. + float x_scale, y_scale; + glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); + monitor.DpiScale = x_scale; +#endif + platform_io.Monitors.push_back(monitor); + } + g_WantUpdateMonitors = false; +} + void ImGui_ImplGlfw_NewFrame() { ImGuiIO& io = ImGui::GetIO(); @@ -746,45 +792,6 @@ static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst } #endif // GLFW_HAS_VULKAN -static void ImGui_ImplGlfw_UpdateMonitors() -{ - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - int monitors_count = 0; - GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count); - platform_io.Monitors.resize(0); - for (int n = 0; n < monitors_count; n++) - { - ImGuiPlatformMonitor monitor; - int x, y; - glfwGetMonitorPos(glfw_monitors[n], &x, &y); - const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]); -#if GLFW_HAS_MONITOR_WORK_AREA - monitor.MainPos = ImVec2((float)x, (float)y); - monitor.MainSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); - int w, h; - glfwGetMonitorWorkarea(glfw_monitors[n], &x, &y, &w, &h); - monitor.WorkPos = ImVec2((float)x, (float)y);; - monitor.WorkSize = ImVec2((float)w, (float)h); -#else - monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y); - monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); -#endif -#if GLFW_HAS_PER_MONITOR_DPI - // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. - float x_scale, y_scale; - glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); - monitor.DpiScale = x_scale; -#endif - platform_io.Monitors.push_back(monitor); - } - g_WantUpdateMonitors = false; -} - -static void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int) -{ - g_WantUpdateMonitors = true; -} - static void ImGui_ImplGlfw_InitPlatformInterface() { // Register platform interface (will be coupled with a renderer interface) @@ -812,10 +819,6 @@ static void ImGui_ImplGlfw_InitPlatformInterface() platform_io.Platform_SetImeInputPos = ImGui_ImplWin32_SetImeInputPos; #endif - // Note: monitor callback are broken GLFW 3.2 and earlier (see github.com/glfw/glfw/issues/784) - ImGui_ImplGlfw_UpdateMonitors(); - glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); - // Register main window handle (which is owned by the main application, not by us) // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport* main_viewport = ImGui::GetMainViewport(); diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index dcab351c..07a34568 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -20,6 +20,7 @@ #pragma once struct GLFWwindow; +struct GLFWmonitor; IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); @@ -32,3 +33,4 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, i IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); +IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 8d52a212..ab2ca5ac 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -77,6 +77,7 @@ static bool g_MouseCanUseGlobalState = true; static bool g_UseVulkan = false; // Forward Declarations +static void ImGui_ImplSDL2_UpdateMonitors(); static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context); static void ImGui_ImplSDL2_ShutdownPlatformInterface(); @@ -222,6 +223,9 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, void* sdl_gl_context) main_viewport->PlatformHandleRaw = info.info.win.window; #endif + // Update monitors + ImGui_ImplSDL2_UpdateMonitors(); + // We need SDL_CaptureMouse(), SDL_GetGlobalMouseState() from SDL 2.0.4+ to support multiple viewports. // We left the call to ImGui_ImplSDL2_InitPlatformInterface() outside of #ifdef to avoid unused-function warnings. if ((io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (io.BackendFlags & ImGuiBackendFlags_PlatformHasViewports)) @@ -405,6 +409,34 @@ static void ImGui_ImplSDL2_UpdateGamepads() #undef MAP_ANALOG } +// FIXME-PLATFORM: SDL doesn't have an event to notify the application of display/monitor changes +static void ImGui_ImplSDL2_UpdateMonitors() +{ + ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + platform_io.Monitors.resize(0); + int display_count = SDL_GetNumVideoDisplays(); + for (int n = 0; n < display_count; n++) + { + // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. + ImGuiPlatformMonitor monitor; + SDL_Rect r; + SDL_GetDisplayBounds(n, &r); + monitor.MainPos = monitor.WorkPos = ImVec2((float)r.x, (float)r.y); + monitor.MainSize = monitor.WorkSize = ImVec2((float)r.w, (float)r.h); +#if SDL_HAS_USABLE_DISPLAY_BOUNDS + SDL_GetDisplayUsableBounds(n, &r); + monitor.WorkPos = ImVec2((float)r.x, (float)r.y); + monitor.WorkSize = ImVec2((float)r.w, (float)r.h); +#endif +#if SDL_HAS_PER_MONITOR_DPI + float dpi = 0.0f; + if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL)) + monitor.DpiScale = dpi / 96.0f; +#endif + platform_io.Monitors.push_back(monitor); + } +} + void ImGui_ImplSDL2_NewFrame(SDL_Window* window) { ImGuiIO& io = ImGui::GetIO(); @@ -632,34 +664,6 @@ static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst } #endif // SDL_HAS_VULKAN -// FIXME-PLATFORM: SDL doesn't have an event to notify the application of display/monitor changes -static void ImGui_ImplSDL2_UpdateMonitors() -{ - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - platform_io.Monitors.resize(0); - int display_count = SDL_GetNumVideoDisplays(); - for (int n = 0; n < display_count; n++) - { - // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. - ImGuiPlatformMonitor monitor; - SDL_Rect r; - SDL_GetDisplayBounds(n, &r); - monitor.MainPos = monitor.WorkPos = ImVec2((float)r.x, (float)r.y); - monitor.MainSize = monitor.WorkSize = ImVec2((float)r.w, (float)r.h); -#if SDL_HAS_USABLE_DISPLAY_BOUNDS - SDL_GetDisplayUsableBounds(n, &r); - monitor.WorkPos = ImVec2((float)r.x, (float)r.y); - monitor.WorkSize = ImVec2((float)r.w, (float)r.h); -#endif -#if SDL_HAS_PER_MONITOR_DPI - float dpi = 0.0f; - if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL)) - monitor.DpiScale = dpi / 96.0f; -#endif - platform_io.Monitors.push_back(monitor); - } -} - static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context) { // Register platform interface (will be coupled with a renderer interface) @@ -689,8 +693,6 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); #endif - ImGui_ImplSDL2_UpdateMonitors(); - // Register main window handle (which is owned by the main application, not by us) // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. ImGuiViewport* main_viewport = ImGui::GetMainViewport(); diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index cc190093..7a607799 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -263,6 +263,33 @@ static void ImGui_ImplWin32_UpdateGamepads() #endif // #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD } +static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, HDC, LPRECT, LPARAM) +{ + MONITORINFO info = { 0 }; + info.cbSize = sizeof(MONITORINFO); + if (!::GetMonitorInfo(monitor, &info)) + return TRUE; + ImGuiPlatformMonitor imgui_monitor; + imgui_monitor.MainPos = ImVec2((float)info.rcMonitor.left, (float)info.rcMonitor.top); + imgui_monitor.MainSize = ImVec2((float)(info.rcMonitor.right - info.rcMonitor.left), (float)(info.rcMonitor.bottom - info.rcMonitor.top)); + imgui_monitor.WorkPos = ImVec2((float)info.rcWork.left, (float)info.rcWork.top); + imgui_monitor.WorkSize = ImVec2((float)(info.rcWork.right - info.rcWork.left), (float)(info.rcWork.bottom - info.rcWork.top)); + imgui_monitor.DpiScale = ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); + ImGuiPlatformIO& io = ImGui::GetPlatformIO(); + if (info.dwFlags & MONITORINFOF_PRIMARY) + io.Monitors.push_front(imgui_monitor); + else + io.Monitors.push_back(imgui_monitor); + return TRUE; +} + +static void ImGui_ImplWin32_UpdateMonitors() +{ + ImGui::GetPlatformIO().Monitors.resize(0); + ::EnumDisplayMonitors(NULL, NULL, ImGui_ImplWin32_UpdateMonitors_EnumFunc, NULL); + g_WantUpdateMonitors = false; +} + void ImGui_ImplWin32_NewFrame() { ImGuiIO& io = ImGui::GetIO(); @@ -764,33 +791,6 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, return DefWindowProc(hWnd, msg, wParam, lParam); } -static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, HDC, LPRECT, LPARAM) -{ - MONITORINFO info = { 0 }; - info.cbSize = sizeof(MONITORINFO); - if (!::GetMonitorInfo(monitor, &info)) - return TRUE; - ImGuiPlatformMonitor imgui_monitor; - imgui_monitor.MainPos = ImVec2((float)info.rcMonitor.left, (float)info.rcMonitor.top); - imgui_monitor.MainSize = ImVec2((float)(info.rcMonitor.right - info.rcMonitor.left), (float)(info.rcMonitor.bottom - info.rcMonitor.top)); - imgui_monitor.WorkPos = ImVec2((float)info.rcWork.left, (float)info.rcWork.top); - imgui_monitor.WorkSize = ImVec2((float)(info.rcWork.right - info.rcWork.left), (float)(info.rcWork.bottom - info.rcWork.top)); - imgui_monitor.DpiScale = ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); - ImGuiPlatformIO& io = ImGui::GetPlatformIO(); - if (info.dwFlags & MONITORINFOF_PRIMARY) - io.Monitors.push_front(imgui_monitor); - else - io.Monitors.push_back(imgui_monitor); - return TRUE; -} - -static void ImGui_ImplWin32_UpdateMonitors() -{ - ImGui::GetPlatformIO().Monitors.resize(0); - ::EnumDisplayMonitors(NULL, NULL, ImGui_ImplWin32_UpdateMonitors_EnumFunc, NULL); - g_WantUpdateMonitors = false; -} - static void ImGui_ImplWin32_InitPlatformInterface() { WNDCLASSEX wcex; diff --git a/imgui.cpp b/imgui.cpp index e0c882b5..2191d378 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -15329,9 +15329,11 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing()); ImGui::ShowViewportThumbnails(); ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing()); - if (g.PlatformIO.Monitors.Size > 0 && ImGui::TreeNode("Monitors", "Monitors (%d)", g.PlatformIO.Monitors.Size)) + bool open = ImGui::TreeNode("Monitors", "Monitors (%d)", g.PlatformIO.Monitors.Size); + ImGui::SameLine(); + MetricsHelpMarker("Dear ImGui uses monitor data:\n- to query DPI settings on a per monitor basis\n- to position popup/tooltips so they don't straddle monitors."); + if (open) { - ImGui::TextWrapped("(When viewports are enabled, imgui needs uses monitor data to position popup/tooltips so they don't straddle monitors.)"); for (int i = 0; i < g.PlatformIO.Monitors.Size; i++) { const ImGuiPlatformMonitor& mon = g.PlatformIO.Monitors[i]; From 58b3e02b95b4c7c5bb9128a28c6d55546501bf93 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 9 Feb 2020 17:36:00 +0100 Subject: [PATCH 266/384] Version 1.75 Comments --- .github/issue_template.md | 14 +++++++------- docs/CHANGELOG.txt | 10 ++++++---- docs/README.md | 1 + examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 4 ++-- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 10 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.github/issue_template.md b/.github/issue_template.md index e2c30e07..3812ad0b 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -1,16 +1,16 @@ -(Click "Preview" to turn any http URL into a clickable link) +(Click "Preview" above ^ to turn URL into clickable links) 1. PLEASE CAREFULLY READ: [FAQ](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md) -2. PLEASE CAREFULLY READ: https://github.com/ocornut/imgui/issues/2261 +2. PLEASE CAREFULLY READ: [Issue Submitting Guidelines](https://github.com/ocornut/imgui/issues/2261) -2. FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING/LOADING FONTS, please use the [Discord server](http://discord.dearimgui.org). +3. FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING/LOADING FONTS, please use the [Discord server](http://discord.dearimgui.org). -3. PLEASE MAKE SURE that you have: read the FAQ; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1) (2). +4. PLEASE MAKE SURE that you have: read the FAQ; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1) (2). -4. Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users. +5. Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users. -5. Delete points 1-6 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue. +6. Delete points 1-6 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue. Thank you! @@ -39,7 +39,7 @@ XXX _(you can drag files here)_ **Standalone, minimal, complete and verifiable example:** _(see https://github.com/ocornut/imgui/issues/2261)_ ``` -// Please do not forget this! +// Here's some code anyone can copy and paste to reproduce your issue ImGui::Begin("Example Bug"); MoreCodeToExplainMyIssue(); ImGui::End(); diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fb8c0fc5..736cb447 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -31,9 +31,11 @@ HOW TO UPDATE? ----------------------------------------------------------------------- - VERSION 1.75 WIP (In Progress) + VERSION 1.75 (Released 2020-02-10) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.75 + Breaking Changes: - Removed redirecting functions/enums names that were marked obsolete in 1.53 (December 2017): @@ -55,14 +57,14 @@ Breaking Changes: documented and rarely if ever used). Instead we added an explicit PrimUnreserve() API which can be implemented faster. Also clarified pre-existing constraints which weren't documented (can only unreserve from the last reserve call). If you suspect you ever - used that feature before, #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing - calls. [@ShironekoBen] + used that feature before (very unlikely, but grep for call to PrimReserve in your code), + you can #define IMGUI_DEBUG_PARANOID in imconfig.h to catch existing calls. [@ShironekoBen] - ImDrawList::AddCircle()/AddCircleFilled() functions don't accept negative radius. - Limiting Columns()/BeginColumns() api to 64 columns with an assert. While the current code technically supports it, future code may not so we're putting the restriction ahead. - imgui_internal.h: changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by - adding multiple points into it, you may need to fix your initial value. + adding points into it without explicit initialization, you may need to fix your initial value. Other Changes: diff --git a/docs/README.md b/docs/README.md index 37952f06..cc1ac39e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -193,6 +193,7 @@ Ongoing Dear ImGui development is financially supported by users and private spo - Blizzard Entertainment - Google - Ubisoft +- Nvidia *Double-chocolate sponsors* - Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Aiden Koss, Kylotonn. diff --git a/examples/README.txt b/examples/README.txt index 5f45fad9..5bd16be4 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.75 WIP + dear imgui, v1.75 ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index d1bf2639..1b78dd83 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index 75a4578b..c2bbb7f7 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (headers) // Help: @@ -59,8 +59,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.75 WIP" -#define IMGUI_VERSION_NUM 17401 +#define IMGUI_VERSION "1.75" +#define IMGUI_VERSION_NUM 17500 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 6fef81c4..7664f1b4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 41a7aff8..4bb91ccf 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (drawing and font code) /* @@ -360,7 +360,7 @@ ImDrawListSharedData::ImDrawListSharedData() const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(CircleVtx12); CircleVtx12[i] = ImVec2(ImCos(a), ImSin(a)); } - memset(CircleSegmentCounts, 0, sizeof(CircleSegmentCounts)); // This will be set by + memset(CircleSegmentCounts, 0, sizeof(CircleSegmentCounts)); // This will be set by SetCircleSegmentMaxError() } void ImDrawListSharedData::SetCircleSegmentMaxError(float max_error) diff --git a/imgui_internal.h b/imgui_internal.h index 47af16fb..5de13c36 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index c5509601..6d2c95d9 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 WIP +// dear imgui, v1.75 // (widgets code) /* From d16c87a5b19e82b922e7a400b897f83d62c8715c Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 10 Feb 2020 16:44:28 +0100 Subject: [PATCH 267/384] Internals: Minor renaming --- imgui_draw.cpp | 5 +++-- imgui_internal.h | 2 +- misc/freetype/imgui_freetype.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 4bb91ccf..5c9d2c6a 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1942,7 +1942,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) { IM_ASSERT(atlas->ConfigData.Size > 0); - ImFontAtlasBuildRegisterDefaultCustomRects(atlas); + ImFontAtlasBuildInit(atlas); // Clear atlas atlas->TexID = (ImTextureID)NULL; @@ -2194,7 +2194,8 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) return true; } -void ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas) +// Register default custom rectangles (this is called/shared by both the stb_truetype and the FreeType builder) +void ImFontAtlasBuildInit(ImFontAtlas* atlas) { if (atlas->CustomRectIds[0] >= 0) return; diff --git a/imgui_internal.h b/imgui_internal.h index 5de13c36..8c1de54e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1868,7 +1868,7 @@ namespace ImGui // ImFontAtlas internals IMGUI_API bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas); -IMGUI_API void ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas); +IMGUI_API void ImFontAtlasBuildInit(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent); IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque); IMGUI_API void ImFontAtlasBuildFinish(ImFontAtlas* atlas); diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 6695fb65..fb2b399d 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -317,7 +317,7 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns { IM_ASSERT(atlas->ConfigData.Size > 0); - ImFontAtlasBuildRegisterDefaultCustomRects(atlas); + ImFontAtlasBuildInit(atlas); // Clear atlas atlas->TexID = (ImTextureID)NULL; From f346b4b3021a83ea920dbf4348b2aa208c9bb0b9 Mon Sep 17 00:00:00 2001 From: coding_jackalope Date: Fri, 7 Feb 2020 12:48:59 -0800 Subject: [PATCH 268/384] Examples: SDL+Metal example. --- examples/example_sdl_metal/Makefile | 46 +++++++ examples/example_sdl_metal/main.mm | 190 ++++++++++++++++++++++++++++ examples/imgui_impl_sdl.cpp | 33 +++++ examples/imgui_impl_sdl.h | 2 + 4 files changed, 271 insertions(+) create mode 100644 examples/example_sdl_metal/Makefile create mode 100644 examples/example_sdl_metal/main.mm diff --git a/examples/example_sdl_metal/Makefile b/examples/example_sdl_metal/Makefile new file mode 100644 index 00000000..9d0d5e0f --- /dev/null +++ b/examples/example_sdl_metal/Makefile @@ -0,0 +1,46 @@ +# +# You will need SDL2 (http://www.libsdl.org): +# brew install sdl2 +# + +#CXX = g++ +#CXX = clang++ + +EXE = example_sdl_metal +SOURCES = main.mm +SOURCES += ../imgui_impl_sdl.cpp ../imgui_impl_metal.mm +SOURCES += ../../imgui.cpp ../../imgui_widgets.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp +OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) + +LIBS = -framework Metal -framework MetalKit -framework Cocoa -framework IOKit -framework CoreVideo -framework QuartzCore +LIBS += `sdl2-config --libs` +LIBS += -L/usr/local/lib + +CXXFLAGS = -I../ -I../../ -I/usr/local/include +CXXFLAGS += `sdl2-config --cflags` +CXXFLAGS += -Wall -Wformat +CFLAGS = $(CXXFLAGS) + +%.o:%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +%.o:../%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +%.o:../../%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +%.o:../%.mm + $(CXX) $(CXXFLAGS) -ObjC++ -fobjc-weak -fobjc-arc -c -o $@ $< + +%.o:%.mm + $(CXX) $(CXXFLAGS) -ObjC++ -fobjc-weak -fobjc-arc -c -o $@ $< + +all: $(EXE) + @echo Build complete + +$(EXE): $(OBJS) + $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS) + +clean: + rm -f $(EXE) $(OBJS) diff --git a/examples/example_sdl_metal/main.mm b/examples/example_sdl_metal/main.mm new file mode 100644 index 00000000..7801ca14 --- /dev/null +++ b/examples/example_sdl_metal/main.mm @@ -0,0 +1,190 @@ +// ImGui - standalone example application for GLFW + Metal, using programmable pipeline +// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. + +#include "imgui.h" +#include "imgui_impl_sdl.h" +#include "imgui_impl_metal.h" + +#include "SDL.h" + +#import +#import + +#include + +int main(int, char**) +{ + // Setup Dear ImGui binding + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'docs/FONTS.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + // Setup SDL + // (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems, + // depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to latest version of SDL is recommended!) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + SDL_Window* window = SDL_CreateWindow( + "Dear ImGui SDL+Metal example", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 1280, + 720, + SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI + ); + + if (window == NULL) + { + printf("Error creating window: %s\n", SDL_GetError()); + return -2; + } + + SDL_Renderer* renderer = SDL_CreateRenderer( + window, + -1, + SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC + ); + + if (renderer == NULL) + { + printf("Error creating renderer: %s\n", SDL_GetError()); + return -3; + } + + CAMetalLayer* layer = (__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(renderer); + layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + ImGui_ImplMetal_Init(layer.device); + ImGui_ImplSDL2_InitForMetal(window); + + id commandQueue = [layer.device newCommandQueue]; + MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor new]; + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + float clear_color[4] = {0.45f, 0.55f, 0.60f, 1.00f}; + + // Main loop + bool done = false; + while (!done) + { + @autoreleasepool + { + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSDL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) + done = true; + } + + int width, height; + SDL_GetRendererOutputSize(renderer, &width, &height); + layer.drawableSize = CGSizeMake(width, height); + id drawable = [layer nextDrawable]; + + id commandBuffer = [commandQueue commandBuffer]; + renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); + renderPassDescriptor.colorAttachments[0].texture = drawable.texture; + renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; + renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; + id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + [renderEncoder pushDebugGroup:@"ImGui demo"]; + + // Start the Dear ImGui frame + ImGui_ImplMetal_NewFrame(renderPassDescriptor); + ImGui_ImplSDL2_NewFrame_Metal(window); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::End(); + } + + // 3. Show another simple window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + ImGui::Text("Hello from another window!"); + if (ImGui::Button("Close Me")) + show_another_window = false; + ImGui::End(); + } + + // Rendering + ImGui::Render(); + ImGui_ImplMetal_RenderDrawData(ImGui::GetDrawData(), commandBuffer, renderEncoder); + + [renderEncoder popDebugGroup]; + [renderEncoder endEncoding]; + + [commandBuffer presentDrawable:drawable]; + [commandBuffer commit]; + } + } + + // Cleanup + ImGui_ImplMetal_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 32722bf6..aac3b82c 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -212,6 +212,11 @@ bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window) return ImGui_ImplSDL2_Init(window); } +bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window) +{ + return ImGui_ImplSDL2_Init(window); +} + void ImGui_ImplSDL2_Shutdown() { g_Window = NULL; @@ -359,3 +364,31 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window) // Update game controllers (if enabled and available) ImGui_ImplSDL2_UpdateGamepads(); } + +void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window) +{ + ImGuiIO& io = ImGui::GetIO(); + IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplMetal_NewFrame()."); + + // Setup display size (every frame to accommodate for window resizing) + SDL_Renderer* renderer = SDL_GetRenderer(window); + int w, h; + int display_w, display_h; + SDL_GetWindowSize(window, &w, &h); + SDL_GetRendererOutputSize(renderer, &display_w, &display_h); + io.DisplaySize = ImVec2((float)w, (float)h); + if (w > 0 && h > 0) + io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); + + // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) + static Uint64 frequency = SDL_GetPerformanceFrequency(); + Uint64 current_time = SDL_GetPerformanceCounter(); + io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f); + g_Time = current_time; + + ImGui_ImplSDL2_UpdateMousePosAndButtons(); + ImGui_ImplSDL2_UpdateMouseCursor(); + + // Update game controllers (if enabled and available) + ImGui_ImplSDL2_UpdateGamepads(); +} diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index 376e622c..42da71ed 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -22,6 +22,8 @@ typedef union SDL_Event SDL_Event; IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); +IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); From 21b9e42964cfaa44b949b701fea37f2e6012e319 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 10 Feb 2020 16:13:29 +0200 Subject: [PATCH 269/384] Minor fixes to example_sdl_metal and a changelog entry. Add example_sdl_metal to CI builds. Closes #3017. --- .github/workflows/build.yml | 3 +++ docs/CHANGELOG.txt | 9 +++++++ examples/README.txt | 6 ++++- examples/example_glfw_metal/main.mm | 8 +++---- examples/example_glfw_opengl2/main.cpp | 2 +- examples/example_glfw_opengl3/main.cpp | 2 +- examples/example_sdl_directx11/main.cpp | 2 +- examples/example_sdl_metal/main.mm | 31 ++++++++----------------- examples/example_sdl_opengl2/main.cpp | 2 +- examples/example_sdl_opengl3/main.cpp | 2 +- examples/imgui_impl_sdl.cpp | 28 ---------------------- examples/imgui_impl_sdl.h | 3 +-- 12 files changed, 37 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a874bfff..ff83bd3d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -241,6 +241,9 @@ jobs: - name: Build example_glfw_metal run: make -C examples/example_glfw_metal + - name: Build example_sdl_metal + run: make -C examples/example_sdl_metal + - name: Build example_sdl_opengl2 run: make -C examples/example_sdl_opengl2 if: github.event_name == 'schedule' diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 736cb447..66c5160a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,6 +30,15 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.76 WIP (In Progress) +----------------------------------------------------------------------- + +Other Changes: + +- Backends: Added SDL2+Metal example application. (#3017) [@coding-jackalope] + + ----------------------------------------------------------------------- VERSION 1.75 (Released 2020-02-10) ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index 5bd16be4..5d07a210 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -190,7 +190,7 @@ example_empscripten: example_glfw_metal/ GLFW (Mac) + Metal example. - = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm. + = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm example_glfw_opengl2/ GLFW + OpenGL2 example (legacy, fixed pipeline). @@ -237,6 +237,10 @@ example_sdl_directx11/ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp This to demonstrate usage of DirectX with SDL. +example_sdl_metal/ + SDL2 (Mac) + Metal example. + = main.mm + imgui_impl_sdl.cpp + imgui_impl_metal.mm + example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 45dbb37b..d6f9ae3f 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -1,9 +1,11 @@ -// ImGui - standalone example application for GLFW + Metal, using programmable pipeline -// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// dear imgui: standalone example application for GLFW + Metal, using programmable pipeline +// If you are new to dear 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/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_metal.h" +#include #define GLFW_INCLUDE_NONE #define GLFW_EXPOSE_NATIVE_COCOA @@ -13,8 +15,6 @@ #import #import -#include - static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Glfw Error %d: %s\n", error, description); diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 5630b6c3..a50b4637 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for GLFW + OpenGL2, using legacy fixed pipeline // If you are new to dear 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.) +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal 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 example_glfw_opengl2/ folder** diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index ef7ddfed..55b379de 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for GLFW + OpenGL 3, using programmable pipeline // If you are new to dear 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.) +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_glfw.h" diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 812b40f4..0a97325d 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + DirectX 11 // If you are new to dear 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.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_sdl.h" diff --git a/examples/example_sdl_metal/main.mm b/examples/example_sdl_metal/main.mm index 7801ca14..3cb1ea4d 100644 --- a/examples/example_sdl_metal/main.mm +++ b/examples/example_sdl_metal/main.mm @@ -1,17 +1,16 @@ -// ImGui - standalone example application for GLFW + Metal, using programmable pipeline -// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// Dear ImGui: standalone example application for SDL2 + Metal +// If you are new to dear 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/Metal graphics context creation, etc.) #include "imgui.h" #include "imgui_impl_sdl.h" #include "imgui_impl_metal.h" - -#include "SDL.h" +#include +#include #import #import -#include - int main(int, char**) { // Setup Dear ImGui binding @@ -49,27 +48,17 @@ int main(int, char**) return -1; } - SDL_Window* window = SDL_CreateWindow( - "Dear ImGui SDL+Metal example", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 1280, - 720, - SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI - ); + // Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail. + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); + SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL+Metal example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); if (window == NULL) { printf("Error creating window: %s\n", SDL_GetError()); return -2; } - SDL_Renderer* renderer = SDL_CreateRenderer( - window, - -1, - SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC - ); - + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == NULL) { printf("Error creating renderer: %s\n", SDL_GetError()); @@ -125,7 +114,7 @@ int main(int, char**) // Start the Dear ImGui frame ImGui_ImplMetal_NewFrame(renderPassDescriptor); - ImGui_ImplSDL2_NewFrame_Metal(window); + ImGui_ImplSDL2_NewFrame(window); ImGui::NewFrame(); // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index b55cb22f..ff54ec41 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + OpenGL // If you are new to dear 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.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal 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 example_sdl_opengl3/ folder** diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index a0cfe240..20801a19 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -1,6 +1,6 @@ // dear imgui: standalone example application for SDL2 + OpenGL // If you are new to dear 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.) +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) // (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) #include "imgui.h" diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index aac3b82c..69172622 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -364,31 +364,3 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window) // Update game controllers (if enabled and available) ImGui_ImplSDL2_UpdateGamepads(); } - -void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window) -{ - ImGuiIO& io = ImGui::GetIO(); - IM_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built! It is generally built by the renderer back-end. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplMetal_NewFrame()."); - - // Setup display size (every frame to accommodate for window resizing) - SDL_Renderer* renderer = SDL_GetRenderer(window); - int w, h; - int display_w, display_h; - SDL_GetWindowSize(window, &w, &h); - SDL_GetRendererOutputSize(renderer, &display_w, &display_h); - io.DisplaySize = ImVec2((float)w, (float)h); - if (w > 0 && h > 0) - io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); - - // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution) - static Uint64 frequency = SDL_GetPerformanceFrequency(); - Uint64 current_time = SDL_GetPerformanceCounter(); - io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f); - g_Time = current_time; - - ImGui_ImplSDL2_UpdateMousePosAndButtons(); - ImGui_ImplSDL2_UpdateMouseCursor(); - - // Update game controllers (if enabled and available) - ImGui_ImplSDL2_UpdateGamepads(); -} diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index 42da71ed..a672ca83 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -22,8 +22,7 @@ typedef union SDL_Event SDL_Event; IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); -IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); -IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame_Metal(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); From d8948b5343fb0102fcea304969a8ba5063362728 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 10 Feb 2020 21:23:34 +0100 Subject: [PATCH 270/384] ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default. --- docs/CHANGELOG.txt | 2 ++ imgui.h | 3 ++- imgui_demo.cpp | 4 +++- imgui_widgets.cpp | 19 +++++++++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 66c5160a..d071c7de 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,6 +36,8 @@ HOW TO UPDATE? Other Changes: +- ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced + by default for standalone ColorButton. - Backends: Added SDL2+Metal example application. (#3017) [@coding-jackalope] diff --git a/imgui.h b/imgui.h index c2bbb7f7..a7b191ee 100644 --- a/imgui.h +++ b/imgui.h @@ -60,7 +60,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.75" -#define IMGUI_VERSION_NUM 17500 +#define IMGUI_VERSION_NUM 17501 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) @@ -1158,6 +1158,7 @@ enum ImGuiColorEditFlags_ ImGuiColorEditFlags_NoLabel = 1 << 7, // // ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker). ImGuiColorEditFlags_NoSidePreview = 1 << 8, // // ColorPicker: disable bigger color preview on right side of the picker, use small colored square preview instead. ImGuiColorEditFlags_NoDragDrop = 1 << 9, // // ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source. + ImGuiColorEditFlags_NoBorder = 1 << 10, // // ColorButton: disable border (which is enforced by default) // User Options (right-click on widget to change some of them). ImGuiColorEditFlags_AlphaBar = 1 << 16, // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 7664f1b4..32579d19 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1264,7 +1264,9 @@ static void ShowDemoWindowWidgets() } ImGui::Text("Color button only:"); - ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, misc_flags, ImVec2(80,80)); + static bool no_border = false; + ImGui::Checkbox("ImGuiColorEditFlags_NoBorder", &no_border); + ImGui::ColorButton("MyColor##3c", *(ImVec4*)&color, misc_flags | (no_border ? ImGuiColorEditFlags_NoBorder : 0), ImVec2(80,80)); ImGui::Text("Color picker:"); static bool alpha = true; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 6d2c95d9..a892b15a 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4956,8 +4956,12 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl float grid_step = ImMin(size.x, size.y) / 2.99f; float rounding = ImMin(g.Style.FrameRounding, grid_step * 0.5f); ImRect bb_inner = bb; - float off = -0.75f; // The border (using Col_FrameBg) tends to look off when color is near-opaque and rounding is enabled. This offset seemed like a good middle ground to reduce those artifacts. - bb_inner.Expand(off); + float off = 0.0f; + if ((flags & ImGuiColorEditFlags_NoBorder) == 0) + { + off = -0.75f; // The border (using Col_FrameBg) tends to look off when color is near-opaque and rounding is enabled. This offset seemed like a good middle ground to reduce those artifacts. + bb_inner.Expand(off); + } if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col_rgb.w < 1.0f) { float mid_x = IM_ROUND((bb_inner.Min.x + bb_inner.Max.x) * 0.5f); @@ -4974,10 +4978,13 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl window->DrawList->AddRectFilled(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), rounding, ImDrawCornerFlags_All); } RenderNavHighlight(bb, id); - if (g.Style.FrameBorderSize > 0.0f) - RenderFrameBorder(bb.Min, bb.Max, rounding); - else - window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border + if ((flags & ImGuiColorEditFlags_NoBorder) == 0) + { + if (g.Style.FrameBorderSize > 0.0f) + RenderFrameBorder(bb.Min, bb.Max, rounding); + else + window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border + } // Drag and Drop Source // NB: The ActiveId test is merely an optional micro-optimization, BeginDragDropSource() does the same test. From 70975fe44d22dc758c5b6ba430107ee2b4a16b74 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 10 Feb 2020 22:08:52 +0100 Subject: [PATCH 271/384] Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. --- docs/CHANGELOG.txt | 5 ++++- imgui_demo.cpp | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d071c7de..b96c0d66 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,7 +38,10 @@ Other Changes: - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. -- Backends: Added SDL2+Metal example application. (#3017) [@coding-jackalope] +- Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. +- Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function + currently does nothing). +- Examples: Added SDL2+Metal example application. (#3017) [@coding-jackalope] ----------------------------------------------------------------------- diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 32579d19..2a1676d6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4471,7 +4471,6 @@ static void ShowExampleAppCustomRendering(bool* p_open) if (ImGui::SliderInt("Circle segments", &circle_segments_override_v, 3, 40)) circle_segments_override = true; ImGui::ColorEdit4("Color", &colf.x); - ImGui::PopItemWidth(); const ImVec2 p = ImGui::GetCursorScreenPos(); const ImU32 col = ImColor(colf); const float spacing = 10.0f; @@ -4510,6 +4509,27 @@ static void ShowExampleAppCustomRendering(bool* p_open) draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine) draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x + sz, y + sz), IM_COL32(0, 0, 0, 255), IM_COL32(255, 0, 0, 255), IM_COL32(255, 255, 0, 255), IM_COL32(0, 255, 0, 255)); ImGui::Dummy(ImVec2((sz + spacing) * 9.8f, (sz + spacing) * 3)); + + // Draw black and white gradients + static int gradient_steps = 16; + ImGui::Separator(); + ImGui::AlignTextToFramePadding(); + ImGui::Text("Gradient steps"); + ImGui::SameLine(); if (ImGui::RadioButton("16", gradient_steps == 16)) { gradient_steps = 16; } + ImGui::SameLine(); if (ImGui::RadioButton("32", gradient_steps == 32)) { gradient_steps = 32; } + ImGui::SameLine(); if (ImGui::RadioButton("256", gradient_steps == 256)) { gradient_steps = 256; } + ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), 64.0f); + x = ImGui::GetCursorScreenPos().x; + y = ImGui::GetCursorScreenPos().y; + for (int n = 0; n < gradient_steps; n++) + { + float f = n / (float)gradient_steps; + ImU32 col32 = ImGui::GetColorU32(ImVec4(f, f, f, 1.0f)); + draw_list->AddRectFilled(ImVec2(x + gradient_size.x * (n / (float)gradient_steps), y), ImVec2(x + gradient_size.x * ((n+1) / (float)gradient_steps), y + gradient_size.y), col32); + } + ImGui::InvisibleButton("##gradient", gradient_size); + + ImGui::PopItemWidth(); ImGui::EndTabItem(); } From 30bb15672d158864aa19914a0dc5f64c27358d14 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 10 Feb 2020 23:22:03 +0100 Subject: [PATCH 272/384] Remove trailing spaces --- imconfig.h | 6 +++--- imgui.cpp | 2 +- imgui.h | 4 ++-- imgui_internal.h | 6 +++--- imgui_widgets.cpp | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/imconfig.h b/imconfig.h index 09bfd16c..4f629795 100644 --- a/imconfig.h +++ b/imconfig.h @@ -26,10 +26,10 @@ //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS -//---- Disable all of Dear ImGui or don't implement standard windows. +//---- Disable all of Dear ImGui or don't implement standard windows. // It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. -//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. -//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. +//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. +//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. //#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty. //---- Don't implement some functions to reduce linkage requirements. diff --git a/imgui.cpp b/imgui.cpp index 1b78dd83..a5dd85a3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4159,7 +4159,7 @@ void ImGui::Render() g.FrameCountRendered = g.FrameCount; g.IO.MetricsRenderWindows = 0; g.DrawDataBuilder.Clear(); - + // Add background ImDrawList if (!g.BackgroundDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.BackgroundDrawList); diff --git a/imgui.h b/imgui.h index a7b191ee..60bd9395 100644 --- a/imgui.h +++ b/imgui.h @@ -1944,8 +1944,8 @@ struct ImDrawList // Primitives // - For rectangular primitives, "p_min" and "p_max" represent the upper-left and lower-right corners. - // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). - // In future versions we will use textures to provide cheaper and higher-quality circles. + // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). + // In future versions we will use textures to provide cheaper and higher-quality circles. // Use AddNgon() and AddNgonFilled() functions if you need to guaranteed a specific number of sides. IMGUI_API void AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness = 1.0f); IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size), rounding_corners_flags: 4 bits corresponding to which corner to round diff --git a/imgui_internal.h b/imgui_internal.h index 8c1de54e..a5cbb05c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -431,10 +431,10 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_NoHoldingActiveId = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_NoNavFocus = 1 << 14, // don't override navigation focus when activated ImGuiButtonFlags_NoHoveredOnNav = 1 << 15, // don't report as hovered when navigated on - ImGuiButtonFlags_MouseButtonLeft = 1 << 16, // [Default] react on left mouse button + ImGuiButtonFlags_MouseButtonLeft = 1 << 16, // [Default] react on left mouse button ImGuiButtonFlags_MouseButtonRight = 1 << 17, // react on right mouse button ImGuiButtonFlags_MouseButtonMiddle = 1 << 18, // react on center mouse button - + ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, ImGuiButtonFlags_MouseButtonShift_ = 16, ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, @@ -1642,7 +1642,7 @@ namespace ImGui IMGUI_API void BringWindowToFocusFront(ImGuiWindow* window); IMGUI_API void BringWindowToDisplayFront(ImGuiWindow* window); IMGUI_API void BringWindowToDisplayBack(ImGuiWindow* window); - + // Fonts, drawing IMGUI_API void SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a892b15a..de403718 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3273,8 +3273,8 @@ static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const Im #define STB_TEXTEDIT_IMPLEMENTATION #include "imstb_textedit.h" -// stb_textedit internally allows for a single undo record to do addition and deletion, but somehow, calling -// the stb_textedit_paste() function creates two separate records, so we perform it manually. (FIXME: Report to nothings/stb?) +// stb_textedit internally allows for a single undo record to do addition and deletion, but somehow, calling +// the stb_textedit_paste() function creates two separate records, so we perform it manually. (FIXME: Report to nothings/stb?) static void stb_textedit_replace(STB_TEXTEDIT_STRING* str, STB_TexteditState* state, const STB_TEXTEDIT_CHARTYPE* text, int text_len) { stb_text_makeundo_replace(str, state, 0, str->CurLenW, text_len); @@ -3859,7 +3859,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. - // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. + // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. // This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize). bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); if (apply_edit_back_to_user_buffer) From ccaec1a270970ee550bc7586468ffbe7ebcb71ac Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 11 Feb 2020 16:56:56 +0100 Subject: [PATCH 273/384] Version 1.76 WIP --- examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/README.txt b/examples/README.txt index 5d07a210..146d79ee 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.75 + dear imgui, v1.76 WIP ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index a5dd85a3..53b05aa4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index 60bd9395..ac2b4c69 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (headers) // Help: @@ -59,8 +59,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.75" -#define IMGUI_VERSION_NUM 17501 +#define IMGUI_VERSION "1.76 WIP" +#define IMGUI_VERSION_NUM 17502 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 2a1676d6..737d9c3c 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 5c9d2c6a..ab45bbb7 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index a5cbb05c..450318da 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index de403718..ef154760 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.75 +// dear imgui, v1.76 WIP // (widgets code) /* From d284a6cffc6d86edf9281b7acf869fc85c034702 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 11 Feb 2020 18:53:57 +0100 Subject: [PATCH 274/384] InputText: Fixed password fields displaying ASCII spaces as blanks. Fixed non-ASCII space occasionally creating unnecessary empty polygons. (#2149, #515) --- docs/CHANGELOG.txt | 3 + imgui.h | 6 +- imgui_demo.cpp | 9 +-- imgui_draw.cpp | 144 ++++++++++++++++++++++++--------------------- 4 files changed, 89 insertions(+), 73 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b96c0d66..4216ab50 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,6 +38,9 @@ Other Changes: - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. +- InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' + glyph. (#2149, #515) +- Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. - Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). diff --git a/imgui.h b/imgui.h index ac2b4c69..7dfc891a 100644 --- a/imgui.h +++ b/imgui.h @@ -2068,9 +2068,12 @@ struct ImFontConfig IMGUI_API ImFontConfig(); }; +// Hold rendering data for one glyph. +// (Note: some language parsers may fail to convert the 31+1 bitfield members, in this case maybe drop store a single u32 or we can rework this) struct ImFontGlyph { - ImWchar Codepoint; // 0x0000..0xFFFF + unsigned int Codepoint : 31; // 0x0000..0xFFFF + unsigned int Visible : 1; // Flag to allow early out when rendering float AdvanceX; // Distance to next character (= data from font + ImFontConfig::GlyphExtraSpacing.x baked in) float X0, Y0, X1, Y1; // Glyph corners float U0, V0, U1, V1; // Texture coordinates @@ -2265,6 +2268,7 @@ struct ImFont IMGUI_API void GrowIndex(int new_size); IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x); IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built. + IMGUI_API void SetGlyphVisible(ImWchar c, bool visible); IMGUI_API void SetFallbackChar(ImWchar c); }; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 737d9c3c..c5f845de 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1040,11 +1040,11 @@ static void ShowDemoWindowWidgets() static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); ImGui::Text("Password input"); - static char bufpass[64] = "password123"; - ImGui::InputText("password", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank); + static char password[64] = "password123"; + ImGui::InputText("password", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password); ImGui::SameLine(); HelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n"); - ImGui::InputTextWithHint("password (w/ hint)", "", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank); - ImGui::InputText("password (clear)", bufpass, 64, ImGuiInputTextFlags_CharsNoBlank); + ImGui::InputTextWithHint("password (w/ hint)", "", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank); + ImGui::InputText("password (clear)", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_CharsNoBlank); ImGui::TreePop(); } @@ -3465,6 +3465,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::BeginTooltip(); ImGui::Text("Codepoint: U+%04X", base + n); ImGui::Separator(); + ImGui::Text("Visible: %d", glyph->Visible); ImGui::Text("AdvanceX: %.1f", glyph->AdvanceX); ImGui::Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1); ImGui::Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index ab45bbb7..b34358d6 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2622,6 +2622,7 @@ void ImFont::BuildLookupTable() for (int i = 0; i != Glyphs.Size; i++) max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint); + // Build lookup table IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved IndexAdvanceX.clear(); IndexLookup.clear(); @@ -2638,7 +2639,7 @@ void ImFont::BuildLookupTable() // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?) if (FindGlyph((ImWchar)' ')) { - if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times + if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times (FIXME: Flaky) Glyphs.resize(Glyphs.Size + 1); ImFontGlyph& tab_glyph = Glyphs.back(); tab_glyph = *FindGlyph((ImWchar)' '); @@ -2648,6 +2649,11 @@ void ImFont::BuildLookupTable() IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1); } + // Mark special glyphs as not visible (note that AddGlyph already mark as non-visible glyphs with zero-size polygons) + SetGlyphVisible((ImWchar)' ', false); + SetGlyphVisible((ImWchar)'\t', false); + + // Setup fall-backs FallbackGlyph = FindGlyphNoFallback(FallbackChar); FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f; for (int i = 0; i < max_codepoint + 1; i++) @@ -2655,6 +2661,12 @@ void ImFont::BuildLookupTable() IndexAdvanceX[i] = FallbackAdvanceX; } +void ImFont::SetGlyphVisible(ImWchar c, bool visible) +{ + if (ImFontGlyph* glyph = (ImFontGlyph*)(void*)FindGlyph((ImWchar)c)) + glyph->Visible = visible ? 1 : 0; +} + void ImFont::SetFallbackChar(ImWchar c) { FallbackChar = c; @@ -2676,7 +2688,8 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, { Glyphs.resize(Glyphs.Size + 1); ImFontGlyph& glyph = Glyphs.back(); - glyph.Codepoint = (ImWchar)codepoint; + glyph.Codepoint = (unsigned int)codepoint; + glyph.Visible = (x0 != x1) && (y0 != y1); glyph.X0 = x0; glyph.Y0 = y0; glyph.X1 = x1; @@ -2925,16 +2938,14 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const { - if (c == ' ' || c == '\t' || c == '\n' || c == '\r') // Match behavior of RenderText(), those 4 codepoints are hard-coded. + const ImFontGlyph* glyph = FindGlyph(c); + if (!glyph || !glyph->Visible) return; - if (const ImFontGlyph* glyph = FindGlyph(c)) - { - float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f; - pos.x = IM_FLOOR(pos.x + DisplayOffset.x); - pos.y = IM_FLOOR(pos.y + DisplayOffset.y); - draw_list->PrimReserve(6, 4); - draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); - } + float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f; + pos.x = IM_FLOOR(pos.x + DisplayOffset.x); + pos.y = IM_FLOOR(pos.y + DisplayOffset.y); + draw_list->PrimReserve(6, 4); + draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); } void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const @@ -3047,73 +3058,70 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col continue; } - float char_width = 0.0f; - if (const ImFontGlyph* glyph = FindGlyph((ImWchar)c)) - { - char_width = glyph->AdvanceX * scale; + const ImFontGlyph* glyph = FindGlyph((ImWchar)c); + if (glyph == NULL) + continue; - // Arbitrarily assume that both space and tabs are empty glyphs as an optimization - if (c != ' ' && c != '\t') + float char_width = glyph->AdvanceX * scale; + if (glyph->Visible) + { + // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w + float x1 = x + glyph->X0 * scale; + float x2 = x + glyph->X1 * scale; + float y1 = y + glyph->Y0 * scale; + float y2 = y + glyph->Y1 * scale; + if (x1 <= clip_rect.z && x2 >= clip_rect.x) { - // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w - float x1 = x + glyph->X0 * scale; - float x2 = x + glyph->X1 * scale; - float y1 = y + glyph->Y0 * scale; - float y2 = y + glyph->Y1 * scale; - if (x1 <= clip_rect.z && x2 >= clip_rect.x) + // Render a character + float u1 = glyph->U0; + float v1 = glyph->V0; + float u2 = glyph->U1; + float v2 = glyph->V1; + + // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads. + if (cpu_fine_clip) { - // Render a character - float u1 = glyph->U0; - float v1 = glyph->V0; - float u2 = glyph->U1; - float v2 = glyph->V1; - - // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads. - if (cpu_fine_clip) + if (x1 < clip_rect.x) { - if (x1 < clip_rect.x) - { - u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1); - x1 = clip_rect.x; - } - if (y1 < clip_rect.y) - { - v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1); - y1 = clip_rect.y; - } - if (x2 > clip_rect.z) - { - u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1); - x2 = clip_rect.z; - } - if (y2 > clip_rect.w) - { - v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1); - y2 = clip_rect.w; - } - if (y1 >= y2) - { - x += char_width; - continue; - } + u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1); + x1 = clip_rect.x; } - - // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here: + if (y1 < clip_rect.y) + { + v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1); + y1 = clip_rect.y; + } + if (x2 > clip_rect.z) { - idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2); - idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3); - vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1; - vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1; - vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2; - vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2; - vtx_write += 4; - vtx_current_idx += 4; - idx_write += 6; + u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1); + x2 = clip_rect.z; + } + if (y2 > clip_rect.w) + { + v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1); + y2 = clip_rect.w; + } + if (y1 >= y2) + { + x += char_width; + continue; } } + + // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here: + { + idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2); + idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3); + vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1; + vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1; + vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2; + vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2; + vtx_write += 4; + vtx_current_idx += 4; + idx_write += 6; + } } } - x += char_width; } From b4ac420fc5c839982476bd2b24ffabd2668dc7d0 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 11 Feb 2020 19:31:33 +0100 Subject: [PATCH 275/384] Demo: Amend d284a6c (#2149, #515) --- imgui_demo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c5f845de..0d800cd4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1043,8 +1043,8 @@ static void ShowDemoWindowWidgets() static char password[64] = "password123"; ImGui::InputText("password", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password); ImGui::SameLine(); HelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n"); - ImGui::InputTextWithHint("password (w/ hint)", "", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank); - ImGui::InputText("password (clear)", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_CharsNoBlank); + ImGui::InputTextWithHint("password (w/ hint)", "", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password); + ImGui::InputText("password (clear)", password, IM_ARRAYSIZE(password)); ImGui::TreePop(); } From 2bc3a92f9614c32283a28c61214b9247a3fbc21b Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 12 Feb 2020 16:10:58 +0100 Subject: [PATCH 276/384] Update README.md --- docs/README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/docs/README.md b/docs/README.md index cc1ac39e..a25e10f9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -190,24 +190,16 @@ Individuals: support continued maintenance and development via [PayPal](https:// Ongoing Dear ImGui development is financially supported by users and private sponsors, recently: *Platinum-chocolate sponsors* -- Blizzard Entertainment -- Google -- Ubisoft -- Nvidia +- [Blizzard](https://careers.blizzard.com/en-us/openings/engineering/all/all/all/1), [Google](https://github.com/google/filament), [Nvidia](https://developer.nvidia.com/nvidia-omniverse), [Ubisoft](https://montreal.ubisoft.com/fr/ubisoft-commandite-la-bibliotheque-dinterface-utilisateur-pour-c-dear-imgui/) -*Double-chocolate sponsors* -- Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Aiden Koss, Kylotonn. +*Double-chocolate and Salty caramel sponsors* +- DotEmu, Framefield, Kylotonn, Media Molecule, Mesh Consultants, Mobigame, Nadeo, Next Level Games, Remedy Entertainment, Supercell, Unit 2 Games. -*Salty caramel supporters* -- Remedy Entertainment, Next Level Games, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, G3DVu, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford, Bill Six, Graham Manders. +From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. Please see [detailed list of Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors). -*Caramel supporters* -- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Morten Skaaning, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis, Matt Reyer. +**THANK YOU to all past and present supporters for helping to keep this project alive and thriving!** -And all other past and present supporters; THANK YOU! -(Please contact me if you would like to be added or removed from this list) - -Dear ImGui is using software and services kindly provided free of charge for open source projects: +Dear ImGui is using software and services provided free of charge for open source projects: - [PVS-Studio](https://www.viva64.com/en/b/0570/) for static analysis. - [GitHub actions](https://github.com/features/actions) for continuous integration systems. From f339b24b3a0b6270c5e1a70df66e39b87d1ccdc6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 12 Feb 2020 16:19:54 +0100 Subject: [PATCH 277/384] Links, alphabetical order --- docs/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index a25e10f9..72d35ded 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ dear imgui Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ -Individuals: support continued maintenance and development via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) donations. +Individuals: support continued maintenance and development with [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S). ---- @@ -164,7 +164,7 @@ You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issue **Who uses Dear ImGui?** -See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for a list of games/software which are publicly known to use dear imgui. Please add yours if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! +See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes), [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors), [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for an idea of who is using Dear ImGui. Please add your game/software if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! How to help ----------- @@ -183,17 +183,18 @@ Your contributions are keeping this project alive. The library is available unde Businesses: support continued development via invoiced technical support, maintenance, sponsoring contracts:
  _E-mail: contact @ dearimgui dot org_ -Individuals: support continued maintenance and development via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S) donations. +Individuals: support continued maintenance and development with [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S). -### Sponsors +Sponsors +-------- Ongoing Dear ImGui development is financially supported by users and private sponsors, recently: *Platinum-chocolate sponsors* -- [Blizzard](https://careers.blizzard.com/en-us/openings/engineering/all/all/all/1), [Google](https://github.com/google/filament), [Nvidia](https://developer.nvidia.com/nvidia-omniverse), [Ubisoft](https://montreal.ubisoft.com/fr/ubisoft-commandite-la-bibliotheque-dinterface-utilisateur-pour-c-dear-imgui/) +- [Blizzard](https://careers.blizzard.com/en-us/openings/engineering/all/all/all/1), [Google](https://github.com/google/filament), [Nvidia](https://developer.nvidia.com/nvidia-omniverse), [Ubisoft](https://montreal.ubisoft.com/en/ubisoft-sponsors-user-interface-library-for-c-dear-imgui/) *Double-chocolate and Salty caramel sponsors* -- DotEmu, Framefield, Kylotonn, Media Molecule, Mesh Consultants, Mobigame, Nadeo, Next Level Games, Remedy Entertainment, Supercell, Unit 2 Games. +- [DotEmu](http://www.dotemu.com), [Framefield](http://framefield.com), [Hexagon](https://hexagonxalt.com/the-technology/xalt-visualization), [Kylotonn](https://www.kylotonn.com), [Media Molecule](http://www.mediamolecule.com), [Mesh Consultants](https://www.meshconsultants.ca), [Mobigame](http://www.mobigame.net), [Nadeo](https://www.nadeo.com), [Supercell](http://www.supercell.com), [Remedy Entertainment](https://www.remedygames.com/), [Unit 2 Games](https://unit2games.com/) From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. Please see [detailed list of Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors). From 8601187feed8e2b937a8b07eb5a59b0ecebb49b4 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 17 Feb 2020 10:11:26 +0100 Subject: [PATCH 278/384] Backends: Win32: Clarify how the WndProc handler requires a forward declaration. --- examples/example_win32_directx10/main.cpp | 4 +++- examples/example_win32_directx11/main.cpp | 4 +++- examples/example_win32_directx12/main.cpp | 4 +++- examples/example_win32_directx9/main.cpp | 4 +++- examples/imgui_impl_win32.cpp | 13 +++++++++---- examples/imgui_impl_win32.h | 10 +++++----- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index 024e5eb7..41833cb5 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -207,8 +207,10 @@ void CleanupRenderTarget() if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; } } +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + // Win32 message handler -extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index fe462e74..05de7433 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -211,8 +211,10 @@ void CleanupRenderTarget() if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; } } +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + // Win32 message handler -extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 87235125..139dea6e 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -427,8 +427,10 @@ void ResizeSwapChain(HWND hWnd, int width, int height) assert(g_hSwapChainWaitableObject != NULL); } +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + // Win32 message handler -extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index 3586bd6f..f510ca4d 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -202,8 +202,10 @@ void ResetDevice() ImGui_ImplDX9_CreateDeviceObjects(); } +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + // Win32 message handler -extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 140e1e4b..2740fe0e 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -2,7 +2,7 @@ // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) // Implemented features: -// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui) +// [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -255,13 +255,18 @@ void ImGui_ImplWin32_NewFrame() #define DBT_DEVNODES_CHANGED 0x0007 #endif -// Process Win32 mouse/keyboard inputs. -// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// Win32 message handler (process Win32 mouse/keyboard inputs, etc.) +// Call from your application's message handler. +// When implementing your own back-end, you can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if Dear ImGui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. -// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// Generally you may always pass all inputs to Dear ImGui, and hide them from your application based on those two flags. // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinates when dragging mouse outside of our window bounds. // PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. +#if 0 +// Copy this line into your .cpp file to forward declare the function. +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +#endif IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui::GetCurrentContext() == NULL) diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index 93dc75a0..e4b9ec3a 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -2,7 +2,7 @@ // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) // Implemented features: -// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui) +// [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. @@ -17,9 +17,9 @@ IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT -// Handler for Win32 messages, update mouse/keyboard data. -// You may or not need this for your implementation, but it can serve as reference for handling inputs. -// Intentionally commented out to avoid dragging dependencies on types. You can COPY this line into your .cpp code instead. +// Win32 message handler +// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on +// - You can COPY this line into your .cpp code to forward declare the function. #if 0 -IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif From ceec3cd3fd1c2331e45b18dd64d985a07328b4cc Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 17 Feb 2020 11:11:08 +0100 Subject: [PATCH 279/384] Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions. (backported from the docking branch) --- docs/CHANGELOG.txt | 4 ++ examples/imgui_impl_win32.cpp | 100 ++++++++++++++++++++++++++++++++++ examples/imgui_impl_win32.h | 10 ++++ 3 files changed, 114 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4216ab50..f3d7cbfe 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,10 @@ Other Changes: glyph. (#2149, #515) - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. - Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. +- Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), + ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). + Those functions makes it easier for example apps to support hi-dpi features without setting up + a manifest. - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). - Examples: Added SDL2+Metal example application. (#3017) [@coding-jackalope] diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 2740fe0e..449922f5 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -28,6 +28,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-02-17: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helper functions. // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter(). @@ -337,3 +338,102 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA return 0; } + +//-------------------------------------------------------------------------------------------------------- +// DPI-related helpers (optional) +//-------------------------------------------------------------------------------------------------------- +// - Use to enable DPI awareness without having to create an application manifest. +// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. +// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. +// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, +// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. +//--------------------------------------------------------------------------------------------------------- +// This is the scheme successfully used by GLFW (from which we borrowed some of the code) and other apps aiming to be highly portable. +// ImGui_ImplWin32_EnableDpiAwareness() is just a helper called by main.cpp, we don't call it automatically. +// If you are trying to implement your own back-end for your own engine, you may ignore that noise. +//--------------------------------------------------------------------------------------------------------- + +// Implement some of the functions and types normally declared in recent Windows SDK. +#if !defined(_versionhelpers_H_INCLUDED_) && !defined(_INC_VERSIONHELPERS) +static BOOL IsWindowsVersionOrGreater(WORD major, WORD minor, WORD sp) +{ + OSVERSIONINFOEXW osvi = { sizeof(osvi), major, minor, 0, 0, { 0 }, sp }; + DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR; + ULONGLONG cond = ::VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL); + cond = ::VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL); + cond = ::VerSetConditionMask(cond, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + return ::VerifyVersionInfoW(&osvi, mask, cond); +} +#define IsWindows8Point1OrGreater() IsWindowsVersionOrGreater(HIBYTE(0x0602), LOBYTE(0x0602), 0) // _WIN32_WINNT_WINBLUE +#endif + +#ifndef DPI_ENUMS_DECLARED +typedef enum { PROCESS_DPI_UNAWARE = 0, PROCESS_SYSTEM_DPI_AWARE = 1, PROCESS_PER_MONITOR_DPI_AWARE = 2 } PROCESS_DPI_AWARENESS; +typedef enum { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2, MDT_DEFAULT = MDT_EFFECTIVE_DPI } MONITOR_DPI_TYPE; +#endif +#ifndef _DPI_AWARENESS_CONTEXTS_ +DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); +#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE (DPI_AWARENESS_CONTEXT)-3 +#endif +#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 +#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (DPI_AWARENESS_CONTEXT)-4 +#endif +typedef HRESULT(WINAPI* PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS); // Shcore.lib + dll, Windows 8.1+ +typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); // Shcore.lib + dll, Windows 8.1+ +typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update) + +// Helper function to enable DPI awareness without setting up a manifest +void ImGui_ImplWin32_EnableDpiAwareness() +{ + // if (IsWindows10OrGreater()) // This needs a manifest to succeed. Instead we try to grab the function pointer! + { + static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process + if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext")) + { + SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + return; + } + } + if (IsWindows8Point1OrGreater()) + { + static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process + if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn = (PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness")) + { + SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE); + return; + } + } + SetProcessDPIAware(); +} + +#ifdef _MSC_VER +#pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps() +#endif + +float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) +{ + UINT xdpi = 96, ydpi = 96; + if (IsWindows8Point1OrGreater()) + { + static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process + if (PFN_GetDpiForMonitor GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor")) + GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); + } + else + { + const HDC dc = ::GetDC(NULL); + xdpi = ::GetDeviceCaps(dc, LOGPIXELSX); + ydpi = ::GetDeviceCaps(dc, LOGPIXELSY); + ::ReleaseDC(NULL, dc); + } + IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! + return xdpi / 96.0f; +} + +float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) +{ + HMONITOR monitor = ::MonitorFromWindow((HWND)hwnd, MONITOR_DEFAULTTONEAREST); + return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); +} + +//--------------------------------------------------------------------------------------------------------- diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index e4b9ec3a..daadf317 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -23,3 +23,13 @@ IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); #if 0 extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif + +// DPI-related helpers (optional) +// - Use to enable DPI awareness without having to create an application manifest. +// - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. +// - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. +// but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, +// neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. +IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); +IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd +IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor From 09329ea4e6e7ff6d0f3ecbb16588a2ccd61dedd1 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 17 Feb 2020 15:29:59 +0100 Subject: [PATCH 280/384] Fix Clang 9.0 zealous warnings --- imgui_demo.cpp | 2 +- imgui_draw.cpp | 6 +++--- imstb_truetype.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 0d800cd4..13a0e8c2 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -629,7 +629,7 @@ static void ShowDemoWindowWidgets() { ImGui::Text("blah blah"); ImGui::SameLine(); - if (ImGui::SmallButton("button")) {}; + if (ImGui::SmallButton("button")) {} ImGui::TreePop(); } } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index b34358d6..69d18945 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -617,8 +617,8 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c // On AddPolyline() and AddConvexPolyFilled() we intentionally avoid using ImVec2 and superflous function calls to optimize debug/non-inlined builds. // Those macros expects l-values. -#define IM_NORMALIZE2F_OVER_ZERO(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = 1.0f / ImSqrt(d2); VX *= inv_len; VY *= inv_len; } } -#define IM_FIXNORMAL2F(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 < 0.5f) d2 = 0.5f; float inv_lensq = 1.0f / d2; VX *= inv_lensq; VY *= inv_lensq; } +#define IM_NORMALIZE2F_OVER_ZERO(VX,VY) do { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = 1.0f / ImSqrt(d2); VX *= inv_len; VY *= inv_len; } } while (0) +#define IM_FIXNORMAL2F(VX,VY) do { float d2 = VX*VX + VY*VY; if (d2 < 0.5f) d2 = 0.5f; float inv_lensq = 1.0f / d2; VX *= inv_lensq; VY *= inv_lensq; } while (0) // TODO: Thickness anti-aliased lines cap are missing their AA fringe. // We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds. @@ -680,7 +680,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 // Average normals float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f; float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f; - IM_FIXNORMAL2F(dm_x, dm_y) + IM_FIXNORMAL2F(dm_x, dm_y); dm_x *= AA_SIZE; dm_y *= AA_SIZE; diff --git a/imstb_truetype.h b/imstb_truetype.h index 193338af..7ccc13e8 100644 --- a/imstb_truetype.h +++ b/imstb_truetype.h @@ -2538,11 +2538,11 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i // There are no other cases. STBTT_assert(0); break; - }; + } // [DEAR IMGUI] removed ; } } break; - }; + } // [DEAR IMGUI] removed ; default: // TODO: Implement other stuff. From b62f1ea8e914b66d1bfb58719d07d074eead0c8f Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 17 Feb 2020 16:07:46 +0100 Subject: [PATCH 281/384] Fix zealous PVS studio warnings. Minor tweaks. --- examples/example_win32_directx9/main.cpp | 6 +++--- examples/imgui_impl_dx9.cpp | 12 ++++++------ imgui_demo.cpp | 7 ++++--- imgui_internal.h | 2 +- imstb_truetype.h | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index f510ca4d..33123625 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -136,9 +136,9 @@ int main(int, char**) // Rendering ImGui::EndFrame(); - g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); - g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); - g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f)); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0); if (g_pd3dDevice->BeginScene() >= 0) diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 342f9d54..03114aa8 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -60,16 +60,16 @@ static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data) g_pd3dDevice->SetPixelShader(NULL); g_pd3dDevice->SetVertexShader(NULL); g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false); - g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); - g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); - g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); + g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE); g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); - g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 13a0e8c2..35fe94d9 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4524,9 +4524,10 @@ static void ShowExampleAppCustomRendering(bool* p_open) y = ImGui::GetCursorScreenPos().y; for (int n = 0; n < gradient_steps; n++) { - float f = n / (float)gradient_steps; - ImU32 col32 = ImGui::GetColorU32(ImVec4(f, f, f, 1.0f)); - draw_list->AddRectFilled(ImVec2(x + gradient_size.x * (n / (float)gradient_steps), y), ImVec2(x + gradient_size.x * ((n+1) / (float)gradient_steps), y + gradient_size.y), col32); + float f0 = n / (float)gradient_steps; + float f1 = (n + 1) / (float)gradient_steps; + ImU32 col32 = ImGui::GetColorU32(ImVec4(f0, f0, f0, 1.0f)); + draw_list->AddRectFilled(ImVec2(x + gradient_size.x * f0, y), ImVec2(x + gradient_size.x * f1, y + gradient_size.y), col32); } ImGui::InvisibleButton("##gradient", gradient_size); diff --git a/imgui_internal.h b/imgui_internal.h index 450318da..d3a30257 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -866,7 +866,7 @@ struct ImGuiColumns // Helper function to calculate a circle's segment count given its radius and a "maximum error" value. #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN 12 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX 512 -#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(_RAD,_MAXERROR) ImClamp((int)((IM_PI * 2.0f) / ImAcos((_RAD - _MAXERROR) / _RAD)), IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX) +#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(_RAD,_MAXERROR) ImClamp((int)((IM_PI * 2.0f) / ImAcos(((_RAD) - (_MAXERROR)) / (_RAD))), IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX) // Data shared between all ImDrawList instances // You may want to create your own instance of this if you want to use ImDrawList completely without ImGui. In that case, watch out for future changes to this structure. diff --git a/imstb_truetype.h b/imstb_truetype.h index 7ccc13e8..b4bdbd86 100644 --- a/imstb_truetype.h +++ b/imstb_truetype.h @@ -4132,7 +4132,7 @@ STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges) { stbtt_fontinfo info; - int i,j,n, return_value = 1; + int i,j,n, return_value; // [DEAR IMGUI] removed = 1 //stbrp_context *context = (stbrp_context *) spc->pack_info; stbrp_rect *rects; From 8836975dcfc770731932ebec3bbb69579fb29071 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 17 Feb 2020 17:41:45 +0100 Subject: [PATCH 282/384] Drag and Drop, Nav: Disabling navigation arrow keys when drag and drop is active. (#3025) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f3d7cbfe..765b81d8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,6 +36,8 @@ HOW TO UPDATE? Other Changes: +- Drag and Drop, Nav: Disabling navigation arrow keys when drag and drop is active. In the docking + branch pressing arrow keys while dragging a window from a tab could trigger an assert. (#3025) - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' diff --git a/imgui.cpp b/imgui.cpp index 53b05aa4..85ecc45c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3254,6 +3254,9 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window) // Handle mouse moving window // Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing() +// FIXME: We don't have strong guarantee that g.MovingWindow stay synched with g.ActiveId == g.MovingWindow->MoveId. +// This is currently enforced by the fact that BeginDragDropSource() is setting all g.ActiveIdUsingXXXX flags to inhibit navigation inputs, +// but if we should more thoroughly test cases where g.ActiveId or g.MovingWindow gets changed and not the other. void ImGui::UpdateMouseMovingWindowNewFrame() { ImGuiContext& g = *GImGui; @@ -8999,6 +9002,11 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) return false; source_parent_id = window->IDStack.back(); source_drag_active = IsMouseDragging(mouse_button); + + // Disable navigation and key inputs while dragging + g.ActiveIdUsingNavDirMask = ~(ImU32)0; + g.ActiveIdUsingNavInputMask = ~(ImU32)0; + g.ActiveIdUsingKeyInputMask = ~(ImU64)0; } else { From ea3fc7603829a420d77ccb2862178bc2334b4b54 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 18 Feb 2020 12:49:02 +0100 Subject: [PATCH 283/384] BeginMenu: Fixed a bug where SetNextWindowXXX data before a BeginMenu() would not be cleared when the menu is not open. (#3030) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 765b81d8..4b2c1b26 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,8 @@ Other Changes: branch pressing arrow keys while dragging a window from a tab could trigger an assert. (#3025) - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. +- BeginMenu: Fixed a bug where SetNextWindowXXX data before a BeginMenu() would not be cleared + when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ef154760..681745bc 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6345,6 +6345,10 @@ bool ImGui::BeginMenu(const char* label, bool enabled) flags |= ImGuiWindowFlags_ChildWindow; menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) } + else + { + g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values + } return menu_is_open; } From 02a6c060804eed00b87604953a1f936a3e7f8609 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 18 Feb 2020 14:25:50 +0100 Subject: [PATCH 284/384] Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] Amend f843facba4d012e225fb55b198001dbfcd0cc099 and 8828889d5ec1d8fb9ddb72bab16d5e21ba8425c6 --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4b2c1b26..1c3edae5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,6 +44,8 @@ Other Changes: when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) +- Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child + window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. - Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), diff --git a/imgui.cpp b/imgui.cpp index 85ecc45c..0b67534d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5844,19 +5844,15 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.ParentLayoutType = parent_window ? parent_window->DC.LayoutType : ImGuiLayoutType_Vertical; window->DC.FocusCounterRegular = window->DC.FocusCounterTabStop = -1; - window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_; window->DC.ItemWidth = window->ItemWidthDefault; window->DC.TextWrapPos = -1.0f; // disabled window->DC.ItemFlagsStack.resize(0); window->DC.ItemWidthStack.resize(0); window->DC.TextWrapPosStack.resize(0); window->DC.GroupStack.resize(0); - - if ((flags & ImGuiWindowFlags_ChildWindow) && (window->DC.ItemFlags != parent_window->DC.ItemFlags)) - { - window->DC.ItemFlags = parent_window->DC.ItemFlags; + window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_; + if (parent_window) window->DC.ItemFlagsStack.push_back(window->DC.ItemFlags); - } if (window->AutoFitFramesX > 0) window->AutoFitFramesX--; From 3c80d57dc7f7fd663e572c4de5388c427e537d5a Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 19 Feb 2020 23:40:08 +0100 Subject: [PATCH 285/384] Viewports, Window: Avoid manually clipping resize grips and borders, which messes up with automation ability to locate the items. Also simpler and more standard. Amend d8f9f6ba2abb6cfc00f704b887264ac9472cf9f7 and 377f7300546e2a43e225d38c724a7f28da0ed6f2. --- imgui.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 706d03d4..54fe7dc6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5383,14 +5383,14 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au ImVec2 pos_target(FLT_MAX, FLT_MAX); ImVec2 size_target(FLT_MAX, FLT_MAX); - // Clip mouse interaction rectangles within the viewport (in practice the narrowing is going to happen most of the time). + // Clip mouse interaction rectangles within the viewport rectangle (in practice the narrowing is going to happen most of the time). // - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits. // This is however not the case with current back-ends under Win32, but a custom borderless window implementation would benefit from it. // - When decoration are enabled we typically benefit from that distance, but then our resize elements would be conflicting with OS resize elements, so we also narrow. // - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold). - ImRect clip_viewport_rect(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX); - if (!(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration)) - clip_viewport_rect = window->Viewport->GetRect(); + const bool clip_with_viewport_rect = !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration); + if (clip_with_viewport_rect) + PushClipRect(window->Viewport->Pos, window->Viewport->Pos + window->Viewport->Size, true); // Won't incur a draw command as we are not drawing here. // Resize grips and borders are on layer 1 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; @@ -5407,12 +5407,8 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au ImRect resize_rect(corner - grip.InnerDir * grip_hover_outer_size, corner + grip.InnerDir * grip_hover_inner_size); if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); - ImVec2 resize_rect_ref_min = resize_rect.Min; - resize_rect.ClipWith(clip_viewport_rect); bool hovered, held; ButtonBehavior(resize_rect, window->GetID(resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); - if (held && g.ActiveIdIsJustActivated) - g.ActiveIdClickOffset = g.IO.MousePos - resize_rect_ref_min; // Override our reference click offset as viewport clipping may be moved it. //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); if (hovered || held) g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; @@ -5438,11 +5434,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au { bool hovered, held; ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); - ImVec2 border_rect_ref_min = border_rect.Min; - border_rect.ClipWith(clip_viewport_rect); ButtonBehavior(border_rect, window->GetID(border_n + 4), &hovered, &held, ImGuiButtonFlags_FlattenChildren); - if (held && g.ActiveIdIsJustActivated) - g.ActiveIdClickOffset = g.IO.MousePos - border_rect_ref_min; // Override our reference click offset as viewport clipping may be moved it. //GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held) { @@ -5462,6 +5454,8 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au } } PopID(); + if (clip_with_viewport_rect) + PopClipRect(); // Restore nav layer window->DC.NavLayerCurrent = ImGuiNavLayer_Main; From 7d80a8f4f502557685ba1f4ed0e4603e86745d40 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 20 Feb 2020 12:21:11 +0100 Subject: [PATCH 286/384] Backends: Fix ImGui_ImplSDL2_InitForMetal() in docking branch. --- examples/imgui_impl_sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 138a1d3a..08cf9924 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -259,7 +259,7 @@ bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window) bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window) { - return ImGui_ImplSDL2_Init(window); + return ImGui_ImplSDL2_Init(window, NULL); } void ImGui_ImplSDL2_Shutdown() From 03453246464cdd414c2f76d4a2569d2d5511870b Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 20 Feb 2020 12:28:06 +0100 Subject: [PATCH 287/384] Backends: SDL: Fixed mapping for ImGuiKey_KeyPadEnter. (#3031) [@Davido71] --- docs/CHANGELOG.txt | 1 + examples/imgui_impl_sdl.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1c3edae5..5b0a1c52 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,7 @@ Other Changes: a manifest. - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). +- Backends: SDL: Fixed mapping for ImGuiKey_KeyPadEnter. (#3031) [@Davido71] - Examples: Added SDL2+Metal example application. (#3017) [@coding-jackalope] diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 69172622..9fd2cc48 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -17,6 +17,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2). // 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state). // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter. @@ -152,7 +153,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window) io.KeyMap[ImGuiKey_Space] = SDL_SCANCODE_SPACE; io.KeyMap[ImGuiKey_Enter] = SDL_SCANCODE_RETURN; io.KeyMap[ImGuiKey_Escape] = SDL_SCANCODE_ESCAPE; - io.KeyMap[ImGuiKey_KeyPadEnter] = SDL_SCANCODE_RETURN2; + io.KeyMap[ImGuiKey_KeyPadEnter] = SDL_SCANCODE_KP_ENTER; io.KeyMap[ImGuiKey_A] = SDL_SCANCODE_A; io.KeyMap[ImGuiKey_C] = SDL_SCANCODE_C; io.KeyMap[ImGuiKey_V] = SDL_SCANCODE_V; From e547f898a94b408ec311c6d1efe2958f83889f78 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 24 Feb 2020 12:44:19 +0100 Subject: [PATCH 288/384] Demo: Added color gradient in demo to identify srgb/linear issues better. Tweaks. --- docs/CHANGELOG.txt | 2 +- docs/README.md | 2 +- imgui.cpp | 2 +- imgui_demo.cpp | 49 +++++++++++++++++++++++----------------------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5b0a1c52..6a25fa65 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -47,7 +47,7 @@ Other Changes: - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. -- Demo: Added a black and white gradient to Demo>Examples>Custom Rendering. +- Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). Those functions makes it easier for example apps to support hi-dpi features without setting up diff --git a/docs/README.md b/docs/README.md index 72d35ded..a843822b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -194,7 +194,7 @@ Ongoing Dear ImGui development is financially supported by users and private spo - [Blizzard](https://careers.blizzard.com/en-us/openings/engineering/all/all/all/1), [Google](https://github.com/google/filament), [Nvidia](https://developer.nvidia.com/nvidia-omniverse), [Ubisoft](https://montreal.ubisoft.com/en/ubisoft-sponsors-user-interface-library-for-c-dear-imgui/) *Double-chocolate and Salty caramel sponsors* -- [DotEmu](http://www.dotemu.com), [Framefield](http://framefield.com), [Hexagon](https://hexagonxalt.com/the-technology/xalt-visualization), [Kylotonn](https://www.kylotonn.com), [Media Molecule](http://www.mediamolecule.com), [Mesh Consultants](https://www.meshconsultants.ca), [Mobigame](http://www.mobigame.net), [Nadeo](https://www.nadeo.com), [Supercell](http://www.supercell.com), [Remedy Entertainment](https://www.remedygames.com/), [Unit 2 Games](https://unit2games.com/) +- [Activision](https://careers.activision.com/c/programmingsoftware-engineering-jobs), [DotEmu](http://www.dotemu.com), [Framefield](http://framefield.com), [Hexagon](https://hexagonxalt.com/the-technology/xalt-visualization), [Kylotonn](https://www.kylotonn.com), [Media Molecule](http://www.mediamolecule.com), [Mesh Consultants](https://www.meshconsultants.ca), [Mobigame](http://www.mobigame.net), [Nadeo](https://www.nadeo.com), [Supercell](http://www.supercell.com), [Remedy Entertainment](https://www.remedygames.com/), [Unit 2 Games](https://unit2games.com/) From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. Please see [detailed list of Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors). diff --git a/imgui.cpp b/imgui.cpp index 0b67534d..0aab2de2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3383,7 +3383,7 @@ static void ImGui::UpdateMouseInputs() ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist) g.IO.MouseDoubleClicked[i] = true; - g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click + g.IO.MouseClickedTime[i] = -DBL_MAX; // so the third click isn't turned into a double-click } else { diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 35fe94d9..a698a91a 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4454,16 +4454,37 @@ static void ShowExampleAppCustomRendering(bool* p_open) if (ImGui::BeginTabBar("##TabBar")) { - // Primitives if (ImGui::BeginTabItem("Primitives")) { + ImGui::PushItemWidth(-ImGui::GetFontSize() * 10); + + // Draw gradients + // (note that those are currently exacerbating our sRGB/Linear issues) + ImGui::Text("Gradients"); + ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight()); + { + ImVec2 p = ImGui::GetCursorScreenPos(); + ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); + ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + draw_list->AddRectFilledMultiColor(p, ImVec2(p.x + gradient_size.x, p.y + gradient_size.y), col_a, col_b, col_b, col_a); + ImGui::InvisibleButton("##gradient1", gradient_size); + } + { + ImVec2 p = ImGui::GetCursorScreenPos(); + ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 1.0f, 0.0f, 1.0f)); + ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); + draw_list->AddRectFilledMultiColor(p, ImVec2(p.x + gradient_size.x, p.y + gradient_size.y), col_a, col_b, col_b, col_a); + ImGui::InvisibleButton("##gradient2", gradient_size); + } + + // Draw a bunch of primitives + ImGui::Text("All primitives"); static float sz = 36.0f; static float thickness = 3.0f; static int ngon_sides = 6; static bool circle_segments_override = false; static int circle_segments_override_v = 12; static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); - ImGui::PushItemWidth(-ImGui::GetFontSize() * 10); ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f"); ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); @@ -4511,26 +4532,6 @@ static void ShowExampleAppCustomRendering(bool* p_open) draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x + sz, y + sz), IM_COL32(0, 0, 0, 255), IM_COL32(255, 0, 0, 255), IM_COL32(255, 255, 0, 255), IM_COL32(0, 255, 0, 255)); ImGui::Dummy(ImVec2((sz + spacing) * 9.8f, (sz + spacing) * 3)); - // Draw black and white gradients - static int gradient_steps = 16; - ImGui::Separator(); - ImGui::AlignTextToFramePadding(); - ImGui::Text("Gradient steps"); - ImGui::SameLine(); if (ImGui::RadioButton("16", gradient_steps == 16)) { gradient_steps = 16; } - ImGui::SameLine(); if (ImGui::RadioButton("32", gradient_steps == 32)) { gradient_steps = 32; } - ImGui::SameLine(); if (ImGui::RadioButton("256", gradient_steps == 256)) { gradient_steps = 256; } - ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), 64.0f); - x = ImGui::GetCursorScreenPos().x; - y = ImGui::GetCursorScreenPos().y; - for (int n = 0; n < gradient_steps; n++) - { - float f0 = n / (float)gradient_steps; - float f1 = (n + 1) / (float)gradient_steps; - ImU32 col32 = ImGui::GetColorU32(ImVec4(f0, f0, f0, 1.0f)); - draw_list->AddRectFilled(ImVec2(x + gradient_size.x * f0, y), ImVec2(x + gradient_size.x * f1, y + gradient_size.y), col32); - } - ImGui::InvisibleButton("##gradient", gradient_size); - ImGui::PopItemWidth(); ImGui::EndTabItem(); } @@ -4598,9 +4599,9 @@ static void ShowExampleAppCustomRendering(bool* p_open) ImVec2 window_size = ImGui::GetWindowSize(); ImVec2 window_center = ImVec2(window_pos.x + window_size.x * 0.5f, window_pos.y + window_size.y * 0.5f); if (draw_bg) - ImGui::GetBackgroundDrawList()->AddCircle(window_center, window_size.x * 0.6f, IM_COL32(255, 0, 0, 200), 48, 10+4); + ImGui::GetBackgroundDrawList()->AddCircle(window_center, window_size.x * 0.6f, IM_COL32(255, 0, 0, 200), 0, 10+4); if (draw_fg) - ImGui::GetForegroundDrawList()->AddCircle(window_center, window_size.y * 0.6f, IM_COL32(0, 255, 0, 200), 48, 10); + ImGui::GetForegroundDrawList()->AddCircle(window_center, window_size.y * 0.6f, IM_COL32(0, 255, 0, 200), 0, 10); ImGui::EndTabItem(); } From 3ff13edad91b58a45ebdf73e56461903a15631d6 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 24 Feb 2020 15:14:04 +0200 Subject: [PATCH 289/384] Viewports: Improve menu positioning in multi-monitor setups. This change uses mouse position for initial positioning of popup menus. It ensures that menu appears in expected location on monitor mouse is currently hovering. This change fixes incorrect menu positioning (permanent or on the first frame) when menu item spans multiple monitors. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 54fe7dc6..3d98a605 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10986,7 +10986,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window) ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos; bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow); bool mouse_valid = IsMousePosValid(&mouse_ref); - if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid)) + if ((window->Appearing || (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_ChildMenu))) && (!use_mouse_ref || mouse_valid)) window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos()); else window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor; From 871727dd2f4446bf1951a8555dc6e0001c35c8ae Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 25 Feb 2020 15:51:57 +0100 Subject: [PATCH 290/384] Viewports: Software mouse cursor is also scaled by current DpiScale. (amend #939) --- imgui.cpp | 19 ++++++++++--------- imgui.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3d98a605..1f272979 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4507,14 +4507,9 @@ void ImGui::Render() if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the top-most window AddRootWindowToDrawData(windows_to_render_top_most[n]); - // Draw software mouse cursor if requested - ImRect mouse_cursor_rect; + ImVec2 mouse_cursor_offset, mouse_cursor_size, mouse_cursor_uv[4]; if (g.IO.MouseDrawCursor && g.MouseCursor != ImGuiMouseCursor_None) - { - ImVec2 offset, size, uv[4]; - if (g.IO.Fonts->GetMouseCursorTexData(g.MouseCursor, &offset, &size, &uv[0], &uv[2])) - mouse_cursor_rect = ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(size.x + 2, size.y + 2) * g.Style.MouseCursorScale); - } + g.IO.Fonts->GetMouseCursorTexData(g.MouseCursor, &mouse_cursor_offset, &mouse_cursor_size, &mouse_cursor_uv[0], &mouse_cursor_uv[2]); // Setup ImDrawData structures for end-user g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = 0; @@ -4523,8 +4518,14 @@ void ImGui::Render() ImGuiViewportP* viewport = g.Viewports[n]; viewport->DrawDataBuilder.FlattenIntoSingleLayer(); - if (viewport->GetRect().Overlaps(mouse_cursor_rect)) - RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); + // Draw software mouse cursor if requested by io.MouseDrawCursor flag + // (note we scale cursor by current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor) + if (mouse_cursor_size.x > 0.0f && mouse_cursor_size.y > 0.0f) + { + float scale = g.Style.MouseCursorScale * viewport->DpiScale; + if (viewport->GetRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale))) + RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, scale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); + } // Add foreground ImDrawList (for each active viewport) if (viewport->DrawLists[1] != NULL) diff --git a/imgui.h b/imgui.h index 50d1a561..8e790dc2 100644 --- a/imgui.h +++ b/imgui.h @@ -1432,7 +1432,7 @@ struct ImGuiStyle ImVec2 SelectableTextAlign; // Alignment of selectable text when selectable is larger than text. Defaults to (0.0f, 0.0f) (top-left aligned). ImVec2 DisplayWindowPadding; // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! - float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. + float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). We apply per-monitor DPI scaling over this scale. May be removed later. bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. bool AntiAliasedFill; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. From 898e91f20d5c35a9148c31596211123958464622 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 25 Feb 2020 16:26:30 +0100 Subject: [PATCH 291/384] Internals: Added TempInputText() to facilitate creation of custom widgets, renamed TempInputTextScalar() to TempInputScalar() etc. (#2718) + Minor imgui.h/todo comments --- docs/TODO.txt | 3 +++ imgui.cpp | 4 ++-- imgui.h | 39 ++++++++++++++++++++++----------------- imgui_internal.h | 9 +++++---- imgui_widgets.cpp | 39 +++++++++++++++++++++++---------------- 5 files changed, 55 insertions(+), 39 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 9f102d7f..24c79e43 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -163,6 +163,9 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing. - tabs: persistent order/focus in BeginTabBar() api (#261, #351) - tabs: TabItem could honor SetNextItemWidth()? + - tabs: explicit api (even if internal) to cleanly manipulate tab order. + - tabs: Mouse wheel over tab bar could scroll? (#2702) + - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? diff --git a/imgui.cpp b/imgui.cpp index 0aab2de2..98293e62 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3678,8 +3678,8 @@ void ImGui::NewFrame() g.ActiveIdHasBeenEditedThisFrame = false; g.ActiveIdPreviousFrameIsAlive = false; g.ActiveIdIsJustActivated = false; - if (g.TempInputTextId != 0 && g.ActiveId != g.TempInputTextId) - g.TempInputTextId = 0; + if (g.TempInputId != 0 && g.ActiveId != g.TempInputId) + g.TempInputId = 0; if (g.ActiveId == 0) { g.ActiveIdUsingNavDirMask = g.ActiveIdUsingNavInputMask = 0; diff --git a/imgui.h b/imgui.h index 7dfc891a..8ddd84a4 100644 --- a/imgui.h +++ b/imgui.h @@ -194,11 +194,11 @@ typedef unsigned long long ImU64; // 64-bit unsigned integer (post C++11) // 2D vector (often used to store positions, sizes, etc.) struct ImVec2 { - float x, y; - ImVec2() { x = y = 0.0f; } - ImVec2(float _x, float _y) { x = _x; y = _y; } - float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. - float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. + float x, y; + ImVec2() { x = y = 0.0f; } + ImVec2(float _x, float _y) { x = _x; y = _y; } + float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. + float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. #ifdef IM_VEC2_CLASS_EXTRA IM_VEC2_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2. #endif @@ -207,9 +207,9 @@ struct ImVec2 // 4D vector (often used to store floating-point colors) struct ImVec4 { - float x, y, z, w; - ImVec4() { x = y = z = w = 0.0f; } - ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } + float x, y, z, w; + ImVec4() { x = y = z = w = 0.0f; } + ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } #ifdef IM_VEC4_CLASS_EXTRA IM_VEC4_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec4. #endif @@ -217,7 +217,7 @@ struct ImVec4 //----------------------------------------------------------------------------- // ImGui: Dear ImGui end-user API -// (Inside a namespace so you can add extra functions in your own separate file. Please don't modify imgui source files!) +// (This is a namespace. You can add extra ImGui:: functions in your own separate file. Please don't modify imgui source files!) //----------------------------------------------------------------------------- namespace ImGui @@ -233,16 +233,16 @@ namespace ImGui // Main IMGUI_API ImGuiIO& GetIO(); // access the IO structure (mouse/keyboard/gamepad inputs, time, various configuration options/flags) - IMGUI_API ImGuiStyle& GetStyle(); // access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame. + IMGUI_API ImGuiStyle& GetStyle(); // access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame! IMGUI_API void NewFrame(); // start a new Dear ImGui frame, you can submit any command from this point until Render()/EndFrame(). - IMGUI_API void EndFrame(); // ends the Dear ImGui frame. automatically called by Render(), you likely don't need to call that yourself directly. If you don't need to render data (skipping rendering) you may call EndFrame() but you'll have wasted CPU already! If you don't need to render, better to not create any imgui windows and not call NewFrame() at all! - IMGUI_API void Render(); // ends the Dear ImGui frame, finalize the draw data. You can get call GetDrawData() to obtain it and run your rendering function. (Obsolete: this used to call io.RenderDrawListsFn(). Nowadays, we allow and prefer calling your render function yourself.) + IMGUI_API void EndFrame(); // ends the Dear ImGui frame. automatically called by Render(). If you don't need to render data (skipping rendering) you may call EndFrame() without Render()... but you'll have wasted CPU already! If you don't need to render, better to not create any windows and not call NewFrame() at all! + IMGUI_API void Render(); // ends the Dear ImGui frame, finalize the draw data. You can get call GetDrawData() to obtain it and run your rendering function (up to v1.60, this used to call io.RenderDrawListsFn(). Nowadays, we allow and prefer calling your render function yourself.) IMGUI_API ImDrawData* GetDrawData(); // valid after Render() and until the next call to NewFrame(). this is what you have to render. // Demo, Debug, Information IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create Demo window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application! IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create About window. display Dear ImGui version, credits and build/system information. - IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create Metrics/Debug window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc. + IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create Debug/Metrics window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc. IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style) IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles. IMGUI_API void ShowFontSelector(const char* label); // add font selector block (not a window), essentially a combo listing the loaded fonts. @@ -345,11 +345,11 @@ namespace ImGui IMGUI_API ImU32 GetColorU32(ImU32 col); // retrieve given color with style alpha applied // Parameters stacks (current window) - IMGUI_API void PushItemWidth(float item_width); // set width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width, + IMGUI_API void PushItemWidth(float item_width); // push width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width, IMGUI_API void PopItemWidth(); IMGUI_API void SetNextItemWidth(float item_width); // set width of the _next_ common large "item+label" widget. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side) IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position. NOT necessarily the width of last item unlike most 'Item' functions. - IMGUI_API void PushTextWrapPos(float wrap_local_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space + IMGUI_API void PushTextWrapPos(float wrap_local_pos_x = 0.0f); // push word-wrapping position for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space IMGUI_API void PopTextWrapPos(); IMGUI_API void PushAllowKeyboardFocus(bool allow_keyboard_focus); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets IMGUI_API void PopAllowKeyboardFocus(); @@ -360,6 +360,9 @@ namespace ImGui // - By "cursor" we mean the current output position. // - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down. // - You can call SameLine() between widgets to undo the last carriage return and output at the right of the preceeding widget. + // - Attention! We currently have inconsistencies between window-local and absolute positions we will aim to fix with future API: + // Window-local coordinates: SameLine(), GetCursorPos(), SetCursorPos(), GetCursorStartPos(), GetContentRegionMax(), GetWindowContentRegion*(), PushTextWrapPos() + // Absolute coordinate: GetCursorScreenPos(), SetCursorScreenPos(), all ImDrawList:: functions. IMGUI_API void Separator(); // separator, generally horizontal. inside a menu bar or in horizontal layout mode, this becomes a vertical separator. IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f); // call between widgets or groups to layout them horizontally. X position given in window coordinates. IMGUI_API void NewLine(); // undo a SameLine() or force a new line when in an horizontal-layout context. @@ -597,7 +600,7 @@ namespace ImGui // - You can also use SameLine(pos_x) to mimic simplified columns. // - The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!) // - There is a maximum of 64 columns. - // - Currently working on new 'Tables' api which will replace columns (see GitHub #2957) + // - Currently working on new 'Tables' api which will replace columns around Q2 2020 (see GitHub #2957). IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished IMGUI_API int GetColumnIndex(); // get current column index @@ -674,11 +677,13 @@ namespace ImGui IMGUI_API const char* GetStyleColorName(ImGuiCol idx); // get a string corresponding to the enum value (for display, saving, etc.). IMGUI_API void SetStateStorage(ImGuiStorage* storage); // replace current window storage with our own (if you want to manipulate it yourself, typically clear subsection of it) IMGUI_API ImGuiStorage* GetStateStorage(); - IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // calculate coarse clipping for large list of evenly sized items. Prefer using the ImGuiListClipper higher-level helper if you can. IMGUI_API bool BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags flags = 0); // helper to create a child window / scrolling region that looks like a normal widget frame IMGUI_API void EndChildFrame(); // always call EndChildFrame() regardless of BeginChildFrame() return values (which indicates a collapsed/clipped window) + // Text Utilities + IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f); + // Color Utilities IMGUI_API ImVec4 ColorConvertU32ToFloat4(ImU32 in); IMGUI_API ImU32 ColorConvertFloat4ToU32(const ImVec4& in); diff --git a/imgui_internal.h b/imgui_internal.h index d3a30257..87773e99 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1147,7 +1147,7 @@ struct ImGuiContext ImVec2 LastValidMousePos; ImGuiInputTextState InputTextState; ImFont InputTextPasswordFont; - ImGuiID TempInputTextId; // Temporary text input when CTRL+clicking on a slider, etc. + ImGuiID TempInputId; // Temporary text input when CTRL+clicking on a slider, etc. ImGuiColorEditFlags ColorEditOptions; // Store user options for color edit widgets float ColorEditLastHue; // Backup of last Hue associated to LastColor[3], so we can restore Hue in lossy RGB<>HSV round trips float ColorEditLastSat; // Backup of last Saturation associated to LastColor[3], so we can restore Saturation in lossy RGB<>HSV round trips @@ -1291,7 +1291,7 @@ struct ImGuiContext CurrentTabBar = NULL; LastValidMousePos = ImVec2(0.0f, 0.0f); - TempInputTextId = 0; + TempInputId = 0; ColorEditOptions = ImGuiColorEditFlags__OptionsDefault; ColorEditLastHue = ColorEditLastSat = 0.0f; ColorEditLastColor[0] = ColorEditLastColor[1] = ColorEditLastColor[2] = FLT_MAX; @@ -1841,8 +1841,9 @@ namespace ImGui // InputText IMGUI_API bool InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); - IMGUI_API bool TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format); - inline bool TempInputTextIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputTextId == id); } + IMGUI_API bool TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags); + IMGUI_API bool TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format); + inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } // Color IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 681745bc..ba35af12 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2109,7 +2109,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, // Tabbing or CTRL-clicking on Drag turns it into an input box const bool hovered = ItemHoverable(frame_bb, id); - bool temp_input_is_active = TempInputTextIsActive(id); + bool temp_input_is_active = TempInputIsActive(id); bool temp_input_start = false; if (!temp_input_is_active) { @@ -2130,7 +2130,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, } } if (temp_input_is_active || temp_input_start) - return TempInputTextScalar(frame_bb, id, label, data_type, p_data, format); + return TempInputScalar(frame_bb, id, label, data_type, p_data, format); // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); @@ -2561,7 +2561,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat // Tabbing or CTRL-clicking on Slider turns it into an input box const bool hovered = ItemHoverable(frame_bb, id); - bool temp_input_is_active = TempInputTextIsActive(id); + bool temp_input_is_active = TempInputIsActive(id); bool temp_input_start = false; if (!temp_input_is_active) { @@ -2581,7 +2581,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat } } if (temp_input_is_active || temp_input_start) - return TempInputTextScalar(frame_bb, id, label, data_type, p_data, format); + return TempInputScalar(frame_bb, id, label, data_type, p_data, format); // Draw frame const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); @@ -2860,32 +2860,39 @@ int ImParseFormatPrecision(const char* fmt, int default_precision) // Create text input in place of another active widget (e.g. used when doing a CTRL+Click on drag/slider widgets) // FIXME: Facilitate using this in variety of other situations. -bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format) +bool ImGui::TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags) { - ImGuiContext& g = *GImGui; - // On the first frame, g.TempInputTextId == 0, then on subsequent frames it becomes == id. // We clear ActiveID on the first frame to allow the InputText() taking it back. - const bool init = (g.TempInputTextId != id); + ImGuiContext& g = *GImGui; + const bool init = (g.TempInputId != id); if (init) ClearActiveID(); + g.CurrentWindow->DC.CursorPos = bb.Min; + bool value_changed = InputTextEx(label, NULL, buf, buf_size, bb.GetSize(), flags); + if (init) + { + // First frame we started displaying the InputText widget, we expect it to take the active id. + IM_ASSERT(g.ActiveId == id); + g.TempInputId = g.ActiveId; + } + return value_changed; +} + +bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format) +{ + ImGuiContext& g = *GImGui; + char fmt_buf[32]; char data_buf[32]; format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf)); DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format); ImStrTrimBlanks(data_buf); - g.CurrentWindow->DC.CursorPos = bb.Min; ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited; flags |= ((data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImGuiInputTextFlags_CharsScientific : ImGuiInputTextFlags_CharsDecimal); - bool value_changed = InputTextEx(label, NULL, data_buf, IM_ARRAYSIZE(data_buf), bb.GetSize(), flags); - if (init) - { - // First frame we started displaying the InputText widget, we expect it to take the active id. - IM_ASSERT(g.ActiveId == id); - g.TempInputTextId = g.ActiveId; - } + bool value_changed = TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags); if (value_changed) { value_changed = DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL); From f032ad6b1fe58d531d2336c0c8d03e6d6ea45669 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 26 Feb 2020 20:18:06 +0100 Subject: [PATCH 292/384] Viewports: Renamed GetRect() to GetMainRect() in prevision for work rect. Comments --- imgui.cpp | 28 ++++++++++++++-------------- imgui.h | 14 ++++++++------ imgui_internal.h | 9 ++++----- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1f272979..a3d5c8f1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3851,7 +3851,7 @@ void ImGui::NewFrame() IM_ASSERT(g.Font->IsLoaded()); ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); for (int n = 0; n < g.Viewports.Size; n++) - virtual_space.Add(g.Viewports[n]->GetRect()); + virtual_space.Add(g.Viewports[n]->GetMainRect()); g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y); g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol; g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError); @@ -4376,7 +4376,7 @@ static void ImGui::EndFrameDrawDimmedBackgrounds() float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding); ImRect bb = window->Rect(); bb.Expand(g.FontSize); - if (bb.Contains(window->Viewport->GetRect())) // If a window fits the entire viewport, adjust its highlight inward + if (bb.Contains(window->Viewport->GetMainRect())) // If a window fits the entire viewport, adjust its highlight inward { bb.Expand(-g.FontSize - 1.0f); rounding = window->WindowRounding; @@ -4523,7 +4523,7 @@ void ImGui::Render() if (mouse_cursor_size.x > 0.0f && mouse_cursor_size.y > 0.0f) { float scale = g.Style.MouseCursorScale * viewport->DpiScale; - if (viewport->GetRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale))) + if (viewport->GetMainRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale))) RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, scale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); } @@ -4648,7 +4648,7 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); if (!rect_for_touch.Contains(g.IO.MousePos)) return false; - if (!g.MouseViewport->GetRect().Overlaps(rect_clipped)) + if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) return false; return true; } @@ -6100,7 +6100,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Late create viewport if we don't fit within our current host viewport. if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_Minimized)) - if (!window->Viewport->GetRect().Contains(window->Rect())) + if (!window->Viewport->GetMainRect().Contains(window->Rect())) { // This is based on the assumption that the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport) //ImGuiViewport* old_viewport = window->Viewport; @@ -6182,7 +6182,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Clamp position/size so window stays visible within its viewport or monitor // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. - ImRect viewport_rect = window->Viewport->GetRect(); + ImRect viewport_rect = window->Viewport->GetMainRect(); if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) { ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); @@ -6242,7 +6242,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->Viewport->Pos = window->Pos; if (!window->Viewport->PlatformRequestResize) window->Viewport->Size = window->Size; - viewport_rect = window->Viewport->GetRect(); + viewport_rect = window->Viewport->GetMainRect(); } // Save last known viewport position within the window itself (so it can be saved in .ini file and restored) @@ -8374,7 +8374,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0) { ImGuiViewportP* viewport = window->WasActive ? window->Viewport : (ImGuiViewportP*)GetMainViewport(); // FIXME-VIEWPORT: What may be our reference viewport? - SetNextWindowPos(viewport->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + SetNextWindowPos(viewport->GetMainRect().GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); } flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDocking; @@ -9009,7 +9009,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() // When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item. const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer]; ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight())); - ImRect visible_rect = g.NavWindow->Viewport->GetRect(); + ImRect visible_rect = g.NavWindow->Viewport->GetMainRect(); return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in back-end might be lossy and result in undesirable non-zero delta. } } @@ -10557,7 +10557,7 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG ImGuiContext& g = *GImGui; if (!(viewport->Flags & (ImGuiViewportFlags_CanHostOtherWindows | ImGuiViewportFlags_Minimized)) || window->Viewport == viewport) return false; - if (!viewport->GetRect().Contains(window->Rect())) + if (!viewport->GetMainRect().Contains(window->Rect())) return false; if (GetWindowAlwaysWantOwnViewport(window)) return false; @@ -10568,7 +10568,7 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG if (window_behind == window) break; if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow)) - if (window_behind->Viewport->GetRect().Overlaps(window->Rect())) + if (window_behind->Viewport->GetMainRect().Overlaps(window->Rect())) return false; } @@ -10636,7 +10636,7 @@ static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 m for (int n = 0; n < g.Viewports.Size; n++) { ImGuiViewportP* viewport = g.Viewports[n]; - if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetRect().Contains(mouse_platform_pos)) + if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetMainRect().Contains(mouse_platform_pos)) if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount) best_candidate = viewport; } @@ -11231,7 +11231,7 @@ static int ImGui::FindPlatformMonitorForRect(const ImRect& rect) // Update monitor from viewport rectangle (we'll use this info to clamp windows and save windows lost in a removed monitor) static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport) { - viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetRect()); + viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetMainRect()); } void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) @@ -14957,7 +14957,7 @@ void ImGui::ShowViewportThumbnails() //for (int n = 0; n < g.PlatformIO.Monitors.Size; n++) // bb_full.Add(GetPlatformMonitorMainRect(g.PlatformIO.Monitors[n])); for (int n = 0; n < g.Viewports.Size; n++) - bb_full.Add(g.Viewports[n]->GetRect()); + bb_full.Add(g.Viewports[n]->GetMainRect()); ImVec2 p = window->DC.CursorPos; ImVec2 off = p - bb_full.Min * SCALE; //for (int n = 0; n < g.PlatformIO.Monitors.Size; n++) diff --git a/imgui.h b/imgui.h index 8e790dc2..59291d11 100644 --- a/imgui.h +++ b/imgui.h @@ -716,7 +716,7 @@ namespace ImGui IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); // Inputs Utilities: Keyboard - // - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[]. + // - For 'int user_key_index' you can use your own indices/enums according to how your back-end/engine stored them in io.KeysDown[]. // - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index. IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key] IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. @@ -2479,15 +2479,17 @@ struct ImGuiViewport ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows. - void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this. - void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this. + // Our design separate the Renderer and Platform back-ends to facilitate combining default back-ends with each others. + // When our create your own back-end for a custom engine, it is possible that both Renderer and Platform will be handled by the same system and you may not need to use all the UserData/Handle fields. + void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). + void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) - void* PlatformHandleRaw; // void* to hold low-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) - bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) + void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position) bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size) + bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) - ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } + ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestMove = PlatformRequestResize = PlatformRequestClose = false; } ~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); } }; diff --git a/imgui_internal.h b/imgui_internal.h index 3ffa83eb..56d6cf9d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -935,11 +935,10 @@ struct ImGuiViewportP : public ImGuiViewport ImVec2 LastPlatformSize; ImVec2 LastRendererSize; - ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } - ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } - ImRect GetRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } - ImVec2 GetCenter() const { return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); } - void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } + ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } + ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } + ImRect GetMainRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } + void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } }; struct ImGuiNavMoveResult From 75de34e281141f851f7e5f9f6a923573167bc0f0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 26 Feb 2020 23:58:45 +0100 Subject: [PATCH 293/384] Viewports, Docking: Added per-viewport work area system for e.g. menu-bars. Fixed DocksapceOverViewport() and demo code (overlay etc) (#3035, #2889, #2474, #1542, #2109) Clarified that BeginMenuMainBar() had an incorrect knowledge of its height (which was previously harmless). Designed to easily allow for status bars although we don't have/use them yet, but custom code could use them. --- imgui.cpp | 28 +++++++++++++++++++++------- imgui.h | 16 ++++++++++++---- imgui_demo.cpp | 16 +++++++++------- imgui_internal.h | 5 ++++- imgui_widgets.cpp | 24 ++++++++++++++++++------ 5 files changed, 64 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a3d5c8f1..cc4c08f2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5273,6 +5273,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont if (is_popup || is_menu) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups) size_min = ImMin(size_min, ImVec2(4.0f, 4.0f)); + // FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows? ImVec2 avail_size = window->Viewport->Size; if (window->ViewportOwned) avail_size = ImVec2(FLT_MAX, FLT_MAX); @@ -6002,6 +6003,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) else window->WindowPadding = style.WindowPadding; + // Lock menu offset so size calculation can use it as menu-bar windows need a minimum size. + window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); + window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y; + // Collapse window by double-clicking on title bar // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse) && !window->DockIsActive) @@ -6182,13 +6187,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Clamp position/size so window stays visible within its viewport or monitor // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. + // FIXME: Similar to code in GetWindowAllowedExtentRect() ImRect viewport_rect = window->Viewport->GetMainRect(); if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) { ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); if (!window->ViewportOwned && viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f) { - ClampWindowRect(window, viewport_rect, clamp_padding); + ClampWindowRect(window, window->Viewport->GetWorkRect(), clamp_padding); } else if (window->ViewportOwned && g.PlatformIO.Monitors.Size > 0) { @@ -6437,8 +6443,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); window->DC.MenuBarAppending = false; - window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); - window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y; window->DC.MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user); window->DC.TreeDepth = 0; window->DC.TreeJumpToParentOnPopMask = 0x00; @@ -8514,6 +8518,7 @@ ImVec2 ImGui::FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& s return pos; } +// Note that this is used for popups, which can overlap the non work-area of individual viewports. ImRect ImGui::GetWindowAllowedExtentRect(ImGuiWindow* window) { ImGuiContext& g = *GImGui; @@ -8527,6 +8532,7 @@ ImRect ImGui::GetWindowAllowedExtentRect(ImGuiWindow* window) } else { + // Use the full viewport area (not work area) for popups r_screen.Min = window->Viewport->Pos; r_screen.Max = window->Viewport->Pos + window->Viewport->Size; } @@ -10731,6 +10737,11 @@ static void ImGui::UpdateViewportsNewFrame() // Update/copy monitor info UpdateViewportPlatformMonitor(viewport); + // Lock down space taken by menu bars and status bars, reset the offset for fucntions like BeginMainMenuBar() to alter them again. + viewport->WorkOffsetMin = viewport->CurrWorkOffsetMin; + viewport->WorkOffsetMax = viewport->CurrWorkOffsetMax; + viewport->CurrWorkOffsetMin = viewport->CurrWorkOffsetMax = ImVec2(0.0f, 0.0f); + // Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back. viewport->Alpha = 1.0f; @@ -13852,14 +13863,14 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags fla // Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode! // The limitation with this call is that your window won't have a menu bar. // Even though we could pass window flags, it would also require the user to be able to call BeginMenuBar() somehow meaning we can't Begin/End in a single function. -// So if you want a menu bar you need to repeat this code manually ourselves. As with advanced other Docking API, we may change this function signature. +// But you can also use BeginMainMenuBar(). If you really want a menu bar inside the same window as the one hosting the dockspace, you will need to copy this code somewhere and tweak it. ImGuiID ImGui::DockSpaceOverViewport(ImGuiViewport* viewport, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class) { if (viewport == NULL) viewport = GetMainViewport(); - SetNextWindowPos(viewport->Pos); - SetNextWindowSize(viewport->Size); + SetNextWindowPos(viewport->GetWorkPos()); + SetNextWindowSize(viewport->GetWorkSize()); SetNextWindowViewport(viewport->ID); ImGuiWindowFlags host_window_flags = 0; @@ -15230,7 +15241,10 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (ImGui::TreeNode((void*)(intptr_t)viewport->ID, "Viewport #%d, ID: 0x%08X, Parent: 0x%08X, Window: \"%s\"", viewport->Idx, viewport->ID, viewport->ParentViewportId, viewport->Window ? viewport->Window->Name : "N/A")) { ImGuiWindowFlags flags = viewport->Flags; - ImGui::BulletText("Pos: (%.0f,%.0f), Size: (%.0f,%.0f), Monitor: %d, DpiScale: %.0f%%", viewport->Pos.x, viewport->Pos.y, viewport->Size.x, viewport->Size.y, viewport->PlatformMonitor, viewport->DpiScale * 100.0f); + ImGui::BulletText("Main Pos: (%.0f,%.0f), Size: (%.0f,%.0f)\nWorkArea Offset Left: %.0f Top: %.0f, Right: %.0f, Bottom: %.0f\nMonitor: %d, DpiScale: %.0f%%", + viewport->Pos.x, viewport->Pos.y, viewport->Size.x, viewport->Size.y, + viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y, + viewport->PlatformMonitor, viewport->DpiScale * 100.0f); if (viewport->Idx > 0) { ImGui::SameLine(); if (ImGui::SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200,200); if (viewport->Window) viewport->Window->Pos = ImVec2(200,200); } } ImGui::BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s", viewport->Flags, (flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : "", (flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "", diff --git a/imgui.h b/imgui.h index 59291d11..3439311e 100644 --- a/imgui.h +++ b/imgui.h @@ -2468,14 +2468,18 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_CanHostOtherWindows = 1 << 9 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). }; -// The viewports created and managed by imgui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport. +// The viewports created and managed by Dear ImGui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport. +// - Main Area = entire viewport. +// - Work Area = entire viewport minus sections optionally used by menu bars, status bars. Some positioning code will prefer to use this. Window are also trying to stay within this area. struct ImGuiViewport { ImGuiID ID; // Unique identifier for the viewport ImGuiViewportFlags Flags; // See ImGuiViewportFlags_ - ImVec2 Pos; // Position of viewport both in imgui space and in OS desktop/native space - ImVec2 Size; // Size of viewport in pixel - float DpiScale; // 1.0f = 96 DPI = No extra scale + ImVec2 Pos; // Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates) + ImVec2 Size; // Main Area: Size of the viewport. + ImVec2 WorkOffsetMin; // Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) + ImVec2 WorkOffsetMax; // Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). + float DpiScale; // 1.0f = 96 DPI = No extra scale. ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows. @@ -2491,6 +2495,10 @@ struct ImGuiViewport ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestMove = PlatformRequestResize = PlatformRequestClose = false; } ~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); } + + // Access work-area rectangle + ImVec2 GetWorkPos() { return ImVec2(Pos.x + WorkOffsetMin.x, Pos.y + WorkOffsetMin.y); } + ImVec2 GetWorkSize() { return ImVec2(Size.x - WorkOffsetMin.x + WorkOffsetMax.x, Size.y - WorkOffsetMin.y + WorkOffsetMax.y); } // This not clamped }; #if defined(__clang__) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 3c42606d..4ae8ae58 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -222,9 +222,9 @@ void ImGui::ShowDemoWindow(bool* p_open) IM_ASSERT(ImGui::GetCurrentContext() != NULL && "Missing dear imgui context. Refer to examples app!"); // Exceptionally add an extra assert here for people confused with initial dear imgui setup // Examples Apps (accessible from the "Examples" menu) + static bool show_app_main_menu_bar = false; static bool show_app_dockspace = false; static bool show_app_documents = false; - static bool show_app_main_menu_bar = false; static bool show_app_console = false; static bool show_app_log = false; static bool show_app_layout = false; @@ -236,9 +236,9 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool show_app_window_titles = false; static bool show_app_custom_rendering = false; + if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); if (show_app_dockspace) ShowExampleAppDockSpace(&show_app_dockspace); // Process the Docking app first, as explicit DockSpace() nodes needs to be submitted early (read comments near the DockSpace function) if (show_app_documents) ShowExampleAppDocuments(&show_app_documents); // Process the Document app next, as it may also use a DockSpace() - if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); if (show_app_console) ShowExampleAppConsole(&show_app_console); if (show_app_log) ShowExampleAppLog(&show_app_log); if (show_app_layout) ShowExampleAppLayout(&show_app_layout); @@ -286,8 +286,8 @@ void ImGui::ShowDemoWindow(bool* p_open) if (no_close) p_open = NULL; // Don't pass our bool* to Begin // We specify a default position/size in case there's no data in the .ini file. Typically this isn't required! We only do it to make the Demo applications a little more welcoming. - ImVec2 main_viewport_pos = ImGui::GetMainViewport()->Pos; - ImGui::SetNextWindowPos(ImVec2(main_viewport_pos.x + 650, main_viewport_pos.y + 20), ImGuiCond_FirstUseEver); + ImGuiViewport* main_viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(ImVec2(main_viewport->GetWorkPos().x + 650, main_viewport->GetWorkPos().y + 20), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver); // Main body of the Demo window starts here. @@ -4458,7 +4458,9 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) if (corner != -1) { ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImVec2 window_pos = ImVec2((corner & 1) ? (viewport->Pos.x + viewport->Size.x - DISTANCE) : (viewport->Pos.x + DISTANCE), (corner & 2) ? (viewport->Pos.y + viewport->Size.y - DISTANCE) : (viewport->Pos.y + DISTANCE)); + ImVec2 work_area_pos = viewport->GetWorkPos(); // Instead of using viewport->Pos we use GetWorkPos() to avoid menu bars, if any! + ImVec2 work_area_size = viewport->GetWorkSize(); + ImVec2 window_pos = ImVec2((corner & 1) ? (work_area_pos.x + work_area_size.x - DISTANCE) : (work_area_pos.x + DISTANCE), (corner & 2) ? (work_area_pos.y + work_area_size.y - DISTANCE) : (work_area_pos.y + DISTANCE)); ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f); ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); ImGui::SetNextWindowViewport(viewport->ID); @@ -4714,8 +4716,8 @@ void ShowExampleAppDockSpace(bool* p_open) if (opt_fullscreen) { ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->Pos); - ImGui::SetNextWindowSize(viewport->Size); + ImGui::SetNextWindowPos(viewport->GetWorkPos()); + ImGui::SetNextWindowSize(viewport->GetWorkSize()); ImGui::SetNextWindowViewport(viewport->ID); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); diff --git a/imgui_internal.h b/imgui_internal.h index 56d6cf9d..c3ab97f3 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -934,10 +934,13 @@ struct ImGuiViewportP : public ImGuiViewport ImVec2 LastPlatformPos; ImVec2 LastPlatformSize; ImVec2 LastRendererSize; + ImVec2 CurrWorkOffsetMin; // Work area top-left offset being increased during the frame + ImVec2 CurrWorkOffsetMax; // Work area bottom-right offset being decreased during the frame ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } ImRect GetMainRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } + ImRect GetWorkRect() const { return ImRect(Pos.x + WorkOffsetMin.x, Pos.y + WorkOffsetMin.y, Pos.x + Size.x + WorkOffsetMax.x, Pos.y + Size.y + WorkOffsetMax.y); } void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } }; @@ -991,7 +994,7 @@ struct ImGuiNextWindowData ImGuiID ViewportId; ImGuiID DockId; ImGuiWindowClass WindowClass; - ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it. + ImVec2 MenuBarOffsetMinVal; // (Always on) This is not exposed publicly, so we don't clear it and it doesn't have a corresponding flag (could we? for consistency?) ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f0f29d26..800432ea 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6182,20 +6182,32 @@ void ImGui::EndMenuBar() window->DC.MenuBarAppending = false; } -// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. bool ImGui::BeginMainMenuBar() { ImGuiContext& g = *GImGui; - ImGuiViewport* viewport = g.Viewports[0]; + ImGuiViewportP* viewport = g.Viewports[0]; + + // For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f)); - SetNextWindowPos(viewport->Pos); - SetNextWindowSize(ImVec2(viewport->Size.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y)); - SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our onw viewport when ImGuiConfigFlags_ViewportsNoMerge is set. + + // Get our rectangle in the work area, and report the size we need for next frame. + // We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height. + ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin; + ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f); + + // Create window + SetNextWindowPos(menu_bar_pos); + SetNextWindowSize(menu_bar_size); + SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set. PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); + PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want. ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar; bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar(); PopStyleVar(2); + + // Feed back into work area using actual window size + viewport->CurrWorkOffsetMin.y += GetCurrentWindow()->Size.y; + g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); if (!is_open) { From 103c5edaaa832ccded2523ea328dc4398ba7b456 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 27 Feb 2020 16:10:36 +0100 Subject: [PATCH 294/384] Internals: debug log macros. --- imgui.cpp | 7 ++++--- imgui_internal.h | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cc4c08f2..f4c53193 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8204,7 +8204,7 @@ void ImGui::OpenPopupEx(ImGuiID id) popup_ref.OpenPopupPos = NavCalcPreferredRefPos(); popup_ref.OpenMousePos = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : popup_ref.OpenPopupPos; - //IMGUI_DEBUG_LOG("OpenPopupEx(0x%08X)\n", g.FrameCount, id); + IMGUI_DEBUG_LOG_POPUP("OpenPopupEx(0x%08X)\n", id); if (g.OpenPopupStack.Size < current_stack_size + 1) { g.OpenPopupStack.push_back(popup_ref); @@ -8265,7 +8265,7 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to } if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below { - //IMGUI_DEBUG_LOG("ClosePopupsOverWindow(%s) -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep); + IMGUI_DEBUG_LOG_POPUP("ClosePopupsOverWindow(\"%s\") -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep); ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup); } } @@ -8273,6 +8273,7 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup) { ImGuiContext& g = *GImGui; + IMGUI_DEBUG_LOG_POPUP("ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup); IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size); ImGuiWindow* focus_window = g.OpenPopupStack[remaining].SourceWindow; ImGuiWindow* popup_window = g.OpenPopupStack[remaining].Window; @@ -8315,7 +8316,7 @@ void ImGui::CloseCurrentPopup() break; popup_idx--; } - //IMGUI_DEBUG_LOG("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); + IMGUI_DEBUG_LOG_POPUP("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); ClosePopupToLevel(popup_idx, true); // A common pattern is to close a popup when selecting a menu item/selectable that will open another window. diff --git a/imgui_internal.h b/imgui_internal.h index c3ab97f3..a6646106 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -156,10 +156,11 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #ifndef IMGUI_DEBUG_LOG #define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) #endif -#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log -//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log + +// Debug Logging for selected systems. Remove the '((void)0) //' to enable. +#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) +#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) +#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) // Static Asserts #if (__cplusplus >= 201100) From 0342a3c54887ebfbcadce8308e866fe60c1dab0b Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 28 Feb 2020 15:50:44 +0200 Subject: [PATCH 295/384] Menus: Implement BeginMenu() appending to existing menu when executed with same ID multiple times. (#1207) --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 1 - imgui.cpp | 1 + imgui_internal.h | 1 + imgui_widgets.cpp | 26 ++++++++++++++++++++------ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6a25fa65..7a7c1cd2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,7 @@ Other Changes: branch pressing arrow keys while dragging a window from a tab could trigger an assert. (#3025) - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. +- BeginMenu: Using same ID multiple times appends content to a menu. (#1207) - BeginMenu: Fixed a bug where SetNextWindowXXX data before a BeginMenu() would not be cleared when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' diff --git a/docs/TODO.txt b/docs/TODO.txt index 24c79e43..ea612c57 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -214,7 +214,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed): IsItemHovered() with timer + implicit aabb-id for items with no ID. (#1485) - tooltip: drag tooltip hovering over source widget with IsItemHovered/SetTooltip flickers. - - menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207) - menus: menu bars inside modal windows are acting weird. - status-bar: add a per-window status bar helper similar to what menu-bar does. - shortcuts: local-style shortcut api, e.g. parse "&Save" diff --git a/imgui.cpp b/imgui.cpp index 98293e62..5a1810f8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3623,6 +3623,7 @@ void ImGui::NewFrame() g.FrameCount += 1; g.TooltipOverrideCount = 0; g.WindowsActiveCount = 0; + g.RenderedMenusId.resize(0); // Setup current font and draw list shared data g.IO.Fonts->Locked = true; diff --git a/imgui_internal.h b/imgui_internal.h index 87773e99..852211f6 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1159,6 +1159,7 @@ struct ImGuiContext float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? int TooltipOverrideCount; ImVector PrivateClipboard; // If no custom clipboard handler is defined + ImVector RenderedMenusId; // A list of menu IDs that were rendered at least once // Platform support ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ba35af12..1a505a3e 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6222,11 +6222,29 @@ bool ImGui::BeginMenu(const char* label, bool enabled) ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); + bool menu_is_open = IsPopupOpen(id); + ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; - ImVec2 label_size = CalcTextSize(label, NULL, true); + // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) + if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) + flags |= ImGuiWindowFlags_ChildWindow; + + if (g.RenderedMenusId.contains(id)) + { + // Menu with same ID was already created - append to it. + if (menu_is_open) + menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) + if (!menu_is_open) + g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values + return menu_is_open; + } + else + { + g.RenderedMenusId.push_back(id); // Tag menu as used. Next time BeginMenu() with same ID is called it will append to existing menu. + } + ImVec2 label_size = CalcTextSize(label, NULL, true); bool pressed; - bool menu_is_open = IsPopupOpen(id); bool menuset_is_open = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].OpenParentId == window->IDStack.back()); ImGuiWindow* backed_nav_window = g.NavWindow; if (menuset_is_open) @@ -6345,11 +6363,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) if (menu_is_open) { - // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) SetNextWindowPos(popup_pos, ImGuiCond_Always); - ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; - if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) - flags |= ImGuiWindowFlags_ChildWindow; menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) } else From 24bd33ace808ed77fd1840b19f2b8b4789a3ae62 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 28 Feb 2020 16:42:24 +0100 Subject: [PATCH 296/384] Menus: Some renaming, comments, add to demo. Amend 0342a3c. (#1207) --- imgui.cpp | 3 ++- imgui.h | 3 ++- imgui_demo.cpp | 36 ++++++++++++++++++++++++++++++++++-- imgui_internal.h | 2 +- imgui_widgets.cpp | 21 +++++++++++---------- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5a1810f8..974a876c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3623,7 +3623,7 @@ void ImGui::NewFrame() g.FrameCount += 1; g.TooltipOverrideCount = 0; g.WindowsActiveCount = 0; - g.RenderedMenusId.resize(0); + g.MenusIdSubmittedThisFrame.resize(0); // Setup current font and draw list shared data g.IO.Fonts->Locked = true; @@ -3915,6 +3915,7 @@ void ImGui::Shutdown(ImGuiContext* context) g.ShrinkWidthBuffer.clear(); g.PrivateClipboard.clear(); + g.MenusIdSubmittedThisFrame.clear(); g.InputTextState.ClearFreeMemory(); g.SettingsWindows.clear(); diff --git a/imgui.h b/imgui.h index 8ddd84a4..1e7b3f33 100644 --- a/imgui.h +++ b/imgui.h @@ -559,7 +559,8 @@ namespace ImGui // Widgets: Menus // - Use BeginMenuBar() on a window ImGuiWindowFlags_MenuBar to append to its menu bar. - // - Use BeginMainMenuBar() to create a menu bar at the top of the screen. + // - Use BeginMainMenuBar() to create a menu bar at the top of the screen and append to it. + // - Use BeginMenu() to create a menu. You can call BeginMenu() multiple time with the same identifier to append more items to it. IMGUI_API bool BeginMenuBar(); // append to menu-bar of current window (requires ImGuiWindowFlags_MenuBar flag set on parent window). IMGUI_API void EndMenuBar(); // only call EndMenuBar() if BeginMenuBar() returns true! IMGUI_API bool BeginMainMenuBar(); // create and append to a full screen menu-bar. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index a698a91a..c219f207 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -288,6 +288,27 @@ void ImGui::ShowDemoWindow(bool* p_open) // Menu Bar if (ImGui::BeginMenuBar()) { + if (ImGui::BeginMenu("Foo")) + { + if (ImGui::BeginMenu("AAA")) + { + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("BBB")) + { + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("AAA")) + { + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("BBB")) + { + ImGui::EndMenu(); + } + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Menu")) { ShowExampleMenuFile(); @@ -3580,6 +3601,7 @@ static void ShowExampleMenuFile() } if (ImGui::MenuItem("Save", "Ctrl+S")) {} if (ImGui::MenuItem("Save As..")) {} + ImGui::Separator(); if (ImGui::BeginMenu("Options")) { @@ -3591,13 +3613,12 @@ static void ShowExampleMenuFile() ImGui::EndChild(); static float f = 0.5f; static int n = 0; - static bool b = true; ImGui::SliderFloat("Value", &f, 0.0f, 1.0f); ImGui::InputFloat("Input", &f, 0.1f); ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0"); - ImGui::Checkbox("Check", &b); ImGui::EndMenu(); } + if (ImGui::BeginMenu("Colors")) { float sz = ImGui::GetTextLineHeight(); @@ -3612,6 +3633,17 @@ static void ShowExampleMenuFile() } ImGui::EndMenu(); } + + // 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. + if (ImGui::BeginMenu("Options")) // <-- Append! + { + static bool b = true; + ImGui::Checkbox("SomeOption", &b); + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Disabled", false)) // Disabled { IM_ASSERT(0); diff --git a/imgui_internal.h b/imgui_internal.h index 852211f6..dd92b6a5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1159,7 +1159,7 @@ struct ImGuiContext float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? int TooltipOverrideCount; ImVector PrivateClipboard; // If no custom clipboard handler is defined - ImVector RenderedMenusId; // A list of menu IDs that were rendered at least once + ImVector MenusIdSubmittedThisFrame; // A list of menu IDs that were rendered at least once // Platform support ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1a505a3e..f79fd9c5 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6223,25 +6223,26 @@ bool ImGui::BeginMenu(const char* label, bool enabled) const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); bool menu_is_open = IsPopupOpen(id); - ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) - if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) + ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; + if (window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) flags |= ImGuiWindowFlags_ChildWindow; - if (g.RenderedMenusId.contains(id)) + // If a menu with same the ID was already submitted, we will append to it, matching the behavior of Begin(). + // We are relying on a O(N) search - so O(N log N) over the frame - which seems like the most efficient for the expected small amount of BeginMenu() calls per frame. + // If somehow this is ever becoming a problem we can switch to use e.g. a ImGuiStorager mapping key to last frame used. + if (g.MenusIdSubmittedThisFrame.contains(id)) { - // Menu with same ID was already created - append to it. if (menu_is_open) menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) - if (!menu_is_open) - g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values + else + g.NextWindowData.ClearFlags(); // we behave like Begin() and need to consume those values return menu_is_open; } - else - { - g.RenderedMenusId.push_back(id); // Tag menu as used. Next time BeginMenu() with same ID is called it will append to existing menu. - } + + // Tag menu as used. Next time BeginMenu() with same ID is called it will append to existing menu + g.MenusIdSubmittedThisFrame.push_back(id); ImVec2 label_size = CalcTextSize(label, NULL, true); bool pressed; From 628614c6ea8e5485da049f106088a5f2459586cc Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 2 Mar 2020 15:49:51 +0100 Subject: [PATCH 297/384] Demo: Remove unnecessary code added by 24bd33ac. --- imgui_demo.cpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c219f207..591d6d99 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -288,27 +288,6 @@ void ImGui::ShowDemoWindow(bool* p_open) // Menu Bar if (ImGui::BeginMenuBar()) { - if (ImGui::BeginMenu("Foo")) - { - if (ImGui::BeginMenu("AAA")) - { - ImGui::EndMenu(); - } - if (ImGui::BeginMenu("BBB")) - { - ImGui::EndMenu(); - } - if (ImGui::BeginMenu("AAA")) - { - ImGui::EndMenu(); - } - if (ImGui::BeginMenu("BBB")) - { - ImGui::EndMenu(); - } - ImGui::EndMenu(); - } - if (ImGui::BeginMenu("Menu")) { ShowExampleMenuFile(); From 095dc996b0e2e6440c945cdbc56bf80357624ce8 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 2 Mar 2020 16:13:48 +0100 Subject: [PATCH 298/384] Disable deprecated-enum-enum-conversion (#3040, #2983) --- imgui_widgets.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f79fd9c5..60456645 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -68,6 +68,9 @@ Index of this file: #if __has_warning("-Wdouble-promotion") #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. #endif +#if __has_warning("-Wdeprecated-enum-enum-conversion") +#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion" // warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') is deprecated +#endif #elif defined(__GNUC__) #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked @@ -5573,7 +5576,9 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags return false; ImGuiID id = window->GetID(label); - flags |= ImGuiTreeNodeFlags_CollapsingHeader | (p_open ? ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_ClipLabelForTrailingButton : 0); + flags |= ImGuiTreeNodeFlags_CollapsingHeader; + if (p_open) + flags |= ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_ClipLabelForTrailingButton; bool is_open = TreeNodeBehavior(id, flags, label); if (p_open) { From 2679bee28d72d10f8dc7622d51b609846ee393f3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 15:23:51 +0100 Subject: [PATCH 299/384] Internals: Refactor: Moved code out of NewFrame() into UpdateTabFocus() and UpdateSettings() --- docs/TODO.txt | 1 + imgui.cpp | 149 ++++++++++++++++++++++++++++---------------------- 2 files changed, 86 insertions(+), 64 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index ea612c57..934d8e83 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -87,6 +87,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: option to Tab after an Enter validation. - input text: add ImGuiInputTextFlags_EnterToApply? (off #218) - input text: easier ways to update buffer (from source char*) while owned. preserve some sort of cursor position for multi-line text. + - input text: add flag (e.g. ImGuiInputTextFlags_EscapeClearsBuffer) to clear instead of revert. what to do with focus? (also see #2890) - input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725) - input text: display bug when clicking a drag/slider after an input text in a different window has all-selected text (order dependent). actually a very old bug but no one appears to have noticed it. - input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position. diff --git a/imgui.cpp b/imgui.cpp index 974a876c..79baf8f4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -904,10 +904,12 @@ static void ErrorCheckEndFrame(); static void ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write); // Misc +static void UpdateSettings(); static void UpdateMouseInputs(); static void UpdateMouseWheel(); -static bool UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]); +static void UpdateTabFocus(); static void UpdateDebugToolItemPicker(); +static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]); static void RenderWindowOuterBorders(ImGuiWindow* window); static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size); static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open); @@ -3495,6 +3497,42 @@ void ImGui::UpdateMouseWheel() } } +void ImGui::UpdateTabFocus() +{ + ImGuiContext& g = *GImGui; + + // Pressing TAB activate widget focus + g.FocusTabPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab)); + if (g.ActiveId == 0 && g.FocusTabPressed) + { + // Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also + // manipulate the Next fields even, even though they will be turned into Curr fields by the code below. + g.FocusRequestNextWindow = g.NavWindow; + g.FocusRequestNextCounterRegular = INT_MAX; + if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX) + g.FocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1); + else + g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0; + } + + // Turn queued focus request into current one + g.FocusRequestCurrWindow = NULL; + g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX; + if (g.FocusRequestNextWindow != NULL) + { + ImGuiWindow* window = g.FocusRequestNextWindow; + g.FocusRequestCurrWindow = window; + if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1) + g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1); + if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1) + g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1); + g.FocusRequestNextWindow = NULL; + g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX; + } + + g.NavIdTabCounter = INT_MAX; +} + // The reason this is exposed in imgui_internal.h is: on touch-based system that don't have hovering, we want to dispatch inputs to the right target (imgui vs imgui+app) void ImGui::UpdateHoveredWindowAndCaptureFlags() { @@ -3595,28 +3633,8 @@ void ImGui::NewFrame() // Check and assert for various common IO and Configuration mistakes NewFrameSanityChecks(); - // Load settings on first frame (if not explicitly loaded manually before) - if (!g.SettingsLoaded) - { - IM_ASSERT(g.SettingsWindows.empty()); - if (g.IO.IniFilename) - LoadIniSettingsFromDisk(g.IO.IniFilename); - g.SettingsLoaded = true; - } - - // Save settings (with a delay after the last modification, so we don't spam disk too much) - if (g.SettingsDirtyTimer > 0.0f) - { - g.SettingsDirtyTimer -= g.IO.DeltaTime; - if (g.SettingsDirtyTimer <= 0.0f) - { - if (g.IO.IniFilename != NULL) - SaveIniSettingsToDisk(g.IO.IniFilename); - else - g.IO.WantSaveIniSettings = true; // Let user know they can call SaveIniSettingsToMemory(). user will need to clear io.WantSaveIniSettings themselves. - g.SettingsDirtyTimer = 0.0f; - } - } + // Load settings on first frame, save settings when modified (after a delay) + UpdateSettings(); g.Time += g.IO.DeltaTime; g.WithinFrameScope = true; @@ -3625,6 +3643,12 @@ void ImGui::NewFrame() g.WindowsActiveCount = 0; g.MenusIdSubmittedThisFrame.resize(0); + // Calculate frame-rate for the user, as a purely luxurious feature + g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx]; + g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime; + g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame); + g.IO.Framerate = (g.FramerateSecPerFrameAccum > 0.0f) ? (1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame))) : FLT_MAX; + // Setup current font and draw list shared data g.IO.Fonts->Locked = true; SetCurrentFont(GetDefaultFont()); @@ -3655,7 +3679,7 @@ void ImGui::NewFrame() if (g.DragDropActive && g.DragDropPayload.SourceId == g.ActiveId) KeepAliveID(g.DragDropPayload.SourceId); - // Clear reference to active widget if the widget isn't alive anymore + // Update HoveredId data if (!g.HoveredIdPreviousFrame) g.HoveredIdTimer = 0.0f; if (!g.HoveredIdPreviousFrame || (g.HoveredId && g.ActiveId == g.HoveredId)) @@ -3667,6 +3691,8 @@ void ImGui::NewFrame() g.HoveredIdPreviousFrame = g.HoveredId; g.HoveredId = 0; g.HoveredIdAllowOverlap = false; + + // Update ActiveId data (clear reference to active widget if the widget isn't alive anymore) if (g.ActiveIdIsAlive != g.ActiveId && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) ClearActiveID(); if (g.ActiveId) @@ -3683,8 +3709,9 @@ void ImGui::NewFrame() g.TempInputId = 0; if (g.ActiveId == 0) { - g.ActiveIdUsingNavDirMask = g.ActiveIdUsingNavInputMask = 0; - g.ActiveIdUsingKeyInputMask = 0; + g.ActiveIdUsingNavDirMask = 0x00; + g.ActiveIdUsingNavInputMask = 0x00; + g.ActiveIdUsingKeyInputMask = 0x00; } // Drag and drop @@ -3704,12 +3731,6 @@ void ImGui::NewFrame() // Update mouse input state UpdateMouseInputs(); - // Calculate frame-rate for the user, as a purely luxurious feature - g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx]; - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime; - g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame); - g.IO.Framerate = (g.FramerateSecPerFrameAccum > 0.0f) ? (1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame))) : FLT_MAX; - // Find hovered window // (needs to be before UpdateMouseMovingWindowNewFrame so we fill g.HoveredWindowUnderMovingWindow on the mouse release frame) UpdateHoveredWindowAndCaptureFlags(); @@ -3730,36 +3751,8 @@ void ImGui::NewFrame() // Mouse wheel scrolling, scale UpdateMouseWheel(); - // Pressing TAB activate widget focus - g.FocusTabPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab)); - if (g.ActiveId == 0 && g.FocusTabPressed) - { - // Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also - // manipulate the Next fields even, even though they will be turned into Curr fields by the code below. - g.FocusRequestNextWindow = g.NavWindow; - g.FocusRequestNextCounterRegular = INT_MAX; - if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX) - g.FocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1); - else - g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0; - } - - // Turn queued focus request into current one - g.FocusRequestCurrWindow = NULL; - g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX; - if (g.FocusRequestNextWindow != NULL) - { - ImGuiWindow* window = g.FocusRequestNextWindow; - g.FocusRequestCurrWindow = window; - if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1) - g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1); - if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1) - g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1); - g.FocusRequestNextWindow = NULL; - g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX; - } - - g.NavIdTabCounter = INT_MAX; + // Update legacy TAB focus + UpdateTabFocus(); // Mark all windows as not visible and compact unused memory. IM_ASSERT(g.WindowsFocusOrder.Size == g.Windows.Size); @@ -4972,7 +4965,7 @@ ImGuiID ImGui::GetWindowResizeID(ImGuiWindow* window, int n) // Handle resize for: Resize Grips, Borders, Gamepad // Return true when using auto-fit (double click on resize grip) -static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]) +static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]) { ImGuiContext& g = *GImGui; ImGuiWindowFlags flags = window->Flags; @@ -5645,7 +5638,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it. const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); if (!window->Collapsed) - if (UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0])) + if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0])) use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true; window->ResizeBorderHeld = (signed char)border_held; @@ -9444,6 +9437,34 @@ void ImGui::LogButtons() // [SECTION] SETTINGS //----------------------------------------------------------------------------- +// Called by NewFrame() +void ImGui::UpdateSettings() +{ + // Load settings on first frame (if not explicitly loaded manually before) + ImGuiContext& g = *GImGui; + if (!g.SettingsLoaded) + { + IM_ASSERT(g.SettingsWindows.empty()); + if (g.IO.IniFilename) + LoadIniSettingsFromDisk(g.IO.IniFilename); + g.SettingsLoaded = true; + } + + // Save settings (with a delay after the last modification, so we don't spam disk too much) + if (g.SettingsDirtyTimer > 0.0f) + { + g.SettingsDirtyTimer -= g.IO.DeltaTime; + if (g.SettingsDirtyTimer <= 0.0f) + { + if (g.IO.IniFilename != NULL) + SaveIniSettingsToDisk(g.IO.IniFilename); + else + g.IO.WantSaveIniSettings = true; // Let user know they can call SaveIniSettingsToMemory(). user will need to clear io.WantSaveIniSettings themselves. + g.SettingsDirtyTimer = 0.0f; + } + } +} + void ImGui::MarkIniSettingsDirty() { ImGuiContext& g = *GImGui; From caca55c642d16cf1c2649831c5d06b1f26146d12 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 15:46:00 +0100 Subject: [PATCH 300/384] Internals: Refactor: Moved code into a Styling section and some code into the Error Handling section. --- imgui.cpp | 422 +++++++++++++++++++++++++++--------------------------- 1 file changed, 211 insertions(+), 211 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 79baf8f4..7d37f379 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -51,7 +51,7 @@ CODE // [SECTION] FORWARD DECLARATIONS // [SECTION] CONTEXT AND MEMORY ALLOCATORS -// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) +// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) // [SECTION] MISC HELPERS/UTILITIES (Geometry functions) // [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions) // [SECTION] MISC HELPERS/UTILITIES (File functions) @@ -61,6 +61,7 @@ CODE // [SECTION] ImGuiTextFilter // [SECTION] ImGuiTextBuffer // [SECTION] ImGuiListClipper +// [SECTION] STYLING // [SECTION] RENDER HELPERS // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) // [SECTION] ERROR CHECKING @@ -954,7 +955,7 @@ static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper; static void* GImAllocatorUserData = NULL; //----------------------------------------------------------------------------- -// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) +// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) //----------------------------------------------------------------------------- ImGuiStyle::ImGuiStyle() @@ -2261,11 +2262,15 @@ bool ImGuiListClipper::Step() } //----------------------------------------------------------------------------- -// [SECTION] RENDER HELPERS -// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change. -// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state. +// [SECTION] STYLING //----------------------------------------------------------------------------- +ImGuiStyle& ImGui::GetStyle() +{ + IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); + return GImGui->Style; +} + ImU32 ImGui::GetColorU32(ImGuiCol idx, float alpha_mul) { ImGuiStyle& style = GImGui->Style; @@ -2298,6 +2303,189 @@ ImU32 ImGui::GetColorU32(ImU32 col) return (col & ~IM_COL32_A_MASK) | (a << IM_COL32_A_SHIFT); } +// FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32 +void ImGui::PushStyleColor(ImGuiCol idx, ImU32 col) +{ + ImGuiContext& g = *GImGui; + ImGuiColorMod backup; + backup.Col = idx; + backup.BackupValue = g.Style.Colors[idx]; + g.ColorModifiers.push_back(backup); + g.Style.Colors[idx] = ColorConvertU32ToFloat4(col); +} + +void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col) +{ + ImGuiContext& g = *GImGui; + ImGuiColorMod backup; + backup.Col = idx; + backup.BackupValue = g.Style.Colors[idx]; + g.ColorModifiers.push_back(backup); + g.Style.Colors[idx] = col; +} + +void ImGui::PopStyleColor(int count) +{ + ImGuiContext& g = *GImGui; + while (count > 0) + { + ImGuiColorMod& backup = g.ColorModifiers.back(); + g.Style.Colors[backup.Col] = backup.BackupValue; + g.ColorModifiers.pop_back(); + count--; + } +} + +struct ImGuiStyleVarInfo +{ + ImGuiDataType Type; + ImU32 Count; + ImU32 Offset; + void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); } +}; + +static const ImGuiStyleVarInfo GStyleVarInfo[] = +{ + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowMinSize) }, // ImGuiStyleVar_WindowMinSize + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowTitleAlign) }, // ImGuiStyleVar_WindowTitleAlign + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildRounding) }, // ImGuiStyleVar_ChildRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildBorderSize) }, // ImGuiStyleVar_ChildBorderSize + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupRounding) }, // ImGuiStyleVar_PopupRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupBorderSize) }, // ImGuiStyleVar_PopupBorderSize + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, FramePadding) }, // ImGuiStyleVar_FramePadding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameRounding) }, // ImGuiStyleVar_FrameRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameBorderSize) }, // ImGuiStyleVar_FrameBorderSize + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemSpacing) }, // ImGuiStyleVar_ItemSpacing + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) }, // ImGuiStyleVar_ItemInnerSpacing + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) }, // ImGuiStyleVar_IndentSpacing + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarSize) }, // ImGuiStyleVar_ScrollbarSize + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarRounding) }, // ImGuiStyleVar_ScrollbarRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign + { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign +}; + +static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx) +{ + IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_COUNT); + IM_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT); + return &GStyleVarInfo[idx]; +} + +void ImGui::PushStyleVar(ImGuiStyleVar idx, float val) +{ + const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) + { + ImGuiContext& g = *GImGui; + float* pvar = (float*)var_info->GetVarPtr(&g.Style); + g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); + *pvar = val; + return; + } + IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!"); +} + +void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) +{ + const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); + if (var_info->Type == ImGuiDataType_Float && var_info->Count == 2) + { + ImGuiContext& g = *GImGui; + ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style); + g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); + *pvar = val; + return; + } + IM_ASSERT(0 && "Called PushStyleVar() ImVec2 variant but variable is not a ImVec2!"); +} + +void ImGui::PopStyleVar(int count) +{ + ImGuiContext& g = *GImGui; + while (count > 0) + { + // We avoid a generic memcpy(data, &backup.Backup.., GDataTypeSize[info->Type] * info->Count), the overhead in Debug is not worth it. + ImGuiStyleMod& backup = g.StyleModifiers.back(); + const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx); + void* data = info->GetVarPtr(&g.Style); + if (info->Type == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; } + else if (info->Type == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; } + g.StyleModifiers.pop_back(); + count--; + } +} + +const char* ImGui::GetStyleColorName(ImGuiCol idx) +{ + // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; + switch (idx) + { + case ImGuiCol_Text: return "Text"; + case ImGuiCol_TextDisabled: return "TextDisabled"; + case ImGuiCol_WindowBg: return "WindowBg"; + case ImGuiCol_ChildBg: return "ChildBg"; + case ImGuiCol_PopupBg: return "PopupBg"; + case ImGuiCol_Border: return "Border"; + case ImGuiCol_BorderShadow: return "BorderShadow"; + case ImGuiCol_FrameBg: return "FrameBg"; + case ImGuiCol_FrameBgHovered: return "FrameBgHovered"; + case ImGuiCol_FrameBgActive: return "FrameBgActive"; + case ImGuiCol_TitleBg: return "TitleBg"; + case ImGuiCol_TitleBgActive: return "TitleBgActive"; + case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; + case ImGuiCol_MenuBarBg: return "MenuBarBg"; + case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; + case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab"; + case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; + case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; + case ImGuiCol_CheckMark: return "CheckMark"; + case ImGuiCol_SliderGrab: return "SliderGrab"; + case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; + case ImGuiCol_Button: return "Button"; + case ImGuiCol_ButtonHovered: return "ButtonHovered"; + case ImGuiCol_ButtonActive: return "ButtonActive"; + case ImGuiCol_Header: return "Header"; + case ImGuiCol_HeaderHovered: return "HeaderHovered"; + case ImGuiCol_HeaderActive: return "HeaderActive"; + case ImGuiCol_Separator: return "Separator"; + case ImGuiCol_SeparatorHovered: return "SeparatorHovered"; + case ImGuiCol_SeparatorActive: return "SeparatorActive"; + case ImGuiCol_ResizeGrip: return "ResizeGrip"; + case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; + case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; + case ImGuiCol_Tab: return "Tab"; + case ImGuiCol_TabHovered: return "TabHovered"; + case ImGuiCol_TabActive: return "TabActive"; + case ImGuiCol_TabUnfocused: return "TabUnfocused"; + case ImGuiCol_TabUnfocusedActive: return "TabUnfocusedActive"; + case ImGuiCol_PlotLines: return "PlotLines"; + case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; + case ImGuiCol_PlotHistogram: return "PlotHistogram"; + case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered"; + case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; + case ImGuiCol_DragDropTarget: return "DragDropTarget"; + case ImGuiCol_NavHighlight: return "NavHighlight"; + case ImGuiCol_NavWindowingHighlight: return "NavWindowingHighlight"; + case ImGuiCol_NavWindowingDimBg: return "NavWindowingDimBg"; + case ImGuiCol_ModalWindowDimBg: return "ModalWindowDimBg"; + } + IM_ASSERT(0); + return "Unknown"; +} + +//----------------------------------------------------------------------------- +// [SECTION] RENDER HELPERS +// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change. +// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state. +//----------------------------------------------------------------------------- + const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end) { const char* text_display_end = text; @@ -3148,24 +3336,6 @@ void ImGui::SetCurrentContext(ImGuiContext* ctx) #endif } -// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui. -// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit -// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code -// may see different structures than what imgui.cpp sees, which is problematic. -// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui. -bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx) -{ - bool error = false; - if (strcmp(version, IMGUI_VERSION)!=0) { error = true; IM_ASSERT(strcmp(version,IMGUI_VERSION)==0 && "Mismatched version string!"); } - if (sz_io != sizeof(ImGuiIO)) { error = true; IM_ASSERT(sz_io == sizeof(ImGuiIO) && "Mismatched struct layout!"); } - if (sz_style != sizeof(ImGuiStyle)) { error = true; IM_ASSERT(sz_style == sizeof(ImGuiStyle) && "Mismatched struct layout!"); } - if (sz_vec2 != sizeof(ImVec2)) { error = true; IM_ASSERT(sz_vec2 == sizeof(ImVec2) && "Mismatched struct layout!"); } - if (sz_vec4 != sizeof(ImVec4)) { error = true; IM_ASSERT(sz_vec4 == sizeof(ImVec4) && "Mismatched struct layout!"); } - if (sz_vert != sizeof(ImDrawVert)) { error = true; IM_ASSERT(sz_vert == sizeof(ImDrawVert) && "Mismatched struct layout!"); } - if (sz_idx != sizeof(ImDrawIdx)) { error = true; IM_ASSERT(sz_idx == sizeof(ImDrawIdx) && "Mismatched struct layout!"); } - return !error; -} - void ImGui::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data) { GImAllocatorAllocFunc = alloc_func; @@ -3198,12 +3368,6 @@ ImGuiIO& ImGui::GetIO() return GImGui->IO; } -ImGuiStyle& ImGui::GetStyle() -{ - IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); - return GImGui->Style; -} - // Same value as passed to the old io.RenderDrawListsFn function. Valid after Render() and until the next call to NewFrame() ImDrawData* ImGui::GetDrawData() { @@ -6243,183 +6407,6 @@ void ImGui::PopTextWrapPos() window->DC.TextWrapPos = window->DC.TextWrapPosStack.empty() ? -1.0f : window->DC.TextWrapPosStack.back(); } -// FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32 -void ImGui::PushStyleColor(ImGuiCol idx, ImU32 col) -{ - ImGuiContext& g = *GImGui; - ImGuiColorMod backup; - backup.Col = idx; - backup.BackupValue = g.Style.Colors[idx]; - g.ColorModifiers.push_back(backup); - g.Style.Colors[idx] = ColorConvertU32ToFloat4(col); -} - -void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col) -{ - ImGuiContext& g = *GImGui; - ImGuiColorMod backup; - backup.Col = idx; - backup.BackupValue = g.Style.Colors[idx]; - g.ColorModifiers.push_back(backup); - g.Style.Colors[idx] = col; -} - -void ImGui::PopStyleColor(int count) -{ - ImGuiContext& g = *GImGui; - while (count > 0) - { - ImGuiColorMod& backup = g.ColorModifiers.back(); - g.Style.Colors[backup.Col] = backup.BackupValue; - g.ColorModifiers.pop_back(); - count--; - } -} - -struct ImGuiStyleVarInfo -{ - ImGuiDataType Type; - ImU32 Count; - ImU32 Offset; - void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); } -}; - -static const ImGuiStyleVarInfo GStyleVarInfo[] = -{ - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowMinSize) }, // ImGuiStyleVar_WindowMinSize - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowTitleAlign) }, // ImGuiStyleVar_WindowTitleAlign - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildRounding) }, // ImGuiStyleVar_ChildRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildBorderSize) }, // ImGuiStyleVar_ChildBorderSize - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupRounding) }, // ImGuiStyleVar_PopupRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupBorderSize) }, // ImGuiStyleVar_PopupBorderSize - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, FramePadding) }, // ImGuiStyleVar_FramePadding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameRounding) }, // ImGuiStyleVar_FrameRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameBorderSize) }, // ImGuiStyleVar_FrameBorderSize - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemSpacing) }, // ImGuiStyleVar_ItemSpacing - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) }, // ImGuiStyleVar_ItemInnerSpacing - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) }, // ImGuiStyleVar_IndentSpacing - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarSize) }, // ImGuiStyleVar_ScrollbarSize - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarRounding) }, // ImGuiStyleVar_ScrollbarRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding - { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign - { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign -}; - -static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx) -{ - IM_ASSERT(idx >= 0 && idx < ImGuiStyleVar_COUNT); - IM_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImGuiStyleVar_COUNT); - return &GStyleVarInfo[idx]; -} - -void ImGui::PushStyleVar(ImGuiStyleVar idx, float val) -{ - const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); - if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) - { - ImGuiContext& g = *GImGui; - float* pvar = (float*)var_info->GetVarPtr(&g.Style); - g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); - *pvar = val; - return; - } - IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!"); -} - -void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) -{ - const ImGuiStyleVarInfo* var_info = GetStyleVarInfo(idx); - if (var_info->Type == ImGuiDataType_Float && var_info->Count == 2) - { - ImGuiContext& g = *GImGui; - ImVec2* pvar = (ImVec2*)var_info->GetVarPtr(&g.Style); - g.StyleModifiers.push_back(ImGuiStyleMod(idx, *pvar)); - *pvar = val; - return; - } - IM_ASSERT(0 && "Called PushStyleVar() ImVec2 variant but variable is not a ImVec2!"); -} - -void ImGui::PopStyleVar(int count) -{ - ImGuiContext& g = *GImGui; - while (count > 0) - { - // We avoid a generic memcpy(data, &backup.Backup.., GDataTypeSize[info->Type] * info->Count), the overhead in Debug is not worth it. - ImGuiStyleMod& backup = g.StyleModifiers.back(); - const ImGuiStyleVarInfo* info = GetStyleVarInfo(backup.VarIdx); - void* data = info->GetVarPtr(&g.Style); - if (info->Type == ImGuiDataType_Float && info->Count == 1) { ((float*)data)[0] = backup.BackupFloat[0]; } - else if (info->Type == ImGuiDataType_Float && info->Count == 2) { ((float*)data)[0] = backup.BackupFloat[0]; ((float*)data)[1] = backup.BackupFloat[1]; } - g.StyleModifiers.pop_back(); - count--; - } -} - -const char* ImGui::GetStyleColorName(ImGuiCol idx) -{ - // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; - switch (idx) - { - case ImGuiCol_Text: return "Text"; - case ImGuiCol_TextDisabled: return "TextDisabled"; - case ImGuiCol_WindowBg: return "WindowBg"; - case ImGuiCol_ChildBg: return "ChildBg"; - case ImGuiCol_PopupBg: return "PopupBg"; - case ImGuiCol_Border: return "Border"; - case ImGuiCol_BorderShadow: return "BorderShadow"; - case ImGuiCol_FrameBg: return "FrameBg"; - case ImGuiCol_FrameBgHovered: return "FrameBgHovered"; - case ImGuiCol_FrameBgActive: return "FrameBgActive"; - case ImGuiCol_TitleBg: return "TitleBg"; - case ImGuiCol_TitleBgActive: return "TitleBgActive"; - case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; - case ImGuiCol_MenuBarBg: return "MenuBarBg"; - case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; - case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab"; - case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; - case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; - case ImGuiCol_CheckMark: return "CheckMark"; - case ImGuiCol_SliderGrab: return "SliderGrab"; - case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; - case ImGuiCol_Button: return "Button"; - case ImGuiCol_ButtonHovered: return "ButtonHovered"; - case ImGuiCol_ButtonActive: return "ButtonActive"; - case ImGuiCol_Header: return "Header"; - case ImGuiCol_HeaderHovered: return "HeaderHovered"; - case ImGuiCol_HeaderActive: return "HeaderActive"; - case ImGuiCol_Separator: return "Separator"; - case ImGuiCol_SeparatorHovered: return "SeparatorHovered"; - case ImGuiCol_SeparatorActive: return "SeparatorActive"; - case ImGuiCol_ResizeGrip: return "ResizeGrip"; - case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; - case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; - case ImGuiCol_Tab: return "Tab"; - case ImGuiCol_TabHovered: return "TabHovered"; - case ImGuiCol_TabActive: return "TabActive"; - case ImGuiCol_TabUnfocused: return "TabUnfocused"; - case ImGuiCol_TabUnfocusedActive: return "TabUnfocusedActive"; - case ImGuiCol_PlotLines: return "PlotLines"; - case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; - case ImGuiCol_PlotHistogram: return "PlotHistogram"; - case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered"; - case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; - case ImGuiCol_DragDropTarget: return "DragDropTarget"; - case ImGuiCol_NavHighlight: return "NavHighlight"; - case ImGuiCol_NavWindowingHighlight: return "NavWindowingHighlight"; - case ImGuiCol_NavWindowingDimBg: return "NavWindowingDimBg"; - case ImGuiCol_ModalWindowDimBg: return "ModalWindowDimBg"; - } - IM_ASSERT(0); - return "Unknown"; -} - bool ImGui::IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent) { if (window->RootWindow == potential_parent) @@ -7125,11 +7112,28 @@ void ImGui::Unindent(float indent_w) window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; } - //----------------------------------------------------------------------------- // [SECTION] ERROR CHECKING //----------------------------------------------------------------------------- +// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui. +// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit +// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code +// may see different structures than what imgui.cpp sees, which is problematic. +// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui. +bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx) +{ + bool error = false; + if (strcmp(version, IMGUI_VERSION)!=0) { error = true; IM_ASSERT(strcmp(version,IMGUI_VERSION)==0 && "Mismatched version string!"); } + if (sz_io != sizeof(ImGuiIO)) { error = true; IM_ASSERT(sz_io == sizeof(ImGuiIO) && "Mismatched struct layout!"); } + if (sz_style != sizeof(ImGuiStyle)) { error = true; IM_ASSERT(sz_style == sizeof(ImGuiStyle) && "Mismatched struct layout!"); } + if (sz_vec2 != sizeof(ImVec2)) { error = true; IM_ASSERT(sz_vec2 == sizeof(ImVec2) && "Mismatched struct layout!"); } + if (sz_vec4 != sizeof(ImVec4)) { error = true; IM_ASSERT(sz_vec4 == sizeof(ImVec4) && "Mismatched struct layout!"); } + if (sz_vert != sizeof(ImDrawVert)) { error = true; IM_ASSERT(sz_vert == sizeof(ImDrawVert) && "Mismatched struct layout!"); } + if (sz_idx != sizeof(ImDrawIdx)) { error = true; IM_ASSERT(sz_idx == sizeof(ImDrawIdx) && "Mismatched struct layout!"); } + return !error; +} + static void ImGui::ErrorCheckEndFrame() { // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you @@ -7173,7 +7177,6 @@ static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool IM_ASSERT(p == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); } - //----------------------------------------------------------------------------- // [SECTION] SCROLLING //----------------------------------------------------------------------------- @@ -7817,7 +7820,6 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) return window->Pos; } - //----------------------------------------------------------------------------- // [SECTION] KEYBOARD/GAMEPAD NAVIGATION //----------------------------------------------------------------------------- @@ -8919,7 +8921,6 @@ void ImGui::NavUpdateWindowingOverlay() PopStyleVar(); } - //----------------------------------------------------------------------------- // [SECTION] DRAG AND DROP //----------------------------------------------------------------------------- @@ -9218,7 +9219,6 @@ void ImGui::EndDragDropTarget() g.DragDropWithinSourceOrTarget = false; } - //----------------------------------------------------------------------------- // [SECTION] LOGGING/CAPTURING //----------------------------------------------------------------------------- From 3ce26f65d43291acf9738b25a8ee4f9c04111d6b Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 16:03:07 +0100 Subject: [PATCH 301/384] Internals: Refactor: Moved ItemAdd(), ItemSize(), BeginGroup(), EndGroup(), SameLine(), Indent(), Unindent() to Layout section. --- imgui.cpp | 425 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 221 insertions(+), 204 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7d37f379..a9d8081e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -65,6 +65,7 @@ CODE // [SECTION] RENDER HELPERS // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) // [SECTION] ERROR CHECKING +// [SECTION] LAYOUT // [SECTION] SCROLLING // [SECTION] TOOLTIPS // [SECTION] POPUPS @@ -3042,102 +3043,6 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla return true; } -// Advance cursor given item size for layout. -void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - if (window->SkipItems) - return; - - // We increase the height in this function to accommodate for baseline offset. - // In theory we should be offsetting the starting position (window->DC.CursorPos), that will be the topic of a larger refactor, - // but since ItemSize() is not yet an API that moves the cursor (to handle e.g. wrapping) enlarging the height has the same effect. - const float offset_to_match_baseline_y = (text_baseline_y >= 0) ? ImMax(0.0f, window->DC.CurrLineTextBaseOffset - text_baseline_y) : 0.0f; - const float line_height = ImMax(window->DC.CurrLineSize.y, size.y + offset_to_match_baseline_y); - - // Always align ourselves on pixel boundaries - //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] - window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; - window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; - window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line - window->DC.CursorPos.y = IM_FLOOR(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line - window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); - window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); - //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] - - window->DC.PrevLineSize.y = line_height; - window->DC.CurrLineSize.y = 0.0f; - window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y); - window->DC.CurrLineTextBaseOffset = 0.0f; - - // Horizontal layout mode - if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) - SameLine(); -} - -void ImGui::ItemSize(const ImRect& bb, float text_baseline_y) -{ - ItemSize(bb.GetSize(), text_baseline_y); -} - -// Declare item bounding box for clipping and interaction. -// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface -// declare their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd(). -bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - - if (id != 0) - { - // Navigation processing runs prior to clipping early-out - // (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget - // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests - // unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of - // thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame. - // We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able - // to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick). - // We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null. - // If we crash on a NULL g.NavWindow we need to fix the bug elsewhere. - window->DC.NavLayerActiveMaskNext |= window->DC.NavLayerCurrentMask; - if (g.NavId == id || g.NavAnyRequest) - if (g.NavWindow->RootWindowForNav == window->RootWindowForNav) - if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened)) - NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id); - - // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd() -#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX - if (id == g.DebugItemPickerBreakId) - { - IM_DEBUG_BREAK(); - g.DebugItemPickerBreakId = 0; - } -#endif - } - - window->DC.LastItemId = id; - window->DC.LastItemRect = bb; - window->DC.LastItemStatusFlags = ImGuiItemStatusFlags_None; - g.NextItemData.Flags = ImGuiNextItemDataFlags_None; - -#ifdef IMGUI_ENABLE_TEST_ENGINE - if (id != 0) - IMGUI_TEST_ENGINE_ITEM_ADD(nav_bb_arg ? *nav_bb_arg : bb, id); -#endif - - // Clipping test - const bool is_clipped = IsClippedEx(bb, id, false); - if (is_clipped) - return false; - //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] - - // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them) - if (IsMouseHoveringRect(bb.Min, bb.Max)) - window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HoveredRect; - return true; -} - // This is roughly matching the behavior of internal-facing ItemHoverable() // - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered() // - this should work even for non-interactive items that have no ID, so we cannot use LastItemId @@ -6988,6 +6893,226 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max) return window->ClipRect.Overlaps(ImRect(rect_min, rect_max)); } + +//----------------------------------------------------------------------------- +// [SECTION] ERROR CHECKING +//----------------------------------------------------------------------------- + +// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui. +// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit +// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code +// may see different structures than what imgui.cpp sees, which is problematic. +// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui. +bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx) +{ + bool error = false; + if (strcmp(version, IMGUI_VERSION) != 0) { error = true; IM_ASSERT(strcmp(version, IMGUI_VERSION) == 0 && "Mismatched version string!"); } + if (sz_io != sizeof(ImGuiIO)) { error = true; IM_ASSERT(sz_io == sizeof(ImGuiIO) && "Mismatched struct layout!"); } + if (sz_style != sizeof(ImGuiStyle)) { error = true; IM_ASSERT(sz_style == sizeof(ImGuiStyle) && "Mismatched struct layout!"); } + if (sz_vec2 != sizeof(ImVec2)) { error = true; IM_ASSERT(sz_vec2 == sizeof(ImVec2) && "Mismatched struct layout!"); } + if (sz_vec4 != sizeof(ImVec4)) { error = true; IM_ASSERT(sz_vec4 == sizeof(ImVec4) && "Mismatched struct layout!"); } + if (sz_vert != sizeof(ImDrawVert)) { error = true; IM_ASSERT(sz_vert == sizeof(ImDrawVert) && "Mismatched struct layout!"); } + if (sz_idx != sizeof(ImDrawIdx)) { error = true; IM_ASSERT(sz_idx == sizeof(ImDrawIdx) && "Mismatched struct layout!"); } + return !error; +} + +static void ImGui::ErrorCheckEndFrame() +{ + // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you + // to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API). + ImGuiContext& g = *GImGui; + if (g.CurrentWindowStack.Size != 1) + { + if (g.CurrentWindowStack.Size > 1) + { + IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); + while (g.CurrentWindowStack.Size > 1) + End(); + } + else + { + IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); + } + } + +} + +// Save and compare stack sizes on Begin()/End() to detect usage errors +// Begin() calls this with write=true +// End() calls this with write=false +static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write) +{ + ImGuiContext& g = *GImGui; + short* p = &window->DC.StackSizesBackup[0]; + + // Window stacks + // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) + { int n = window->IDStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "PushID/PopID or TreeNode/TreePop Mismatch!"); p++; } // Too few or too many PopID()/TreePop() + { int n = window->DC.GroupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginGroup/EndGroup Mismatch!"); p++; } // Too few or too many EndGroup() + + // Global stacks + // For color, style and font stacks there is an incentive to use Push/Begin/Pop/.../End patterns, so we relax our checks a little to allow them. + { int n = g.BeginPopupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch!"); p++; }// Too few or too many EndMenu()/EndPopup() + { int n = g.ColorModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleColor/PopStyleColor Mismatch!"); p++; } // Too few or too many PopStyleColor() + { int n = g.StyleModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleVar/PopStyleVar Mismatch!"); p++; } // Too few or too many PopStyleVar() + { int n = g.FontStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushFont/PopFont Mismatch!"); p++; } // Too few or too many PopFont() + IM_ASSERT(p == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); +} + + +//----------------------------------------------------------------------------- +// [SECTION] LAYOUT +//----------------------------------------------------------------------------- +// - ItemSize() +// - ItemAdd() +// - SameLine() +// - Indent() +// - Unindent() +// - BeginGroup() +// - EndGroup() +// Also see in imgui_widgets: tab bars, columns. +//----------------------------------------------------------------------------- + +// Advance cursor given item size for layout. +void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + if (window->SkipItems) + return; + + // We increase the height in this function to accommodate for baseline offset. + // In theory we should be offsetting the starting position (window->DC.CursorPos), that will be the topic of a larger refactor, + // but since ItemSize() is not yet an API that moves the cursor (to handle e.g. wrapping) enlarging the height has the same effect. + const float offset_to_match_baseline_y = (text_baseline_y >= 0) ? ImMax(0.0f, window->DC.CurrLineTextBaseOffset - text_baseline_y) : 0.0f; + const float line_height = ImMax(window->DC.CurrLineSize.y, size.y + offset_to_match_baseline_y); + + // Always align ourselves on pixel boundaries + //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] + window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; + window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; + window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line + window->DC.CursorPos.y = IM_FLOOR(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); + //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] + + window->DC.PrevLineSize.y = line_height; + window->DC.CurrLineSize.y = 0.0f; + window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y); + window->DC.CurrLineTextBaseOffset = 0.0f; + + // Horizontal layout mode + if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) + SameLine(); +} + +void ImGui::ItemSize(const ImRect& bb, float text_baseline_y) +{ + ItemSize(bb.GetSize(), text_baseline_y); +} + +// Declare item bounding box for clipping and interaction. +// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface +// declare their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd(). +bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + if (id != 0) + { + // Navigation processing runs prior to clipping early-out + // (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget + // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests + // unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of + // thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame. + // We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able + // to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick). + // We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null. + // If we crash on a NULL g.NavWindow we need to fix the bug elsewhere. + window->DC.NavLayerActiveMaskNext |= window->DC.NavLayerCurrentMask; + if (g.NavId == id || g.NavAnyRequest) + if (g.NavWindow->RootWindowForNav == window->RootWindowForNav) + if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened)) + NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id); + + // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd() +#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX + if (id == g.DebugItemPickerBreakId) + { + IM_DEBUG_BREAK(); + g.DebugItemPickerBreakId = 0; + } +#endif + } + + window->DC.LastItemId = id; + window->DC.LastItemRect = bb; + window->DC.LastItemStatusFlags = ImGuiItemStatusFlags_None; + g.NextItemData.Flags = ImGuiNextItemDataFlags_None; + +#ifdef IMGUI_ENABLE_TEST_ENGINE + if (id != 0) + IMGUI_TEST_ENGINE_ITEM_ADD(nav_bb_arg ? *nav_bb_arg : bb, id); +#endif + + // Clipping test + const bool is_clipped = IsClippedEx(bb, id, false); + if (is_clipped) + return false; + //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] + + // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them) + if (IsMouseHoveringRect(bb.Min, bb.Max)) + window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HoveredRect; + return true; +} + +// Gets back to previous line and continue with horizontal layout +// offset_from_start_x == 0 : follow right after previous item +// offset_from_start_x != 0 : align to specified x position (relative to window/group left) +// spacing_w < 0 : use default spacing if pos_x == 0, no spacing if pos_x != 0 +// spacing_w >= 0 : enforce spacing amount +void ImGui::SameLine(float offset_from_start_x, float spacing_w) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + if (offset_from_start_x != 0.0f) + { + if (spacing_w < 0.0f) spacing_w = 0.0f; + window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + offset_from_start_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; + } + else + { + if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; + window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w; + window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; + } + window->DC.CurrLineSize = window->DC.PrevLineSize; + window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; +} + +void ImGui::Indent(float indent_w) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.Indent.x += (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; +} + +void ImGui::Unindent(float indent_w) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.Indent.x -= (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; +} + // Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) void ImGui::BeginGroup() { @@ -7068,114 +7193,6 @@ void ImGui::EndGroup() //window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug] } -// Gets back to previous line and continue with horizontal layout -// offset_from_start_x == 0 : follow right after previous item -// offset_from_start_x != 0 : align to specified x position (relative to window/group left) -// spacing_w < 0 : use default spacing if pos_x == 0, no spacing if pos_x != 0 -// spacing_w >= 0 : enforce spacing amount -void ImGui::SameLine(float offset_from_start_x, float spacing_w) -{ - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; - - ImGuiContext& g = *GImGui; - if (offset_from_start_x != 0.0f) - { - if (spacing_w < 0.0f) spacing_w = 0.0f; - window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + offset_from_start_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x; - window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; - } - else - { - if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; - window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w; - window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; - } - window->DC.CurrLineSize = window->DC.PrevLineSize; - window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; -} - -void ImGui::Indent(float indent_w) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - window->DC.Indent.x += (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; -} - -void ImGui::Unindent(float indent_w) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - window->DC.Indent.x -= (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; -} - -//----------------------------------------------------------------------------- -// [SECTION] ERROR CHECKING -//----------------------------------------------------------------------------- - -// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui. -// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit -// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code -// may see different structures than what imgui.cpp sees, which is problematic. -// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui. -bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx) -{ - bool error = false; - if (strcmp(version, IMGUI_VERSION)!=0) { error = true; IM_ASSERT(strcmp(version,IMGUI_VERSION)==0 && "Mismatched version string!"); } - if (sz_io != sizeof(ImGuiIO)) { error = true; IM_ASSERT(sz_io == sizeof(ImGuiIO) && "Mismatched struct layout!"); } - if (sz_style != sizeof(ImGuiStyle)) { error = true; IM_ASSERT(sz_style == sizeof(ImGuiStyle) && "Mismatched struct layout!"); } - if (sz_vec2 != sizeof(ImVec2)) { error = true; IM_ASSERT(sz_vec2 == sizeof(ImVec2) && "Mismatched struct layout!"); } - if (sz_vec4 != sizeof(ImVec4)) { error = true; IM_ASSERT(sz_vec4 == sizeof(ImVec4) && "Mismatched struct layout!"); } - if (sz_vert != sizeof(ImDrawVert)) { error = true; IM_ASSERT(sz_vert == sizeof(ImDrawVert) && "Mismatched struct layout!"); } - if (sz_idx != sizeof(ImDrawIdx)) { error = true; IM_ASSERT(sz_idx == sizeof(ImDrawIdx) && "Mismatched struct layout!"); } - return !error; -} - -static void ImGui::ErrorCheckEndFrame() -{ - // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you - // to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API). - ImGuiContext& g = *GImGui; - if (g.CurrentWindowStack.Size != 1) - { - if (g.CurrentWindowStack.Size > 1) - { - IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?"); - while (g.CurrentWindowStack.Size > 1) - End(); - } - else - { - IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); - } - } - -} - -// Save and compare stack sizes on Begin()/End() to detect usage errors -// Begin() calls this with write=true -// End() calls this with write=false -static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write) -{ - ImGuiContext& g = *GImGui; - short* p = &window->DC.StackSizesBackup[0]; - - // Window stacks - // NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin) - { int n = window->IDStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "PushID/PopID or TreeNode/TreePop Mismatch!"); p++; } // Too few or too many PopID()/TreePop() - { int n = window->DC.GroupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginGroup/EndGroup Mismatch!"); p++; } // Too few or too many EndGroup() - - // Global stacks - // For color, style and font stacks there is an incentive to use Push/Begin/Pop/.../End patterns, so we relax our checks a little to allow them. - { int n = g.BeginPopupStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p == n && "BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch!"); p++; }// Too few or too many EndMenu()/EndPopup() - { int n = g.ColorModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleColor/PopStyleColor Mismatch!"); p++; } // Too few or too many PopStyleColor() - { int n = g.StyleModifiers.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushStyleVar/PopStyleVar Mismatch!"); p++; } // Too few or too many PopStyleVar() - { int n = g.FontStack.Size; if (write) *p = (short)n; else IM_ASSERT(*p >= n && "PushFont/PopFont Mismatch!"); p++; } // Too few or too many PopFont() - IM_ASSERT(p == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup)); -} //----------------------------------------------------------------------------- // [SECTION] SCROLLING From 6c1810e503f7c0f03f289be5add384e4433e44fd Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 16:18:59 +0100 Subject: [PATCH 302/384] Internals: Refactor: Moved cursor position functions to Layout section. --- imgui.cpp | 125 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a9d8081e..6916f797 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6705,66 +6705,6 @@ void ImGui::SetWindowFontScale(float scale) g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); } -// User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient. -// Conversion happens as we pass the value to user, but it makes our naming convention confusing because GetCursorPos() == (DC.CursorPos - window.Pos). May want to rename 'DC.CursorPos'. -ImVec2 ImGui::GetCursorPos() -{ - ImGuiWindow* window = GetCurrentWindowRead(); - return window->DC.CursorPos - window->Pos + window->Scroll; -} - -float ImGui::GetCursorPosX() -{ - ImGuiWindow* window = GetCurrentWindowRead(); - return window->DC.CursorPos.x - window->Pos.x + window->Scroll.x; -} - -float ImGui::GetCursorPosY() -{ - ImGuiWindow* window = GetCurrentWindowRead(); - return window->DC.CursorPos.y - window->Pos.y + window->Scroll.y; -} - -void ImGui::SetCursorPos(const ImVec2& local_pos) -{ - ImGuiWindow* window = GetCurrentWindow(); - window->DC.CursorPos = window->Pos - window->Scroll + local_pos; - window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); -} - -void ImGui::SetCursorPosX(float x) -{ - ImGuiWindow* window = GetCurrentWindow(); - window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + x; - window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); -} - -void ImGui::SetCursorPosY(float y) -{ - ImGuiWindow* window = GetCurrentWindow(); - window->DC.CursorPos.y = window->Pos.y - window->Scroll.y + y; - window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); -} - -ImVec2 ImGui::GetCursorStartPos() -{ - ImGuiWindow* window = GetCurrentWindowRead(); - return window->DC.CursorStartPos - window->Pos; -} - -ImVec2 ImGui::GetCursorScreenPos() -{ - ImGuiWindow* window = GetCurrentWindowRead(); - return window->DC.CursorPos; -} - -void ImGui::SetCursorScreenPos(const ImVec2& pos) -{ - ImGuiWindow* window = GetCurrentWindow(); - window->DC.CursorPos = pos; - window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); -} - void ImGui::ActivateItem(ImGuiID id) { ImGuiContext& g = *GImGui; @@ -6966,6 +6906,11 @@ static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool // - ItemSize() // - ItemAdd() // - SameLine() +// - GetCursorScreenPos() +// - SetCursorScreenPos() +// - GetCursorPos(), GetCursorPosX(), GetCursorPosY() +// - SetCursorPos(), SetCursorPosX(), SetCursorPosY() +// - GetCursorStartPos() // - Indent() // - Unindent() // - BeginGroup() @@ -7097,6 +7042,66 @@ void ImGui::SameLine(float offset_from_start_x, float spacing_w) window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; } +ImVec2 ImGui::GetCursorScreenPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos; +} + +void ImGui::SetCursorScreenPos(const ImVec2& pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = pos; + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); +} + +// User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient. +// Conversion happens as we pass the value to user, but it makes our naming convention confusing because GetCursorPos() == (DC.CursorPos - window.Pos). May want to rename 'DC.CursorPos'. +ImVec2 ImGui::GetCursorPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos - window->Pos + window->Scroll; +} + +float ImGui::GetCursorPosX() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos.x - window->Pos.x + window->Scroll.x; +} + +float ImGui::GetCursorPosY() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorPos.y - window->Pos.y + window->Scroll.y; +} + +void ImGui::SetCursorPos(const ImVec2& local_pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = window->Pos - window->Scroll + local_pos; + window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos); +} + +void ImGui::SetCursorPosX(float x) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + x; + window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPos.x); +} + +void ImGui::SetCursorPosY(float y) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.y = window->Pos.y - window->Scroll.y + y; + window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); +} + +ImVec2 ImGui::GetCursorStartPos() +{ + ImGuiWindow* window = GetCurrentWindowRead(); + return window->DC.CursorStartPos - window->Pos; +} + void ImGui::Indent(float indent_w) { ImGuiContext& g = *GImGui; From 602df11f19c55907900c219a9d520cd234e19b75 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 16:21:04 +0100 Subject: [PATCH 303/384] Internals: Refactor: Moved item width/size functions to Layout section. --- imgui.cpp | 171 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 82 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6916f797..23a4492c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6145,88 +6145,6 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind FocusWindow(NULL); } -void ImGui::SetNextItemWidth(float item_width) -{ - ImGuiContext& g = *GImGui; - g.NextItemData.Flags |= ImGuiNextItemDataFlags_HasWidth; - g.NextItemData.Width = item_width; -} - -void ImGui::PushItemWidth(float item_width) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width); - window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); - g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth; -} - -void ImGui::PushMultiItemsWidths(int components, float w_full) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - const ImGuiStyle& style = g.Style; - const float w_item_one = ImMax(1.0f, IM_FLOOR((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, IM_FLOOR(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); - window->DC.ItemWidthStack.push_back(w_item_last); - for (int i = 0; i < components-1; i++) - window->DC.ItemWidthStack.push_back(w_item_one); - window->DC.ItemWidth = window->DC.ItemWidthStack.back(); - g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth; -} - -void ImGui::PopItemWidth() -{ - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ItemWidthStack.pop_back(); - window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back(); -} - -// Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth(). -// The SetNextItemWidth() data is generally cleared/consumed by ItemAdd() or NextItemData.ClearFlags() -float ImGui::CalcItemWidth() -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - float w; - if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) - w = g.NextItemData.Width; - else - w = window->DC.ItemWidth; - if (w < 0.0f) - { - float region_max_x = GetContentRegionMaxAbs().x; - w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w); - } - w = IM_FLOOR(w); - return w; -} - -// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth(). -// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical. -// Note that only CalcItemWidth() is publicly exposed. -// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable) -ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) -{ - ImGuiWindow* window = GImGui->CurrentWindow; - - ImVec2 region_max; - if (size.x < 0.0f || size.y < 0.0f) - region_max = GetContentRegionMaxAbs(); - - if (size.x == 0.0f) - size.x = default_w; - else if (size.x < 0.0f) - size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x + size.x); - - if (size.y == 0.0f) - size.y = default_h; - else if (size.y < 0.0f) - size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y + size.y); - - return size; -} - void ImGui::SetCurrentFont(ImFont* font) { ImGuiContext& g = *GImGui; @@ -6913,6 +6831,12 @@ static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool // - GetCursorStartPos() // - Indent() // - Unindent() +// - SetNextItemWidth() +// - PushItemWidth() +// - PushMultiItemsWidths() +// - PopItemWidth() +// - CalcItemWidth() +// - CalcItemSize() // - BeginGroup() // - EndGroup() // Also see in imgui_widgets: tab bars, columns. @@ -7118,6 +7042,89 @@ void ImGui::Unindent(float indent_w) window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x; } +// Affect large frame+labels widgets only. +void ImGui::SetNextItemWidth(float item_width) +{ + ImGuiContext& g = *GImGui; + g.NextItemData.Flags |= ImGuiNextItemDataFlags_HasWidth; + g.NextItemData.Width = item_width; +} + +void ImGui::PushItemWidth(float item_width) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width); + window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); + g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth; +} + +void ImGui::PushMultiItemsWidths(int components, float w_full) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + const ImGuiStyle& style = g.Style; + const float w_item_one = ImMax(1.0f, IM_FLOOR((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, IM_FLOOR(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1))); + window->DC.ItemWidthStack.push_back(w_item_last); + for (int i = 0; i < components-1; i++) + window->DC.ItemWidthStack.push_back(w_item_one); + window->DC.ItemWidth = window->DC.ItemWidthStack.back(); + g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth; +} + +void ImGui::PopItemWidth() +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ItemWidthStack.pop_back(); + window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back(); +} + +// Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth(). +// The SetNextItemWidth() data is generally cleared/consumed by ItemAdd() or NextItemData.ClearFlags() +float ImGui::CalcItemWidth() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + float w; + if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) + w = g.NextItemData.Width; + else + w = window->DC.ItemWidth; + if (w < 0.0f) + { + float region_max_x = GetContentRegionMaxAbs().x; + w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w); + } + w = IM_FLOOR(w); + return w; +} + +// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth(). +// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical. +// Note that only CalcItemWidth() is publicly exposed. +// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable) +ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) +{ + ImGuiWindow* window = GImGui->CurrentWindow; + + ImVec2 region_max; + if (size.x < 0.0f || size.y < 0.0f) + region_max = GetContentRegionMaxAbs(); + + if (size.x == 0.0f) + size.x = default_w; + else if (size.x < 0.0f) + size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x + size.x); + + if (size.y == 0.0f) + size.y = default_h; + else if (size.y < 0.0f) + size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y + size.y); + + return size; +} + // Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) void ImGui::BeginGroup() { From 8c683de33f96349dc8cfa83b3915521306e921eb Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 16:25:42 +0100 Subject: [PATCH 304/384] Internals: Refactor: Moved get height and contents regions functions, to Layout section. IF YOU GREAT CONFLICTS WHILE MERGING (NOT REBASING) THOSE 6 PREV COMMITS, TRY MERGING THEM INDIVIDUALLY 1 by 1 or 2 by 2 etc. --- imgui.cpp | 154 +++++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 72 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 23a4492c..2a721923 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6523,77 +6523,6 @@ void ImGui::SetNextWindowBgAlpha(float alpha) g.NextWindowData.BgAlphaVal = alpha; } -// FIXME: This is in window space (not screen space!). We should try to obsolete all those functions. -ImVec2 ImGui::GetContentRegionMax() -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - ImVec2 mx = window->ContentRegionRect.Max - window->Pos; - if (window->DC.CurrentColumns) - mx.x = window->WorkRect.Max.x - window->Pos.x; - return mx; -} - -// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features. -ImVec2 ImGui::GetContentRegionMaxAbs() -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - ImVec2 mx = window->ContentRegionRect.Max; - if (window->DC.CurrentColumns) - mx.x = window->WorkRect.Max.x; - return mx; -} - -ImVec2 ImGui::GetContentRegionAvail() -{ - ImGuiWindow* window = GImGui->CurrentWindow; - return GetContentRegionMaxAbs() - window->DC.CursorPos; -} - -// In window space (not screen space!) -ImVec2 ImGui::GetWindowContentRegionMin() -{ - ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentRegionRect.Min - window->Pos; -} - -ImVec2 ImGui::GetWindowContentRegionMax() -{ - ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentRegionRect.Max - window->Pos; -} - -float ImGui::GetWindowContentRegionWidth() -{ - ImGuiWindow* window = GImGui->CurrentWindow; - return window->ContentRegionRect.GetWidth(); -} - -float ImGui::GetTextLineHeight() -{ - ImGuiContext& g = *GImGui; - return g.FontSize; -} - -float ImGui::GetTextLineHeightWithSpacing() -{ - ImGuiContext& g = *GImGui; - return g.FontSize + g.Style.ItemSpacing.y; -} - -float ImGui::GetFrameHeight() -{ - ImGuiContext& g = *GImGui; - return g.FontSize + g.Style.FramePadding.y * 2.0f; -} - -float ImGui::GetFrameHeightWithSpacing() -{ - ImGuiContext& g = *GImGui; - return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y; -} - ImDrawList* ImGui::GetWindowDrawList() { ImGuiWindow* window = GetCurrentWindow(); @@ -6792,7 +6721,6 @@ static void ImGui::ErrorCheckEndFrame() IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?"); } } - } // Save and compare stack sizes on Begin()/End() to detect usage errors @@ -6837,6 +6765,15 @@ static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool // - PopItemWidth() // - CalcItemWidth() // - CalcItemSize() +// - GetTextLineHeight() +// - GetTextLineHeightWithSpacing() +// - GetFrameHeight() +// - GetFrameHeightWithSpacing() +// - GetContentRegionMax() +// - GetContentRegionMaxAbs() [Internal] +// - GetContentRegionAvail(), +// - GetWindowContentRegionMin(), GetWindowContentRegionMax() +// - GetWindowContentRegionWidth() // - BeginGroup() // - EndGroup() // Also see in imgui_widgets: tab bars, columns. @@ -7125,6 +7062,79 @@ ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) return size; } +float ImGui::GetTextLineHeight() +{ + ImGuiContext& g = *GImGui; + return g.FontSize; +} + +float ImGui::GetTextLineHeightWithSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.ItemSpacing.y; +} + +float ImGui::GetFrameHeight() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.FramePadding.y * 2.0f; +} + +float ImGui::GetFrameHeightWithSpacing() +{ + ImGuiContext& g = *GImGui; + return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y; +} + +// FIXME: All the Contents Region function are messy or misleading. WE WILL AIM TO OBSOLETE ALL OF THEM WITH A NEW "WORK RECT" API. Thanks for your patience! + +// FIXME: This is in window space (not screen space!). +ImVec2 ImGui::GetContentRegionMax() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImVec2 mx = window->ContentRegionRect.Max - window->Pos; + if (window->DC.CurrentColumns) + mx.x = window->WorkRect.Max.x - window->Pos.x; + return mx; +} + +// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features. +ImVec2 ImGui::GetContentRegionMaxAbs() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImVec2 mx = window->ContentRegionRect.Max; + if (window->DC.CurrentColumns) + mx.x = window->WorkRect.Max.x; + return mx; +} + +ImVec2 ImGui::GetContentRegionAvail() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return GetContentRegionMaxAbs() - window->DC.CursorPos; +} + +// In window space (not screen space!) +ImVec2 ImGui::GetWindowContentRegionMin() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return window->ContentRegionRect.Min - window->Pos; +} + +ImVec2 ImGui::GetWindowContentRegionMax() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return window->ContentRegionRect.Max - window->Pos; +} + +float ImGui::GetWindowContentRegionWidth() +{ + ImGuiWindow* window = GImGui->CurrentWindow; + return window->ContentRegionRect.GetWidth(); +} + // Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.) void ImGui::BeginGroup() { From 6d59653e825f687d28763fd8ff9141b2cff246b0 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 8 May 2019 10:10:20 +0800 Subject: [PATCH 305/384] Unicode: full Unicode Support (6 squashed commits) (#2541, #2538) fix build for WideCharToMultiByte [3181ff1e] Full Unicode Support [6c9e73ac] Fix ImTextCountUtf8BytesFromChar and ImTextCharToUtf8, these APIs assume the input is an unicode code point, not UTF-16 [ba85665b] Add AddInputCharacterUTF16 for windows backend to handle WM_CHAR [fafdcaf0] Use Windows API to convert UTF-16 for ImFileOpen [dc7d5925] Use windows API to convert UTF-16 for clipboard --- examples/imgui_impl_win32.cpp | 3 +- imconfig.h | 3 ++ imgui.cpp | 82 ++++++++++++++++++++++------------- imgui.h | 14 +++++- imgui_draw.cpp | 3 +- 5 files changed, 70 insertions(+), 35 deletions(-) diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 449922f5..8b1c8087 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -324,7 +324,8 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA return 0; case WM_CHAR: // You can also use ToAscii()+GetKeyboardState() to retrieve characters. - io.AddInputCharacter((unsigned int)wParam); + if (wParam > 0 && wParam < 0x10000) + io.AddInputCharacterUTF16((unsigned short)wParam); return 0; case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor()) diff --git a/imconfig.h b/imconfig.h index 4f629795..4f01b778 100644 --- a/imconfig.h +++ b/imconfig.h @@ -77,6 +77,9 @@ // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. //#define ImDrawIdx unsigned int +//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points. +//#define ImWchar ImWchar32 + //---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly) //struct ImDrawList; //struct ImDrawCmd; diff --git a/imgui.cpp b/imgui.cpp index 2a721923..9e7ac21c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1098,13 +1098,35 @@ void ImGuiIO::AddInputCharacter(unsigned int c) InputQueueCharacters.push_back((ImWchar)c); } +// UTF16 string use Surrogate to encode unicode > 0x10000, so we should save the Surrogate. +void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) +{ + if (c >= 0xD800 && c <= 0xDBFF) + { + Surrogate = c; + } + else + { + ImWchar cp = c; + if (c >= 0xDC00 && c <= 0xDFFF) + { + if (sizeof(ImWchar) == 2) + cp = IM_UNICODE_CODEPOINT_INVALID; + else + cp = ((ImWchar)(Surrogate - 0xD800) << 10) + (c - 0xDC00) + 0x10000; + Surrogate = 0; + } + InputQueueCharacters.push_back(cp); + } +} + void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) { while (*utf8_chars != 0) { unsigned int c = 0; utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL); - if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX) + if (c > 0) InputQueueCharacters.push_back((ImWchar)c); } } @@ -1488,13 +1510,13 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. - const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; - const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; + const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); + const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0); ImVector buf; buf.resize(filename_wsize + mode_wsize); - ImTextStrFromUtf8(&buf[0], filename_wsize, filename, NULL); - ImTextStrFromUtf8(&buf[filename_wsize], mode_wsize, mode, NULL); - return _wfopen((wchar_t*)&buf[0], (wchar_t*)&buf[filename_wsize]); + ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, &buf[0], filename_wsize); + ::MultiByteToWideChar(CP_UTF8, 0, mode, -1,&buf[filename_wsize], mode_wsize); + return _wfopen(&buf[0], &buf[filename_wsize]); #else return fopen(filename, mode); #endif @@ -1606,6 +1628,8 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* c += (*str++ & 0x3f); // utf-8 encodings of values used in surrogate pairs are invalid if ((c & 0xFFFFF800) == 0xD800) return 4; + // If ImWchar is 16bit, use replacement character U+FFFD instead + if (sizeof(ImWchar) == 2 && c >= 0x10000) c = IM_UNICODE_CODEPOINT_INVALID; *out_char = c; return 4; } @@ -1623,8 +1647,7 @@ int ImTextStrFromUtf8(ImWchar* buf, int buf_size, const char* in_text, const cha in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); if (c == 0) break; - if (c <= IM_UNICODE_CODEPOINT_MAX) // FIXME: Losing characters that don't fit in 2 bytes - *buf_out++ = (ImWchar)c; + *buf_out++ = (ImWchar)c; } *buf_out = 0; if (in_text_remaining) @@ -1641,8 +1664,7 @@ int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end) in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); if (c == 0) break; - if (c <= IM_UNICODE_CODEPOINT_MAX) - char_count++; + char_count++; } return char_count; } @@ -1662,11 +1684,15 @@ static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c) buf[1] = (char)(0x80 + (c & 0x3f)); return 2; } - if (c >= 0xdc00 && c < 0xe000) + if (c < 0x10000) { - return 0; + if (buf_size < 3) return 0; + buf[0] = (char)(0xe0 + (c >> 12)); + buf[1] = (char)(0x80 + ((c>> 6) & 0x3f)); + buf[2] = (char)(0x80 + ((c ) & 0x3f)); + return 3; } - if (c >= 0xd800 && c < 0xdc00) + if (c <= 0x10FFFF) { if (buf_size < 4) return 0; buf[0] = (char)(0xf0 + (c >> 18)); @@ -1675,14 +1701,8 @@ static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c) buf[3] = (char)(0x80 + ((c ) & 0x3f)); return 4; } - //else if (c < 0x10000) - { - if (buf_size < 3) return 0; - buf[0] = (char)(0xe0 + (c >> 12)); - buf[1] = (char)(0x80 + ((c>> 6) & 0x3f)); - buf[2] = (char)(0x80 + ((c ) & 0x3f)); - return 3; - } + // Invalid code point, the max unicode is 0x10FFFF + return 0; } // Not optimal but we very rarely use this function. @@ -1696,8 +1716,8 @@ static inline int ImTextCountUtf8BytesFromChar(unsigned int c) { if (c < 0x80) return 1; if (c < 0x800) return 2; - if (c >= 0xdc00 && c < 0xe000) return 0; - if (c >= 0xd800 && c < 0xdc00) return 4; + if (c < 0x10000) return 3; + if (c <= 0x10FFFF) return 4; return 3; } @@ -9748,6 +9768,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #else #include #endif +#include #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have Win32 functions #define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS #define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS @@ -9760,6 +9781,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #ifdef _MSC_VER #pragma comment(lib, "user32") +#pragma comment(lib, "kernel32") #endif // Win32 clipboard implementation @@ -9775,11 +9797,11 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) ::CloseClipboard(); return NULL; } - if (ImWchar* wbuf_global = (ImWchar*)::GlobalLock(wbuf_handle)) + if (const WCHAR* wbuf_global = (const WCHAR*)::GlobalLock(wbuf_handle)) { - int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1; + int buf_len = ::WideCharToMultiByte(CP_UTF8, 0, wbuf_global, -1, NULL, 0, NULL, NULL); buf_local.resize(buf_len); - ImTextStrToUtf8(buf_local.Data, buf_len, wbuf_global, NULL); + ::WideCharToMultiByte(CP_UTF8, 0, wbuf_global, -1, buf_local.Data, buf_len, NULL, NULL); } ::GlobalUnlock(wbuf_handle); ::CloseClipboard(); @@ -9790,15 +9812,15 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) { if (!::OpenClipboard(NULL)) return; - const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1; - HGLOBAL wbuf_handle = ::GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar)); + const int wbuf_length = ::MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0); + HGLOBAL wbuf_handle = ::GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(WCHAR)); if (wbuf_handle == NULL) { ::CloseClipboard(); return; } - ImWchar* wbuf_global = (ImWchar*)::GlobalLock(wbuf_handle); - ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL); + WCHAR* wbuf_global = (WCHAR*)::GlobalLock(wbuf_handle); + ::MultiByteToWideChar(CP_UTF8, 0, text, -1, wbuf_global, wbuf_length); ::GlobalUnlock(wbuf_handle); ::EmptyClipboard(); if (::SetClipboardData(CF_UNICODETEXT, wbuf_handle) == NULL) diff --git a/imgui.h b/imgui.h index 1e7b3f33..09160d11 100644 --- a/imgui.h +++ b/imgui.h @@ -143,7 +143,11 @@ struct ImGuiTextFilter; // Helper to parse and apply text filters (e typedef void* ImTextureID; // User data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp) #endif typedef unsigned int ImGuiID; // Unique ID used by widgets (typically hashed from a stack of string) -typedef unsigned short ImWchar; // A single U16 character for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. +#ifndef ImWchar +#define ImWchar ImWchar16 +#endif +typedef unsigned short ImWchar16; // A single U16 character for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. +typedef int ImWchar32; // A single 32bit character for keyboard input/display, define ImWchar to ImWchar32 to use it. See imconfig.h . typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type @@ -1465,6 +1469,7 @@ struct ImGuiIO // Functions IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input + IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually @@ -1507,6 +1512,7 @@ struct ImGuiIO float KeysDownDurationPrev[512]; // Previous duration the key has been down float NavInputsDownDuration[ImGuiNavInput_COUNT]; float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; + ImWchar16 Surrogate; // For AddInputCharacterUTF16 ImVector InputQueueCharacters; // Queue of _characters_ input (obtained by platform back-end). Fill using AddInputCharacter() helper. IMGUI_API ImGuiIO(); @@ -2092,7 +2098,11 @@ struct ImFontGlyphRangesBuilder ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used) ImFontGlyphRangesBuilder() { Clear(); } - inline void Clear() { int size_in_bytes = (IM_UNICODE_CODEPOINT_MAX+1) / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); } + inline void Clear() + { + int MaxUnicode = sizeof(ImWchar) == 2 ? 0x10000 : 0x110000; + UsedChars.resize(MaxUnicode / sizeof(int)); memset(UsedChars.Data, 0, MaxUnicode / sizeof(int)); + } inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array inline void AddChar(ImWchar c) { SetBit(c); } // Add character diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 69d18945..28f77281 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2550,8 +2550,7 @@ void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end) text += c_len; if (c_len == 0) break; - if (c <= IM_UNICODE_CODEPOINT_MAX) - AddChar((ImWchar)c); + AddChar((ImWchar)c); } } From c8ea0a017d0ea851225f159f26816d86799163a8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 29 Sep 2019 12:15:13 +0200 Subject: [PATCH 306/384] Unicode: UTF32 support improvements (#2541, #2538, #2815) - Make ImWchar32 unsigned. - Fix Win32 version of ImFileOpen by including windows.h sooner. - Make ImGuiIO::AddInputCharacterUTF16() more robust by disallowing illegal surrogate pairs. - Allow pushing higher plane codepoints through ImGuiIO::AddInputCharacter(). - Minor cleaning up in the high-plane Unicode support. - Fix Clang -Wunreachable-code warning --- imgui.cpp | 57 +++++++++++++++++++++++++++++++------------------- imgui.h | 20 +++++++----------- imgui_draw.cpp | 4 ++-- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9e7ac21c..8b1bda5c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1094,30 +1094,33 @@ ImGuiIO::ImGuiIO() // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message void ImGuiIO::AddInputCharacter(unsigned int c) { - if (c > 0 && c <= IM_UNICODE_CODEPOINT_MAX) - InputQueueCharacters.push_back((ImWchar)c); + InputQueueCharacters.push_back(c > 0 && c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID); } -// UTF16 string use Surrogate to encode unicode > 0x10000, so we should save the Surrogate. +// UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so +// we should save the high surrogate. void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) { - if (c >= 0xD800 && c <= 0xDBFF) + if ((c & 0xFC00) == 0xD800) // High surrogate, must save { - Surrogate = c; + if (InputQueueSurrogate != 0) + InputQueueCharacters.push_back(0xFFFD); + InputQueueSurrogate = c; + return; } - else + + ImWchar cp = c; + if (InputQueueSurrogate != 0) { - ImWchar cp = c; - if (c >= 0xDC00 && c <= 0xDFFF) - { - if (sizeof(ImWchar) == 2) - cp = IM_UNICODE_CODEPOINT_INVALID; - else - cp = ((ImWchar)(Surrogate - 0xD800) << 10) + (c - 0xDC00) + 0x10000; - Surrogate = 0; - } - InputQueueCharacters.push_back(cp); + if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate + InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID); + else if (IM_UNICODE_CODEPOINT_MAX == (0xFFFF)) // Codepoint will not fit in ImWchar (extra parenthesis around 0xFFFF somehow fixes -Wunreachable-code with Clang) + cp = IM_UNICODE_CODEPOINT_INVALID; + else + cp = (ImWchar)(((InputQueueSurrogate - 0xD800) << 10) + (c - 0xDC00) + 0x10000); + InputQueueSurrogate = 0; } + InputQueueCharacters.push_back(cp); } void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) @@ -1506,6 +1509,18 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) // Default file functions #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS + +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef __MINGW32__ +#include +#else +#include +#endif +#endif + ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) @@ -1514,9 +1529,9 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0); ImVector buf; buf.resize(filename_wsize + mode_wsize); - ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, &buf[0], filename_wsize); - ::MultiByteToWideChar(CP_UTF8, 0, mode, -1,&buf[filename_wsize], mode_wsize); - return _wfopen(&buf[0], &buf[filename_wsize]); + ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, (wchar_t*)&buf[0], filename_wsize); + ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, (wchar_t*)&buf[filename_wsize], mode_wsize); + return _wfopen((const wchar_t*)&buf[0], (const wchar_t*)&buf[filename_wsize]); #else return fopen(filename, mode); #endif @@ -1628,8 +1643,8 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* c += (*str++ & 0x3f); // utf-8 encodings of values used in surrogate pairs are invalid if ((c & 0xFFFFF800) == 0xD800) return 4; - // If ImWchar is 16bit, use replacement character U+FFFD instead - if (sizeof(ImWchar) == 2 && c >= 0x10000) c = IM_UNICODE_CODEPOINT_INVALID; + // If codepoint does not fit in ImWchar, use replacement character U+FFFD instead + if (c > IM_UNICODE_CODEPOINT_MAX) c = IM_UNICODE_CODEPOINT_INVALID; *out_char = c; return 4; } diff --git a/imgui.h b/imgui.h index 09160d11..cbed1010 100644 --- a/imgui.h +++ b/imgui.h @@ -92,7 +92,7 @@ Index of this file: #else #define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro. #endif -#define IM_UNICODE_CODEPOINT_MAX 0xFFFF // Last Unicode code point supported by this build. +#define IM_UNICODE_CODEPOINT_MAX (sizeof(ImWchar) == 2 ? 0xFFFF : 0x10FFFF) // Last Unicode code point supported by this build. #define IM_UNICODE_CODEPOINT_INVALID 0xFFFD // Standard invalid Unicode code point. // Warnings @@ -147,7 +147,7 @@ typedef unsigned int ImGuiID; // Unique ID used by widgets (typically hash #define ImWchar ImWchar16 #endif typedef unsigned short ImWchar16; // A single U16 character for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. -typedef int ImWchar32; // A single 32bit character for keyboard input/display, define ImWchar to ImWchar32 to use it. See imconfig.h . +typedef unsigned int ImWchar32; // A single U32 character for keyboard input/display. Define ImWchar to ImWchar32 to use it. See imconfig.h . typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type @@ -1512,7 +1512,7 @@ struct ImGuiIO float KeysDownDurationPrev[512]; // Previous duration the key has been down float NavInputsDownDuration[ImGuiNavInput_COUNT]; float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; - ImWchar16 Surrogate; // For AddInputCharacterUTF16 + ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16 ImVector InputQueueCharacters; // Queue of _characters_ input (obtained by platform back-end). Fill using AddInputCharacter() helper. IMGUI_API ImGuiIO(); @@ -2097,15 +2097,11 @@ struct ImFontGlyphRangesBuilder { ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used) - ImFontGlyphRangesBuilder() { Clear(); } - inline void Clear() - { - int MaxUnicode = sizeof(ImWchar) == 2 ? 0x10000 : 0x110000; - UsedChars.resize(MaxUnicode / sizeof(int)); memset(UsedChars.Data, 0, MaxUnicode / sizeof(int)); - } - inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array - inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array - inline void AddChar(ImWchar c) { SetBit(c); } // Add character + ImFontGlyphRangesBuilder() { Clear(); } + inline void Clear() { int size_in_bytes = (IM_UNICODE_CODEPOINT_MAX + 1) / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); } + inline bool GetBit(size_t n) const { int off = (int)(n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array + inline void SetBit(size_t n) { int off = (int)(n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array + inline void AddChar(ImWchar c) { SetBit(c); } // Add character IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added) IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext IMGUI_API void BuildRanges(ImVector* out_ranges); // Output new ranges diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 28f77281..ae6b9803 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2724,7 +2724,7 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst) const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const { - if (c >= IndexLookup.Size) + if (c >= (size_t)IndexLookup.Size) return FallbackGlyph; const ImWchar i = IndexLookup.Data[c]; if (i == (ImWchar)-1) @@ -2734,7 +2734,7 @@ const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const const ImFontGlyph* ImFont::FindGlyphNoFallback(ImWchar c) const { - if (c >= IndexLookup.Size) + if (c >= (size_t)IndexLookup.Size) return NULL; const ImWchar i = IndexLookup.Data[c]; if (i == (ImWchar)-1) From 0283a6e566ca0365b3fbadffc9eaa7f780711466 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 29 Oct 2019 23:48:59 +0100 Subject: [PATCH 307/384] ImFont: Demo, Store Used4kPagesMap[] map in ImFont to facilitate iteration on all codepoints with a large value of IM_UNICODE_CODEPOINT_MAX. (#2815) Demo uses IsGlyphRangeUnused() --- imgui.h | 2 ++ imgui_demo.cpp | 9 +++++++++ imgui_draw.cpp | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/imgui.h b/imgui.h index cbed1010..021c12b7 100644 --- a/imgui.h +++ b/imgui.h @@ -2257,6 +2257,7 @@ struct ImFont float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) + ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8]; // 2 bytes if ImWchar=ImWchar16, 34 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations accross all used codepoints. // Methods IMGUI_API ImFont(); @@ -2282,6 +2283,7 @@ struct ImFont IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built. IMGUI_API void SetGlyphVisible(ImWchar c, bool visible); IMGUI_API void SetFallbackChar(ImWchar c); + IMGUI_API bool IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last); }; #if defined(__clang__) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 591d6d99..2664cb14 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -3443,6 +3443,15 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) // Display all glyphs of the fonts in separate pages of 256 characters for (unsigned int base = 0; base <= IM_UNICODE_CODEPOINT_MAX; base += 256) { + // Skip ahead if a large bunch of glyphs are not present in the font (test in chunks of 4k) + // This is only a small optimization to reduce the number of iterations when IM_UNICODE_MAX_CODEPOINT is large. + // (if ImWchar==ImWchar32 we will do at least about 272 queries here) + if (!(base & 4095) && font->IsGlyphRangeUnused(base, base + 4095)) + { + base += 4096 - 256; + continue; + } + int count = 0; for (unsigned int n = 0; n < 256; n++) count += font->FindGlyphNoFallback((ImWchar)(base + n)) ? 1 : 0; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index ae6b9803..12f06d60 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2594,6 +2594,7 @@ ImFont::ImFont() Scale = 1.0f; Ascent = Descent = 0.0f; MetricsTotalSurface = 0; + memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap)); } ImFont::~ImFont() @@ -2626,12 +2627,17 @@ void ImFont::BuildLookupTable() IndexAdvanceX.clear(); IndexLookup.clear(); DirtyLookupTables = false; + memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap)); GrowIndex(max_codepoint + 1); for (int i = 0; i < Glyphs.Size; i++) { int codepoint = (int)Glyphs[i].Codepoint; IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX; IndexLookup[codepoint] = (ImWchar)i; + + // Mark 4K page as used + const int page_n = codepoint / 4096; + Used4kPagesMap[page_n >> 3] |= 1 << (page_n & 7); } // Create a glyph to handle TAB @@ -2660,6 +2666,19 @@ void ImFont::BuildLookupTable() IndexAdvanceX[i] = FallbackAdvanceX; } +// API is designed this way to avoid exposing the 4K page size +// e.g. use with IsGlyphRangeUnused(0, 255) +bool ImFont::IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last) +{ + unsigned int page_begin = (c_begin / 4096); + unsigned int page_last = (c_last / 4096); + for (unsigned int page_n = page_begin; page_n <= page_last; page_n++) + if ((page_n >> 3) < sizeof(Used4kPagesMap)) + if (Used4kPagesMap[page_n >> 3] & (1 << (page_n & 7))) + return false; + return true; +} + void ImFont::SetGlyphVisible(ImWchar c, bool visible) { if (ImFontGlyph* glyph = (ImFontGlyph*)(void*)FindGlyph((ImWchar)c)) From a41332453efed294f21d530c5346887af1213563 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 17:45:06 +0100 Subject: [PATCH 308/384] Unicode: Changelog, comments, minimum CI integration. (#2541, #2538, #2815) --- .github/workflows/build.yml | 12 ++++++++++-- docs/CHANGELOG.txt | 11 +++++++++++ examples/imgui_impl_win32.cpp | 1 + imgui.cpp | 1 + imgui.h | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff83bd3d..ccc5c244 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: - name: Build example_null (single file build) shell: bash run: | - echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#define IMGUI_IMPLEMENTATION' > example_single_file.cpp echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp @@ -190,6 +190,14 @@ jobs: - name: Build example_null (single file build) run: | + echo '#define IMGUI_IMPLEMENTATION' > example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + + - name: Build example_null (with ImWchar32) + run: | + echo '#define ImWchar ImWchar32' > example_single_file.cpp echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp @@ -226,7 +234,7 @@ jobs: - name: Build example_null (single file build) run: | - echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#define IMGUI_IMPLEMENTATION' > example_single_file.cpp echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp clang++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7a7c1cd2..792b8330 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -45,6 +45,15 @@ Other Changes: when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) +- Added optional support for Unicode plane 1-16 (#2538, #2541, #2815) [@cloudwu, @samhocevar] + - Compile-time enable with '#define ImWchar ImWchar32' in imconfig.h. + - Generally more consistent support for unsupported codepoints (0xFFFD), in particular when + using the default, non-fitting characters will be turned into 0xFFFD instead of being ignored. + - Surrogate pairs are supported when submitting UTF-16 data via io.AddInputCharacterUTF16(), + allowing for more complete CJK input. + - sizeof(ImWchar) goes from 2 to 4. IM_UNICODE_CODEPOINT_MAX goes from 0xFFFF to 0x10FFFF. + - Various structures such as ImFont, ImFontGlyphRangesBuilder will use more memory, this + is currently not particularly efficient. - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. @@ -53,6 +62,8 @@ Other Changes: ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). Those functions makes it easier for example apps to support hi-dpi features without setting up a manifest. +- Backends: Win32: Calling AddInputCharacterUTF16() from WM_CHAR message handler in order to support + high-plane surrogate pairs. (#2815) [@cloudwu, @samhocevar] - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). - Backends: SDL: Fixed mapping for ImGuiKey_KeyPadEnter. (#3031) [@Davido71] diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 8b1c8087..f8868ce6 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -28,6 +28,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-03-03: Inputs: Calling AddInputCharacterUTF16() to support surrogate pairs leading to codepoint >= 0x10000 (for more complete CJK inputs) // 2020-02-17: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helper functions. // 2020-01-14: Inputs: Added support for #define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD/IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT. // 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor. diff --git a/imgui.cpp b/imgui.cpp index 8b1bda5c..75c2fee2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1525,6 +1525,7 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. + // Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32! const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0); ImVector buf; diff --git a/imgui.h b/imgui.h index 021c12b7..70798230 100644 --- a/imgui.h +++ b/imgui.h @@ -2101,7 +2101,7 @@ struct ImFontGlyphRangesBuilder inline void Clear() { int size_in_bytes = (IM_UNICODE_CODEPOINT_MAX + 1) / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); } inline bool GetBit(size_t n) const { int off = (int)(n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array inline void SetBit(size_t n) { int off = (int)(n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array - inline void AddChar(ImWchar c) { SetBit(c); } // Add character + inline void AddChar(ImWchar c) { SetBit(c); } // Add character IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added) IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext IMGUI_API void BuildRanges(ImVector* out_ranges); // Output new ranges From 897704cb499c287bbf570dfaa792bf006dfd7e6d Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 2 Mar 2020 20:18:43 +0100 Subject: [PATCH 309/384] Menus: Tweak for first-level menu windows to be positioned regardless of MenuBarHeight() which is not stored in window, allowing undocumented modification of the menu bar height). --- docs/CHANGELOG.txt | 2 +- imgui.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7a7c1cd2..1906d535 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,7 +40,7 @@ Other Changes: branch pressing arrow keys while dragging a window from a tab could trigger an assert. (#3025) - ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced by default for standalone ColorButton. -- BeginMenu: Using same ID multiple times appends content to a menu. (#1207) +- BeginMenu: Using same ID multiple times appends content to a menu. (#1207) [@rokups] - BeginMenu: Fixed a bug where SetNextWindowXXX data before a BeginMenu() would not be cleared when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' diff --git a/imgui.cpp b/imgui.cpp index 2a721923..1da439f1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7830,7 +7830,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) float horizontal_overlap = g.Style.ItemInnerSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x). ImRect r_avoid; if (parent_window->DC.MenuBarAppending) - r_avoid = ImRect(-FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight(), FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight() + parent_window->MenuBarHeight()); + r_avoid = ImRect(-FLT_MAX, parent_window->ClipRect.Min.y, FLT_MAX, parent_window->ClipRect.Max.y); // Avoid parent menu-bar. If we wanted multi-line menu-bar, we may instead want to have the calling window setup e.g. a NextWindowData.PosConstraintAvoidRect field else r_avoid = ImRect(parent_window->Pos.x + horizontal_overlap, -FLT_MAX, parent_window->Pos.x + parent_window->Size.x - horizontal_overlap - parent_window->ScrollbarSizes.x, FLT_MAX); return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid); From 0850b46c88daa92443dedf8609a80dbc1da52558 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 3 Mar 2020 19:26:27 +0100 Subject: [PATCH 310/384] ImDrawList: Internals: Added IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER setting. --- imgui_draw.cpp | 16 ++++++++++++---- imgui_internal.h | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 12f06d60..1cd23042 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -355,10 +355,10 @@ ImDrawListSharedData::ImDrawListSharedData() InitialFlags = ImDrawListFlags_None; // Lookup tables - for (int i = 0; i < IM_ARRAYSIZE(CircleVtx12); i++) + for (int i = 0; i < IM_ARRAYSIZE(ArcFastVtx); i++) { - const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(CircleVtx12); - CircleVtx12[i] = ImVec2(ImCos(a), ImSin(a)); + const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(ArcFastVtx); + ArcFastVtx[i] = ImVec2(ImCos(a), ImSin(a)); } memset(CircleSegmentCounts, 0, sizeof(CircleSegmentCounts)); // This will be set by SetCircleSegmentMaxError() } @@ -898,10 +898,18 @@ void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_ _Path.push_back(center); return; } + + // For legacy reason the PathArcToFast() always takes angles where 2*PI is represented by 12, + // but it is possible to set IM_DRAWLIST_ARCFAST_TESSELATION_MULTIPLIER to a higher value. This should compile to a no-op otherwise. +#if IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER != 1 + a_min_of_12 *= IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER; + a_max_of_12 *= IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER; +#endif + _Path.reserve(_Path.Size + (a_max_of_12 - a_min_of_12 + 1)); for (int a = a_min_of_12; a <= a_max_of_12; a++) { - const ImVec2& c = _Data->CircleVtx12[a % IM_ARRAYSIZE(_Data->CircleVtx12)]; + const ImVec2& c = _Data->ArcFastVtx[a % IM_ARRAYSIZE(_Data->ArcFastVtx)]; _Path.push_back(ImVec2(center.x + c.x * radius, center.y + c.y * radius)); } } diff --git a/imgui_internal.h b/imgui_internal.h index dd92b6a5..dfa45ddd 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -863,11 +863,16 @@ struct ImGuiColumns } }; -// Helper function to calculate a circle's segment count given its radius and a "maximum error" value. +// ImDrawList: Helper function to calculate a circle's segment count given its radius and a "maximum error" value. #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN 12 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX 512 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(_RAD,_MAXERROR) ImClamp((int)((IM_PI * 2.0f) / ImAcos(((_RAD) - (_MAXERROR)) / (_RAD))), IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX) +// ImDrawList: You may set this to higher values (e.g. 2 or 3) to increase tessellation of fast rounded corners path. +#ifndef IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER +#define IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER 1 +#endif + // Data shared between all ImDrawList instances // You may want to create your own instance of this if you want to use ImDrawList completely without ImGui. In that case, watch out for future changes to this structure. struct IMGUI_API ImDrawListSharedData @@ -881,7 +886,7 @@ struct IMGUI_API ImDrawListSharedData ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards) // [Internal] Lookup tables - ImVec2 CircleVtx12[12]; // FIXME: Bake rounded corners fill/borders in atlas + ImVec2 ArcFastVtx[12 * IM_DRAWLIST_ARCFAST_TESSELLATION_MULTIPLIER]; // FIXME: Bake rounded corners fill/borders in atlas ImU8 CircleSegmentCounts[64]; // Precomputed segment count for given radius (array index + 1) before we calculate it dynamically (to avoid calculation overhead) ImDrawListSharedData(); From 1ecc1db226592ea61923fd19ec86ed8bc2109ee9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 5 Mar 2020 12:35:01 +0100 Subject: [PATCH 311/384] Fix GCC warning --- imgui.cpp | 4 ++-- imgui_internal.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ef3c3eeb..533216e0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11849,7 +11849,7 @@ static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDoc else if (node->ParentNode && node->ParentNode->ChildNodes[1] == NULL) node->ParentNode->ChildNodes[1] = node; node->SelectedTabId = settings->SelectedWindowId; - node->SplitAxis = settings->SplitAxis; + node->SplitAxis = (ImGuiAxis)settings->SplitAxis; node->LocalFlags |= (settings->Flags & ImGuiDockNodeFlags_SavedFlagsMask_); // Bind host window immediately if it already exist (in case of a rebuild) @@ -14778,7 +14778,7 @@ static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDo node_settings.ParentNodeId = node->ParentNode ? node->ParentNode->ID : 0; node_settings.ParentWindowId = (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) ? node->HostWindow->ParentWindow->ID : 0; node_settings.SelectedWindowId = node->SelectedTabId; - node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None; + node_settings.SplitAxis = (signed char)(node->IsSplitNode() ? node->SplitAxis : ImGuiAxis_None); node_settings.Depth = (char)depth; node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_); node_settings.Pos = ImVec2ih(node->Pos); diff --git a/imgui_internal.h b/imgui_internal.h index a3c31b1a..2e82ed41 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1094,7 +1094,7 @@ struct ImGuiDockNode ImVec2 Pos; // Current position ImVec2 Size; // Current size ImVec2 SizeRef; // [Split node only] Last explicitly written-to size (overridden when using a splitter affecting the node), used to calculate Size. - int SplitAxis; // [Split node only] Split axis (X or Y) + ImGuiAxis SplitAxis; // [Split node only] Split axis (X or Y) ImGuiWindowClass WindowClass; // [Root node only] ImGuiDockNodeState State; From 7e00cde8a9ebf41948f629f86ce8c4cf0f68334f Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 5 Mar 2020 16:22:16 +0200 Subject: [PATCH 312/384] Disable false-positive warning that papeared in pvs-studio v7.06.37052.34. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 533216e0..1331aef9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3476,7 +3476,7 @@ void ImGui::StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* nod // - part of a floating node hierarchy with more than one visible node (if only one is visible, we'll just move the whole hierarchy) // - part of a dockspace node hierarchy (trivia: undocking from a fixed/central node will create a new node and copy windows) ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (root_node->OnlyNodeWithWindows != node || root_node->CentralNode != NULL) + if (root_node->OnlyNodeWithWindows != node || root_node->CentralNode != NULL) // -V1051 PVS-Studio thinks node should be root_node and is wrong about that. if (undock_floating_node || root_node->IsDockSpace()) can_undock_node = true; } From 1b579a110dfd6919d6716dc97d2603cd23b395d5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 5 Mar 2020 18:26:18 +0100 Subject: [PATCH 313/384] Viewports: Lots of comments about setting up multi-viewports. (#1542) --- imgui.h | 168 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 109 insertions(+), 59 deletions(-) diff --git a/imgui.h b/imgui.h index e9d08a2b..b13f3535 100644 --- a/imgui.h +++ b/imgui.h @@ -32,7 +32,7 @@ Index of this file: // Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor) // Draw List API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData) // Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont) -// Platform interface for multi-viewport support (ImGuiPlatformMonitor, ImGuiPlatformIO, ImGuiViewport) +// Platform interface for multi-viewport support (ImGuiPlatformIO, ImGuiPlatformMonitor, ImGuiViewportFlags, ImGuiViewport) */ @@ -775,11 +775,12 @@ namespace ImGui IMGUI_API void MemFree(void* ptr); // (Optional) Platform/OS interface for multi-viewport support + // Read comments around the ImGuiPlatformIO structure for more details. // Note: You may use GetWindowViewport() to get the current viewport of the current window. IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for back-end to setup + viewports list. IMGUI_API ImGuiViewport* GetMainViewport(); // main viewport. same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0]. IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. - IMGUI_API void RenderPlatformWindowsDefault(void* platform_arg = NULL, void* renderer_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. + IMGUI_API void RenderPlatformWindowsDefault(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // this is a helper for back-ends. IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // this is a helper for back-ends. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.) @@ -2392,32 +2393,54 @@ struct ImFont //----------------------------------------------------------------------------- // [BETA] Platform interface for multi-viewport support -// - completely optional, for advanced users! -// - this is used for back-ends aiming to support the seamless creation of multiple viewport (= multiple Platform/OS windows) -// dear imgui manages the viewports, and the back-end create one Platform/OS windows for each secondary viewport. -// - if you are new to dear imgui and trying to integrate it into your engine, you should probably ignore this for now. +//----------------------------------------------------------------------------- +// (Optional) This is completely optional, for advanced users! +// If you are new to Dear ImGui and trying to integrate it into your engine, you can probably ignore this for now. +// +// This feature allows you to seamlessly drag Dear ImGui windows outside of your application viewport. +// This is achieved by creating new Platform/OS windows on the fly, and rendering into them. +// Dear ImGui manages the viewport structures, and the back-end create and maintain one Platform/OS window for each of those viewports. +// +// See Glossary https://github.com/ocornut/imgui/wiki/Glossary for details about some of the terminology. +// See Thread https://github.com/ocornut/imgui/issues/1542 for gifs, news and questions about this evolving feature. +// +// About the coordinates system: +// - When multi-viewports are enabled, all Dear ImGui coordinates become absolute coordinates (same as OS coordinates!) +// - So e.g. ImGui::SetNextWindowPos(ImVec2(0,0)) will position a window relative to your primary monitor! +// - If you want to position windows relative to your main application viewport, use ImGui::GetMainViewport()->Pos as a base position. +// +// Steps to use multi-viewports in your application, when using a default back-end from the examples/ folder: +// - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. +// - Back-end: The back-end initialization will setup all necessary ImGuiPlatformIO's functions and update monitors info every frame. +// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). +// - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. +// +// Steps to use multi-viewports in your application, when using a custom back-end: +// - Important: THIS IS NOT EASY TO DO and comes with many subtleties not described here! +// It's also an experimental feature, so some of the requirements may evolve. +// Consider using default back-ends if you can. Either way, carefully follow and refer to examples/ back-ends for details. +// - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. +// - Back-end: Hook ImGuiPlatformIO's Platform_* and Renderer_* callbacks (see below). +// Set 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports' and 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports'. +// Update ImGuiPlatformIO's Monitors list every frame. +// Update MousePos every frame, in absolute coordinates. +// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). +// You may skip calling RenderPlatformWindowsDefault() if its API is not convenient for your needs. Read comments below. +// - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. +// +// About ImGui::RenderPlatformWindowsDefault(): +// - This function is a mostly a _helper_ for the common-most cases, and to facilitate using default back-ends. +// - You can check its simple source code to understand what it does. +// It basically iterates secondary viewports and call 4 functions that are setup in ImGuiPlatformIO, if available: +// Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers() +// Those functions pointers exists only for the benefit of RenderPlatformWindowsDefault(). +// - If you have very specific rendering needs (e.g. flipping multiple swap-chain simultaneously, unusual sync/threading issues, etc.), +// you may be tempted to ignore RenderPlatformWindowsDefault() and write customized code to perform your renderingg. +// You may decide to setup the platform_io's *RenderWindow and *SwapBuffers pointers and call your functions through those pointers, +// or you may decide to never setup those pointers and call your code directly. They are a convenience, not an obligatory interface. //----------------------------------------------------------------------------- -// (Optional) This is required when enabling multi-viewport. Represent the bounds of each connected monitor/display and their DPI. -// We use this information for multiple DPI support + clamping the position of popups and tooltips so they don't straddle multiple monitors. -struct ImGuiPlatformMonitor -{ - ImVec2 MainPos, MainSize; // Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) - ImVec2 WorkPos, WorkSize; // (Optional) Coordinates without task bars / side bars / menu bars. imgui uses this to avoid positioning popups/tooltips inside this region. - float DpiScale; // 1.0f = 96 DPI - ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0,0); DpiScale = 1.0f; } -}; - -// (Optional) Setup required only if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) is enabled. -// Access via ImGui::GetPlatformIO(). This is designed so we can mix and match two imgui_impl_xxxx files, -// one for the Platform (~window handling), one for Renderer. Custom engine back-ends will often provide -// both Platform and Renderer interfaces and so may not need to use all functions. -// Platform functions are typically called before their Renderer counterpart, -// apart from Destroy which are called the other way. -// RenderPlatformWindowsDefault() is that helper that iterate secondary viewports and call, in this order: -// Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers() -// You may skip using RenderPlatformWindowsDefault() and call your draw/swap functions yourself if you need -// specific behavior for your multi-window rendering. +// (Optional) Access via ImGui::GetPlatformIO() struct ImGuiPlatformIO { //------------------------------------------------------------------ @@ -2425,47 +2448,72 @@ struct ImGuiPlatformIO //------------------------------------------------------------------ // (Optional) Platform functions (e.g. Win32, GLFW, SDL2) - // Most of them are called by ImGui::UpdatePlatformWindows() and ImGui::RenderPlatformWindowsDefault(). - void (*Platform_CreateWindow)(ImGuiViewport* vp); // Create a new platform window for the given viewport - void (*Platform_DestroyWindow)(ImGuiViewport* vp); - void (*Platform_ShowWindow)(ImGuiViewport* vp); // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them first - void (*Platform_SetWindowPos)(ImGuiViewport* vp, ImVec2 pos); - ImVec2 (*Platform_GetWindowPos)(ImGuiViewport* vp); - void (*Platform_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); - ImVec2 (*Platform_GetWindowSize)(ImGuiViewport* vp); - void (*Platform_SetWindowFocus)(ImGuiViewport* vp); // Move window to front and set input focus - bool (*Platform_GetWindowFocus)(ImGuiViewport* vp); - bool (*Platform_GetWindowMinimized)(ImGuiViewport* vp); - void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* title); - void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // (Optional) Setup window transparency - void (*Platform_UpdateWindow)(ImGuiViewport* vp); // (Optional) Called in UpdatePlatforms(). Optional hook to allow the platform back-end from doing general book-keeping every frame. - void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Setup for render - void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (platform side) - float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // (Optional) [BETA] (FIXME-DPI) DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. - void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // (Optional) [BETA] (FIXME-DPI) DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style. - void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. - int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For Renderer to call into Platform code - - // (Optional) Renderer functions (e.g. DirectX, OpenGL3, Vulkan) - void (*Renderer_CreateWindow)(ImGuiViewport* vp); // Create swap chains, frame buffers etc. - void (*Renderer_DestroyWindow)(ImGuiViewport* vp); - void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // Resize swap chain, frame buffers etc. - void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Clear targets, Render viewport->DrawData - void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (renderer side) - - // (Optional) List of monitors (updated by: app/back-end, used by: imgui to clamp popups/tooltips within same monitor and not have them straddle monitors) + // For reference, the second column shows which function are generally calling the Platform Functions: + // N = ImGui::NewFrame() ~ beginning of the dear imgui frame: read info from platform/OS windows (latest size/position) + // F = ImGui::Begin(), ImGui::EndFrame() ~ during the dear imgui frame + // U = ImGui::UpdatePlatformWindows() ~ after the dear imgui frame: create and update all platform/OS windows + // R = ImGui::RenderPlatformWindowsDefault() ~ render + // D = ImGui::DestroyPlatformWindows() ~ shutdown + // The general idea is that NewFrame() we will read the current Platform/OS state, and UpdatePlatformWindows() will write to it. + // + // The functions are designed so we can mix and match 2 imgui_impl_xxxx files, one for the Platform (~window/input handling), one for Renderer. + // Custom engine back-ends will often provide both Platform and Renderer interfaces and so may not need to use all functions. + // Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way. + + // Platform function --------------------------------------------------- Called by ----- + void (*Platform_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create a new platform window for the given viewport + void (*Platform_DestroyWindow)(ImGuiViewport* vp); // N . U . D // + void (*Platform_ShowWindow)(ImGuiViewport* vp); // . . U . . // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them before showing the window + void (*Platform_SetWindowPos)(ImGuiViewport* vp, ImVec2 pos); // . . U . . // Set platform window position (given the upper-left corner of client area) + ImVec2 (*Platform_GetWindowPos)(ImGuiViewport* vp); // N . . . . // + void (*Platform_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Set platform window client area size (ignoring OS decorations such as OS title bar etc.) + ImVec2 (*Platform_GetWindowSize)(ImGuiViewport* vp); // N . . . . // Get platform window client area size + void (*Platform_SetWindowFocus)(ImGuiViewport* vp); // N . . . . // Move window to front and set input focus + bool (*Platform_GetWindowFocus)(ImGuiViewport* vp); // . . U . . // + bool (*Platform_GetWindowMinimized)(ImGuiViewport* vp); // N . . . . // Get platform window minimized state. When minimized, we generally won't attempt to get/set size and contents will be culled more easily + void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* str); // . . U . . // Set platform window title (given an UTF-8 string) + void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // . . U . . // (Optional) Setup window transparency + void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by UpdatePlatformWindows(). Optional hook to allow the platform back-end from doing general book-keeping every frame. + void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. + void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // . F . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style. + void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // . F . . . // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. FIXME: The call timing of this is inconsistent because we want to support without multi-viewports. + int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For a Vulkan Renderer to call into Platform code (since the surface creation needs to tie them both). + + // (Optional) Renderer functions (e.g. DirectX, OpenGL, Vulkan) + void (*Renderer_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create swap chain, frame buffers etc. (called after Platform_CreateWindow) + void (*Renderer_DestroyWindow)(ImGuiViewport* vp); // N . U . D // Destroy swap chain, frame buffers etc. (called before Platform_DestroyWindow) + void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Resize swap chain, frame buffers etc. (called after Platform_SetWindowSize) + void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + + // (Optional) Monitor list + // - Updated by: app/back-end. Update every frame to dynamically support changing monitor or DPI configuration. + // - Used by: dear imgui to query DPI info, clamp popups/tooltips within same monitor and not have them straddle monitors. ImVector Monitors; //------------------------------------------------------------------ // Output - List of viewports to render into platform windows //------------------------------------------------------------------ - // List of viewports (the list is updated by calling ImGui::EndFrame or ImGui::Render) + // Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render) + // (in the future we will attempt to organize this feature to remove the need for a "main viewport") ImGuiViewport* MainViewport; // Guaranteed to be == Viewports[0] ImVector Viewports; // Main viewports, followed by all secondary viewports. ImGuiPlatformIO() { memset(this, 0, sizeof(*this)); } // Zero clear }; +// (Optional) This is required when enabling multi-viewport. Represent the bounds of each connected monitor/display and their DPI. +// We use this information for multiple DPI support + clamping the position of popups and tooltips so they don't straddle multiple monitors. +struct ImGuiPlatformMonitor +{ + ImVec2 MainPos, MainSize; // Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) + ImVec2 WorkPos, WorkSize; // (Optional) Coordinates without task bars / side bars / menu bars. imgui uses this to avoid positioning popups/tooltips inside this region. + float DpiScale; // 1.0f = 96 DPI + ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; } +}; + // Flags stored in ImGuiViewport::Flags, giving indications to the platform back-ends. enum ImGuiViewportFlags_ { @@ -2498,9 +2546,11 @@ struct ImGuiViewport ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows. // Our design separate the Renderer and Platform back-ends to facilitate combining default back-ends with each others. - // When our create your own back-end for a custom engine, it is possible that both Renderer and Platform will be handled by the same system and you may not need to use all the UserData/Handle fields. - void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). - void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). + // When our create your own back-end for a custom engine, it is possible that both Renderer and Platform will be handled + // by the same system and you may not need to use all the UserData/Handle fields. + // The library never uses those fields, they are merely storage to facilitate back-end implementation. + void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function. + void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function. void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position) From f2c7f3b200d82f3965bedbe4f52d6082fb74d1be Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 6 Mar 2020 17:28:32 +0100 Subject: [PATCH 314/384] Viewports: Renamed UpdatePlatformWindows > PlatformWindowsUpdate, RenderPlatformWindowsDefault -> PlatformWindowsRender, DestroyPlatformWindows > PlatformWindowsDestroy (#1542) --- docs/CHANGELOG.txt | 2 +- examples/example_glfw_opengl2/main.cpp | 4 +-- examples/example_glfw_opengl3/main.cpp | 4 +-- examples/example_glfw_vulkan/main.cpp | 4 +-- examples/example_sdl_directx11/main.cpp | 4 +-- examples/example_sdl_opengl2/main.cpp | 4 +-- examples/example_sdl_opengl3/main.cpp | 4 +-- examples/example_sdl_vulkan/main.cpp | 4 +-- examples/example_win32_directx10/main.cpp | 4 +-- examples/example_win32_directx11/main.cpp | 4 +-- examples/example_win32_directx12/main.cpp | 4 +-- examples/example_win32_directx9/main.cpp | 4 +-- examples/imgui_impl_dx10.cpp | 2 +- examples/imgui_impl_dx11.cpp | 2 +- examples/imgui_impl_dx12.cpp | 2 +- examples/imgui_impl_dx9.cpp | 2 +- examples/imgui_impl_glfw.cpp | 2 +- examples/imgui_impl_opengl2.cpp | 2 +- examples/imgui_impl_opengl3.cpp | 2 +- examples/imgui_impl_vulkan.cpp | 2 +- examples/imgui_impl_win32.cpp | 2 +- imgui.cpp | 36 ++++++++++---------- imgui.h | 40 +++++++++++------------ imgui_internal.h | 2 +- 24 files changed, 71 insertions(+), 71 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 0289741a..c1810aba 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -82,7 +82,7 @@ Other changes: - Added GetWindowDpiScale(). - Added GetOverlayDrawList(ImGuiViewport* viewport). The no-parameter version of GetOverlayDrawList() return the overlay for the current window's viewport. -- Added UpdatePlatformWindows(), RenderPlatformWindows(), DestroyPlatformWindows() for usage for application core. +- Added PlatformWindowsUpdate(), PlatformWindowsRender(), PlatformWindowsDestroy() for usage for application core. - Added FindViewportByID(), FindViewportByPlatformHandle() for usage by back-ends. - Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options. - Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options. diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 051d4281..585db73f 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -160,8 +160,8 @@ int main(int, char**) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { GLFWwindow* backup_current_context = glfwGetCurrentContext(); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); glfwMakeContextCurrent(backup_current_context); } diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 0f29f849..b8de5cbe 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -205,8 +205,8 @@ int main(int, char**) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { GLFWwindow* backup_current_context = glfwGetCurrentContext(); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); glfwMakeContextCurrent(backup_current_context); } diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index da23d247..f30219f6 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -525,8 +525,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } FramePresent(wd); diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 60c06245..ea2e85a5 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -166,8 +166,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index aa765634..78b0b220 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -158,8 +158,8 @@ int main(int, char**) { SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); SDL_GL_MakeCurrent(backup_current_window, backup_current_context); } diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index af089287..e8f7441b 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -207,8 +207,8 @@ int main(int, char**) { SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); SDL_GL_MakeCurrent(backup_current_window, backup_current_context); } diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index 7d84f34a..ec99439b 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -522,8 +522,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } FramePresent(wd); diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index 284bf787..f30b2682 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -159,8 +159,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index d3828ff9..07cf519d 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -166,8 +166,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 259c3026..6c1e3deb 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -210,8 +210,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(NULL, (void*)g_pd3dCommandList); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(NULL, (void*)g_pd3dCommandList); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index d96e5c48..3be45fa0 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -165,8 +165,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + ImGui::PlatformWindowsUpdate(); + ImGui::PlatformWindowsRender(); } HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL); diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 95dc6fd2..852a908e 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -655,6 +655,6 @@ void ImGui_ImplDX10_InitPlatformInterface() void ImGui_ImplDX10_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index ffd05625..2a40cc58 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -671,5 +671,5 @@ static void ImGui_ImplDX11_InitPlatformInterface() static void ImGui_ImplDX11_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 3ead29c5..57ac0afe 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -947,5 +947,5 @@ void ImGui_ImplDX12_InitPlatformInterface() void ImGui_ImplDX12_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 27435cbc..0a22f922 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -423,7 +423,7 @@ static void ImGui_ImplDX9_InitPlatformInterface() static void ImGui_ImplDX9_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } static void ImGui_ImplDX9_CreateDeviceObjectsForPlatformWindows() diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index bcbee436..462c35fe 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -598,7 +598,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR // Let mouse pass-through the window. This will allow the back-end to set io.MouseHoveredViewport properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in - // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. + // your main loop after calling PlatformWindowsUpdate(). Iterate all viewports/platform windows and pass the flag to your windowing system. ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT"); if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index ba440957..d3a264a3 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -283,5 +283,5 @@ static void ImGui_ImplOpenGL2_InitPlatformInterface() static void ImGui_ImplOpenGL2_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 6eb38c7c..624c30ff 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -712,5 +712,5 @@ static void ImGui_ImplOpenGL3_InitPlatformInterface() static void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 3d0ad9a1..6482ffd8 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -1445,5 +1445,5 @@ void ImGui_ImplVulkan_InitPlatformInterface() void ImGui_ImplVulkan_ShutdownPlatformInterface() { - ImGui::DestroyPlatformWindows(); + ImGui::PlatformWindowsDestroy(); } diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 716709a3..b5b272d3 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -798,7 +798,7 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, // Let mouse pass-through the window. This will allow the back-end to set io.MouseHoveredViewport properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in - // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. + // your main loop after calling PlatformWindowsUpdate(). Iterate all viewports/platform windows and pass the flag to your windowing system. if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; break; diff --git a/imgui.cpp b/imgui.cpp index 1331aef9..9d3688d6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3912,7 +3912,7 @@ static void NewFrameSanityChecks() { if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) { - IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() in main loop after EndFrame()? Check examples/ applications for reference."); + IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call PlatformWindowsUpdate() in main loop after EndFrame()? Check examples/ applications for reference."); IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?"); @@ -4233,7 +4233,7 @@ void ImGui::Shutdown(ImGuiContext* context) // Destroy platform windows ImGuiContext* backup_context = ImGui::GetCurrentContext(); SetCurrentContext(context); - DestroyPlatformWindows(); + PlatformWindowsDestroy(); SetCurrentContext(backup_context); // Shutdown extensions @@ -10582,13 +10582,13 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl // - UpdateViewportsEndFrame() [Internal] // - AddUpdateViewport() [Internal] // - UpdateSelectWindowViewport() [Internal] -// - UpdatePlatformWindows() -// - RenderPlatformWindowsDefault() +// - PlatformWindowsUpdate() +// - PlatformWindowsRender() // - FindPlatformMonitorForPos() [Internal] // - FindPlatformMonitorForRect() [Internal] // - UpdateViewportPlatformMonitor() [Internal] -// - DestroyPlatformWindow() [Internal] -// - DestroyPlatformWindows() +// - PlatformWindowsDestroyOne() [Internal] +// - PlatformWindowsDestroy() //----------------------------------------------------------------------------- ImGuiViewport* ImGui::GetMainViewport() @@ -10809,7 +10809,7 @@ static void ImGui::UpdateViewportsNewFrame() // Destroy IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); - DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here. + PlatformWindowsDestroyOne(viewport); // In most circumstances the platform window will already be destroyed here. IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); IM_DELETE(viewport); n--; @@ -10820,7 +10820,7 @@ static void ImGui::UpdateViewportsNewFrame() if (viewports_enabled) { // Update Position and Size (from Platform Window to ImGui) if requested. - // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities. + // We do it early in the frame instead of waiting for PlatformWindowsUpdate() to avoid a frame of lag when moving/resizing using OS facilities. if (!(viewport->Flags & ImGuiViewportFlags_Minimized) && platform_funcs_available) { if (viewport->PlatformRequestMove) @@ -10943,7 +10943,7 @@ static void ImGui::UpdateViewportsEndFrame() IM_ASSERT(viewport->Window != NULL); g.PlatformIO.Viewports.push_back(viewport); } - g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called + g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because PlatformWindowsUpdate() won't do it and may not even be called } // FIXME: We should ideally refactor the system to call this every frame (we currently don't) @@ -11135,11 +11135,11 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window) } // Called by user at the end of the main loop, after EndFrame() -// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api. -void ImGui::UpdatePlatformWindows() +// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO API. +void ImGui::PlatformWindowsUpdate() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?"); + IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before PlatformWindowsUpdate()?"); IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount); g.FrameCountPlatformEnded = g.FrameCount; if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) @@ -11152,13 +11152,13 @@ void ImGui::UpdatePlatformWindows() ImGuiViewportP* viewport = g.Viewports[i]; // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window - // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame) + // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy PlatformWindowsDestroyOne to be made each frame) bool destroy_platform_window = false; destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1); destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)); if (destroy_platform_window) { - DestroyPlatformWindow(viewport); + PlatformWindowsDestroyOne(viewport); continue; } @@ -11267,7 +11267,7 @@ void ImGui::UpdatePlatformWindows() // if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) // MySwapBufferFunction(platform_io.Viewports[i], my_args); // -void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* renderer_render_arg) +void ImGui::PlatformWindowsRender(void* platform_render_arg, void* renderer_render_arg) { // Skip the main viewport (index 0), which is always fully handled by the application! ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); @@ -11341,7 +11341,7 @@ static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport) viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetMainRect()); } -void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) +void ImGui::PlatformWindowsDestroyOne(ImGuiViewportP* viewport) { ImGuiContext& g = *GImGui; if (viewport->PlatformWindowCreated) @@ -11365,7 +11365,7 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) viewport->ClearRequestFlags(); } -void ImGui::DestroyPlatformWindows() +void ImGui::PlatformWindowsDestroy() { // We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the back-end // to clear any data they may have stored in e.g. PlatformUserData, RendererUserData. @@ -11375,7 +11375,7 @@ void ImGui::DestroyPlatformWindows() // crashing if it doesn't have data stored. ImGuiContext& g = *GImGui; for (int i = 0; i < g.Viewports.Size; i++) - DestroyPlatformWindow(g.Viewports[i]); + PlatformWindowsDestroyOne(g.Viewports[i]); } diff --git a/imgui.h b/imgui.h index b13f3535..f277e8ff 100644 --- a/imgui.h +++ b/imgui.h @@ -779,11 +779,11 @@ namespace ImGui // Note: You may use GetWindowViewport() to get the current viewport of the current window. IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for back-end to setup + viewports list. IMGUI_API ImGuiViewport* GetMainViewport(); // main viewport. same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0]. - IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. - IMGUI_API void RenderPlatformWindowsDefault(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. - IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). - IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // this is a helper for back-ends. - IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // this is a helper for back-ends. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.) + IMGUI_API void PlatformWindowsUpdate(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. + IMGUI_API void PlatformWindowsRender(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. + IMGUI_API void PlatformWindowsDestroy(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). + IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // helper for back-ends to find a viewport. + IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // helper for back-ends to find a viewport. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.) } // namespace ImGui @@ -2412,7 +2412,7 @@ struct ImFont // Steps to use multi-viewports in your application, when using a default back-end from the examples/ folder: // - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // - Back-end: The back-end initialization will setup all necessary ImGuiPlatformIO's functions and update monitors info every frame. -// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). +// - Application: In your main loop, call ImGui::PlatformWindowsUpdate(), ImGui::PlatformWindowsRender() after EndFrame() or Render(). // - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. // // Steps to use multi-viewports in your application, when using a custom back-end: @@ -2424,18 +2424,18 @@ struct ImFont // Set 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports' and 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports'. // Update ImGuiPlatformIO's Monitors list every frame. // Update MousePos every frame, in absolute coordinates. -// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). -// You may skip calling RenderPlatformWindowsDefault() if its API is not convenient for your needs. Read comments below. +// - Application: In your main loop, call ImGui::PlatformWindowsUpdate(), ImGui::PlatformWindowsRender() after EndFrame() or Render(). +// You may skip calling PlatformWindowsRender() if its API is not convenient for your needs. Read comments below. // - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. // -// About ImGui::RenderPlatformWindowsDefault(): +// About ImGui::PlatformWindowsRender(): // - This function is a mostly a _helper_ for the common-most cases, and to facilitate using default back-ends. // - You can check its simple source code to understand what it does. // It basically iterates secondary viewports and call 4 functions that are setup in ImGuiPlatformIO, if available: // Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers() -// Those functions pointers exists only for the benefit of RenderPlatformWindowsDefault(). +// Those functions pointers exists only for the benefit of PlatformWindowsRender(). // - If you have very specific rendering needs (e.g. flipping multiple swap-chain simultaneously, unusual sync/threading issues, etc.), -// you may be tempted to ignore RenderPlatformWindowsDefault() and write customized code to perform your renderingg. +// you may be tempted to ignore PlatformWindowsRender() and write customized code to perform your renderingg. // You may decide to setup the platform_io's *RenderWindow and *SwapBuffers pointers and call your functions through those pointers, // or you may decide to never setup those pointers and call your code directly. They are a convenience, not an obligatory interface. //----------------------------------------------------------------------------- @@ -2451,10 +2451,10 @@ struct ImGuiPlatformIO // For reference, the second column shows which function are generally calling the Platform Functions: // N = ImGui::NewFrame() ~ beginning of the dear imgui frame: read info from platform/OS windows (latest size/position) // F = ImGui::Begin(), ImGui::EndFrame() ~ during the dear imgui frame - // U = ImGui::UpdatePlatformWindows() ~ after the dear imgui frame: create and update all platform/OS windows - // R = ImGui::RenderPlatformWindowsDefault() ~ render - // D = ImGui::DestroyPlatformWindows() ~ shutdown - // The general idea is that NewFrame() we will read the current Platform/OS state, and UpdatePlatformWindows() will write to it. + // U = ImGui::PlatformWindowsUpdate() ~ after the dear imgui frame: create and update all platform/OS windows + // R = ImGui::PlatformWindowsRender() ~ render (read comment above about this function!) + // D = ImGui::PlatformWindowsDestroy() ~ shutdown + // The general idea is that NewFrame() we will read the current Platform/OS state, and PlatformWindowsUpdate() will write to it. // // The functions are designed so we can mix and match 2 imgui_impl_xxxx files, one for the Platform (~window/input handling), one for Renderer. // Custom engine back-ends will often provide both Platform and Renderer interfaces and so may not need to use all functions. @@ -2473,9 +2473,9 @@ struct ImGuiPlatformIO bool (*Platform_GetWindowMinimized)(ImGuiViewport* vp); // N . . . . // Get platform window minimized state. When minimized, we generally won't attempt to get/set size and contents will be culled more easily void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* str); // . . U . . // Set platform window title (given an UTF-8 string) void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // . . U . . // (Optional) Setup window transparency - void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by UpdatePlatformWindows(). Optional hook to allow the platform back-end from doing general book-keeping every frame. - void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). - void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by PlatformWindowsUpdate(). Optional hook to allow the platform back-end from doing general book-keeping every frame. + void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to PlatformWindowsRender(). + void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to PlatformWindowsRender(). float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // . F . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style. void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // . F . . . // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. FIXME: The call timing of this is inconsistent because we want to support without multi-viewports. @@ -2485,8 +2485,8 @@ struct ImGuiPlatformIO void (*Renderer_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create swap chain, frame buffers etc. (called after Platform_CreateWindow) void (*Renderer_DestroyWindow)(ImGuiViewport* vp); // N . U . D // Destroy swap chain, frame buffers etc. (called before Platform_DestroyWindow) void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Resize swap chain, frame buffers etc. (called after Platform_SetWindowSize) - void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). - void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to PlatformWindowsRender(). + void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to PlatformWindowsRender(). // (Optional) Monitor list // - Updated by: app/back-end. Update every frame to dynamically support changing monitor or DPI configuration. diff --git a/imgui_internal.h b/imgui_internal.h index 2e82ed41..9b71f806 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1869,7 +1869,7 @@ namespace ImGui // Viewports IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos); IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale); - IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport); + IMGUI_API void PlatformWindowsDestroyOne(ImGuiViewportP* viewport); IMGUI_API void ShowViewportThumbnails(); // Settings From fbaf65b8f6b1fe47a70d85ab19e601eb1398bc94 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 6 Mar 2020 17:53:09 +0100 Subject: [PATCH 315/384] Revert "Viewports: Renamed UpdatePlatformWindows > PlatformWindowsUpdate, RenderPlatformWindowsDefault -> PlatformWindowsRender, DestroyPlatformWindows > PlatformWindowsDestroy (#1542)" This reverts commit f2c7f3b200d82f3965bedbe4f52d6082fb74d1be. --- docs/CHANGELOG.txt | 2 +- examples/example_glfw_opengl2/main.cpp | 4 +-- examples/example_glfw_opengl3/main.cpp | 4 +-- examples/example_glfw_vulkan/main.cpp | 4 +-- examples/example_sdl_directx11/main.cpp | 4 +-- examples/example_sdl_opengl2/main.cpp | 4 +-- examples/example_sdl_opengl3/main.cpp | 4 +-- examples/example_sdl_vulkan/main.cpp | 4 +-- examples/example_win32_directx10/main.cpp | 4 +-- examples/example_win32_directx11/main.cpp | 4 +-- examples/example_win32_directx12/main.cpp | 4 +-- examples/example_win32_directx9/main.cpp | 4 +-- examples/imgui_impl_dx10.cpp | 2 +- examples/imgui_impl_dx11.cpp | 2 +- examples/imgui_impl_dx12.cpp | 2 +- examples/imgui_impl_dx9.cpp | 2 +- examples/imgui_impl_glfw.cpp | 2 +- examples/imgui_impl_opengl2.cpp | 2 +- examples/imgui_impl_opengl3.cpp | 2 +- examples/imgui_impl_vulkan.cpp | 2 +- examples/imgui_impl_win32.cpp | 2 +- imgui.cpp | 36 ++++++++++---------- imgui.h | 40 +++++++++++------------ imgui_internal.h | 2 +- 24 files changed, 71 insertions(+), 71 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c1810aba..0289741a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -82,7 +82,7 @@ Other changes: - Added GetWindowDpiScale(). - Added GetOverlayDrawList(ImGuiViewport* viewport). The no-parameter version of GetOverlayDrawList() return the overlay for the current window's viewport. -- Added PlatformWindowsUpdate(), PlatformWindowsRender(), PlatformWindowsDestroy() for usage for application core. +- Added UpdatePlatformWindows(), RenderPlatformWindows(), DestroyPlatformWindows() for usage for application core. - Added FindViewportByID(), FindViewportByPlatformHandle() for usage by back-ends. - Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options. - Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options. diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 585db73f..051d4281 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -160,8 +160,8 @@ int main(int, char**) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { GLFWwindow* backup_current_context = glfwGetCurrentContext(); - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); glfwMakeContextCurrent(backup_current_context); } diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index b8de5cbe..0f29f849 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -205,8 +205,8 @@ int main(int, char**) if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { GLFWwindow* backup_current_context = glfwGetCurrentContext(); - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); glfwMakeContextCurrent(backup_current_context); } diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index f30219f6..da23d247 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -525,8 +525,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } FramePresent(wd); diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index ea2e85a5..60c06245 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -166,8 +166,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 78b0b220..aa765634 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -158,8 +158,8 @@ int main(int, char**) { SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); SDL_GL_MakeCurrent(backup_current_window, backup_current_context); } diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index e8f7441b..af089287 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -207,8 +207,8 @@ int main(int, char**) { SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); SDL_GL_MakeCurrent(backup_current_window, backup_current_context); } diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index ec99439b..7d84f34a 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -522,8 +522,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } FramePresent(wd); diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index f30b2682..284bf787 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -159,8 +159,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 07cf519d..d3828ff9 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -166,8 +166,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 6c1e3deb..259c3026 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -210,8 +210,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(NULL, (void*)g_pd3dCommandList); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(NULL, (void*)g_pd3dCommandList); } g_pSwapChain->Present(1, 0); // Present with vsync diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index 3be45fa0..d96e5c48 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -165,8 +165,8 @@ int main(int, char**) // Update and Render additional Platform Windows if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::PlatformWindowsUpdate(); - ImGui::PlatformWindowsRender(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); } HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL); diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index 852a908e..95dc6fd2 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -655,6 +655,6 @@ void ImGui_ImplDX10_InitPlatformInterface() void ImGui_ImplDX10_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index 2a40cc58..ffd05625 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -671,5 +671,5 @@ static void ImGui_ImplDX11_InitPlatformInterface() static void ImGui_ImplDX11_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 57ac0afe..3ead29c5 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -947,5 +947,5 @@ void ImGui_ImplDX12_InitPlatformInterface() void ImGui_ImplDX12_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 0a22f922..27435cbc 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -423,7 +423,7 @@ static void ImGui_ImplDX9_InitPlatformInterface() static void ImGui_ImplDX9_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } static void ImGui_ImplDX9_CreateDeviceObjectsForPlatformWindows() diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 462c35fe..bcbee436 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -598,7 +598,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR // Let mouse pass-through the window. This will allow the back-end to set io.MouseHoveredViewport properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in - // your main loop after calling PlatformWindowsUpdate(). Iterate all viewports/platform windows and pass the flag to your windowing system. + // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT"); if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index d3a264a3..ba440957 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -283,5 +283,5 @@ static void ImGui_ImplOpenGL2_InitPlatformInterface() static void ImGui_ImplOpenGL2_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 624c30ff..6eb38c7c 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -712,5 +712,5 @@ static void ImGui_ImplOpenGL3_InitPlatformInterface() static void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 6482ffd8..3d0ad9a1 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -1445,5 +1445,5 @@ void ImGui_ImplVulkan_InitPlatformInterface() void ImGui_ImplVulkan_ShutdownPlatformInterface() { - ImGui::PlatformWindowsDestroy(); + ImGui::DestroyPlatformWindows(); } diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index b5b272d3..716709a3 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -798,7 +798,7 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, // Let mouse pass-through the window. This will allow the back-end to set io.MouseHoveredViewport properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in - // your main loop after calling PlatformWindowsUpdate(). Iterate all viewports/platform windows and pass the flag to your windowing system. + // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; break; diff --git a/imgui.cpp b/imgui.cpp index 9d3688d6..1331aef9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3912,7 +3912,7 @@ static void NewFrameSanityChecks() { if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) { - IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call PlatformWindowsUpdate() in main loop after EndFrame()? Check examples/ applications for reference."); + IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() in main loop after EndFrame()? Check examples/ applications for reference."); IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?"); IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?"); @@ -4233,7 +4233,7 @@ void ImGui::Shutdown(ImGuiContext* context) // Destroy platform windows ImGuiContext* backup_context = ImGui::GetCurrentContext(); SetCurrentContext(context); - PlatformWindowsDestroy(); + DestroyPlatformWindows(); SetCurrentContext(backup_context); // Shutdown extensions @@ -10582,13 +10582,13 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl // - UpdateViewportsEndFrame() [Internal] // - AddUpdateViewport() [Internal] // - UpdateSelectWindowViewport() [Internal] -// - PlatformWindowsUpdate() -// - PlatformWindowsRender() +// - UpdatePlatformWindows() +// - RenderPlatformWindowsDefault() // - FindPlatformMonitorForPos() [Internal] // - FindPlatformMonitorForRect() [Internal] // - UpdateViewportPlatformMonitor() [Internal] -// - PlatformWindowsDestroyOne() [Internal] -// - PlatformWindowsDestroy() +// - DestroyPlatformWindow() [Internal] +// - DestroyPlatformWindows() //----------------------------------------------------------------------------- ImGuiViewport* ImGui::GetMainViewport() @@ -10809,7 +10809,7 @@ static void ImGui::UpdateViewportsNewFrame() // Destroy IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); - PlatformWindowsDestroyOne(viewport); // In most circumstances the platform window will already be destroyed here. + DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here. IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); IM_DELETE(viewport); n--; @@ -10820,7 +10820,7 @@ static void ImGui::UpdateViewportsNewFrame() if (viewports_enabled) { // Update Position and Size (from Platform Window to ImGui) if requested. - // We do it early in the frame instead of waiting for PlatformWindowsUpdate() to avoid a frame of lag when moving/resizing using OS facilities. + // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities. if (!(viewport->Flags & ImGuiViewportFlags_Minimized) && platform_funcs_available) { if (viewport->PlatformRequestMove) @@ -10943,7 +10943,7 @@ static void ImGui::UpdateViewportsEndFrame() IM_ASSERT(viewport->Window != NULL); g.PlatformIO.Viewports.push_back(viewport); } - g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because PlatformWindowsUpdate() won't do it and may not even be called + g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called } // FIXME: We should ideally refactor the system to call this every frame (we currently don't) @@ -11135,11 +11135,11 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window) } // Called by user at the end of the main loop, after EndFrame() -// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO API. -void ImGui::PlatformWindowsUpdate() +// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api. +void ImGui::UpdatePlatformWindows() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before PlatformWindowsUpdate()?"); + IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?"); IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount); g.FrameCountPlatformEnded = g.FrameCount; if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) @@ -11152,13 +11152,13 @@ void ImGui::PlatformWindowsUpdate() ImGuiViewportP* viewport = g.Viewports[i]; // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window - // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy PlatformWindowsDestroyOne to be made each frame) + // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame) bool destroy_platform_window = false; destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1); destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)); if (destroy_platform_window) { - PlatformWindowsDestroyOne(viewport); + DestroyPlatformWindow(viewport); continue; } @@ -11267,7 +11267,7 @@ void ImGui::PlatformWindowsUpdate() // if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) // MySwapBufferFunction(platform_io.Viewports[i], my_args); // -void ImGui::PlatformWindowsRender(void* platform_render_arg, void* renderer_render_arg) +void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* renderer_render_arg) { // Skip the main viewport (index 0), which is always fully handled by the application! ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); @@ -11341,7 +11341,7 @@ static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport) viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetMainRect()); } -void ImGui::PlatformWindowsDestroyOne(ImGuiViewportP* viewport) +void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) { ImGuiContext& g = *GImGui; if (viewport->PlatformWindowCreated) @@ -11365,7 +11365,7 @@ void ImGui::PlatformWindowsDestroyOne(ImGuiViewportP* viewport) viewport->ClearRequestFlags(); } -void ImGui::PlatformWindowsDestroy() +void ImGui::DestroyPlatformWindows() { // We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the back-end // to clear any data they may have stored in e.g. PlatformUserData, RendererUserData. @@ -11375,7 +11375,7 @@ void ImGui::PlatformWindowsDestroy() // crashing if it doesn't have data stored. ImGuiContext& g = *GImGui; for (int i = 0; i < g.Viewports.Size; i++) - PlatformWindowsDestroyOne(g.Viewports[i]); + DestroyPlatformWindow(g.Viewports[i]); } diff --git a/imgui.h b/imgui.h index f277e8ff..b13f3535 100644 --- a/imgui.h +++ b/imgui.h @@ -779,11 +779,11 @@ namespace ImGui // Note: You may use GetWindowViewport() to get the current viewport of the current window. IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for back-end to setup + viewports list. IMGUI_API ImGuiViewport* GetMainViewport(); // main viewport. same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0]. - IMGUI_API void PlatformWindowsUpdate(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. - IMGUI_API void PlatformWindowsRender(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. - IMGUI_API void PlatformWindowsDestroy(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). - IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // helper for back-ends to find a viewport. - IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // helper for back-ends to find a viewport. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.) + IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. + IMGUI_API void RenderPlatformWindowsDefault(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. + IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). + IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // this is a helper for back-ends. + IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // this is a helper for back-ends. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.) } // namespace ImGui @@ -2412,7 +2412,7 @@ struct ImFont // Steps to use multi-viewports in your application, when using a default back-end from the examples/ folder: // - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // - Back-end: The back-end initialization will setup all necessary ImGuiPlatformIO's functions and update monitors info every frame. -// - Application: In your main loop, call ImGui::PlatformWindowsUpdate(), ImGui::PlatformWindowsRender() after EndFrame() or Render(). +// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). // - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. // // Steps to use multi-viewports in your application, when using a custom back-end: @@ -2424,18 +2424,18 @@ struct ImFont // Set 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports' and 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports'. // Update ImGuiPlatformIO's Monitors list every frame. // Update MousePos every frame, in absolute coordinates. -// - Application: In your main loop, call ImGui::PlatformWindowsUpdate(), ImGui::PlatformWindowsRender() after EndFrame() or Render(). -// You may skip calling PlatformWindowsRender() if its API is not convenient for your needs. Read comments below. +// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). +// You may skip calling RenderPlatformWindowsDefault() if its API is not convenient for your needs. Read comments below. // - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. // -// About ImGui::PlatformWindowsRender(): +// About ImGui::RenderPlatformWindowsDefault(): // - This function is a mostly a _helper_ for the common-most cases, and to facilitate using default back-ends. // - You can check its simple source code to understand what it does. // It basically iterates secondary viewports and call 4 functions that are setup in ImGuiPlatformIO, if available: // Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers() -// Those functions pointers exists only for the benefit of PlatformWindowsRender(). +// Those functions pointers exists only for the benefit of RenderPlatformWindowsDefault(). // - If you have very specific rendering needs (e.g. flipping multiple swap-chain simultaneously, unusual sync/threading issues, etc.), -// you may be tempted to ignore PlatformWindowsRender() and write customized code to perform your renderingg. +// you may be tempted to ignore RenderPlatformWindowsDefault() and write customized code to perform your renderingg. // You may decide to setup the platform_io's *RenderWindow and *SwapBuffers pointers and call your functions through those pointers, // or you may decide to never setup those pointers and call your code directly. They are a convenience, not an obligatory interface. //----------------------------------------------------------------------------- @@ -2451,10 +2451,10 @@ struct ImGuiPlatformIO // For reference, the second column shows which function are generally calling the Platform Functions: // N = ImGui::NewFrame() ~ beginning of the dear imgui frame: read info from platform/OS windows (latest size/position) // F = ImGui::Begin(), ImGui::EndFrame() ~ during the dear imgui frame - // U = ImGui::PlatformWindowsUpdate() ~ after the dear imgui frame: create and update all platform/OS windows - // R = ImGui::PlatformWindowsRender() ~ render (read comment above about this function!) - // D = ImGui::PlatformWindowsDestroy() ~ shutdown - // The general idea is that NewFrame() we will read the current Platform/OS state, and PlatformWindowsUpdate() will write to it. + // U = ImGui::UpdatePlatformWindows() ~ after the dear imgui frame: create and update all platform/OS windows + // R = ImGui::RenderPlatformWindowsDefault() ~ render + // D = ImGui::DestroyPlatformWindows() ~ shutdown + // The general idea is that NewFrame() we will read the current Platform/OS state, and UpdatePlatformWindows() will write to it. // // The functions are designed so we can mix and match 2 imgui_impl_xxxx files, one for the Platform (~window/input handling), one for Renderer. // Custom engine back-ends will often provide both Platform and Renderer interfaces and so may not need to use all functions. @@ -2473,9 +2473,9 @@ struct ImGuiPlatformIO bool (*Platform_GetWindowMinimized)(ImGuiViewport* vp); // N . . . . // Get platform window minimized state. When minimized, we generally won't attempt to get/set size and contents will be culled more easily void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* str); // . . U . . // Set platform window title (given an UTF-8 string) void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // . . U . . // (Optional) Setup window transparency - void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by PlatformWindowsUpdate(). Optional hook to allow the platform back-end from doing general book-keeping every frame. - void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to PlatformWindowsRender(). - void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to PlatformWindowsRender(). + void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by UpdatePlatformWindows(). Optional hook to allow the platform back-end from doing general book-keeping every frame. + void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // . F . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style. void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // . F . . . // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. FIXME: The call timing of this is inconsistent because we want to support without multi-viewports. @@ -2485,8 +2485,8 @@ struct ImGuiPlatformIO void (*Renderer_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create swap chain, frame buffers etc. (called after Platform_CreateWindow) void (*Renderer_DestroyWindow)(ImGuiViewport* vp); // N . U . D // Destroy swap chain, frame buffers etc. (called before Platform_DestroyWindow) void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Resize swap chain, frame buffers etc. (called after Platform_SetWindowSize) - void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to PlatformWindowsRender(). - void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to PlatformWindowsRender(). + void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). + void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). // (Optional) Monitor list // - Updated by: app/back-end. Update every frame to dynamically support changing monitor or DPI configuration. diff --git a/imgui_internal.h b/imgui_internal.h index 9b71f806..2e82ed41 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1869,7 +1869,7 @@ namespace ImGui // Viewports IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos); IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale); - IMGUI_API void PlatformWindowsDestroyOne(ImGuiViewportP* viewport); + IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport); IMGUI_API void ShowViewportThumbnails(); // Settings From 1b5b87a40e5f9b68a18456d94b5f5c16d2347b2e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 7 Mar 2020 15:19:51 +0100 Subject: [PATCH 316/384] Internals: Added #define NOMINMAX before windows.h include for single-compile-unit builds. --- imgui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index ad65e9f2..50c4a12f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1514,6 +1514,7 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#define NOMINMAX #ifndef __MINGW32__ #include #else @@ -9779,6 +9780,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#define NOMINMAX #ifndef __MINGW32__ #include #else From de37a0bfabf0d3b6f88384607745835056f63990 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 7 Mar 2020 15:35:44 +0100 Subject: [PATCH 317/384] Internals: fix potential warning. Comments around include sections. Moved a few bits. --- imgui.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 50c4a12f..cce1ca23 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -49,6 +49,7 @@ DOCUMENTATION CODE (search for "[SECTION]" in the code to find them) +// [SECTION] INCLUDES // [SECTION] FORWARD DECLARATIONS // [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO) @@ -788,6 +789,10 @@ CODE */ +//------------------------------------------------------------------------- +// [SECTION] INCLUDES +//------------------------------------------------------------------------- + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS #endif @@ -800,6 +805,7 @@ CODE #endif #include "imgui_internal.h" +// System includes #include // toupper #include // vsnprintf, sscanf, printf #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier @@ -808,17 +814,12 @@ CODE #include // intptr_t #endif -// Debug options -#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL -#define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window -#define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file (particularly helps for Docking, but makes saving slower) - // Visual Studio warnings #ifdef _MSC_VER -#pragma warning (disable: 4127) // condition expression is constant -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen -#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later -#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types +#pragma warning (disable: 4127) // condition expression is constant +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later +#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types #endif #endif @@ -852,6 +853,11 @@ CODE #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif +// Debug options +#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL +#define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window +#define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file (particularly helps for Docking, but makes saving slower) + // When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch. static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the highlight and screen dimming starts fading in static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time before the window list starts to appear @@ -1514,7 +1520,9 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#ifndef NOMINMAX #define NOMINMAX +#endif #ifndef __MINGW32__ #include #else @@ -9780,7 +9788,9 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#ifndef NOMINMAX #define NOMINMAX +#endif #ifndef __MINGW32__ #include #else From 2dcf8df9f448f2230576df9a6ea630a0d00c7e27 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 7 Mar 2020 15:51:50 +0100 Subject: [PATCH 318/384] Internals: Shuffled some of the windows-specific includes to avoid duplication. Might have undesirable side-effects on some compilers, please report! --- imgui.cpp | 65 +++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cce1ca23..8245e83a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -814,6 +814,34 @@ CODE #include // intptr_t #endif +// [Windows] OS specific includes (optional) +#if defined(_WIN32) && defined(IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) +#define IMGUI_DISABLE_WIN32_FUNCTIONS +#endif +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#ifndef __MINGW32__ +#include // _wfopen, OpenClipboard +#else +#include +#endif +#include // MultiByteToWideChar, WideCharToMultiByte +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have all Win32 functions +#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS +#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS +#endif +#endif + +// [Apple] OS specific includes +#if defined(__APPLE__) +#include +#endif + // Visual Studio warnings #ifdef _MSC_VER #pragma warning (disable: 4127) // condition expression is constant @@ -1516,20 +1544,6 @@ ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed) // Default file functions #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS -#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef NOMINMAX -#define NOMINMAX -#endif -#ifndef __MINGW32__ -#include -#else -#include -#endif -#endif - ImFileHandle ImFileOpen(const char* filename, const char* mode) { #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__) @@ -1541,7 +1555,7 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode) buf.resize(filename_wsize + mode_wsize); ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, (wchar_t*)&buf[0], filename_wsize); ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, (wchar_t*)&buf[filename_wsize], mode_wsize); - return _wfopen((const wchar_t*)&buf[0], (const wchar_t*)&buf[filename_wsize]); + return ::_wfopen((const wchar_t*)&buf[0], (const wchar_t*)&buf[filename_wsize]); #else return fopen(filename, mode); #endif @@ -9784,27 +9798,6 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl // [SECTION] PLATFORM DEPENDENT HELPERS //----------------------------------------------------------------------------- -#if defined(_WIN32) && !defined(_WINDOWS_) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef NOMINMAX -#define NOMINMAX -#endif -#ifndef __MINGW32__ -#include -#else -#include -#endif -#include -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have Win32 functions -#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS -#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS -#endif -#elif defined(__APPLE__) -#include -#endif - #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) #ifdef _MSC_VER From aef057e9754bce3d2cb20bc2386787beef1d09ec Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 7 Mar 2020 15:55:05 +0100 Subject: [PATCH 319/384] Internals: Added GetInputTextState() + comments. --- docs/TODO.txt | 4 +++- examples/imgui_impl_glfw.h | 5 +++-- imgui.cpp | 1 + imgui_internal.h | 6 ++++-- imgui_widgets.cpp | 6 ++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 934d8e83..f13d85e1 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -41,7 +41,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. - scrolling: forward mouse wheel scrolling to parent window when at the edge of scrolling limits? (useful for listbox,tables?) - scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro) - - scrolling/style: shadows on scrollable areas to denote that there is more contents + - scrolling/style: shadows on scrollable areas to denote that there is more contents (see e.g. DaVinci Resolve ui) - drawdata: make it easy to clone (or swap?) a full ImDrawData so user can easily save that data if they use threaded rendering. (e.g. #2646) ! drawlist: add calctextsize func to facilitate consistent code from user pov (currently need to use ImGui or ImFont alternatives!) @@ -294,6 +294,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font: a CalcTextHeight() helper could run faster than CalcTextSize().y - font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX - font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data + - font: remove ID from CustomRect registration, it seems unnecessary! - font: make it easier to submit own bitmap font (same texture, another texture?). (#2127, #2575) - font: PushFontSize API (#1018) - font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite? @@ -377,6 +378,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - examples: window minimize, maximize (#583) - examples: provide a zero frame-rate/idle example. + - examples: dx11/dx12: try to use new swapchain blit models (#2970) - backends: apple: example_apple should be using modern GL3. - backends: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) - backends: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900) diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index ccbe840d..a86790b7 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -25,8 +25,9 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool in IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); -// InitXXX function with 'install_callbacks=true': install GLFW callbacks. They will call user's previously installed callbacks, if any. -// InitXXX function with 'install_callbacks=false': do not install GLFW callbacks. You will need to call them yourself from your own GLFW callbacks. +// GLFW callbacks +// - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any. +// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks. IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); diff --git a/imgui.cpp b/imgui.cpp index 8245e83a..1a26dd1e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1570,6 +1570,7 @@ ImU64 ImFileWrite(const void* data, ImU64 sz, ImU64 count, ImFileHandle f) // Helper: Load file content into memory // Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() +// This can't really be used with "rt" because fseek size won't match read size. void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes) { IM_ASSERT(filename && mode); diff --git a/imgui_internal.h b/imgui_internal.h index dfa45ddd..df98f51b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -746,10 +746,11 @@ struct IMGUI_API ImGuiMenuColumns }; // Internal state of the currently focused/edited text input box +// For a given item ID, access with ImGui::GetInputTextState() struct IMGUI_API ImGuiInputTextState { ImGuiID ID; // widget id owning the text state - int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 len is valid even if TextA is not. + int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 length is valid even if TextA is not. ImVector TextW; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. ImVector TextA; // temporary UTF8 buffer for callbacks and other operations. this is not updated in every code-path! size=capacity. ImVector InitialTextA; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) @@ -1849,7 +1850,8 @@ namespace ImGui IMGUI_API bool InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); IMGUI_API bool TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags); IMGUI_API bool TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format); - inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } + inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } + inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active // Color IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 60456645..01080c63 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3516,10 +3516,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (hovered) g.MouseCursor = ImGuiMouseCursor_TextInput; - // NB: we are only allowed to access 'edit_state' if we are the active widget. - ImGuiInputTextState* state = NULL; - if (g.InputTextState.ID == id) - state = &g.InputTextState; + // We are only allowed to access the state if we are already the active widget. + ImGuiInputTextState* state = GetInputTextState(id); const bool focus_requested = FocusableItemRegister(window, id); const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterRegular == window->DC.FocusCounterRegular); From e137db2df7c8d3ea89f95d96d28ed9f4b7b11242 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 9 Mar 2020 18:55:22 +0100 Subject: [PATCH 320/384] CI: Enable error on warnings for the extra warnings builds as an experiment. FAQ tweaks --- .github/workflows/build.yml | 8 ++++---- docs/FAQ.md | 27 ++++++++++++++++++++------- docs/README.md | 1 + 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ccc5c244..16ab157d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -171,22 +171,22 @@ jobs: - name: Build example_null (extra warnings, gcc 32-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m32" make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m32 -Werror" make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, gcc 64-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m64" make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m64 -Werror" make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, clang 32-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m32" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m32 -Werror" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, clang 64-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m64" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m64 -Werror" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 - name: Build example_null (single file build) run: | diff --git a/docs/FAQ.md b/docs/FAQ.md index 571c94c7..b173a73d 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -161,22 +161,35 @@ Interactive widgets (such as calls to Button buttons) need a unique ID. Unique ID are used internally to track active widgets and occasionally associate state to widgets. Unique ID are implicitly built from the hash of multiple elements that identify the "path" to the UI element. -- Unique ID are often derived from a string label: +- Unique ID are often derived from a string label and at minimum scoped within their host window: ```c -Button("OK"); // Label = "OK", ID = hash of (..., "OK") -Button("Cancel"); // Label = "Cancel", ID = hash of (..., "Cancel") +Begin("MyWindow"); +Button("OK"); // Label = "OK", ID = hash of ("MyWindow" "OK") +Button("Cancel"); // Label = "Cancel", ID = hash of ("MyWindow", "Cancel") +End(); ``` -- ID are uniquely scoped within windows, tree nodes, etc. which all pushes to the ID stack. Having -two buttons labeled "OK" in different windows or different tree locations is fine. -We used "..." above to signify whatever was already pushed to the ID stack previously: +- Other elements such as tree nodes, etc. also pushes to the ID stack: ```c Begin("MyWindow"); -Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "OK") +if (TreeNode("MyTreeNode")) +{ + Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "MyTreeNode", "OK") + TreePop(); +} +End(); +``` +- Two items labeled "OK" in different windows or different tree locations won't collide: +``` +Begin("MyFirstWindow"); +Button("OK"); // Label = "OK", ID = hash of ("MyFirstWindow", "OK") End(); Begin("MyOtherWindow"); Button("OK"); // Label = "OK", ID = hash of ("MyOtherWindow", "OK") End(); ``` + +We used "..." above to signify whatever was already pushed to the ID stack previously: + - If you have a same ID twice in the same location, you'll have a conflict: ```c Button("OK"); diff --git a/docs/README.md b/docs/README.md index a843822b..8c1636ef 100644 --- a/docs/README.md +++ b/docs/README.md @@ -203,6 +203,7 @@ From November 2014 to December 2019, ongoing development has also been financial Dear ImGui is using software and services provided free of charge for open source projects: - [PVS-Studio](https://www.viva64.com/en/b/0570/) for static analysis. - [GitHub actions](https://github.com/features/actions) for continuous integration systems. +- [OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage) for code coverage analysis. Credits ------- From 4a10af2bda0bdc647f0757c2bf459598c8244930 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Mar 2020 13:24:48 +0100 Subject: [PATCH 321/384] Unicode, Windows: Remove stringapiset.h include (breaks vs2010 and seems unnecessary?). (#2541, #2815) --- docs/TODO.txt | 1 + imgui.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index f13d85e1..9ba3a984 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -253,6 +253,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs. - log: obsolete LogButtons() all together. - log: LogButtons() options for specifying depth and/or hiding depth slider + - log: enabling log ends up pushing and growing vertices buffersbecause we don't distinguish layout vs render clipping - filters: set a current filter that tree node can automatically query to hide themselves - filters: handle wild-cards (with implicit leading/trailing *), reg-exprs diff --git a/imgui.cpp b/imgui.cpp index 1a26dd1e..f1424da7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -830,7 +830,6 @@ CODE #else #include #endif -#include // MultiByteToWideChar, WideCharToMultiByte #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have all Win32 functions #define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS #define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS From 9a46a19e99ac011fe3c6a9bd5b3b9eb88860bca6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 10 Mar 2020 21:51:35 +0100 Subject: [PATCH 322/384] Internals: Rename ImGuiSelectableFlags_PressedOnXXX to ImGuiSelectableFlags_SelectOnXXX, ImGuiButtonFlags_NoHoveredOnNav to ImGuiButtonFlags_NoHoveredOnFocus. --- imgui_internal.h | 6 +++--- imgui_widgets.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index df98f51b..88191036 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -430,7 +430,7 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_NoKeyModifiers = 1 << 12, // disable mouse interaction if a key modifier is held ImGuiButtonFlags_NoHoldingActiveId = 1 << 13, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) ImGuiButtonFlags_NoNavFocus = 1 << 14, // don't override navigation focus when activated - ImGuiButtonFlags_NoHoveredOnNav = 1 << 15, // don't report as hovered when navigated on + ImGuiButtonFlags_NoHoveredOnFocus = 1 << 15, // don't report as hovered when nav focus is on this item ImGuiButtonFlags_MouseButtonLeft = 1 << 16, // [Default] react on left mouse button ImGuiButtonFlags_MouseButtonRight = 1 << 17, // react on right mouse button ImGuiButtonFlags_MouseButtonMiddle = 1 << 18, // react on center mouse button @@ -470,8 +470,8 @@ enum ImGuiSelectableFlagsPrivate_ { // NB: need to be in sync with last value of ImGuiSelectableFlags_ ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20, - ImGuiSelectableFlags_PressedOnClick = 1 << 21, - ImGuiSelectableFlags_PressedOnRelease = 1 << 22, + ImGuiSelectableFlags_SelectOnClick = 1 << 21, // Override button behavior to react on Click (default is Click+Release) + ImGuiSelectableFlags_SelectOnRelease = 1 << 22, // Override button behavior to react on Release (default is Click+Release) ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus) ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 24, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25 diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 01080c63..d22c1fa4 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -572,7 +572,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // Gamepad/Keyboard navigation // We report navigated item as hovered but we don't set g.HoveredId to not interfere with mouse. if (g.NavId == id && !g.NavDisableHighlight && g.NavDisableMouseHover && (g.ActiveId == 0 || g.ActiveId == id || g.ActiveId == window->MoveId)) - if (!(flags & ImGuiButtonFlags_NoHoveredOnNav)) + if (!(flags & ImGuiButtonFlags_NoHoveredOnFocus)) hovered = true; if (g.NavActivateDownId == id) { @@ -5665,8 +5665,8 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries ImGuiButtonFlags button_flags = 0; if (flags & ImGuiSelectableFlags_NoHoldingActiveID) { button_flags |= ImGuiButtonFlags_NoHoldingActiveId; } - if (flags & ImGuiSelectableFlags_PressedOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } - if (flags & ImGuiSelectableFlags_PressedOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } + if (flags & ImGuiSelectableFlags_SelectOnClick) { button_flags |= ImGuiButtonFlags_PressedOnClick; } + if (flags & ImGuiSelectableFlags_SelectOnRelease) { button_flags |= ImGuiButtonFlags_PressedOnRelease; } if (flags & ImGuiSelectableFlags_Disabled) { button_flags |= ImGuiButtonFlags_Disabled; } if (flags & ImGuiSelectableFlags_AllowDoubleClick) { button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; } if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; } @@ -6267,7 +6267,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * 0.5f); PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); float w = label_size.x; - pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); PopStyleVar(); window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). } @@ -6277,7 +6277,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); float w = window->DC.MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); - pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled); RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right); } @@ -6407,7 +6407,7 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo // We've been using the equivalent of ImGuiSelectableFlags_SetNavIdOnHover on all Selectable() since early Nav system days (commit 43ee5d73), // but I am unsure whether this should be kept at all. For now moved it to be an opt-in feature used by menus only. - ImGuiSelectableFlags flags = ImGuiSelectableFlags_PressedOnRelease | ImGuiSelectableFlags_SetNavIdOnHover | (enabled ? 0 : ImGuiSelectableFlags_Disabled); + ImGuiSelectableFlags flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_SetNavIdOnHover | (enabled ? 0 : ImGuiSelectableFlags_Disabled); bool pressed; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { From a5041c8820866bffb59f606c4d31abdb1ea6d8e2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Mar 2020 21:07:10 +0100 Subject: [PATCH 323/384] Focus: Child inherit focus scope from parent (amend 2ebe08be). --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index f1424da7..267abd4d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5950,7 +5950,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; - window->DC.NavFocusScopeIdCurrent = 0; + window->DC.NavFocusScopeIdCurrent = parent_window ? parent_window->DC.NavFocusScopeIdCurrent : 0; window->DC.NavHideHighlightOneFrame = false; window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); From a0f01d229039417d139a06fd3da687c8add56377 Mon Sep 17 00:00:00 2001 From: joeslay <54322500+joeslay@users.noreply.github.com> Date: Wed, 11 Mar 2020 17:51:02 +0000 Subject: [PATCH 324/384] Improve resizing in dx11 example (#3057) Make the dx11 example implementation resize the window in a sane way, i.e. not the stretching/scaling the initial render to fit the new window size (current behaviour). --- examples/example_sdl_directx11/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 0a97325d..5b748ed6 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -101,6 +101,15 @@ int main(int, char**) done = true; if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) + { + g_pd3dDeviceContext->OMSetRenderTargets(0, 0, 0); + // Release all outstanding references to the swap chain's buffers. + g_mainRenderTargetView->Release(); + + g_pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0); + CreateRenderTarget(); + } } // Start the Dear ImGui frame From b016f1ad709d6f7d22f43ce7b6e49ea343c70824 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Mar 2020 21:22:18 +0100 Subject: [PATCH 325/384] Examples: SDL+DX11: Fixed resizing main window. Amend (#3057) --- docs/CHANGELOG.txt | 3 ++- examples/example_sdl_directx11/main.cpp | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 878ca98b..b41a1800 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,7 +67,8 @@ Other Changes: - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). - Backends: SDL: Fixed mapping for ImGuiKey_KeyPadEnter. (#3031) [@Davido71] -- Examples: Added SDL2+Metal example application. (#3017) [@coding-jackalope] +- Examples: SDL+DX11: Fixed resizing main window. (#3057) [@joeslay] +- Examples: Added SDL+Metal example application. (#3017) [@coding-jackalope] ----------------------------------------------------------------------- diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index 5b748ed6..eadf8ff7 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -101,12 +101,10 @@ int main(int, char**) done = true; if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) done = true; - if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window)) { - g_pd3dDeviceContext->OMSetRenderTargets(0, 0, 0); - // Release all outstanding references to the swap chain's buffers. - g_mainRenderTargetView->Release(); - + // Release all outstanding references to the swap chain's buffers before resizing. + CleanupRenderTarget(); g_pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0); CreateRenderTarget(); } From 1abb02fb67e44af8610cd2af94eb8344a30e056f Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 9 Mar 2020 14:20:59 +0100 Subject: [PATCH 326/384] Viewports: Fix for UWP on IME code moved back-end side (#2895, #2892) + Docking: Comments. --- examples/imgui_impl_win32.cpp | 4 ++++ imgui.h | 2 +- imgui_internal.h | 7 ++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 716709a3..a63fa464 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -529,6 +529,10 @@ float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd) // IME (Input Method Editor) basic support for e.g. Asian language users //-------------------------------------------------------------------------------------------------------- +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have Win32 functions +#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS +#endif + #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && !defined(__GNUC__) #define HAS_WIN32_IME 1 #include diff --git a/imgui.h b/imgui.h index b13f3535..881c91f7 100644 --- a/imgui.h +++ b/imgui.h @@ -2526,7 +2526,7 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_NoRendererClear = 1 << 5, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). ImGuiViewportFlags_TopMost = 1 << 6, // Platform Window: Display on top (for tooltips only). ImGuiViewportFlags_Minimized = 1 << 7, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. - ImGuiViewportFlags_NoAutoMerge = 1 << 8, // Platform Window: Avoid merging this widow into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). + ImGuiViewportFlags_NoAutoMerge = 1 << 8, // Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). ImGuiViewportFlags_CanHostOtherWindows = 1 << 9 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). }; diff --git a/imgui_internal.h b/imgui_internal.h index 2e82ed41..fbce3e64 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1053,7 +1053,7 @@ enum ImGuiDockNodeFlagsPrivate_ { // [Internal] ImGuiDockNodeFlags_DockSpace = 1 << 10, // Local, Saved // A dockspace is a node that occupy space within an existing user window. Otherwise the node is floating and create its own window. - ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local, Saved // + ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local, Saved // The central node has 2 main properties: stay visible when empty, only use "remaining" spaces from its neighbor. ImGuiDockNodeFlags_NoTabBar = 1 << 12, // Local, Saved // Tab bar is completely unavailable. No triangle in the corner to enable it back. ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local, Saved // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar) ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local, Saved // Disable window/docking menu (that one that appears instead of the collapse button) @@ -1987,7 +1987,8 @@ namespace ImGui // - The DockBuilderXXX functions are designed to _eventually_ become a public API, but it is too early to expose it and guarantee stability. // - Do not hold on ImGuiDockNode* pointers! They may be invalidated by any split/merge/remove operation and every frame. // - To create a DockSpace() node, make sure to set the ImGuiDockNodeFlags_DockSpace flag when calling DockBuilderAddNode(). - // You can create dockspace nodes (attached to a window) _or_ floating nodes (carry its own window) with this API. + // You can create dockspace nodes (attached to a window) _or_ floating nodes (carry its own window) with this API. + // - DockBuilderSplitNode() create 2 child nodes within 1 node. The initial node becomes a parent node. // - If you intend to split the node immediately after creation using DockBuilderSplitNode(), make sure // to call DockBuilderSetNodeSize() beforehand. If you don't, the resulting split sizes may not be reliable. // - Call DockBuilderFinish() after you are done. @@ -2000,7 +2001,7 @@ namespace ImGui IMGUI_API void DockBuilderRemoveNodeChildNodes(ImGuiID node_id); // Remove all split/hierarchy. All remaining docked windows will be re-docked to the root. IMGUI_API void DockBuilderSetNodePos(ImGuiID node_id, ImVec2 pos); IMGUI_API void DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size); - IMGUI_API ImGuiID DockBuilderSplitNode(ImGuiID node_id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir); + IMGUI_API ImGuiID DockBuilderSplitNode(ImGuiID node_id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir); // Create 2 child nodes in this parent node. IMGUI_API void DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs); IMGUI_API void DockBuilderCopyNode(ImGuiID src_node_id, ImGuiID dst_node_id, ImVector* out_node_remap_pairs); IMGUI_API void DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name); From 1d5612a05e274fc49277cd35648998c4463b1ab4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Mar 2020 17:05:35 +0100 Subject: [PATCH 327/384] Internal: Added two missing ImVec2 operators for consistency. Split up DragDropWithinSourceOrTarget ImVec2 *= ImVec2 to match ImVec2 * ImVec2, likewise with / --- imgui.cpp | 27 ++++++++++++++------------- imgui_internal.h | 11 +++++++---- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 267abd4d..bb6dd25f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3846,7 +3846,8 @@ void ImGui::NewFrame() g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr; g.DragDropAcceptIdCurr = 0; g.DragDropAcceptIdCurrRectSurface = FLT_MAX; - g.DragDropWithinSourceOrTarget = false; + g.DragDropWithinSource = false; + g.DragDropWithinTarget = false; // Update keyboard input state memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); @@ -4237,9 +4238,9 @@ void ImGui::EndFrame() // Drag and Drop: Fallback for source tooltip. This is not ideal but better than nothing. if (g.DragDropActive && g.DragDropSourceFrameCount < g.FrameCount) { - g.DragDropWithinSourceOrTarget = true; + g.DragDropWithinSource = true; SetTooltip("..."); - g.DragDropWithinSourceOrTarget = false; + g.DragDropWithinSource = false; } // End frame @@ -7459,7 +7460,7 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags toolt { ImGuiContext& g = *GImGui; - if (g.DragDropWithinSourceOrTarget) + if (g.DragDropWithinSource || g.DragDropWithinTarget) { // The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor) // In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor. @@ -9119,7 +9120,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) g.DragDropMouseButton = mouse_button; } g.DragDropSourceFrameCount = g.FrameCount; - g.DragDropWithinSourceOrTarget = true; + g.DragDropWithinSource = true; if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) { @@ -9146,7 +9147,7 @@ void ImGui::EndDragDropSource() { ImGuiContext& g = *GImGui; IM_ASSERT(g.DragDropActive); - IM_ASSERT(g.DragDropWithinSourceOrTarget && "Not after a BeginDragDropSource()?"); + IM_ASSERT(g.DragDropWithinSource && "Not after a BeginDragDropSource()?"); if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) EndTooltip(); @@ -9154,7 +9155,7 @@ void ImGui::EndDragDropSource() // Discard the drag if have not called SetDragDropPayload() if (g.DragDropPayload.DataFrameCount == -1) ClearDragDrop(); - g.DragDropWithinSourceOrTarget = false; + g.DragDropWithinSource = false; } // Use 'cond' to choose to submit payload on drag start or every frame @@ -9216,10 +9217,10 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) if (window->SkipItems) return false; - IM_ASSERT(g.DragDropWithinSourceOrTarget == false); + IM_ASSERT(g.DragDropWithinTarget == false); g.DragDropTargetRect = bb; g.DragDropTargetId = id; - g.DragDropWithinSourceOrTarget = true; + g.DragDropWithinTarget = true; return true; } @@ -9246,10 +9247,10 @@ bool ImGui::BeginDragDropTarget() if (g.DragDropPayload.SourceId == id) return false; - IM_ASSERT(g.DragDropWithinSourceOrTarget == false); + IM_ASSERT(g.DragDropWithinTarget == false); g.DragDropTargetRect = display_rect; g.DragDropTargetId = id; - g.DragDropWithinSourceOrTarget = true; + g.DragDropWithinTarget = true; return true; } @@ -9313,8 +9314,8 @@ void ImGui::EndDragDropTarget() { ImGuiContext& g = *GImGui; IM_ASSERT(g.DragDropActive); - IM_ASSERT(g.DragDropWithinSourceOrTarget); - g.DragDropWithinSourceOrTarget = false; + IM_ASSERT(g.DragDropWithinTarget); + g.DragDropWithinTarget = false; } //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 88191036..d31f00e9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -261,10 +261,12 @@ static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); } static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } -static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } -static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } +static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } +static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } +static inline ImVec2& operator*=(ImVec2& lhs, const ImVec2& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; return lhs; } +static inline ImVec2& operator/=(ImVec2& lhs, const ImVec2& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; return lhs; } static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z, lhs.w+rhs.w); } static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); } static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); } @@ -1128,7 +1130,8 @@ struct ImGuiContext // Drag and Drop bool DragDropActive; - bool DragDropWithinSourceOrTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block. + bool DragDropWithinSource; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag source. + bool DragDropWithinTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag target. ImGuiDragDropFlags DragDropSourceFlags; int DragDropSourceFrameCount; int DragDropMouseButton; @@ -1284,7 +1287,7 @@ struct ImGuiContext ForegroundDrawList._OwnerName = "##Foreground"; // Give it a name for debugging MouseCursor = ImGuiMouseCursor_Arrow; - DragDropActive = DragDropWithinSourceOrTarget = false; + DragDropActive = DragDropWithinSource = DragDropWithinTarget = false; DragDropSourceFlags = ImGuiDragDropFlags_None; DragDropSourceFrameCount = -1; DragDropMouseButton = -1; From 339ffd25a948bf1fd45a1896e045680b33920292 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 13 Mar 2020 18:42:10 +0100 Subject: [PATCH 328/384] Internals: Renamed ImBoolVector to ImBitVector, added low-level loose function to replicate the behavior include a help SetBitRange() function. --- imgui_draw.cpp | 32 +++++++++++++------------- imgui_internal.h | 39 +++++++++++++++++++++++--------- misc/freetype/README.md | 2 +- misc/freetype/imgui_freetype.cpp | 28 +++++++++++------------ 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1cd23042..d256c8d4 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1921,7 +1921,7 @@ struct ImFontBuildSrcData int DstIndex; // Index into atlas->Fonts[] and dst_tmp_array[] int GlyphsHighest; // Highest requested codepoint int GlyphsCount; // Glyph count (excluding missing glyphs and glyphs already set by an earlier source font) - ImBoolVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB) + ImBitVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB) ImVector GlyphsList; // Glyph codepoints list (flattened version of GlyphsMap) }; @@ -1931,19 +1931,19 @@ struct ImFontBuildDstData int SrcCount; // Number of source fonts targeting this destination font. int GlyphsHighest; int GlyphsCount; - ImBoolVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font. + ImBitVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font. }; -static void UnpackBoolVectorToFlatIndexList(const ImBoolVector* in, ImVector* out) +static void UnpackBitVectorToFlatIndexList(const ImBitVector* in, ImVector* out) { IM_ASSERT(sizeof(in->Storage.Data[0]) == sizeof(int)); - const int* it_begin = in->Storage.begin(); - const int* it_end = in->Storage.end(); - for (const int* it = it_begin; it < it_end; it++) - if (int entries_32 = *it) - for (int bit_n = 0; bit_n < 32; bit_n++) - if (entries_32 & (1u << bit_n)) - out->push_back((int)((it - it_begin) << 5) + bit_n); + const ImU32* it_begin = in->Storage.begin(); + const ImU32* it_end = in->Storage.end(); + for (const ImU32* it = it_begin; it < it_end; it++) + if (ImU32 entries_32 = *it) + for (ImU32 bit_n = 0; bit_n < 32; bit_n++) + if (entries_32 & ((ImU32)1 << bit_n)) + out->push_back((int)(((it - it_begin) << 5) + bit_n)); } bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) @@ -2004,14 +2004,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) { ImFontBuildSrcData& src_tmp = src_tmp_array[src_i]; ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; - src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1); + src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1); if (dst_tmp.GlyphsSet.Storage.empty()) - dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1); + dst_tmp.GlyphsSet.Create(dst_tmp.GlyphsHighest + 1); for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) for (unsigned int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) { - if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true) + if (dst_tmp.GlyphsSet.TestBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true) continue; if (!stbtt_FindGlyphIndex(&src_tmp.FontInfo, codepoint)) // It is actually in the font? continue; @@ -2019,8 +2019,8 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) // Add to avail set/counters src_tmp.GlyphsCount++; dst_tmp.GlyphsCount++; - src_tmp.GlyphsSet.SetBit(codepoint, true); - dst_tmp.GlyphsSet.SetBit(codepoint, true); + src_tmp.GlyphsSet.SetBit(codepoint); + dst_tmp.GlyphsSet.SetBit(codepoint); total_glyphs_count++; } } @@ -2030,7 +2030,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) { ImFontBuildSrcData& src_tmp = src_tmp_array[src_i]; src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount); - UnpackBoolVectorToFlatIndexList(&src_tmp.GlyphsSet, &src_tmp.GlyphsList); + UnpackBitVectorToFlatIndexList(&src_tmp.GlyphsSet, &src_tmp.GlyphsList); src_tmp.GlyphsSet.Clear(); IM_ASSERT(src_tmp.GlyphsList.Size == src_tmp.GlyphsCount); } diff --git a/imgui_internal.h b/imgui_internal.h index d31f00e9..eed5d82e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -73,7 +73,7 @@ Index of this file: // Forward declarations //----------------------------------------------------------------------------- -struct ImBoolVector; // Store 1-bit per value +struct ImBitVector; // Store 1-bit per value struct ImRect; // An axis-aligned rectangle (2 points) struct ImDrawDataBuilder; // Helper to build a ImDrawData instance struct ImDrawListSharedData; // Data shared between all ImDrawList instances @@ -204,7 +204,8 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer // - Helpers: ImVec2/ImVec4 operators // - Helpers: Maths // - Helpers: Geometry -// - Helper: ImBoolVector +// - Helpers: Bit arrays +// - Helper: ImBitVector // - Helper: ImPool<> // - Helper: ImChunkStream<> //----------------------------------------------------------------------------- @@ -350,16 +351,32 @@ IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; } IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy); -// Helper: ImBoolVector -// Store 1-bit per value. Note that Resize() currently clears the whole vector. -struct IMGUI_API ImBoolVector +// Helpers: Bit arrays +inline bool ImBitArrayTestBit(const ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); return (arr[n >> 5] & mask) != 0; } +inline void ImBitArrayClearBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] &= ~mask; } +inline void ImBitArraySetBit(ImU32* arr, int n) { ImU32 mask = (ImU32)1 << (n & 31); arr[n >> 5] |= mask; } +inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) { - ImVector Storage; - ImBoolVector() { } - void Resize(int sz) { Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } - void Clear() { Storage.clear(); } - bool GetBit(int n) const { int off = (n >> 5); int mask = 1 << (n & 31); return (Storage[off] & mask) != 0; } - void SetBit(int n, bool v) { int off = (n >> 5); int mask = 1 << (n & 31); if (v) Storage[off] |= mask; else Storage[off] &= ~mask; } + while (n <= n2) + { + int a_mod = (n & 31); + int b_mod = ((n2 >= n + 31) ? 31 : (n2 & 31)) + 1; + ImU32 mask = (ImU32)(((ImU64)1 << b_mod) - 1) & ~(ImU32)(((ImU64)1 << a_mod) - 1); + arr[n >> 5] |= mask; + n = (n + 32) & ~31; + } +} + +// Helper: ImBitVector +// Store 1-bit per value. +struct IMGUI_API ImBitVector +{ + ImVector Storage; + void Create(int sz) { Storage.resize((sz + 31) >> 5); memset(Storage.Data, 0, (size_t)Storage.Size * sizeof(Storage.Data[0])); } + void Clear() { Storage.clear(); } + bool TestBit(int n) const { IM_ASSERT(n < (Storage.Size << 5)); return ImBitArrayTestBit(Storage.Data, n); } + void SetBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArraySetBit(Storage.Data, n); } + void ClearBit(int n) { IM_ASSERT(n < (Storage.Size << 5)); ImBitArrayClearBit(Storage.Data, n); } }; // Helper: ImPool<> diff --git a/misc/freetype/README.md b/misc/freetype/README.md index 87b27364..e565097a 100644 --- a/misc/freetype/README.md +++ b/misc/freetype/README.md @@ -5,7 +5,7 @@ Build font atlases using FreeType instead of stb_truetype (which is the default ### Usage -1. Get latest FreeType binaries or build yourself (under Windows you may use vcpkg with `vcpkg install freetype`). +1. Get latest FreeType binaries or build yourself (under Windows you may use vcpkg with `vcpkg install freetype`, `vcpkg integrate install`). 2. Add imgui_freetype.h/cpp alongside your imgui sources. 3. Include imgui_freetype.h after imgui.h. 4. Call `ImGuiFreeType::BuildFontAtlas()` *BEFORE* calling `ImFontAtlas::GetTexDataAsRGBA32()` or `ImFontAtlas::Build()` (so normal Build() won't be called): diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index fb2b399d..be418359 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -300,7 +300,7 @@ struct ImFontBuildSrcDataFT int DstIndex; // Index into atlas->Fonts[] and dst_tmp_array[] int GlyphsHighest; // Highest requested codepoint int GlyphsCount; // Glyph count (excluding missing glyphs and glyphs already set by an earlier source font) - ImBoolVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB) + ImBitVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB) ImVector GlyphsList; }; @@ -310,7 +310,7 @@ struct ImFontBuildDstDataFT int SrcCount; // Number of source fonts targeting this destination font. int GlyphsHighest; int GlyphsCount; - ImBoolVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font. + ImBitVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font. }; bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, unsigned int extra_flags) @@ -370,14 +370,14 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns { ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i]; ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex]; - src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1); + src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1); if (dst_tmp.GlyphsSet.Storage.empty()) - dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1); + dst_tmp.GlyphsSet.Create(dst_tmp.GlyphsHighest + 1); for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2) for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++) { - if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite) + if (dst_tmp.GlyphsSet.TestBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite) continue; uint32_t glyph_index = FT_Get_Char_Index(src_tmp.Font.Face, codepoint); // It is actually in the font? (FIXME-OPT: We are not storing the glyph_index..) if (glyph_index == 0) @@ -386,8 +386,8 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns // Add to avail set/counters src_tmp.GlyphsCount++; dst_tmp.GlyphsCount++; - src_tmp.GlyphsSet.SetBit(codepoint, true); - dst_tmp.GlyphsSet.SetBit(codepoint, true); + src_tmp.GlyphsSet.SetBit(codepoint); + dst_tmp.GlyphsSet.SetBit(codepoint); total_glyphs_count++; } } @@ -398,13 +398,13 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i]; src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount); - IM_ASSERT(sizeof(src_tmp.GlyphsSet.Storage.Data[0]) == sizeof(int)); - const int* it_begin = src_tmp.GlyphsSet.Storage.begin(); - const int* it_end = src_tmp.GlyphsSet.Storage.end(); - for (const int* it = it_begin; it < it_end; it++) - if (int entries_32 = *it) - for (int bit_n = 0; bit_n < 32; bit_n++) - if (entries_32 & (1 << bit_n)) + IM_ASSERT(sizeof(src_tmp.GlyphsSet.Storage.Data[0]) == sizeof(ImU32)); + const ImU32* it_begin = src_tmp.GlyphsSet.Storage.begin(); + const ImU32* it_end = src_tmp.GlyphsSet.Storage.end(); + for (const ImU32* it = it_begin; it < it_end; it++) + if (ImU32 entries_32 = *it) + for (ImU32 bit_n = 0; bit_n < 32; bit_n++) + if (entries_32 & ((ImU32)1 << bit_n)) { ImFontBuildSrcGlyphFT src_glyph; memset(&src_glyph, 0, sizeof(src_glyph)); From 75a65f6fb040f02a1fea6527dadfa7601038c859 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 16 Mar 2020 10:04:36 +0200 Subject: [PATCH 329/384] CI: Test build with large indices, obsolete functions disabled and demo/metrics windows disabled. + amend notes --- .github/workflows/build.yml | 25 +++++++++++++++++++++++++ docs/CHANGELOG.txt | 3 +++ docs/TODO.txt | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16ab157d..7718196e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -203,6 +203,31 @@ jobs: echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + - name: Build example_null (with large ImDrawIdx) + run: | + echo '#define ImDrawIdx unsigned int' > example_single_file.cpp + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + + - name: Build example_null (with IMGUI_DISABLE_OBSOLETE_FUNCTIONS) + run: | + echo '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' > example_single_file.cpp + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + + - name: Build example_null (with IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_METRICS_WINDOW) + run: | + echo '#define IMGUI_DISABLE_DEMO_WINDOWS' > example_single_file.cpp + echo '#define IMGUI_DISABLE_METRICS_WINDOW' >> example_single_file.cpp + echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp + echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp + echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp + g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b41a1800..f37c6883 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -58,6 +58,9 @@ Other Changes: window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. - Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. +- CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building + SDL+Metal example, and more compile-time imconfig.h settings: disabling obsolete functions, + enabling 32-bit draw indices, enabling 32-bit ImWchar, disabling demo/metrics, etc. [@rokups] - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). Those functions makes it easier for example apps to support hi-dpi features without setting up diff --git a/docs/TODO.txt b/docs/TODO.txt index 9ba3a984..8d50dbe2 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -14,8 +14,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: calling SetNextWindowSize() every frame with <= 0 doesn't do anything, may be useful to allow (particularly when used for a single axis). (#690) - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. perhaps a lightweight explicit cleanup pass. - window: auto-fit feedback loop when user relies on any dynamic layout (window width multiplier, column) appears weird to end-user. clarify. - - window: allow resizing of child windows (possibly given min/max for each axis?.) - - window: background options for child windows, border option (disable rounding). - window: begin with *p_open == false could return false. - window: get size/pos helpers given names (see discussion in #249) - window: a collapsed window can be stuck behind the main menu bar? @@ -31,6 +29,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: the size_on_first_use path of Begin() can probably be removed - window/size: manually triggered auto-fit (double-click on grip) shouldn't resize window down to viewport size? - window/opt: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. -> this may require enforcing that it is illegal to submit contents if Begin returns false. + - window/child: background options for child windows, border option (disable rounding). + - window/child: allow resizing of child windows (possibly given min/max for each axis?.) - window/child: the first draw command of a child window could be moved into the current draw command of the parent window (unless child+tooltip?). - window/child: border could be emitted in parent as well. - window/child: allow SetNextWindowContentSize() to work on child windows. From 2fd411a83ee639d0faf64e2401e41756eb3ed583 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 15 Mar 2020 22:27:04 +0100 Subject: [PATCH 330/384] Support custom stb_rect_pack filename in Freetype (#3062) Copies the #define magic from imgui_draw.cpp to the imgui_freetype implementation to allow the use of a custom stb rect_pack here as well. References: fe5347ef94d7dc648c237323cc9e257aff6ab917 --- docs/CHANGELOG.txt | 2 ++ misc/freetype/imgui_freetype.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f37c6883..703e48a5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -57,6 +57,8 @@ Other Changes: - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. +- Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive + in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult] - Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. - CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building SDL+Metal example, and more compile-time imconfig.h settings: disabling obsolete functions, diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index be418359..93a56163 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -278,12 +278,18 @@ namespace } } -#ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) -#define STBRP_ASSERT(x) IM_ASSERT(x) +#ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) +#ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +#define STBRP_ASSERT(x) IM_ASSERT(x) #define STBRP_STATIC #define STB_RECT_PACK_IMPLEMENTATION +#endif +#ifdef IMGUI_STB_RECT_PACK_FILENAME +#include IMGUI_STB_RECT_PACK_FILENAME +#else #include "imstb_rectpack.h" #endif +#endif struct ImFontBuildSrcGlyphFT { From 0bbbbe0f68c5cb6cc3d09141fbe1c974325c3ca7 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Mar 2020 22:36:51 +0100 Subject: [PATCH 331/384] Internal: Refactor: Moved RenderArrow, RenderBullet, RenderCheckMark to imgui_draw.cpp, changed RenderCheckMark to avoid using ImGui context --- imgui.cpp | 60 +++----------------------------------------- imgui_draw.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++--- imgui_internal.h | 2 +- imgui_widgets.cpp | 4 +-- 4 files changed, 66 insertions(+), 63 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bb6dd25f..c1b429de 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2542,8 +2542,9 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx) //----------------------------------------------------------------------------- // [SECTION] RENDER HELPERS -// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change. -// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state. +// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change, +// we need a nicer separation between low-level functions and high-level functions relying on the ImGui context. +// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: context. //----------------------------------------------------------------------------- const char* ImGui::FindRenderedTextEnd(const char* text, const char* text_end) @@ -2753,61 +2754,6 @@ void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding) } } -// Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state -void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale) -{ - const float h = draw_list->_Data->FontSize * 1.00f; - float r = h * 0.40f * scale; - ImVec2 center = pos + ImVec2(h * 0.50f, h * 0.50f * scale); - - ImVec2 a, b, c; - switch (dir) - { - case ImGuiDir_Up: - case ImGuiDir_Down: - if (dir == ImGuiDir_Up) r = -r; - a = ImVec2(+0.000f,+0.750f) * r; - b = ImVec2(-0.866f,-0.750f) * r; - c = ImVec2(+0.866f,-0.750f) * r; - break; - case ImGuiDir_Left: - case ImGuiDir_Right: - if (dir == ImGuiDir_Left) r = -r; - a = ImVec2(+0.750f,+0.000f) * r; - b = ImVec2(-0.750f,+0.866f) * r; - c = ImVec2(-0.750f,-0.866f) * r; - break; - case ImGuiDir_None: - case ImGuiDir_COUNT: - IM_ASSERT(0); - break; - } - draw_list->AddTriangleFilled(center + a, center + b, center + c, col); -} - -void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col) -{ - draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8); -} - -void ImGui::RenderCheckMark(ImVec2 pos, ImU32 col, float sz) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - - float thickness = ImMax(sz / 5.0f, 1.0f); - sz -= thickness*0.5f; - pos += ImVec2(thickness*0.25f, thickness*0.25f); - - float third = sz / 3.0f; - float bx = pos.x + third; - float by = pos.y + sz - third*0.5f; - window->DrawList->PathLineTo(ImVec2(bx - third, by - third)); - window->DrawList->PathLineTo(ImVec2(bx, by)); - window->DrawList->PathLineTo(ImVec2(bx + third*2, by - third*2)); - window->DrawList->PathStroke(col, false, thickness); -} - void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags) { ImGuiContext& g = *GImGui; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index d256c8d4..a7927108 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -16,7 +16,7 @@ Index of this file: // [SECTION] ImFontAtlas glyph ranges helpers // [SECTION] ImFontGlyphRangesBuilder // [SECTION] ImFont -// [SECTION] Internal Render Helpers +// [SECTION] ImGui Internal Render Helpers // [SECTION] Decompression code // [SECTION] Default font data (ProggyClean.ttf) @@ -3161,13 +3161,70 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col } //----------------------------------------------------------------------------- -// [SECTION] Internal Render Helpers -// (progressively moved from imgui.cpp to here when they are redesigned to stop accessing ImGui global state) +// [SECTION] ImGui Internal Render Helpers //----------------------------------------------------------------------------- +// Vaguely redesigned to stop accessing ImGui global state: +// - RenderArrow() +// - RenderBullet() +// - RenderCheckMark() // - RenderMouseCursor() // - RenderArrowPointingAt() // - RenderRectFilledRangeH() //----------------------------------------------------------------------------- +// Function in need of a redesign (legacy mess) +//----------------------------------------------------------------------------- + +// Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state +void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale) +{ + const float h = draw_list->_Data->FontSize * 1.00f; + float r = h * 0.40f * scale; + ImVec2 center = pos + ImVec2(h * 0.50f, h * 0.50f * scale); + + ImVec2 a, b, c; + switch (dir) + { + case ImGuiDir_Up: + case ImGuiDir_Down: + if (dir == ImGuiDir_Up) r = -r; + a = ImVec2(+0.000f, +0.750f) * r; + b = ImVec2(-0.866f, -0.750f) * r; + c = ImVec2(+0.866f, -0.750f) * r; + break; + case ImGuiDir_Left: + case ImGuiDir_Right: + if (dir == ImGuiDir_Left) r = -r; + a = ImVec2(+0.750f, +0.000f) * r; + b = ImVec2(-0.750f, +0.866f) * r; + c = ImVec2(-0.750f, -0.866f) * r; + break; + case ImGuiDir_None: + case ImGuiDir_COUNT: + IM_ASSERT(0); + break; + } + draw_list->AddTriangleFilled(center + a, center + b, center + c, col); +} + +void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col) +{ + draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8); +} + +void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz) +{ + float thickness = ImMax(sz / 5.0f, 1.0f); + sz -= thickness * 0.5f; + pos += ImVec2(thickness * 0.25f, thickness * 0.25f); + + float third = sz / 3.0f; + float bx = pos.x + third; + float by = pos.y + sz - third * 0.5f; + draw_list->PathLineTo(ImVec2(bx - third, by - third)); + draw_list->PathLineTo(ImVec2(bx, by)); + draw_list->PathLineTo(ImVec2(bx + third * 2.0f, by - third * 2.0f)); + draw_list->PathStroke(col, false, thickness); +} void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) { diff --git a/imgui_internal.h b/imgui_internal.h index eed5d82e..d544fafe 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1813,7 +1813,6 @@ namespace ImGui IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); - IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col, float sz); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL); @@ -1821,6 +1820,7 @@ namespace ImGui // Render helpers (those functions don't access any ImGui state!) IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col); + IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d22c1fa4..1815df49 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1044,7 +1044,7 @@ bool ImGui::Checkbox(const char* label, bool* v) else if (*v) { const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); - RenderCheckMark(check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad*2.0f); + RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad*2.0f); } if (g.LogEnabled) @@ -6433,7 +6433,7 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo PopStyleColor(); } if (selected) - RenderCheckMark(pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); + RenderCheckMark(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.40f, g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); } IMGUI_TEST_ENGINE_ITEM_INFO(window->DC.LastItemId, label, window->DC.ItemFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0)); From bdd31ec4dbb6ec415168722392c4dae91e27b7d0 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 18 Mar 2020 22:46:12 +0100 Subject: [PATCH 332/384] Internal: Refactor: Moved RenderColorRectWithAlphaCheckerboard() to imgui_draw.cpp, tweaked signature. --- imgui.cpp | 11 +++++++++- imgui_draw.cpp | 38 ++++++++++++++++++++++++++++++++++ imgui_internal.h | 5 ++++- imgui_widgets.cpp | 52 +++-------------------------------------------- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c1b429de..7a0954a1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1791,10 +1791,19 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e } //----------------------------------------------------------------------------- -// [SECTION] MISC HELPERS/UTILTIES (Color functions) +// [SECTION] MISC HELPERS/UTILITIES (Color functions) // Note: The Convert functions are early design which are not consistent with other API. //----------------------------------------------------------------------------- +IMGUI_API ImU32 ImAlphaBlendColors(ImU32 col_a, ImU32 col_b) +{ + float t = ((col_b >> IM_COL32_A_SHIFT) & 0xFF) / 255.f; + int r = ImLerp((int)(col_a >> IM_COL32_R_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_R_SHIFT) & 0xFF, t); + int g = ImLerp((int)(col_a >> IM_COL32_G_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_G_SHIFT) & 0xFF, t); + int b = ImLerp((int)(col_a >> IM_COL32_B_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_B_SHIFT) & 0xFF, t); + return IM_COL32(r, g, b, 0xFF); +} + ImVec4 ImGui::ColorConvertU32ToFloat4(ImU32 in) { float s = 1.0f/255.0f; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a7927108..87c81edc 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3172,6 +3172,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderRectFilledRangeH() //----------------------------------------------------------------------------- // Function in need of a redesign (legacy mess) +// - RenderColorRectWithAlphaCheckerboard() //----------------------------------------------------------------------------- // Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state @@ -3329,6 +3330,43 @@ void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, Im draw_list->PathFillConvex(col); } +// Helper for ColorPicker4() +// NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that. +// Spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding alltogether. +// FIXME: uses ImGui::GetColorU32 +void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, ImVec2 grid_off, float rounding, int rounding_corners_flags) +{ + if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF) + { + ImU32 col_bg1 = ImGui::GetColorU32(ImAlphaBlendColors(IM_COL32(204, 204, 204, 255), col)); + ImU32 col_bg2 = ImGui::GetColorU32(ImAlphaBlendColors(IM_COL32(128, 128, 128, 255), col)); + draw_list->AddRectFilled(p_min, p_max, col_bg1, rounding, rounding_corners_flags); + + int yi = 0; + for (float y = p_min.y + grid_off.y; y < p_max.y; y += grid_step, yi++) + { + float y1 = ImClamp(y, p_min.y, p_max.y), y2 = ImMin(y + grid_step, p_max.y); + if (y2 <= y1) + continue; + for (float x = p_min.x + grid_off.x + (yi & 1) * grid_step; x < p_max.x; x += grid_step * 2.0f) + { + float x1 = ImClamp(x, p_min.x, p_max.x), x2 = ImMin(x + grid_step, p_max.x); + if (x2 <= x1) + continue; + int rounding_corners_flags_cell = 0; + if (y1 <= p_min.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopRight; } + if (y2 >= p_max.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotRight; } + rounding_corners_flags_cell &= rounding_corners_flags; + draw_list->AddRectFilled(ImVec2(x1, y1), ImVec2(x2, y2), col_bg2, rounding_corners_flags_cell ? rounding : 0.0f, rounding_corners_flags_cell); + } + } + } + else + { + draw_list->AddRectFilled(p_min, p_max, col, rounding, rounding_corners_flags); + } +} + //----------------------------------------------------------------------------- // [SECTION] Decompression code //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index d544fafe..bb13be00 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -218,6 +218,9 @@ IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 static inline ImU32 ImHash(const void* data, int size, ImU32 seed = 0) { return size ? ImHashData(data, (size_t)size, seed) : ImHashStr((const char*)data, 0, seed); } // [moved to ImHashStr/ImHashData in 1.68] #endif +// Helpers: Color Blending +IMGUI_API ImU32 ImAlphaBlendColors(ImU32 col_a, ImU32 col_b); + // Helpers: Bit manipulation static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & (v - 1)) == 0; } static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } @@ -1812,7 +1815,7 @@ namespace ImGui IMGUI_API void RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known); IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); - IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); + IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1815df49..938e94cb 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4493,52 +4493,6 @@ bool ImGui::ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags fl return true; } -static inline ImU32 ImAlphaBlendColor(ImU32 col_a, ImU32 col_b) -{ - float t = ((col_b >> IM_COL32_A_SHIFT) & 0xFF) / 255.f; - int r = ImLerp((int)(col_a >> IM_COL32_R_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_R_SHIFT) & 0xFF, t); - int g = ImLerp((int)(col_a >> IM_COL32_G_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_G_SHIFT) & 0xFF, t); - int b = ImLerp((int)(col_a >> IM_COL32_B_SHIFT) & 0xFF, (int)(col_b >> IM_COL32_B_SHIFT) & 0xFF, t); - return IM_COL32(r, g, b, 0xFF); -} - -// Helper for ColorPicker4() -// NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that. -// I spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding alltogether. -void ImGui::RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, ImVec2 grid_off, float rounding, int rounding_corners_flags) -{ - ImGuiWindow* window = GetCurrentWindow(); - if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF) - { - ImU32 col_bg1 = GetColorU32(ImAlphaBlendColor(IM_COL32(204,204,204,255), col)); - ImU32 col_bg2 = GetColorU32(ImAlphaBlendColor(IM_COL32(128,128,128,255), col)); - window->DrawList->AddRectFilled(p_min, p_max, col_bg1, rounding, rounding_corners_flags); - - int yi = 0; - for (float y = p_min.y + grid_off.y; y < p_max.y; y += grid_step, yi++) - { - float y1 = ImClamp(y, p_min.y, p_max.y), y2 = ImMin(y + grid_step, p_max.y); - if (y2 <= y1) - continue; - for (float x = p_min.x + grid_off.x + (yi & 1) * grid_step; x < p_max.x; x += grid_step * 2.0f) - { - float x1 = ImClamp(x, p_min.x, p_max.x), x2 = ImMin(x + grid_step, p_max.x); - if (x2 <= x1) - continue; - int rounding_corners_flags_cell = 0; - if (y1 <= p_min.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_TopRight; } - if (y2 >= p_max.y) { if (x1 <= p_min.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotLeft; if (x2 >= p_max.x) rounding_corners_flags_cell |= ImDrawCornerFlags_BotRight; } - rounding_corners_flags_cell &= rounding_corners_flags; - window->DrawList->AddRectFilled(ImVec2(x1,y1), ImVec2(x2,y2), col_bg2, rounding_corners_flags_cell ? rounding : 0.0f, rounding_corners_flags_cell); - } - } - } - else - { - window->DrawList->AddRectFilled(p_min, p_max, col, rounding, rounding_corners_flags); - } -} - // Helper for ColorPicker4() static void RenderArrowsForVerticalBar(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, float bar_w, float alpha) { @@ -4909,7 +4863,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl { float alpha = ImSaturate(col[3]); ImRect bar1_bb(bar1_pos_x, picker_pos.y, bar1_pos_x + bars_width, picker_pos.y + sv_picker_size); - RenderColorRectWithAlphaCheckerboard(bar1_bb.Min, bar1_bb.Max, 0, bar1_bb.GetWidth() / 2.0f, ImVec2(0.0f, 0.0f)); + RenderColorRectWithAlphaCheckerboard(draw_list, bar1_bb.Min, bar1_bb.Max, 0, bar1_bb.GetWidth() / 2.0f, ImVec2(0.0f, 0.0f)); draw_list->AddRectFilledMultiColor(bar1_bb.Min, bar1_bb.Max, user_col32_striped_of_alpha, user_col32_striped_of_alpha, user_col32_striped_of_alpha & ~IM_COL32_A_MASK, user_col32_striped_of_alpha & ~IM_COL32_A_MASK); float bar1_line_y = IM_ROUND(picker_pos.y + (1.0f - alpha) * sv_picker_size); RenderFrameBorder(bar1_bb.Min, bar1_bb.Max, 0.0f); @@ -4973,7 +4927,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl if ((flags & ImGuiColorEditFlags_AlphaPreviewHalf) && col_rgb.w < 1.0f) { float mid_x = IM_ROUND((bb_inner.Min.x + bb_inner.Max.x) * 0.5f); - RenderColorRectWithAlphaCheckerboard(ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col_rgb), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight| ImDrawCornerFlags_BotRight); + RenderColorRectWithAlphaCheckerboard(window->DrawList, ImVec2(bb_inner.Min.x + grid_step, bb_inner.Min.y), bb_inner.Max, GetColorU32(col_rgb), grid_step, ImVec2(-grid_step + off, off), rounding, ImDrawCornerFlags_TopRight| ImDrawCornerFlags_BotRight); window->DrawList->AddRectFilled(bb_inner.Min, ImVec2(mid_x, bb_inner.Max.y), GetColorU32(col_rgb_without_alpha), rounding, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotLeft); } else @@ -4981,7 +4935,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl // Because GetColorU32() multiplies by the global style Alpha and we don't want to display a checkerboard if the source code had no alpha ImVec4 col_source = (flags & ImGuiColorEditFlags_AlphaPreview) ? col_rgb : col_rgb_without_alpha; if (col_source.w < 1.0f) - RenderColorRectWithAlphaCheckerboard(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), grid_step, ImVec2(off, off), rounding); + RenderColorRectWithAlphaCheckerboard(window->DrawList, bb_inner.Min, bb_inner.Max, GetColorU32(col_source), grid_step, ImVec2(off, off), rounding); else window->DrawList->AddRectFilled(bb_inner.Min, bb_inner.Max, GetColorU32(col_source), rounding, ImDrawCornerFlags_All); } From ac5ffffc23c3ce2130ea6e010b5f6795d32512a3 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 18 Mar 2020 09:26:51 +0200 Subject: [PATCH 333/384] CI: Test builds with freetype on linux. --- .github/workflows/build.yml | 7 ++++++- examples/example_null/Makefile | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7718196e..ee5591ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -166,7 +166,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y libglfw3-dev libsdl2-dev gcc-multilib g++-multilib + sudo apt-get install -y libglfw3-dev libsdl2-dev gcc-multilib g++-multilib libfreetype6-dev - name: Build example_null (extra warnings, gcc 32-bit) run: | @@ -188,6 +188,11 @@ jobs: make -C examples/example_null clean CXXFLAGS="$CXXFLAGS -m64 -Werror" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + - name: Build example_null (freetype) + run: | + make -C examples/example_null clean + make -C examples/example_null WITH_FREETYPE=1 + - name: Build example_null (single file build) run: | echo '#define IMGUI_IMPLEMENTATION' > example_single_file.cpp diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 7d39e824..6bc69b81 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -5,6 +5,7 @@ EXE = example_null EXTRA_WARNINGS ?= 0 +WITH_FREETYPE ?= 0 SOURCES = main.cpp SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) @@ -19,6 +20,13 @@ ifeq ($(EXTRA_WARNINGS), 1) CXXFLAGS += -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros endif +# We use the WITH_FREETYPE flag on our CI setup to test misc/freetype/imgui_freetype.cpp font rasterizer +ifeq ($(WITH_FREETYPE), 1) + SOURCES += ../../misc/freetype/imgui_freetype.cpp + CXXFLAGS += $(shell pkg-config --cflags freetype2) + LIBS += $(shell pkg-config --libs freetype2) +endif + ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM ##--------------------------------------------------------------------- @@ -60,6 +68,9 @@ endif %.o:../../%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< +%.o:../../misc/freetype/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + all: $(EXE) @echo Build complete for $(ECHO_MESSAGE) From d8824f9a9abffecf11f389644646df2d94fda66e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Mar 2020 11:10:58 +0100 Subject: [PATCH 334/384] CI: Clarify purpose of example_null, Changelog --- .github/workflows/build.yml | 14 +++++++------- docs/CHANGELOG.txt | 4 ++-- examples/README.txt | 5 ++++- examples/example_null/Makefile | 22 ++++++++++++++-------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee5591ad..d68c8da9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: # Not using matrix here because it would inflate job count too much. Check out and setup is done for every job and that makes build times way too long. - name: Build example_null (extra warnings, mingw 64-bit) - run: mingw32-make -C examples/example_null EXTRA_WARNINGS=1 + run: mingw32-make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, msvc 64-bit) shell: cmd @@ -171,22 +171,22 @@ jobs: - name: Build example_null (extra warnings, gcc 32-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m32 -Werror" make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m32 -Werror" make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, gcc 64-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m64 -Werror" make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m64 -Werror" make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, clang 32-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m32 -Werror" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m32 -Werror" CXX=clang++ make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (extra warnings, clang 64-bit) run: | make -C examples/example_null clean - CXXFLAGS="$CXXFLAGS -m64 -Werror" CXX=clang++ make -C examples/example_null EXTRA_WARNINGS=1 + CXXFLAGS="$CXXFLAGS -m64 -Werror" CXX=clang++ make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (freetype) run: | @@ -260,7 +260,7 @@ jobs: brew install sdl2 - name: Build example_null (extra warnings, clang 64-bit) - run: make -C examples/example_null EXTRA_WARNINGS=1 + run: make -C examples/example_null WITH_EXTRA_WARNINGS=1 - name: Build example_null (single file build) run: | @@ -358,6 +358,6 @@ jobs: exit 0 fi cd examples/example_null - pvs-studio-analyzer trace -- make EXTRA_WARNINGS=1 + pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1 pvs-studio-analyzer analyze -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log plog-converter -a 'GA:1,2;OP:1' -t errorfile -w pvs-studio.log diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 703e48a5..c5d70d0b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -61,8 +61,8 @@ Other Changes: in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult] - Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. - CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building - SDL+Metal example, and more compile-time imconfig.h settings: disabling obsolete functions, - enabling 32-bit draw indices, enabling 32-bit ImWchar, disabling demo/metrics, etc. [@rokups] + SDL+Metal example, building imgui_freetype.cpp, more compile-time imconfig.h settings: disabling + obsolete functions, enabling 32-bit ImDrawIdx, enabling 32-bit ImWchar, disabling demo. [@rokups] - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). Those functions makes it easier for example apps to support hi-dpi features without setting up diff --git a/examples/README.txt b/examples/README.txt index 146d79ee..75d97729 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -153,7 +153,7 @@ Those will allow you to create portable applications and will solve and abstract --------------------------------------- Building: - Unfortunately in 2018 it is still tedious to create and maintain portable build files using external + Unfortunately in 2020 it is still tedious to create and maintain portable build files using external libraries (the kind we're using here to create a window and render 3D triangles) without relying on third party software. For most examples here I choose to provide: - Makefiles for Linux/OSX @@ -164,6 +164,9 @@ Building: You can probably just import the imgui_impl_xxx.cpp/.h files into your own codebase or compile those directly with a command-line compiler. + If you are interested in using Cmake to build and links examples, see: + https://github.com/ocornut/imgui/pull/1713 and https://github.com/ocornut/imgui/pull/3027 + example_allegro5/ Allegro 5 example. diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 6bc69b81..0ccee11b 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -2,10 +2,15 @@ # Cross Platform Makefile # Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X # +# Important: This is a "null back-end" application, with no visible output or interaction! +# This is used for testing purpose and continuous integration, and has little use for end-user. +# -EXE = example_null -EXTRA_WARNINGS ?= 0 +# Options +WITH_EXTRA_WARNINGS ?= 0 WITH_FREETYPE ?= 0 + +EXE = example_null SOURCES = main.cpp SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) @@ -15,12 +20,13 @@ CXXFLAGS += -I../ -I../../ CXXFLAGS += -g -Wall -Wformat LIBS = -# We use the EXTRA_WARNINGS flag on our CI setup to eagerly catch zealous warnings -ifeq ($(EXTRA_WARNINGS), 1) +# We use the WITH_EXTRA_WARNINGS flag on our CI setup to eagerly catch zealous warnings +ifeq ($(WITH_EXTRA_WARNINGS), 1) CXXFLAGS += -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros endif -# We use the WITH_FREETYPE flag on our CI setup to test misc/freetype/imgui_freetype.cpp font rasterizer +# We use the WITH_FREETYPE flag on our CI setup to test compiling misc/freetype/imgui_freetype.cpp +# (only supported on Linux, and note that the imgui_freetype code currently won't be executed) ifeq ($(WITH_FREETYPE), 1) SOURCES += ../../misc/freetype/imgui_freetype.cpp CXXFLAGS += $(shell pkg-config --cflags freetype2) @@ -33,7 +39,7 @@ endif ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" - ifneq ($(EXTRA_WARNINGS), 0) + ifneq ($(WITH_EXTRA_WARNINGS), 0) CXXFLAGS += -Wextra -pedantic endif CFLAGS = $(CXXFLAGS) @@ -41,7 +47,7 @@ endif ifeq ($(UNAME_S), Darwin) #APPLE ECHO_MESSAGE = "Mac OS X" - ifneq ($(EXTRA_WARNINGS), 0) + ifneq ($(WITH_EXTRA_WARNINGS), 0) CXXFLAGS += -Weverything -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-padded -Wno-c++11-long-long endif CFLAGS = $(CXXFLAGS) @@ -49,7 +55,7 @@ endif ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) ECHO_MESSAGE = "MinGW" - ifneq ($(EXTRA_WARNINGS), 0) + ifneq ($(WITH_EXTRA_WARNINGS), 0) CXXFLAGS += -Wextra -pedantic endif CFLAGS = $(CXXFLAGS) From ccf0cc85840a5edbeb7c4450cfd67949d0534512 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Mar 2020 12:24:32 +0100 Subject: [PATCH 335/384] Added ImGuiKeyModFlags. Added additional checks in EndFrame() to verify that io.KeyXXX values have not been tampered with between NewFrame() and EndFrame(). --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 21 ++++++++++++++++++++- imgui.h | 12 ++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c5d70d0b..96d02a88 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -57,6 +57,8 @@ Other Changes: - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. +- Misc: Added additional checks in EndFrame() to verify that io.KeyXXX values have not been + tampered with between NewFrame() and EndFrame(). - Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult] - Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. diff --git a/imgui.cpp b/imgui.cpp index 7a0954a1..d7872164 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3704,6 +3704,17 @@ static void NewFrameSanityChecks() g.IO.ConfigWindowsResizeFromEdges = false; } +static ImGuiKeyModFlags GetMergedKeyModFlags() +{ + ImGuiContext& g = *GImGui; + ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None; + if (g.IO.KeyCtrl) { key_mod_flags |= ImGuiKeyModFlags_Ctrl; } + if (g.IO.KeyShift) { key_mod_flags |= ImGuiKeyModFlags_Shift; } + if (g.IO.KeyAlt) { key_mod_flags |= ImGuiKeyModFlags_Alt; } + if (g.IO.KeySuper) { key_mod_flags |= ImGuiKeyModFlags_Super; } + return key_mod_flags; +} + void ImGui::NewFrame() { IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?"); @@ -3805,6 +3816,8 @@ void ImGui::NewFrame() g.DragDropWithinTarget = false; // Update keyboard input state + // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools + g.IO.KeyMods = GetMergedKeyModFlags(); memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f; @@ -6720,9 +6733,15 @@ bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, si static void ImGui::ErrorCheckEndFrame() { + ImGuiContext& g = *GImGui; + + // Verify that io.KeyXXX fields haven't been tampered with. Key mods shoudl not be modified between NewFrame() and EndFrame() + const ImGuiKeyModFlags expected_key_mod_flags = GetMergedKeyModFlags(); + IM_ASSERT(g.IO.KeyMods == expected_key_mod_flags && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); + IM_UNUSED(expected_key_mod_flags); + // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you // to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API). - ImGuiContext& g = *GImGui; if (g.CurrentWindowStack.Size != 1) { if (g.CurrentWindowStack.Size > 1) diff --git a/imgui.h b/imgui.h index 70798230..d45e873b 100644 --- a/imgui.h +++ b/imgui.h @@ -168,6 +168,7 @@ typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: f typedef int ImGuiFocusedFlags; // -> enum ImGuiFocusedFlags_ // Flags: for IsWindowFocused() typedef int ImGuiHoveredFlags; // -> enum ImGuiHoveredFlags_ // Flags: for IsItemHovered(), IsWindowHovered() etc. typedef int ImGuiInputTextFlags; // -> enum ImGuiInputTextFlags_ // Flags: for InputText(), InputTextMultiline() +typedef int ImGuiKeyModFlags; // -> enum ImGuiKeyModFlags_ // Flags: for io.KeyMods (Ctrl/Shift/Alt/Super) typedef int ImGuiSelectableFlags; // -> enum ImGuiSelectableFlags_ // Flags: for Selectable() typedef int ImGuiTabBarFlags; // -> enum ImGuiTabBarFlags_ // Flags: for BeginTabBar() typedef int ImGuiTabItemFlags; // -> enum ImGuiTabItemFlags_ // Flags: for BeginTabItem() @@ -997,6 +998,16 @@ enum ImGuiKey_ ImGuiKey_COUNT }; +// To test io.KeyMods (which is a combination of individual fields io.KeyCtrl, io.KeyShift, io.KeyAlt set by user/back-end) +enum ImGuiKeyModFlags_ +{ + ImGuiKeyModFlags_None = 0, + ImGuiKeyModFlags_Ctrl = 1 << 0, + ImGuiKeyModFlags_Shift = 1 << 1, + ImGuiKeyModFlags_Alt = 1 << 2, + ImGuiKeyModFlags_Super = 1 << 3 +}; + // Gamepad/Keyboard directional navigation // Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. // Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Back-end: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame(). @@ -1496,6 +1507,7 @@ struct ImGuiIO // [Internal] Dear ImGui will maintain those fields. Forward compatibility not guaranteed! //------------------------------------------------------------------ + ImGuiKeyModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame() ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) ImVec2 MouseClickedPos[5]; // Position at time of clicking double MouseClickedTime[5]; // Time of last click (used to figure out double-click) From fbc93debf96521350ee93eb74fa30c4de42e0707 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Mar 2020 12:27:16 +0100 Subject: [PATCH 336/384] Internal: Refactor: Moved NewFrameSanityChecks as ErrorCheckNewFrameSanityChecks() --- imgui.cpp | 73 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d7872164..9d344aee 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -935,7 +935,8 @@ static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window); static int FindWindowFocusIndex(ImGuiWindow* window); // Error Checking -static void ErrorCheckEndFrame(); +static void ErrorCheckNewFrameSanityChecks(); +static void ErrorCheckEndFrameSanityChecks(); static void ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool write); // Misc @@ -3675,35 +3676,6 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags() g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false; } -static void NewFrameSanityChecks() -{ - ImGuiContext& g = *GImGui; - - // Check user data - // (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument) - IM_ASSERT(g.Initialized); - IM_ASSERT((g.IO.DeltaTime > 0.0f || g.FrameCount == 0) && "Need a positive DeltaTime!"); - IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?"); - IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!"); - IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); - IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); - IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!"); - IM_ASSERT(g.Style.CircleSegmentMaxError > 0.0f && "Invalid style setting!"); - IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!"); - IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."); - IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); - for (int n = 0; n < ImGuiKey_COUNT; n++) - IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)"); - - // Perform simple check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only recently added in 1.60 WIP) - if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) - IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation."); - - // Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly. - if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors)) - g.IO.ConfigWindowsResizeFromEdges = false; -} - static ImGuiKeyModFlags GetMergedKeyModFlags() { ImGuiContext& g = *GImGui; @@ -3725,7 +3697,7 @@ void ImGui::NewFrame() #endif // Check and assert for various common IO and Configuration mistakes - NewFrameSanityChecks(); + ErrorCheckNewFrameSanityChecks(); // Load settings on first frame, save settings when modified (after a delay) UpdateSettings(); @@ -4171,10 +4143,14 @@ void ImGui::EndFrame() { ImGuiContext& g = *GImGui; IM_ASSERT(g.Initialized); - if (g.FrameCountEnded == g.FrameCount) // Don't process EndFrame() multiple times. + + // Don't process EndFrame() multiple times. + if (g.FrameCountEnded == g.FrameCount) return; IM_ASSERT(g.WithinFrameScope && "Forgot to call ImGui::NewFrame()?"); + ErrorCheckEndFrameSanityChecks(); + // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) if (g.IO.ImeSetInputScreenPosFn && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImeLastPos - g.PlatformImePos) > 0.0001f)) { @@ -4182,8 +4158,6 @@ void ImGui::EndFrame() g.PlatformImeLastPos = g.PlatformImePos; } - ErrorCheckEndFrame(); - // Hide implicit/fallback "Debug" window if it hasn't been used g.WithinFrameScopeWithImplicitWindow = false; if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed) @@ -6731,7 +6705,36 @@ bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, si return !error; } -static void ImGui::ErrorCheckEndFrame() +static void ImGui::ErrorCheckNewFrameSanityChecks() +{ + ImGuiContext& g = *GImGui; + + // Check user data + // (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument) + IM_ASSERT(g.Initialized); + IM_ASSERT((g.IO.DeltaTime > 0.0f || g.FrameCount == 0) && "Need a positive DeltaTime!"); + IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?"); + IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!"); + IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); + IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?"); + IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!"); + IM_ASSERT(g.Style.CircleSegmentMaxError > 0.0f && "Invalid style setting!"); + IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!"); + IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."); + IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); + for (int n = 0; n < ImGuiKey_COUNT; n++) + IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)"); + + // Perform simple check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only recently added in 1.60 WIP) + if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) + IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation."); + + // Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly. + if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors)) + g.IO.ConfigWindowsResizeFromEdges = false; +} + +static void ImGui::ErrorCheckEndFrameSanityChecks() { ImGuiContext& g = *GImGui; From 110f506ec0dd10999ed685c87c609553cb162028 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 19 Mar 2020 18:35:08 +0100 Subject: [PATCH 337/384] Comments in imgui.h --- imgui.h | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/imgui.h b/imgui.h index d45e873b..44a011d6 100644 --- a/imgui.h +++ b/imgui.h @@ -112,6 +112,7 @@ Index of this file: // Forward declarations and basic types //----------------------------------------------------------------------------- +// Forward declarations struct ImDrawChannel; // Temporary storage to output draw commands out of order, used by ImDrawListSplitter and ImDrawList::ChannelsSplit() struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call, unless it is a callback) struct ImDrawData; // All draw command lists required to render the frame + pos/size coordinates to use for the projection matrix. @@ -135,19 +136,12 @@ struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSiz struct ImGuiStorage; // Helper for key->value storage struct ImGuiStyle; // Runtime data for styling/colors struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder) -struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]") +struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbbb][,ccccc]") -// Typedefs and Enums/Flags (declared as int for compatibility with old C++, to allow using as flags and to not pollute the top of this file) -// Use your programming IDE "Go to definition" facility on the names in the central column below to find the actual flags/enum lists. -#ifndef ImTextureID -typedef void* ImTextureID; // User data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp) -#endif -typedef unsigned int ImGuiID; // Unique ID used by widgets (typically hashed from a stack of string) -#ifndef ImWchar -#define ImWchar ImWchar16 -#endif -typedef unsigned short ImWchar16; // A single U16 character for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. -typedef unsigned int ImWchar32; // A single U32 character for keyboard input/display. Define ImWchar to ImWchar32 to use it. See imconfig.h . +// Enums/Flags (declared as int for compatibility with old C++, to allow using as flags and to not pollute the top of this file) +// - Tip: Use your programming IDE navigation facilities on the names in the _central column_ below to find the actual flags/enum lists! +// In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type @@ -174,10 +168,21 @@ typedef int ImGuiTabBarFlags; // -> enum ImGuiTabBarFlags_ // Flags: f typedef int ImGuiTabItemFlags; // -> enum ImGuiTabItemFlags_ // Flags: for BeginTabItem() typedef int ImGuiTreeNodeFlags; // -> enum ImGuiTreeNodeFlags_ // Flags: for TreeNode(), TreeNodeEx(), CollapsingHeader() typedef int ImGuiWindowFlags; // -> enum ImGuiWindowFlags_ // Flags: for Begin(), BeginChild() + +// Other types +#ifndef ImTextureID // ImTextureID [configurable type: override in imconfig.h] +typedef void* ImTextureID; // User data for rendering back-end to identify a texture. This is whatever to you want it to be! read the FAQ about ImTextureID for details. +#endif +#ifndef ImWchar // ImWchar [configurable type: override in imconfig.h] +#define ImWchar ImWchar16 // Storage for a single decoded character/code point, default to 16-bit. Set to ImWchar32 to support larger Unicode planes. Note that we generally support UTF-8 encoded string, this is storage for a decoded character. +#endif +typedef unsigned int ImGuiID; // A unique ID used by widgets, typically hashed from a stack of string. +typedef unsigned short ImWchar16; // A single decoded U16 character/code point for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. +typedef unsigned int ImWchar32; // A single decoded U32 character/code point for keyboard input/display. To enable, use '#define ImWchar ImWchar32' in imconfig.h. typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data); typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); -// Scalar data types +// Basic scalar data types typedef signed char ImS8; // 8-bit signed integer typedef unsigned char ImU8; // 8-bit unsigned integer typedef signed short ImS16; // 16-bit signed integer @@ -196,7 +201,7 @@ typedef signed long long ImS64; // 64-bit signed integer (post C++11) typedef unsigned long long ImU64; // 64-bit unsigned integer (post C++11) #endif -// 2D vector (often used to store positions, sizes, etc.) +// 2D vector (often used to store positions or sizes) struct ImVec2 { float x, y; @@ -234,7 +239,6 @@ namespace ImGui IMGUI_API void DestroyContext(ImGuiContext* ctx = NULL); // NULL = destroy current context IMGUI_API ImGuiContext* GetCurrentContext(); IMGUI_API void SetCurrentContext(ImGuiContext* ctx); - IMGUI_API bool DebugCheckVersionAndDataLayout(const char* version_str, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_drawvert, size_t sz_drawidx); // Main IMGUI_API ImGuiIO& GetIO(); // access the IO structure (mouse/keyboard/gamepad inputs, time, various configuration options/flags) @@ -633,7 +637,7 @@ namespace ImGui IMGUI_API void LogText(const char* fmt, ...) IM_FMTARGS(1); // pass text data straight to log (without being displayed) // Drag and Drop - // [BETA API] API may evolve! + // - [BETA API] API may evolve! IMGUI_API bool BeginDragDropSource(ImGuiDragDropFlags flags = 0); // call when the current item is active. If this return true, you can call SetDragDropPayload() + EndDragDropSource() IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t sz, ImGuiCond cond = 0); // type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui. IMGUI_API void EndDragDropSource(); // only call EndDragDropSource() if BeginDragDropSource() returns true! @@ -726,7 +730,8 @@ namespace ImGui IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired cursor type IMGUI_API void CaptureMouseFromApp(bool want_capture_mouse_value = true); // attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse_value;" after the next NewFrame() call. - // Clipboard Utilities (also see the LogToClipboard() function to capture or output text data to the clipboard) + // Clipboard Utilities + // - Also see the LogToClipboard() function to capture GUI into clipboard, or easily output text data to the clipboard. IMGUI_API const char* GetClipboardText(); IMGUI_API void SetClipboardText(const char* text); @@ -738,6 +743,9 @@ namespace ImGui IMGUI_API void SaveIniSettingsToDisk(const char* ini_filename); // this is automatically called (if io.IniFilename is not empty) a few seconds after any modification that should be reflected in the .ini file (and also by DestroyContext). IMGUI_API const char* SaveIniSettingsToMemory(size_t* out_ini_size = NULL); // return a zero-terminated string with the .ini data which you can save by your own mean. call when io.WantSaveIniSettings is set, then save data by your own mean and clear io.WantSaveIniSettings. + // Debug Utilities + IMGUI_API bool DebugCheckVersionAndDataLayout(const char* version_str, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_drawvert, size_t sz_drawidx); // This is called by IMGUI_CHECKVERSION() macro. + // Memory Allocators // - All those functions are not reliant on the current context. // - If you reload the contents of imgui.cpp at runtime, you may need to call SetCurrentContext() + SetAllocatorFunctions() again because we use global storage for those. @@ -1825,7 +1833,7 @@ struct ImColor // Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList. //----------------------------------------------------------------------------- -// Draw callbacks for advanced uses. +// ImDrawCallback: Draw callbacks for advanced uses [configurable type: override in imconfig.h] // NB: You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering, // you can poke into the draw list for that! Draw callback may be useful for example to: // A) Change your GPU render state, @@ -1858,9 +1866,9 @@ struct ImDrawCmd ImDrawCmd() { ElemCount = 0; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; } }; -// Vertex index -// (to allow large meshes with 16-bit indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end) -// (to use 32-bit indices: override with '#define ImDrawIdx unsigned int' in imconfig.h) +// Vertex index, default to 16-bit +// To allow large meshes with 16-bit indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end (recommended). +// To use 32-bit indices: override with '#define ImDrawIdx unsigned int' in imconfig.h. #ifndef ImDrawIdx typedef unsigned short ImDrawIdx; #endif From 4986dba270131850d892c0fbe028878358aad4a0 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Mar 2020 11:56:21 +0100 Subject: [PATCH 338/384] Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial cursor position. (#3073) This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 96d02a88..226e79ed 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -45,6 +45,9 @@ Other Changes: when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) +- Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial + cursor position. This would often get fixed after the fix item submission, but using the + ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) - Added optional support for Unicode plane 1-16 (#2538, #2541, #2815) [@cloudwu, @samhocevar] - Compile-time enable with '#define ImWchar ImWchar32' in imconfig.h. - Generally more consistent support for unsupported codepoints (0xFFFD), in particular when diff --git a/imgui.cpp b/imgui.cpp index 9d344aee..477b0f67 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7283,7 +7283,8 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool s target_y = window->ContentSize.y + window->WindowPadding.y * 2.0f; scroll.y = target_y - cr_y * (window->SizeFull.y - window->ScrollbarSizes.y - decoration_up_height); } - scroll = ImMax(scroll, ImVec2(0.0f, 0.0f)); + scroll.x = IM_FLOOR(ImMax(scroll.x, 0.0f)); + scroll.y = IM_FLOOR(ImMax(scroll.y, 0.0f)); if (!window->Collapsed && !window->SkipItems) { scroll.x = ImMin(scroll.x, window->ScrollMax.x); From e8568f3ec967106ac393a924ac2fde797f496d97 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 24 Mar 2020 10:13:41 +0200 Subject: [PATCH 339/384] Menus: Fix appending to main menubar (#3068). --- imgui_widgets.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d86d057d..353fab09 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6150,18 +6150,23 @@ bool ImGui::BeginMainMenuBar() { ImGuiContext& g = *GImGui; ImGuiViewportP* viewport = g.Viewports[0]; + ImGuiWindow* menu_bar_window = FindWindowByName("##MainMenuBar"); // For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f)); - // Get our rectangle in the work area, and report the size we need for next frame. - // We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height. - ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin; - ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f); + // Get our rectangle at the top of the work area + if (menu_bar_window == NULL || menu_bar_window->BeginCount == 0) + { + // Set window position + // We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height. + ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin; + ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f); + SetNextWindowPos(menu_bar_pos); + SetNextWindowSize(menu_bar_size); + } // Create window - SetNextWindowPos(menu_bar_pos); - SetNextWindowSize(menu_bar_size); SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set. PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want. @@ -6169,8 +6174,10 @@ bool ImGui::BeginMainMenuBar() bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar(); PopStyleVar(2); - // Feed back into work area using actual window size - viewport->CurrWorkOffsetMin.y += GetCurrentWindow()->Size.y; + // Report our size into work area (for next frame) using actual window size + menu_bar_window = GetCurrentWindow(); + if (menu_bar_window->BeginCount == 1) + viewport->CurrWorkOffsetMin.y += menu_bar_window->Size.y; g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); if (!is_open) From ac4262ad01cdfa8a089e3a43e8cafd1c3887d2ff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 20 Feb 2020 15:49:15 +0100 Subject: [PATCH 340/384] Backends: OpenGL3: Support older 2.x series of glbinding as loader for OpenGL3 (#3061) This removes the unversioned definition IMGUI_IMPL_OPENGL_LOADER_GLBINDING in favor of two versioned ones to choose explicitly. References: #2870, 5e2329b98e6562c9e7883e92dcf878e969d81878 --- examples/example_glfw_opengl3/Makefile | 7 +++++-- examples/example_glfw_opengl3/main.cpp | 11 +++++++++-- examples/example_sdl_opengl3/Makefile | 7 +++++-- examples/example_sdl_opengl3/main.cpp | 11 +++++++++-- examples/imgui_impl_opengl3.cpp | 18 +++++++++++++----- examples/imgui_impl_opengl3.h | 9 ++++++--- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index f0160b19..7696eaae 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -42,8 +42,11 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W # CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD ## Using OpenGL loader: glbinding -## (This assumes a system-wide installation) -# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING +## This assumes a system-wide installation +## of either version 3.0.0 (or newer) +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING3 +## or the older version 2.x +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING2 ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 55b379de..61797d3e 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -17,9 +17,13 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) #define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#include // Initialize with glbinding::Binding::initialize() +#else #include // Initialize with glbinding::initialize() +#endif #include using namespace gl; #else @@ -79,7 +83,10 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) + bool err = false; + glbinding::Binding::initialize(); +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) bool err = false; glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)glfwGetProcAddress(name); }); #else diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 77140b5e..ada77197 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -42,8 +42,11 @@ CXXFLAGS += -I../libs/gl3w -DIMGUI_IMPL_OPENGL_LOADER_GL3W # CXXFLAGS += -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD ## Using OpenGL loader: glbinding -## (This assumes a system-wide installation) -# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING +## This assumes a system-wide installation +## of either version 3.0.0 (or newer) +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING3 +## or the older version 2.x +# CXXFLAGS += -lglbinding -DIMGUI_IMPL_OPENGL_LOADER_GLBINDING2 ##--------------------------------------------------------------------- ## BUILD FLAGS PER PLATFORM diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 20801a19..4eb4110f 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -19,8 +19,12 @@ #include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#include // Initialize with glbinding::Binding::initialize() +#else #include // Initialize with glbinding::initialize() +#endif #include using namespace gl; #else @@ -73,7 +77,10 @@ int main(int, char**) bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) bool err = gladLoadGL() == 0; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) + bool err = false; + glbinding::Binding::initialize(); +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) bool err = false; glbinding::initialize([](const char* name) { return (glbinding::ProcAddress)SDL_GL_GetProcAddress(name); }); #else diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 9289913e..1514567d 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -86,14 +86,16 @@ #undef IMGUI_IMPL_OPENGL_LOADER_GL3W #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD -#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING3 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #elif defined(__EMSCRIPTEN__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" #undef IMGUI_IMPL_OPENGL_LOADER_GL3W #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD -#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 +#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING3 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif #endif @@ -118,9 +120,13 @@ #include // Needs to be initialized with glewInit() in user's code #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include // Needs to be initialized with gladLoadGL() in user's code -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) #include // Initialize with glbinding::initialize() +#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#include +#else #include +#endif using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM @@ -193,8 +199,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) gl_loader = "GLEW"; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) gl_loader = "GLAD"; -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) - gl_loader = "glbinding"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) + gl_loader = "glbinding2"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) + gl_loader = "glbinding3"; #else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM gl_loader = "Custom"; #endif diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 98cefe7d..a9a1e199 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -46,7 +46,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ - && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) \ + && !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) \ && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) #if defined(__has_include) #if __has_include() @@ -55,8 +56,10 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); #define IMGUI_IMPL_OPENGL_LOADER_GLAD #elif __has_include() #define IMGUI_IMPL_OPENGL_LOADER_GL3W - #elif __has_include() - #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3 + #elif __has_include() + #define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 #else #error "Cannot detect OpenGL loader!" #endif From f2b01c3436e13be22beba4f7831bc26f40cca1c5 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Mar 2020 18:42:18 +0100 Subject: [PATCH 341/384] Changelog, tweak OpenGL3 backends. (#3061), update Gallery thread links. --- docs/CHANGELOG.txt | 3 +- docs/FAQ.md | 4 +-- docs/README.md | 4 +-- examples/README.txt | 4 +-- examples/example_glfw_opengl3/main.cpp | 21 +++++++------ examples/example_sdl_opengl3/main.cpp | 20 ++++++------ examples/imgui_impl_opengl3.cpp | 42 ++++++++++++++------------ imgui.cpp | 4 +-- imgui.h | 2 +- 9 files changed, 55 insertions(+), 49 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 226e79ed..ee49d325 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,7 @@ Other Changes: - CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building SDL+Metal example, building imgui_freetype.cpp, more compile-time imconfig.h settings: disabling obsolete functions, enabling 32-bit ImDrawIdx, enabling 32-bit ImWchar, disabling demo. [@rokups] +- Backends: OpenGL3: Added include support for older glbinding 2.x loader. (#3061) [@DonKult] - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). Those functions makes it easier for example apps to support hi-dpi features without setting up @@ -172,7 +173,7 @@ Other Changes: - Examples: OpenGL: Explicitly adding -DIMGUI_IMPL_OPENGL_LOADER_GL3W to Makefile to match linking settings (otherwise if another loader such as Glew is accessible, the OpenGL3 backend might automatically use it). (#2919, #2798) -- Examples: OpenGL: Added support for glbindings OpenGL loader. (#2870) [@rokups] +- Examples: OpenGL: Added support for glbinding OpenGL loader. (#2870) [@rokups] - Examples: Emscripten: Demonstrating embedding fonts in Makefile and code. (#2953) [@Oipo] - Examples: Metal: Wrapped main loop in @autoreleasepool block to ensure allocations get freed even if underlying system event loop gets paused due to app nap. (#2910, #2917) [@bear24rw] diff --git a/docs/FAQ.md b/docs/FAQ.md index b173a73d..d629ff4b 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -552,7 +552,7 @@ You may take a look at: - [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) - [Software using Dear ImGui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) -- [Gallery](https://github.com/ocornut/imgui/issues/2847) +- [Gallery](https://github.com/ocornut/imgui/issues/3075) ##### [Return to Index](#index) @@ -598,7 +598,7 @@ There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/ci - Individuals: you can support continued maintenance and development via PayPal donations. See [README](https://github.com/ocornut/imgui/blob/master/docs/README.md). - If you are experienced with Dear ImGui and C++, look at the [GitHub Issues](https://github.com/ocornut/imgui/issues), look at the [Wiki](https://github.com/ocornut/imgui/wiki), read [docs/TODO.txt](https://github.com/ocornut/imgui/blob/master/docs/TODO.txt) and see how you want to help and can help! - Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. -You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. Disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. +You may post screenshot or links in the [gallery threads](https://github.com/ocornut/imgui/issues/3075). Visuals are ideal as they inspire other programmers. Disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues or sometimes incomplete PR. ##### [Return to Index](#index) diff --git a/docs/README.md b/docs/README.md index 8c1636ef..3e001024 100644 --- a/docs/README.md +++ b/docs/README.md @@ -131,7 +131,7 @@ Some of the goals for 2020 are: ### Gallery -For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! +For more user-submitted screenshots of projects using Dear ImGui, check out the [Gallery Threads](https://github.com/ocornut/imgui/issues/3075)! Custom engine [![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png) @@ -164,7 +164,7 @@ You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issue **Who uses Dear ImGui?** -See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes), [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors), [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for an idea of who is using Dear ImGui. Please add your game/software if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/2847)! +See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes), [Sponsors](https://github.com/ocornut/imgui/wiki/Sponsors), [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for an idea of who is using Dear ImGui. Please add your game/software if you can! Also see the [Gallery Threads](https://github.com/ocornut/imgui/issues/3075)! How to help ----------- diff --git a/examples/README.txt b/examples/README.txt index 75d97729..355d616c 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -199,7 +199,7 @@ example_glfw_opengl2/ GLFW + OpenGL2 example (legacy, fixed pipeline). = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp **DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** - **Prefer using OPENGL3 code (with gl3w/glew/glad/glbindings, you can replace the OpenGL function loader)** + **Prefer using OPENGL3 code (with gl3w/glew/glad/glbinding, you can replace the OpenGL function loader)** This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to make things more complicated, will require your code to reset many OpenGL attributes to their initial @@ -248,7 +248,7 @@ example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp **DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** - **Prefer using OPENGL3 code (with gl3w/glew/glad/glbindings, you can replace the OpenGL function loader)** + **Prefer using OPENGL3 code (with gl3w/glew/glad/glbinding, you can replace the OpenGL function loader)** This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter. If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to make things more complicated, will require your code to reset many OpenGL attributes to their initial diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index 61797d3e..8df734bd 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -12,18 +12,19 @@ // Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad). // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) -#include // Initialize with gl3wInit() +#include // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) -#include // Initialize with glewInit() +#include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) -#include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) -#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. -#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) -#include // Initialize with glbinding::Binding::initialize() -#else -#include // Initialize with glbinding::initialize() -#endif +#include // Initialize with gladLoadGL() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Initialize with glbinding::Binding::initialize() +#include +using namespace gl; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Initialize with glbinding::initialize() #include using namespace gl; #else diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 4eb4110f..ae794ef4 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -14,17 +14,19 @@ // Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad). // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) -#include // Initialize with gl3wInit() +#include // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) -#include // Initialize with glewInit() +#include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) -#include // Initialize with gladLoadGL() -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) -#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) -#include // Initialize with glbinding::Binding::initialize() -#else -#include // Initialize with glbinding::initialize() -#endif +#include // Initialize with gladLoadGL() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Initialize with glbinding::Binding::initialize() +#include +using namespace gl; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Initialize with glbinding::initialize() #include using namespace gl; #else diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 1514567d..2f908f46 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -13,7 +13,8 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2020-01-07: OpenGL: Added support for glbindings OpenGL loader. +// 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader. +// 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader. // 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders. // 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility. // 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call. @@ -83,14 +84,12 @@ #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" -#undef IMGUI_IMPL_OPENGL_LOADER_GL3W -#undef IMGUI_IMPL_OPENGL_LOADER_GLEW -#undef IMGUI_IMPL_OPENGL_LOADER_GLAD -#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING2 -#undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING3 -#undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #elif defined(__EMSCRIPTEN__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" +#endif +#endif + +#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3) #undef IMGUI_IMPL_OPENGL_LOADER_GL3W #undef IMGUI_IMPL_OPENGL_LOADER_GLEW #undef IMGUI_IMPL_OPENGL_LOADER_GLAD @@ -98,7 +97,6 @@ #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING3 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif -#endif // GL includes #if defined(IMGUI_IMPL_OPENGL_ES2) @@ -115,18 +113,20 @@ // Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad). // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) -#include // Needs to be initialized with gl3wInit() in user's code +#include // Needs to be initialized with gl3wInit() in user's code #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) -#include // Needs to be initialized with glewInit() in user's code +#include // Needs to be initialized with glewInit() in user's code. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) -#include // Needs to be initialized with gladLoadGL() in user's code -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) || defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) -#include // Initialize with glbinding::initialize() -#if defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) -#include -#else -#include -#endif +#include // Needs to be initialized with gladLoadGL() in user's code. +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Needs to be initialized with glbinding::Binding::initialize() in user's code. +#include +using namespace gl; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) +#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors. +#include // Needs to be initialized with glbinding::initialize() in user's code. +#include using namespace gl; #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM @@ -203,8 +203,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) gl_loader = "glbinding2"; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) gl_loader = "glbinding3"; -#else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM - gl_loader = "Custom"; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) + gl_loader = "custom"; +#else + gl_loader = "none"; #endif // Make a dummy GL call (we don't actually need the result) diff --git a/imgui.cpp b/imgui.cpp index 477b0f67..9c3a9c8c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10,7 +10,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/2847 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/3075 (please post your screenshots/video there!) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Wiki https://github.com/ocornut/imgui/wiki // - Issues & support https://github.com/ocornut/imgui/issues @@ -783,7 +783,7 @@ CODE - If you are experienced with Dear ImGui and C++, look at the github issues, look at the Wiki, read docs/TODO.txt and see how you want to help and can help! - Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. - You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/2847). Visuals are ideal as they inspire other programmers. + You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/3075). Visuals are ideal as they inspire other programmers. But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. - If you have issues or if you need to hack into the library, even if you don't expect any support it is useful that you share your issues (on github or privately). diff --git a/imgui.h b/imgui.h index 44a011d6..b61c4647 100644 --- a/imgui.h +++ b/imgui.h @@ -11,7 +11,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/2847 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/3075 (please post your screenshots/video there!) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Wiki https://github.com/ocornut/imgui/wiki // - Issues & support https://github.com/ocornut/imgui/issues From 9085c2cae27571d4dc83aa80f953737458584d31 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Mar 2020 18:51:04 +0100 Subject: [PATCH 342/384] Docking: Fixed unused definition leftover from a hasty merge. --- imgui_internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index 20c777ea..c42f595f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2072,7 +2072,6 @@ namespace ImGui IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight - IMGUI_API void RenderMouseCursor(ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor = ImGuiMouseCursor_Arrow); IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. IMGUI_API void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL); From 670367e51d92128fc80b90ae1469f9f0feb4db78 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 24 Mar 2020 20:11:05 +0100 Subject: [PATCH 343/384] Added IMGUI_USE_WCHAR32 instead of "#define ImWchar ImWchar32" to faclitate C-binding. (#2538, #2541, #2815) --- .github/workflows/build.yml | 2 +- docs/CHANGELOG.txt | 2 +- imconfig.h | 6 +++--- imgui.cpp | 1 + imgui.h | 21 +++++++++++++-------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d68c8da9..b089bfb4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -202,7 +202,7 @@ jobs: - name: Build example_null (with ImWchar32) run: | - echo '#define ImWchar ImWchar32' > example_single_file.cpp + echo '#define IMGUI_USE_WCHAR32' > example_single_file.cpp echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ee49d325..54aa11bc 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -49,7 +49,7 @@ Other Changes: cursor position. This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) - Added optional support for Unicode plane 1-16 (#2538, #2541, #2815) [@cloudwu, @samhocevar] - - Compile-time enable with '#define ImWchar ImWchar32' in imconfig.h. + - Compile-time enable with '#define IMGUI_USE_WCHAR32' in imconfig.h. - Generally more consistent support for unsupported codepoints (0xFFFD), in particular when using the default, non-fitting characters will be turned into 0xFFFD instead of being ignored. - Surrogate pairs are supported when submitting UTF-16 data via io.AddInputCharacterUTF16(), diff --git a/imconfig.h b/imconfig.h index 4f01b778..c6817de7 100644 --- a/imconfig.h +++ b/imconfig.h @@ -48,6 +48,9 @@ //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) //#define IMGUI_USE_BGRA_PACKED_COLOR +//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points. +//#define IMGUI_USE_WCHAR32 + //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version // By default the embedded implementations are declared static and not available outside of imgui cpp files. //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" @@ -77,9 +80,6 @@ // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. //#define ImDrawIdx unsigned int -//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points. -//#define ImWchar ImWchar32 - //---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly) //struct ImDrawList; //struct ImDrawCmd; diff --git a/imgui.cpp b/imgui.cpp index 9c3a9c8c..c0fa2fb9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5,6 +5,7 @@ // - Read FAQ at http://dearimgui.org/faq // - Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase. // - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that. +// Read imgui.cpp for details, links and comments. // Resources: // - FAQ http://dearimgui.org/faq diff --git a/imgui.h b/imgui.h index b61c4647..712ddfa1 100644 --- a/imgui.h +++ b/imgui.h @@ -5,7 +5,7 @@ // - Read FAQ at http://dearimgui.org/faq // - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase. // - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that. -// Read imgui.cpp for more details, documentation and comments. +// Read imgui.cpp for details, links and comments. // Resources: // - FAQ http://dearimgui.org/faq @@ -65,7 +65,7 @@ Index of this file: // Define attributes of all API symbols declarations (e.g. for DLL under Windows) // IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default bindings files (imgui_impl_xxx.h) -// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. +// Using dear imgui via a shared library is not recommended, because we don't guarantee backward nor forward ABI compatibility (also function call overhead, as dear imgui is a call-heavy API) #ifndef IMGUI_API #define IMGUI_API #endif @@ -170,18 +170,23 @@ typedef int ImGuiTreeNodeFlags; // -> enum ImGuiTreeNodeFlags_ // Flags: f typedef int ImGuiWindowFlags; // -> enum ImGuiWindowFlags_ // Flags: for Begin(), BeginChild() // Other types -#ifndef ImTextureID // ImTextureID [configurable type: override in imconfig.h] +#ifndef ImTextureID // ImTextureID [configurable type: override in imconfig.h with '#define ImTextureID xxx'] typedef void* ImTextureID; // User data for rendering back-end to identify a texture. This is whatever to you want it to be! read the FAQ about ImTextureID for details. #endif -#ifndef ImWchar // ImWchar [configurable type: override in imconfig.h] -#define ImWchar ImWchar16 // Storage for a single decoded character/code point, default to 16-bit. Set to ImWchar32 to support larger Unicode planes. Note that we generally support UTF-8 encoded string, this is storage for a decoded character. -#endif typedef unsigned int ImGuiID; // A unique ID used by widgets, typically hashed from a stack of string. -typedef unsigned short ImWchar16; // A single decoded U16 character/code point for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings. -typedef unsigned int ImWchar32; // A single decoded U32 character/code point for keyboard input/display. To enable, use '#define ImWchar ImWchar32' in imconfig.h. typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data); typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); +// Decoded character types +// (we generally use UTF-8 encoded string in the API. This is storage specifically for a decoded character used for keyboard input and display) +typedef unsigned short ImWchar16; // A single decoded U16 character/code point. We encode them as multi bytes UTF-8 when used in strings. +typedef unsigned int ImWchar32; // A single decoded U32 character/code point. We encode them as multi bytes UTF-8 when used in strings. +#ifdef IMGUI_USE_WCHAR32 // ImWchar [configurable type: override in imconfig.h with '#define IMGUI_USE_WCHAR32' to support Unicode planes 1-16] +typedef ImWchar32 ImWchar; +#else +typedef ImWchar16 ImWchar; +#endif + // Basic scalar data types typedef signed char ImS8; // 8-bit signed integer typedef unsigned char ImU8; // 8-bit unsigned integer From 1d4b5def51e905836f02d5d003c43bb878d2e541 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 25 Mar 2020 21:38:24 +0100 Subject: [PATCH 344/384] Alter definition of IM_UNICODE_ defines to faclitate C-binding. (#2538, #2541, #2815) --- imgui.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index 712ddfa1..32059b3b 100644 --- a/imgui.h +++ b/imgui.h @@ -92,8 +92,6 @@ Index of this file: #else #define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro. #endif -#define IM_UNICODE_CODEPOINT_MAX (sizeof(ImWchar) == 2 ? 0xFFFF : 0x10FFFF) // Last Unicode code point supported by this build. -#define IM_UNICODE_CODEPOINT_INVALID 0xFFFD // Standard invalid Unicode code point. // Warnings #if defined(__clang__) @@ -1652,6 +1650,14 @@ typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData; // Helpers //----------------------------------------------------------------------------- +// Helper: Unicode defines +#define IM_UNICODE_CODEPOINT_INVALID 0xFFFD // Invalid Unicode code point (standard value). +#ifdef IMGUI_USE_WCHAR32 +#define IM_UNICODE_CODEPOINT_MAX 0x10FFFF // Maximum Unicode code point supported by this build. +#else +#define IM_UNICODE_CODEPOINT_MAX 0xFFFF // Maximum Unicode code point supported by this build. +#endif + // Helper: Execute a block of code at maximum once a frame. Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame. // Usage: static ImGuiOnceUponAFrame oaf; if (oaf) ImGui::Text("This will be called only once per frame"); struct ImGuiOnceUponAFrame From ac2247f5519a353ecd8bb9ab8fc5c11bbfae5b0c Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 26 Mar 2020 14:12:13 +0100 Subject: [PATCH 345/384] Selectable: Removed seemingly ineffective text clipping offset in SpanAllColumns handling path + tweaks. made max_x absolutely to reduce confusion. amend cf481e1 --- imgui_widgets.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 938e94cb..061fecaf 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5580,14 +5580,14 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl // Fill horizontal space. ImVec2 window_padding = window->WindowPadding; - float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x : GetContentRegionMax().x; - float w_draw = ImMax(label_size.x, window->Pos.x + max_x - window_padding.x - pos.x); - ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size_arg.y != 0.0f ? size_arg.y : size.y); + float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; + float w_draw = ImMax(label_size.x, max_x - window_padding.x - pos.x); + ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size.y); ImRect bb(pos, pos + size_draw); if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth)) bb.Max.x += window_padding.x; - // Selectables are tightly packed together so we extend the box to cover spacing between selectable. + // Selectables are meant to be tightly packed together with no click-gap, so we extend the box to cover spacing between selectable. const float spacing_x = style.ItemSpacing.x; const float spacing_y = style.ItemSpacing.y; const float spacing_L = IM_FLOOR(spacing_x * 0.50f); @@ -5662,10 +5662,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl } if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns) - { PopColumnsBackground(); - bb.Max.x -= (GetContentRegionMax().x - max_x); - } if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); RenderTextClipped(bb_inner.Min, bb_inner.Max, label, NULL, &label_size, style.SelectableTextAlign, &bb); From 7c11997bcc31e545ba3d9751212f7da0d322c4a6 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 26 Mar 2020 14:53:07 +0100 Subject: [PATCH 346/384] Selectable: Fixed honoring style.SelectableTextAlign with unspecified size. (#2347, #2601) --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 1 + imgui_widgets.cpp | 27 +++++++++++++++------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 54aa11bc..05739c5c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -45,6 +45,7 @@ Other Changes: when the menu is not open. (#3030) - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) +- Selectable: Fixed honoring style.SelectableTextAlign with unspecified size. (#2347, #2601) - Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial cursor position. This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) diff --git a/docs/TODO.txt b/docs/TODO.txt index 8d50dbe2..e0a8bc12 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -223,6 +223,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - menus: menu-bar: main menu-bar could affect clamping of windows position (~ akin to modifying DisplayMin) - menus: hovering from menu to menu on a menu-bar has 1 frame without any menu, which is a little annoying. ideally either 0 either longer. - menus: could merge draw call in most cases (how about storing an optional aabb in ImDrawCmd to move the burden of merging in a single spot). + - menus: would be nice if the Selectable() supported horizontal alignment (must be given the equivalent of WorkRect.Max.x matching the position of the shortcut column) - tree node: add treenode/treepush int variants? not there because (void*) cast from int warns on some platforms/settings? - tree node: try to apply scrolling at time of TreePop() if node was just opened and end of node is past scrolling limits? diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 061fecaf..a8f72380 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5583,31 +5583,33 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; float w_draw = ImMax(label_size.x, max_x - window_padding.x - pos.x); ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size.y); - ImRect bb(pos, pos + size_draw); + + ImRect bb_align(pos, pos + size_draw); if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth)) - bb.Max.x += window_padding.x; + bb_align.Max.x += window_padding.x; // Selectables are meant to be tightly packed together with no click-gap, so we extend the box to cover spacing between selectable. + ImRect bb_enlarged = bb_align; const float spacing_x = style.ItemSpacing.x; const float spacing_y = style.ItemSpacing.y; const float spacing_L = IM_FLOOR(spacing_x * 0.50f); const float spacing_U = IM_FLOOR(spacing_y * 0.50f); - bb.Min.x -= spacing_L; - bb.Min.y -= spacing_U; - bb.Max.x += (spacing_x - spacing_L); - bb.Max.y += (spacing_y - spacing_U); + bb_enlarged.Min.x -= spacing_L; + bb_enlarged.Min.y -= spacing_U; + bb_enlarged.Max.x += (spacing_x - spacing_L); + bb_enlarged.Max.y += (spacing_y - spacing_U); bool item_add; if (flags & ImGuiSelectableFlags_Disabled) { ImGuiItemFlags backup_item_flags = window->DC.ItemFlags; window->DC.ItemFlags |= ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNavDefaultFocus; - item_add = ItemAdd(bb, id); + item_add = ItemAdd(bb_enlarged, id); window->DC.ItemFlags = backup_item_flags; } else { - item_add = ItemAdd(bb, id); + item_add = ItemAdd(bb_enlarged, id); } if (!item_add) { @@ -5630,7 +5632,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl const bool was_selected = selected; bool hovered, held; - bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); + bool pressed = ButtonBehavior(bb_enlarged, id, &hovered, &held, button_flags); // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) @@ -5657,21 +5659,22 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (hovered || selected) { const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); - RenderFrame(bb.Min, bb.Max, col, false, 0.0f); - RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding); + RenderFrame(bb_enlarged.Min, bb_enlarged.Max, col, false, 0.0f); + RenderNavHighlight(bb_enlarged, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding); } if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns) PopColumnsBackground(); if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); - RenderTextClipped(bb_inner.Min, bb_inner.Max, label, NULL, &label_size, style.SelectableTextAlign, &bb); + RenderTextClipped(bb_align.Min, bb_align.Max, label, NULL, &label_size, style.SelectableTextAlign, &bb_enlarged); if (flags & ImGuiSelectableFlags_Disabled) PopStyleColor(); // Automatically close popups if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(window->DC.ItemFlags & ImGuiItemFlags_SelectableDontClosePopup)) CloseCurrentPopup(); + //if (g.IO.KeyCtrl) { window->DrawList->AddRect(bb_align.Min, bb_align.Max, IM_COL32(0, 255, 0, 255)); } IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); return pressed; } From b4d1287011b8eb2abb48a02b4a2cb36c43d99bc7 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 26 Mar 2020 16:58:24 +0100 Subject: [PATCH 347/384] Selectable: Clarifying the code around use of ImGuiSelectableFlags_DrawFillAvailWidth (with intent of trying to remove it). Amend old 6251d379, 2bcafc86 --- imgui.cpp | 4 +++- imgui_internal.h | 2 +- imgui_widgets.cpp | 33 +++++++++++++++++---------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c0fa2fb9..da5c5c3f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6818,6 +6818,8 @@ static void ImGui::ErrorCheckBeginEndCompareStacksSize(ImGuiWindow* window, bool //----------------------------------------------------------------------------- // Advance cursor given item size for layout. +// Register minimum needed size so it can extend the bounding box used for auto-fit calculation. +// See comments in ItemAdd() about how/why the size provided to ItemSize() vs ItemAdd() may often different. void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) { ImGuiContext& g = *GImGui; @@ -6858,7 +6860,7 @@ void ImGui::ItemSize(const ImRect& bb, float text_baseline_y) // Declare item bounding box for clipping and interaction. // Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface -// declare their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd(). +// declare their minimum size requirement to ItemSize() and provide a larger region to ItemAdd() which is used drawing/interaction. bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg) { ImGuiContext& g = *GImGui; diff --git a/imgui_internal.h b/imgui_internal.h index bb13be00..c4a32745 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -494,7 +494,7 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20, ImGuiSelectableFlags_SelectOnClick = 1 << 21, // Override button behavior to react on Click (default is Click+Release) ImGuiSelectableFlags_SelectOnRelease = 1 << 22, // Override button behavior to react on Release (default is Click+Release) - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus) + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // Draw over all avail width even if we declared less for layout. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 24, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25 }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a8f72380..5d246994 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5578,15 +5578,11 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl ImRect bb_inner(pos, pos + size); ItemSize(size, 0.0f); - // Fill horizontal space. - ImVec2 window_padding = window->WindowPadding; - float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; - float w_draw = ImMax(label_size.x, max_x - window_padding.x - pos.x); - ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size.y); - - ImRect bb_align(pos, pos + size_draw); + // Fill horizontal space + const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth)) - bb_align.Max.x += window_padding.x; + size.x = ImMax(label_size.x, max_x - window->WindowPadding.x - pos.x) + window->WindowPadding.x; + ImRect bb_align(pos, pos + size); // Selectables are meant to be tightly packed together with no click-gap, so we extend the box to cover spacing between selectable. ImRect bb_enlarged = bb_align; @@ -6228,10 +6224,12 @@ bool ImGui::BeginMenu(const char* label, bool enabled) else { // Menu inside a menu + // (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f. + // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system. popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); - float w = window->DC.MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame - float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); - pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f)); + float min_w = window->DC.MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame + float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(min_w, 0.0f)); ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled); RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right); } @@ -6376,11 +6374,14 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo } else { - ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); - float w = window->DC.MenuColumns.DeclColumns(label_size.x, shortcut_size.x, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame - float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); - pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f)); - if (shortcut_size.x > 0.0f) + // Menu item inside a vertical menu + // (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f. + // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system. + float shortcut_w = shortcut ? CalcTextSize(shortcut, NULL).x : 0.0f; + float min_w = window->DC.MenuColumns.DeclColumns(label_size.x, shortcut_w, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame + float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); + pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(min_w, 0.0f)); + if (shortcut_w > 0.0f) { PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); RenderText(pos + ImVec2(window->DC.MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); From 5be5add1ade50ea3e36de8a44f659b26aaea93e8 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 26 Mar 2020 18:03:43 +0100 Subject: [PATCH 348/384] Selectable: Removed extraneous WindowPadding.x worth of width when auto-sized selectable label goes off available width (would not be noticeable) + Renamed ImGuiSelectableFlags_DrawFillAvailWidth to ImGuiSelectableFlags_SpanAvailWidth. --- imgui_internal.h | 2 +- imgui_widgets.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index c4a32745..eb5c82e7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -494,7 +494,7 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20, ImGuiSelectableFlags_SelectOnClick = 1 << 21, // Override button behavior to react on Click (default is Click+Release) ImGuiSelectableFlags_SelectOnRelease = 1 << 22, // Override button behavior to react on Release (default is Click+Release) - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // Draw over all avail width even if we declared less for layout. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) + ImGuiSelectableFlags_SpanAvailWidth = 1 << 23, // Span all avail width even if we declared less for layout purpose. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 24, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. ImGuiSelectableFlags_SetNavIdOnHover = 1 << 25 }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5d246994..7d0c9cbe 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5570,21 +5570,21 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.CurrentColumns) // FIXME-OPT: Avoid if vertically clipped. PushColumnsBackground(); + // Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle. ImGuiID id = window->GetID(label); ImVec2 label_size = CalcTextSize(label, NULL, true); ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); ImVec2 pos = window->DC.CursorPos; pos.y += window->DC.CurrLineTextBaseOffset; - ImRect bb_inner(pos, pos + size); ItemSize(size, 0.0f); // Fill horizontal space const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; - if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth)) - size.x = ImMax(label_size.x, max_x - window->WindowPadding.x - pos.x) + window->WindowPadding.x; + if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth)) + size.x = ImMax(label_size.x, max_x - pos.x); ImRect bb_align(pos, pos + size); - // Selectables are meant to be tightly packed together with no click-gap, so we extend the box to cover spacing between selectable. + // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable. ImRect bb_enlarged = bb_align; const float spacing_x = style.ItemSpacing.x; const float spacing_y = style.ItemSpacing.y; @@ -5594,6 +5594,8 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl bb_enlarged.Min.y -= spacing_U; bb_enlarged.Max.x += (spacing_x - spacing_L); bb_enlarged.Max.y += (spacing_y - spacing_U); + //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb_align.Min, bb_align.Max, IM_COL32(255, 0, 0, 255)); } + //if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb_enlarged.Min, bb_enlarged.Max, IM_COL32(0, 255, 0, 255)); } bool item_add; if (flags & ImGuiSelectableFlags_Disabled) @@ -5670,7 +5672,6 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(window->DC.ItemFlags & ImGuiItemFlags_SelectableDontClosePopup)) CloseCurrentPopup(); - //if (g.IO.KeyCtrl) { window->DrawList->AddRect(bb_align.Min, bb_align.Max, IM_COL32(0, 255, 0, 255)); } IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); return pressed; } @@ -6229,7 +6230,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y); float min_w = window->DC.MenuColumns.DeclColumns(label_size.x, 0.0f, IM_FLOOR(g.FontSize * 1.20f)); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); - pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(min_w, 0.0f)); + pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_SpanAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(min_w, 0.0f)); ImU32 text_col = GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled); RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right); } @@ -6380,7 +6381,7 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo float shortcut_w = shortcut ? CalcTextSize(shortcut, NULL).x : 0.0f; float min_w = window->DC.MenuColumns.DeclColumns(label_size.x, shortcut_w, IM_FLOOR(g.FontSize * 1.20f)); // Feedback for next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); - pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(min_w, 0.0f)); + pressed = Selectable(label, false, flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f)); if (shortcut_w > 0.0f) { PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); From ec2a24a5f13fe8724acda7fc77c3328db6bf076a Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 26 Mar 2020 20:15:44 +0100 Subject: [PATCH 349/384] Selectable: Allow using ImGuiSelectableFlags_SpanAllColumns in other columns than first. Comments. (#125) --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 5 +++-- imgui.cpp | 2 +- imgui.h | 10 +++++++--- imgui_demo.cpp | 6 +++--- imgui_widgets.cpp | 16 +++++++++++----- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 05739c5c..07c882ba 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -46,6 +46,7 @@ Other Changes: - InputText: Fixed password fields displaying ASCII spaces as blanks instead of using the '*' glyph. (#2149, #515) - Selectable: Fixed honoring style.SelectableTextAlign with unspecified size. (#2347, #2601) +- Selectable: Allow using ImGuiSelectableFlags_SpanAllColumns in other columns than first. (#125) - Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial cursor position. This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) diff --git a/docs/TODO.txt b/docs/TODO.txt index e0a8bc12..474b5ce5 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -71,11 +71,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260 - widgets: activate by identifier (trigger button, focus given id) - widgets: a way to represent "mixed" values, so e.g. all values replaced with *, including check-boxes, colors, etc. with support for multi-components widgets (e.g. SliderFloat3, make only "Y" mixed) (#2644) - - widgets: selectable: generic BeginSelectable()/EndSelectable() mechanism. - - widgets: selectable: a way to visualize partial/mixed selection (e.g. parent tree node has children with mixed selection) - widgets: checkbox: checkbox with custom glyph inside frame. - widgets: coloredit: keep reporting as active when picker is on? - widgets: group/scalarn functions: expose more per-component information. e.g. store NextItemData.ComponentIdx set by scalarn function, groups can expose them back somehow. + - selectable: using (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported. + - selectable: generic BeginSelectable()/EndSelectable() mechanism. + - selectable: a way to visualize partial/mixed selection (e.g. parent tree node has children with mixed selection) - input text: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now and super fragile. - input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541) diff --git a/imgui.cpp b/imgui.cpp index da5c5c3f..5dc479f7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1023,7 +1023,7 @@ ImGuiStyle::ImGuiStyle() TabBorderSize = 0.0f; // Thickness of border around tabs. ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text. - SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text when button is larger than text. + SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. diff --git a/imgui.h b/imgui.h index 32059b3b..098ff637 100644 --- a/imgui.h +++ b/imgui.h @@ -1141,8 +1141,12 @@ enum ImGuiCol_ }; // Enumeration for PushStyleVar() / PopStyleVar() to temporarily modify the ImGuiStyle structure. -// NB: the enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. During initialization, feel free to just poke into ImGuiStyle directly. -// NB: if changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type. +// - The enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. +// During initialization or between frames, feel free to just poke into ImGuiStyle directly. +// - Tip: Use your programming IDE navigation facilities on the names in the _second column_ below to find the actual members and their description. +// In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. +// - When changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type. enum ImGuiStyleVar_ { // Enum name --------------------- // Member in ImGuiStyle structure (see ImGuiStyle for descriptions) @@ -1387,7 +1391,7 @@ struct ImGuiStyle float TabBorderSize; // Thickness of border around tabs. ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right. ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered). - ImVec2 SelectableTextAlign; // Alignment of selectable text when selectable is larger than text. Defaults to (0.0f, 0.0f) (top-left aligned). + ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. ImVec2 DisplayWindowPadding; // Window position are clamped to be visible within the display area by at least this amount. Only applies to regular windows. ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 2664cb14..28a5940e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -643,9 +643,9 @@ static void ShowDemoWindowWidgets() static bool align_label_with_current_x_position = false; ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnArrow", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnArrow); ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnDoubleClick", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnDoubleClick); - ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanAvailWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanAvailWidth); + ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanAvailWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanAvailWidth); ImGui::SameLine(); HelpMarker("Extend hit area to all available width instead of allowing more items to be layed out after the node."); ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanFullWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanFullWidth); - ImGui::Checkbox("Align label with current X position)", &align_label_with_current_x_position); + ImGui::Checkbox("Align label with current X position", &align_label_with_current_x_position); ImGui::Text("Hello!"); if (align_label_with_current_x_position) ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing()); @@ -980,7 +980,7 @@ static void ShowDemoWindowWidgets() } if (ImGui::TreeNode("Alignment")) { - HelpMarker("Alignment applies when a selectable is larger than its text content.\nBy default, Selectables uses style.SelectableTextAlign but it can be overriden on a per-item basis using PushStyleVar()."); + HelpMarker("By default, Selectables uses style.SelectableTextAlign but it can be overriden on a per-item basis using PushStyleVar(). You'll probably want to always keep your default situation to left-align otherwise it becomes difficult to layout multiple items on a same line"); static bool selected[3*3] = { true, false, true, false, true, false, true, false, true }; for (int y = 0; y < 3; y++) { diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 7d0c9cbe..3a360b96 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5558,6 +5558,8 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags // Tip: pass a non-visible label (e.g. "##dummy") then you can use the space to draw other text or image. // But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID or use ##unique_id. +// With this scheme, ImGuiSelectableFlags_SpanAllColumns and ImGuiSelectableFlags_AllowItemOverlap are also frequently used flags. +// FIXME: Selectable() with (size.x == 0.0f) and (SelectableTextAlign.x > 0.0f) followed by SameLine() is currently not supported. bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg) { ImGuiWindow* window = GetCurrentWindow(); @@ -5579,13 +5581,17 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl ItemSize(size, 0.0f); // Fill horizontal space - const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax().x + window->Pos.x : GetContentRegionMaxAbs().x; + const float min_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? window->ContentRegionRect.Min.x : pos.x; + const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? window->ContentRegionRect.Max.x : GetContentRegionMaxAbs().x; if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth)) - size.x = ImMax(label_size.x, max_x - pos.x); - ImRect bb_align(pos, pos + size); + size.x = ImMax(label_size.x, max_x - min_x); + + // Text stays at the submission position, but bounding box may be extended on both sides + const ImVec2 text_min = pos; + const ImVec2 text_max(min_x + size.x, pos.y + size.y); // Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable. - ImRect bb_enlarged = bb_align; + ImRect bb_enlarged(min_x, pos.y, text_max.x, text_max.y); const float spacing_x = style.ItemSpacing.x; const float spacing_y = style.ItemSpacing.y; const float spacing_L = IM_FLOOR(spacing_x * 0.50f); @@ -5665,7 +5671,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl PopColumnsBackground(); if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); - RenderTextClipped(bb_align.Min, bb_align.Max, label, NULL, &label_size, style.SelectableTextAlign, &bb_enlarged); + RenderTextClipped(text_min, text_max, label, NULL, &label_size, style.SelectableTextAlign, &bb_enlarged); if (flags & ImGuiSelectableFlags_Disabled) PopStyleColor(); // Automatically close popups From 68c5d030cdb7c5f928bd961ac7081cdac7009b17 Mon Sep 17 00:00:00 2001 From: Dylan <24949824+dylanmit@users.noreply.github.com> Date: Mon, 30 Mar 2020 00:34:57 +1100 Subject: [PATCH 350/384] Typo in readme (#3078) --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 3e001024..30c5d1a9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -80,7 +80,7 @@ ImGui::End(); Result:
![sample code output](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/code_sample_03_color.gif) -Dear ImGui allows you **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. +Dear ImGui allows you to **create elaborate tools** as well as very short-lived ones. On the extreme side of short-livedness: using the Edit&Continue (hot code reload) feature of modern compilers you can add a few widgets to tweaks variables while your application is running, and remove the code a minute later! Dear ImGui is not just for tweaking values. You can use it to trace a running algorithm by just emitting text commands. You can use it along with your own reflection data to browse your dataset live. You can use it to expose the internals of a subsystem in your engine, to create a logger, an inspection tool, a profiler, a debugger, an entire game making editor/framework, etc. ### How it works From 05420ea2cfaab2fa5e4a66a2abf9b134d19f6fac Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 31 Mar 2020 19:29:46 +0200 Subject: [PATCH 351/384] TreeNode: Made clicking on arrow with _OpenOnArrow toggle the open state on the Mouse Down event rather than the Mouse Down+Up sequence (this is rather standard behavior). --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 07c882ba..8d8ea0b8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -47,6 +47,8 @@ Other Changes: glyph. (#2149, #515) - Selectable: Fixed honoring style.SelectableTextAlign with unspecified size. (#2347, #2601) - Selectable: Allow using ImGuiSelectableFlags_SpanAllColumns in other columns than first. (#125) +- TreeNode: Made clicking on arrow with _OpenOnArrow toggle the open state on the Mouse Down + event rather than the Mouse Down+Up sequence (this is rather standard behavior). - Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial cursor position. This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3a360b96..08b09f1d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5319,30 +5319,39 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l return is_open; } - // Flags that affects opening behavior: - // - 0 (default) .................... single-click anywhere to open - // - OpenOnDoubleClick .............. double-click anywhere to open - // - OpenOnArrow .................... single-click on arrow to open - // - OpenOnDoubleClick|OpenOnArrow .. single-click on arrow or double-click anywhere to open - ImGuiButtonFlags button_flags = 0; + ImGuiButtonFlags button_flags = ImGuiTreeNodeFlags_None; if (flags & ImGuiTreeNodeFlags_AllowItemOverlap) button_flags |= ImGuiButtonFlags_AllowItemOverlap; - if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) - button_flags |= ImGuiButtonFlags_PressedOnDoubleClick | ((flags & ImGuiTreeNodeFlags_OpenOnArrow) ? ImGuiButtonFlags_PressedOnClickRelease : 0); - else - button_flags |= ImGuiButtonFlags_PressedOnClickRelease; if (!is_leaf) button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; // We allow clicking on the arrow section with keyboard modifiers held, in order to easily // allow browsing a tree while preserving selection with code implementing multi-selection patterns. // When clicking on the rest of the tree node we always disallow keyboard modifiers. - const float hit_padding_x = style.TouchExtraPadding.x; - const float arrow_hit_x1 = (text_pos.x - text_offset_x) - hit_padding_x; - const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + hit_padding_x; - if (window != g.HoveredWindow || !(g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2)) + const float arrow_hit_x1 = (text_pos.x - text_offset_x) - style.TouchExtraPadding.x; + const float arrow_hit_x2 = (text_pos.x - text_offset_x) + (g.FontSize + padding.x * 2.0f) + style.TouchExtraPadding.x; + const bool is_mouse_x_over_arrow = (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2); + if (window != g.HoveredWindow || !is_mouse_x_over_arrow) button_flags |= ImGuiButtonFlags_NoKeyModifiers; + // Open behaviors can be altered with the _OpenOnArrow and _OnOnDoubleClick flags. + // Some alteration have subtle effects (e.g. toggle on MouseUp vs MouseDown events) due to requirements for multi-selection and drag and drop support. + // - Single-click on label = Toggle on MouseUp (default) + // - Single-click on arrow = Toggle on MouseUp (when _OpenOnArrow=0) + // - Single-click on arrow = Toggle on MouseDown (when _OpenOnArrow=1) + // - Double-click on label = Toggle on MouseDoubleClick (when _OpenOnDoubleClick=1) + // - Double-click on arrow = Toggle on MouseDoubleClick (when _OpenOnDoubleClick=1 and _OpenOnArrow=0) + // This makes _OpenOnArrow have a subtle effect on _OpenOnDoubleClick: arrow click reacts on Down rather than Up. + // It is rather standard that arrow click react on Down rather than Up and we'd be tempted to make it the default + // (by removing the _OpenOnArrow test below), however this would have a perhaps surprising effect on CollapsingHeader()? + // So right now we are making this optional. May evolve later. + if (is_mouse_x_over_arrow && (flags & ImGuiTreeNodeFlags_OpenOnArrow)) + button_flags |= ImGuiButtonFlags_PressedOnClick; + else if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) + button_flags |= ImGuiButtonFlags_PressedOnDoubleClick; + else + button_flags |= ImGuiButtonFlags_PressedOnClickRelease; + bool selected = (flags & ImGuiTreeNodeFlags_Selected) != 0; const bool was_selected = selected; @@ -5356,7 +5365,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) toggled = true; if (flags & ImGuiTreeNodeFlags_OpenOnArrow) - toggled |= (g.IO.MousePos.x >= arrow_hit_x1 && g.IO.MousePos.x < arrow_hit_x2) && (!g.NavDisableMouseHover); // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job + toggled |= is_mouse_x_over_arrow && !g.NavDisableMouseHover; // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0]) toggled = true; if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. From fd56de11447dbb79c88696e8e1b573cc5efedab1 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Apr 2020 16:45:57 +0200 Subject: [PATCH 352/384] Nav: Store key mods associated to a nav request (for range_select) + use io.KeyMods. + renamed NavScoringRectScreen > NavScoringRect --- imgui.cpp | 19 ++++++++++--------- imgui_internal.h | 9 +++++++-- imgui_widgets.cpp | 10 ++++++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5dc479f7..984c6676 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2226,7 +2226,7 @@ void ImGui::CalcListClipping(int items_count, float items_height, int* out_items // We create the union of the ClipRect and the NavScoringRect which at worst should be 1 page away from ClipRect ImRect unclipped_rect = window->ClipRect; if (g.NavMoveRequest) - unclipped_rect.Add(g.NavScoringRectScreen); + unclipped_rect.Add(g.NavScoringRect); const ImVec2 pos = window->DC.CursorPos; int start = (int)((unclipped_rect.Min.y - pos.y) / items_height); @@ -3677,7 +3677,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags() g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false; } -static ImGuiKeyModFlags GetMergedKeyModFlags() +ImGuiKeyModFlags ImGui::GetMergedKeyModFlags() { ImGuiContext& g = *GImGui; ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None; @@ -7988,7 +7988,7 @@ static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) if (g.NavLayer != window->DC.NavLayerCurrent) return false; - const ImRect& curr = g.NavScoringRectScreen; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width) + const ImRect& curr = g.NavScoringRect; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width) g.NavScoringCount++; // When entering through a NavFlattened border, we consider child window items as fully clipped for scoring @@ -8569,6 +8569,7 @@ static void ImGui::NavUpdate() if (g.NavMoveDir != ImGuiDir_None) { g.NavMoveRequest = true; + g.NavMoveRequestKeyMods = g.IO.KeyMods; g.NavMoveDirLast = g.NavMoveDir; } if (g.NavMoveRequest && g.NavId == 0) @@ -8632,11 +8633,11 @@ static void ImGui::NavUpdate() // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items) ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0); - g.NavScoringRectScreen = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : GetViewportRect(); - g.NavScoringRectScreen.TranslateY(nav_scoring_rect_offset_y); - g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x); - g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x; - IM_ASSERT(!g.NavScoringRectScreen.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem(). + g.NavScoringRect = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : GetViewportRect(); + g.NavScoringRect.TranslateY(nav_scoring_rect_offset_y); + g.NavScoringRect.Min.x = ImMin(g.NavScoringRect.Min.x + 1.0f, g.NavScoringRect.Max.x); + g.NavScoringRect.Max.x = g.NavScoringRect.Min.x; + IM_ASSERT(!g.NavScoringRect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem(). //GetForegroundDrawList()->AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG] g.NavScoringCount = 0; #if IMGUI_DEBUG_NAV_RECTS @@ -8706,7 +8707,7 @@ static void ImGui::NavUpdateMoveResult() // Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId) g.NavJustMovedToId = result->ID; g.NavJustMovedToFocusScopeId = result->FocusScopeId; - + g.NavJustMovedToKeyMods = g.NavMoveRequestKeyMods; } SetNavIDWithRectRel(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel); g.NavMoveFromClampedRefRect = false; diff --git a/imgui_internal.h b/imgui_internal.h index eb5c82e7..705f904d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1098,9 +1098,10 @@ struct ImGuiContext ImGuiID NavJustTabbedId; // Just tabbed to this id. ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). + ImGuiKeyModFlags NavJustMovedToKeyMods; ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. - ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. + ImRect NavScoringRect; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring. int NavScoringCount; // Metrics for debugging ImGuiNavLayer NavLayer; // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later. int NavIdTabCounter; // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing @@ -1117,6 +1118,7 @@ struct ImGuiContext bool NavMoveRequest; // Move request for this frame ImGuiNavMoveFlags NavMoveRequestFlags; ImGuiNavForward NavMoveRequestForward; // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu) + ImGuiKeyModFlags NavMoveRequestKeyMods; ImGuiDir NavMoveDir, NavMoveDirLast; // Direction of the move request (left/right/up/down), direction of the previous move request ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename? ImGuiNavMoveResult NavMoveResultLocal; // Best move request candidate within NavWindow @@ -1274,8 +1276,9 @@ struct ImGuiContext NavWindow = NULL; NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; + NavJustMovedToKeyMods = ImGuiKeyModFlags_None; NavInputSource = ImGuiInputSource_None; - NavScoringRectScreen = ImRect(); + NavScoringRect = ImRect(); NavScoringCount = 0; NavLayer = ImGuiNavLayer_Main; NavIdTabCounter = INT_MAX; @@ -1291,6 +1294,7 @@ struct ImGuiContext NavMoveRequest = false; NavMoveRequestFlags = ImGuiNavMoveFlags_None; NavMoveRequestForward = ImGuiNavForward_None; + NavMoveRequestKeyMods = ImGuiKeyModFlags_None; NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None; NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL; @@ -1777,6 +1781,7 @@ namespace ImGui inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } + IMGUI_API ImGuiKeyModFlags GetMergedKeyModFlags(); // Drag and Drop IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 08b09f1d..c204a652 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3728,14 +3728,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id) { IM_ASSERT(state != NULL); + IM_ASSERT(io.KeyMods == GetMergedKeyModFlags() && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); // We rarely do this check, but if anything let's do it here. + const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0); const bool is_osx = io.ConfigMacOSXBehaviors; - const bool is_shortcut_key = (is_osx ? (io.KeySuper && !io.KeyCtrl) : (io.KeyCtrl && !io.KeySuper)) && !io.KeyAlt && !io.KeyShift; // OS X style: Shortcuts using Cmd/Super instead of Ctrl - const bool is_osx_shift_shortcut = is_osx && io.KeySuper && io.KeyShift && !io.KeyCtrl && !io.KeyAlt; + const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiKeyModFlags_Super | ImGuiKeyModFlags_Shift)); const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl; // OS X style: Text editing cursor movement using Alt instead of Ctrl const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt; // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End - const bool is_ctrl_key_only = io.KeyCtrl && !io.KeyShift && !io.KeyAlt && !io.KeySuper; - const bool is_shift_key_only = io.KeyShift && !io.KeyCtrl && !io.KeyAlt && !io.KeySuper; + const bool is_ctrl_key_only = (io.KeyMods == ImGuiKeyModFlags_Ctrl); + const bool is_shift_key_only = (io.KeyMods == ImGuiKeyModFlags_Shift); + const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiKeyModFlags_Super) : (io.KeyMods == ImGuiKeyModFlags_Ctrl); const bool is_cut = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection()); const bool is_copy = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressedMap(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection()); From 3490046c9746a1beedef6da921fe3f5412792ec9 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Apr 2020 17:36:23 +0200 Subject: [PATCH 353/384] Nav: Disabled clipping g.NavId and fixed interactions with ImGuiListClipper. (#787) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8d8ea0b8..adc5fac2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -49,6 +49,9 @@ Other Changes: - Selectable: Allow using ImGuiSelectableFlags_SpanAllColumns in other columns than first. (#125) - TreeNode: Made clicking on arrow with _OpenOnArrow toggle the open state on the Mouse Down event rather than the Mouse Down+Up sequence (this is rather standard behavior). +- Nav: Fixed interactions with ImGuiListClipper, so e.g. Home/End result would not clip the + landing item on the landing frame. (#787) +- Nav: Fixed currently focused item from ever being clipped by ItemAdd(). (#787) - Scrolling: Fixed scrolling centering API leading to non-integer scrolling values and initial cursor position. This would often get fixed after the fix item submission, but using the ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) diff --git a/imgui.cpp b/imgui.cpp index 984c6676..2d3f3164 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2227,6 +2227,8 @@ void ImGui::CalcListClipping(int items_count, float items_height, int* out_items ImRect unclipped_rect = window->ClipRect; if (g.NavMoveRequest) unclipped_rect.Add(g.NavScoringRect); + if (g.NavJustMovedToId && window->NavLastIds[0] == g.NavJustMovedToId) + unclipped_rect.Add(ImRect(window->Pos + window->NavRectRel[0].Min, window->Pos + window->NavRectRel[0].Max)); const ImVec2 pos = window->DC.CursorPos; int start = (int)((unclipped_rect.Min.y - pos.y) / items_height); @@ -3142,7 +3144,7 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; if (!bb.Overlaps(window->ClipRect)) - if (id == 0 || id != g.ActiveId) + if (id == 0 || (id != g.ActiveId && id != g.NavId)) if (clip_even_when_logged || !g.LogEnabled) return true; return false; From 11116eee8068d285397930cd08b5486990533ccf Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Apr 2020 20:01:48 +0200 Subject: [PATCH 354/384] Columns: undid the change in 1.75 were Columns()/BeginColumns() were preemptively limited to 64 columns with an assert. (#3037, #125) Essentially reverting 9d444062f974b21f1fc09b7e85479fff3e0789c2. --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 2 +- imgui_widgets.cpp | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index adc5fac2..bec2d702 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,8 @@ Other Changes: - sizeof(ImWchar) goes from 2 to 4. IM_UNICODE_CODEPOINT_MAX goes from 0xFFFF to 0x10FFFF. - Various structures such as ImFont, ImFontGlyphRangesBuilder will use more memory, this is currently not particularly efficient. +- Columns: undid the change in 1.75 were Columns()/BeginColumns() were preemptively limited + to 64 columns with an assert. (#3037, #125) - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. @@ -121,6 +123,7 @@ Breaking Changes: - ImDrawList::AddCircle()/AddCircleFilled() functions don't accept negative radius. - Limiting Columns()/BeginColumns() api to 64 columns with an assert. While the current code technically supports it, future code may not so we're putting the restriction ahead. + [Undid that change in 1.76] - imgui_internal.h: changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding points into it without explicit initialization, you may need to fix your initial value. diff --git a/imgui.cpp b/imgui.cpp index 2d3f3164..99689a43 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -367,7 +367,7 @@ CODE You can read releases logs https://github.com/ocornut/imgui/releases for more details. - 2020/01/22 (1.75) - ImDrawList::AddCircle()/AddCircleFilled() functions don't accept negative radius any more. - - 2019/12/17 (1.75) - made Columns() limited to 64 columns by asserting above that limit. While the current code technically supports it, future code may not so we're putting the restriction ahead. + - 2019/12/17 (1.75) - [undid this change in 1.76] made Columns() limited to 64 columns by asserting above that limit. While the current code technically supports it, future code may not so we're putting the restriction ahead. - 2019/12/13 (1.75) - [imgui_internal.h] changed ImRect() default constructor initializes all fields to 0.0f instead of (FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX). If you used ImRect::Add() to create bounding boxes by adding multiple points into it, you may need to fix your initial value. - 2019/12/08 (1.75) - removed redirecting functions/enums that were marked obsolete in 1.53 (December 2017): - ShowTestWindow() -> use ShowDemoWindow() diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index c204a652..a43205c8 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7498,8 +7498,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - IM_ASSERT(columns_count >= 1 && columns_count <= 64); // Maximum 64 columns - IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported + IM_ASSERT(columns_count >= 1); + IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported // Acquire storage for the columns set ImGuiID id = GetColumnsID(str_id, columns_count); From b7e1b13ca7a09e1afd23ffb3d9a87508bcbc7ba8 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Apr 2020 21:53:10 +0200 Subject: [PATCH 355/384] Update docs, FAQ, comments (mainly related to io.WantCaptureMouse / WantCaptureKeyboard flags). --- docs/FAQ.md | 8 ++++++-- imgui.cpp | 26 ++++++++++++++++---------- imgui.h | 26 ++++++++++++++------------ imgui_internal.h | 4 ++-- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index d629ff4b..3d73a0f4 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -96,9 +96,13 @@ e.g. `if (ImGui::GetIO().WantCaptureMouse) { ... }` **Note:** You should always pass your mouse/keyboard inputs to Dear ImGui, even when the io.WantCaptureXXX flag are set false. This is because imgui needs to detect that you clicked in the void to unfocus its own windows. -**Note:** The `io.WantCaptureMouse` is more accurate that any manual attempt to "check if the mouse is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs. Those flags are updated by `ImGui::NewFrame()`. Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you might find use for an early call to `UpdateHoveredWindowAndCaptureFlags()`. +**Note:** The `io.WantCaptureMouse` is more correct that any manual attempt to "check if the mouse is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging that started over your application or over a Dear ImGui window) and handle e.g. popup and modal windows blocking inputs. -**Note:** Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp" event that your application receive will typically have `io.WantCaptureKeyboard == false`. Depending on your application logic it may or not be inconvenient. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) +**Note:** Those flags are updated by `ImGui::NewFrame()`. However it is generally more correct and easier that you poll flags from the previous frame, then submit your inputs, then call `NewFrame()`. If you attempt to do the opposite (which is generally harder) you are likely going to submit your inputs after `NewFrame()`, and therefore too late. + +**Note:** If you are using a touch device, you may find use for an early call to `UpdateHoveredWindowAndCaptureFlags()` to correctly dispatch your initial touch. We will work on better out-of-the-box touch support in the future. + +**Note:** Text input widget releases focus on the "KeyDown" event of the Return key, so the subsequent "KeyUp" event that your application receive will typically have `io.WantCaptureKeyboard == false`. Depending on your application logic it may or not be inconvenient to receive that KeyUp event. You might want to track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and filter out the corresponding key-ups.) ##### [Return to Index](#index) diff --git a/imgui.cpp b/imgui.cpp index 99689a43..90513c18 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -40,7 +40,7 @@ DOCUMENTATION - READ FIRST - HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI - GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE - - HOW A SIMPLE APPLICATION MAY LOOK LIKE (2 variations) + - HOW A SIMPLE APPLICATION MAY LOOK LIKE - HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE - USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS - API BREAKING CHANGES (read me when you update!) @@ -139,7 +139,7 @@ CODE - Call and read ImGui::ShowDemoWindow() for demo code demonstrating most features. - The library is designed to be built from sources. Avoid pre-compiled binaries and packaged versions. See imconfig.h to configure your build. - Dear ImGui is an implementation of the IMGUI paradigm (immediate-mode graphical user interface, a term coined by Casey Muratori). - You can learn about IMGUI principles at http://www.johno.se/book/imgui.html, http://mollyrocket.com/861 & more links docs/README.md. + You can learn about IMGUI principles at http://www.johno.se/book/imgui.html, http://mollyrocket.com/861 & more links in the FAQ. - Dear ImGui is a "single pass" rasterizing implementation of the IMGUI paradigm, aimed at ease of use and high-performances. For every application frame your UI code will be called only once. This is in contrast to e.g. Unity's own implementation of an IMGUI, where the UI code is called multiple times ("multiple passes") from a single entry point. There are pros and cons to both approaches. @@ -153,6 +153,7 @@ CODE However, imgui_internal.h can optionally export math operators for ImVec2/ImVec4, which we use in this codebase. - C++: pay attention that ImVector<> manipulates plain-old-data and does not honor construction/destruction (avoid using it in your code!). + HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI ---------------------------------------------- - Overwrite all the sources files except for imconfig.h (if you have made modification to your copy of imconfig.h) @@ -163,6 +164,7 @@ CODE likely be a comment about it. Please report any issue to the GitHub page! - Try to keep your copy of dear imgui reasonably up to date. + GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE --------------------------------------------------------------- - Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library. @@ -177,9 +179,11 @@ CODE - Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code. - If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder. + HOW A SIMPLE APPLICATION MAY LOOK LIKE -------------------------------------- - EXHIBIT 1: USING THE EXAMPLE BINDINGS (imgui_impl_XXX.cpp files from the examples/ folder). + EXHIBIT 1: USING THE EXAMPLE BINDINGS (= imgui_impl_XXX.cpp files from the examples/ folder). + The sub-folders in examples/ contains examples applications following this structure. // Application init: create a dear imgui context, setup some options, load fonts ImGui::CreateContext(); @@ -268,8 +272,15 @@ CODE // Shutdown ImGui::DestroyContext(); + To decide whether to dispatch mouse/keyboard inputs to Dear ImGui to the rest your application, + you should read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags! + Please read the FAQ and example applications for details about this! + + HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE --------------------------------------------- + The bindings in impl_impl_XXX.cpp files contains many working implementations of a rendering function. + void void MyImGuiRenderFunction(ImDrawData* draw_data) { // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled @@ -314,11 +325,6 @@ CODE } } - - The examples/ folders contains many actual implementation of the pseudo-codes above. - - When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated. - They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs from the - rest of your application. In every cases you need to pass on the inputs to Dear ImGui. - - Refer to the FAQ for more information. Amusingly, it is called a FAQ because people frequently run into the same issues! USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS ------------------------------------------ @@ -3797,7 +3803,7 @@ void ImGui::NewFrame() for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f; - // Update gamepad/keyboard directional navigation + // Update gamepad/keyboard navigation NavUpdate(); // Update mouse input state @@ -7982,7 +7988,7 @@ static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect } } -// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057 +// Scoring function for gamepad/keyboard directional navigation. Based on https://gist.github.com/rygorous/6981057 static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index 098ff637..53b2ccab 100644 --- a/imgui.h +++ b/imgui.h @@ -910,12 +910,12 @@ enum ImGuiFocusedFlags_ ImGuiFocusedFlags_None = 0, ImGuiFocusedFlags_ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused ImGuiFocusedFlags_RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) - ImGuiFocusedFlags_AnyWindow = 1 << 2, // IsWindowFocused(): Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use ImGui::GetIO().WantCaptureMouse instead. + ImGuiFocusedFlags_AnyWindow = 1 << 2, // IsWindowFocused(): Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use 'io.WantCaptureMouse' instead! Please read the FAQ! ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows }; // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() -// Note: if you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that. Please read the FAQ! +// Note: if you are trying to check whether your mouse should be dispatched to Dear ImGui or to your app, you should use 'io.WantCaptureMouse' instead! Please read the FAQ! // Note: windows with the ImGuiWindowFlags_NoInputs flag are ignored by IsWindowHovered() calls. enum ImGuiHoveredFlags_ { @@ -1019,7 +1019,7 @@ enum ImGuiKeyModFlags_ ImGuiKeyModFlags_Super = 1 << 3 }; -// Gamepad/Keyboard directional navigation +// Gamepad/Keyboard navigation // Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. // Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Back-end: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame(). // Read instructions in imgui.cpp for more details. Download PNG/PSD at http://goo.gl/9LgVZW. @@ -1500,17 +1500,19 @@ struct ImGuiIO IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually //------------------------------------------------------------------ - // Output - Retrieve after calling NewFrame() + // Output - Updated by NewFrame() or EndFrame()/Render() + // (when reading from the io.WantCaptureMouse, io.WantCaptureKeyboard flags to dispatch your inputs, it is + // generally easier and more correct to use their state BEFORE calling NewFrame(). See FAQ for details!) //------------------------------------------------------------------ - bool WantCaptureMouse; // When io.WantCaptureMouse is true, imgui will use the mouse inputs, do not dispatch them to your main game/application (in both cases, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.). - bool WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, imgui will use the keyboard inputs, do not dispatch them to your main game/application (in both cases, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.). - bool WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). - bool WantSetMousePos; // MousePos has been altered, back-end should reposition mouse on next frame. Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled. - bool WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. IMPORTANT: You need to clear io.WantSaveIniSettings yourself. - bool NavActive; // Directional navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. - bool NavVisible; // Directional navigation is visible and allowed (will handle ImGuiKey_NavXXX events). - float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames + bool WantCaptureMouse; // Set when Dear ImGui will use mouse inputs, in this case do not dispatch them to your main game/application (either way, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.). + bool WantCaptureKeyboard; // Set when Dear ImGui will use keyboard inputs, in this case do not dispatch them to your main game/application (either way, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.). + bool WantTextInput; // Mobile/console: when set, you may display an on-screen keyboard. This is set by Dear ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). + bool WantSetMousePos; // MousePos has been altered, back-end should reposition mouse on next frame. Rarely used! Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled. + bool WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. Important: clear io.WantSaveIniSettings yourself after saving! + bool NavActive; // Keyboard/Gamepad navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. + bool NavVisible; // Keyboard/Gamepad navigation is visible and allowed (will handle ImGuiKey_NavXXX events). + float Framerate; // Application framerate estimate, in frame per second. Solely for convenience. Rolling average estimation based on io.DeltaTime over 120 frames. int MetricsRenderVertices; // Vertices output during last call to Render() int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 int MetricsRenderWindows; // Number of visible windows diff --git a/imgui_internal.h b/imgui_internal.h index 705f904d..06832ee7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -86,7 +86,7 @@ struct ImGuiGroupData; // Stacked storage data for BeginGroup()/End struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box struct ImGuiItemHoveredDataBackup; // Backup and restore IsItemHovered() internal data struct ImGuiMenuColumns; // Simple column measurement, currently used for MenuItem() only -struct ImGuiNavMoveResult; // Result of a directional navigation move query result +struct ImGuiNavMoveResult; // Result of a gamepad/keyboard directional navigation move query result struct ImGuiNextWindowData; // Storage for SetNextWindow** functions struct ImGuiNextItemData; // Storage for SetNextItem** functions struct ImGuiPopupData; // Storage for current popup stack @@ -1062,7 +1062,7 @@ struct ImGuiContext bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch. bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state. bool ActiveIdHasBeenEditedThisFrame; - ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those directional navigation requests (e.g. can activate a button and move away from it) + ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it) ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs. ImU64 ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) From cc0d4e346a3e4a5408c85c7e6bf0df5e1307bb2d Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 Apr 2020 12:14:03 +0200 Subject: [PATCH 356/384] Misc: Added an explicit compile-time test for non-scoped IM_ASSERT() macros to redirect users to a solution + fixed our stb wrappers. + Nav: Use nav layer enum, comments. --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_win32.h | 6 +++--- imgui.cpp | 24 ++++++++++++++++-------- imgui_draw.cpp | 4 ++-- imgui_widgets.cpp | 2 +- misc/freetype/imgui_freetype.cpp | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bec2d702..5b7fa035 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -69,6 +69,8 @@ Other Changes: - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] - Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. +- Misc: Added an explicit compile-time test for non-scoped IM_ASSERT() macros to redirect users + to a solution rather than encourage people to add braces in the codebase. - Misc: Added additional checks in EndFrame() to verify that io.KeyXXX values have not been tampered with between NewFrame() and EndFrame(). - Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index daadf317..41bae701 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -17,9 +17,9 @@ IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT -// Win32 message handler -// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on -// - You can COPY this line into your .cpp code to forward declare the function. +// Win32 message handler your application need to call. +// - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. +// - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. #if 0 extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif diff --git a/imgui.cpp b/imgui.cpp index 90513c18..ad39fa14 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6718,6 +6718,14 @@ static void ImGui::ErrorCheckNewFrameSanityChecks() { ImGuiContext& g = *GImGui; + // Check user IM_ASSERT macro + // (IF YOU GET A WARNING OR COMPILE ERROR HERE: it means you assert macro is incorrectly defined! + // If your macro uses multiple statements, it NEEDS to be surrounded by a 'do { ... } while (0)' block. + // This is a common C/C++ idiom to allow multiple statements macros to be used in control flow blocks.) + // #define IM_ASSERT(EXPR) SomeCode(EXPR); SomeMoreCode(); // Wrong! + // #define IM_ASSERT(EXPR) do { SomeCode(EXPR); SomeMoreCode(); } while (0) // Correct! + if (true) IM_ASSERT(1); else IM_ASSERT(0); + // Check user data // (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument) IM_ASSERT(g.Initialized); @@ -7631,7 +7639,7 @@ void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_ } else { - if (g.NavLayer == 0 && focus_window) + if (g.NavLayer == ImGuiNavLayer_Main && focus_window) focus_window = NavRestoreLastChildNavWindow(focus_window); FocusWindow(focus_window); } @@ -8110,7 +8118,7 @@ static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand) // 2017/09/29: FIXME: This now currently only enabled inside menu bars, ideally we'd disable it everywhere. Menus in particular need to catch failure. For general navigation it feels awkward. // Disabling it may lead to disconnected graphs when nodes are very spaced out on different axis. Perhaps consider offering this as an option? if (result->DistBox == FLT_MAX && dist_axial < result->DistAxial) // Check axial match - if (g.NavLayer == 1 && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu)) + if (g.NavLayer == ImGuiNavLayer_Menu && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu)) if ((g.NavMoveDir == ImGuiDir_Left && dax < 0.0f) || (g.NavMoveDir == ImGuiDir_Right && dax > 0.0f) || (g.NavMoveDir == ImGuiDir_Up && day < 0.0f) || (g.NavMoveDir == ImGuiDir_Down && day > 0.0f)) { result->DistAxial = dist_axial; @@ -8221,7 +8229,7 @@ void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const Im void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags) { ImGuiContext& g = *GImGui; - if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != 0) + if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != ImGuiNavLayer_Main) return; IM_ASSERT(move_flags != 0); // No points calling this with no wrapping ImRect bb_rel = window->NavRectRel[0]; @@ -8466,7 +8474,7 @@ static void ImGui::NavUpdate() // Store our return window (for returning from Layer 1 to Layer 0) and clear it as soon as we step back in our own Layer 0 if (g.NavWindow) NavSaveLastChildNavWindowIntoParent(g.NavWindow); - if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0) + if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == ImGuiNavLayer_Main) g.NavWindow->NavLastChildNavWindow = NULL; // Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.) @@ -8503,7 +8511,7 @@ static void ImGui::NavUpdate() if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); } - else if (g.NavLayer != 0) + else if (g.NavLayer != ImGuiNavLayer_Main) { // Leave the "menu" layer NavRestoreLayer(ImGuiNavLayer_Main); @@ -8625,7 +8633,7 @@ static void ImGui::NavUpdate() g.NavMoveResultOther.Clear(); // When we have manually scrolled (without using navigation) and NavId becomes out of bounds, we project its bounding box to the visible area to restart navigation within visible items - if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0) + if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == ImGuiNavLayer_Main) { ImGuiWindow* window = g.NavWindow; ImRect window_rect_rel(window->InnerRect.Min - window->Pos - ImVec2(1,1), window->InnerRect.Max - window->Pos + ImVec2(1,1)); @@ -8688,7 +8696,7 @@ static void ImGui::NavUpdateMoveResult() IM_ASSERT(g.NavWindow && result->Window); // Scroll to keep newly navigated item fully into view. - if (g.NavLayer == 0) + if (g.NavLayer == ImGuiNavLayer_Main) { ImVec2 delta_scroll; if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_ScrollToEdge) @@ -8727,7 +8735,7 @@ static float ImGui::NavUpdatePageUpPageDown() ImGuiContext& g = *GImGui; if (g.NavMoveDir != ImGuiDir_None || g.NavWindow == NULL) return 0.0f; - if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != 0) + if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != ImGuiNavLayer_Main) return 0.0f; ImGuiWindow* window = g.NavWindow; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 87c81edc..f02c7a90 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -120,7 +120,7 @@ namespace IMGUI_STB_NAMESPACE #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION #define STBRP_STATIC -#define STBRP_ASSERT(x) IM_ASSERT(x) +#define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0) #define STBRP_SORT ImQsort #define STB_RECT_PACK_IMPLEMENTATION #endif @@ -135,7 +135,7 @@ namespace IMGUI_STB_NAMESPACE #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION #define STBTT_malloc(x,u) ((void)(u), IM_ALLOC(x)) #define STBTT_free(x,u) ((void)(u), IM_FREE(x)) -#define STBTT_assert(x) IM_ASSERT(x) +#define STBTT_assert(x) do { IM_ASSERT(x); } while(0) #define STBTT_fmod(x,y) ImFmod(x,y) #define STBTT_sqrt(x) ImSqrt(x) #define STBTT_pow(x,y) ImPow(x,y) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a43205c8..a28fbdaa 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6178,7 +6178,7 @@ void ImGui::EndMainMenuBar() // When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window // FIXME: With this strategy we won't be able to restore a NULL focus. ImGuiContext& g = *GImGui; - if (g.CurrentWindow == g.NavWindow && g.NavLayer == 0 && !g.NavAnyRequest) + if (g.CurrentWindow == g.NavWindow && g.NavLayer == ImGuiNavLayer_Main && !g.NavAnyRequest) FocusTopMostWindowUnderOne(g.NavWindow, NULL); End(); diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 93a56163..b4ef795a 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -280,7 +280,7 @@ namespace #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION -#define STBRP_ASSERT(x) IM_ASSERT(x) +#define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0) #define STBRP_STATIC #define STB_RECT_PACK_IMPLEMENTATION #endif From 6d03f93067223b2f1e63e50649308eb5f85a8fea Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Apr 2020 15:03:01 +0200 Subject: [PATCH 357/384] Docking: Fixed assert preventing dockspace from being stored into a tab. (#3101) --- imgui_widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5081650c..64c3e7ea 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6849,7 +6849,7 @@ void ImGui::TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGu { ImGuiContext& g = *GImGui; IM_ASSERT(TabBarFindTabByID(tab_bar, window->ID) == NULL); - IM_ASSERT(g.CurrentTabBar == NULL); // Can't work while the tab bar is active as our tab doesn't have an X offset yet + IM_ASSERT(g.CurrentTabBar != tab_bar); // Can't work while the tab bar is active as our tab doesn't have an X offset yet, in theory we could/should test something like (tab_bar->CurrFrameVisible < g.FrameCount) but we'd need to solve why triggers the commented early-out assert in BeginTabBarEx() (probably dock node going from implicit to explicit in same frame) ImGuiTabItem new_tab; new_tab.ID = window->ID; From 752436219d2c34ff8993115c8bc826900a88ce3a Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Apr 2020 18:07:42 +0200 Subject: [PATCH 358/384] Metrics: Made Tools section more prominent, added options, made mesh viewer more accessible. --- docs/CHANGELOG.txt | 3 ++ imgui.cpp | 131 ++++++++++++++++++++++++++------------------- 2 files changed, 79 insertions(+), 55 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5b7fa035..6bdb7512 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,9 @@ Other Changes: tampered with between NewFrame() and EndFrame(). - Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult] +- Metrics: Made Tools section more prominent. Showing wire-frame mesh directly hovering the ImDrawCmd + instead of requiring to open it. Added options to disable bounding box and mesh display. + Added notes on inactive/gc-ed windows. - Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering. - CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building SDL+Metal example, building imgui_freetype.cpp, more compile-time imconfig.h settings: disabling diff --git a/imgui.cpp b/imgui.cpp index ad39fa14..9876cf92 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9990,7 +9990,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) static bool show_windows_begin_order = false; static bool show_tables_rects = false; static int show_tables_rect_type = TRT_WorkRect; - static bool show_drawcmd_details = true; + static bool show_drawcmd_mesh = true; + static bool show_drawcmd_aabb = true; // Basic info ImGuiContext& g = *GImGui; @@ -10024,6 +10025,38 @@ void ImGui::ShowMetricsWindow(bool* p_open) return ImRect(); } + static void NodeDrawCmdShowMeshAndBoundingBox(ImGuiWindow* window, const ImDrawList* draw_list, const ImDrawCmd* draw_cmd, int elem_offset, bool show_mesh, bool show_aabb) + { + IM_ASSERT(show_mesh || show_aabb); + ImDrawList* fg_draw_list = GetForegroundDrawList(window); // Render additional visuals into the top-most draw list + ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL; + + // Draw wire-frame version of all triangles + ImRect clip_rect = draw_cmd->ClipRect; + ImRect vtxs_rect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); + ImDrawListFlags backup_flags = fg_draw_list->Flags; + fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles. + for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + draw_cmd->ElemCount); base_idx += 3) + { + ImVec2 triangle[3]; + for (int n = 0; n < 3; n++) + { + ImVec2 p = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos; + triangle[n] = p; + vtxs_rect.Add(p); + } + if (show_mesh) + fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); // In yellow: mesh triangles + } + // Draw bounding boxes + if (show_aabb) + { + fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255, 0, 255, 255)); // In pink: clipping rectangle submitted to GPU + fg_draw_list->AddRect(ImFloor(vtxs_rect.Min), ImFloor(vtxs_rect.Max), IM_COL32(0, 255, 255, 255)); // In cyan: bounding box of triangles + } + fg_draw_list->Flags = backup_flags; + } + static void NodeDrawList(ImGuiWindow* window, ImDrawList* draw_list, const char* label) { bool node_open = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d indices, %d cmds", label, draw_list->_OwnerName ? draw_list->_OwnerName : "", draw_list->VtxBuffer.Size, draw_list->IdxBuffer.Size, draw_list->CmdBuffer.Size); @@ -10061,15 +10094,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w); bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf); - if (show_drawcmd_details && fg_draw_list && ImGui::IsItemHovered()) - { - ImRect clip_rect = pcmd->ClipRect; - ImRect vtxs_rect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); - for (unsigned int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++) - vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos); - fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255,0,255,255)); - fg_draw_list->AddRect(ImFloor(vtxs_rect.Min), ImFloor(vtxs_rect.Max), IM_COL32(255,255,0,255)); - } + if (ImGui::IsItemHovered() && (show_drawcmd_mesh || show_drawcmd_aabb) && fg_draw_list) + NodeDrawCmdShowMeshAndBoundingBox(window, draw_list, pcmd, elem_offset, show_drawcmd_mesh, show_drawcmd_aabb); if (!pcmd_node_open) continue; @@ -10087,22 +10113,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) // Display vertex information summary. Hover to get all triangles drawn in wire-frame ImFormatString(buf, IM_ARRAYSIZE(buf), "Mesh: ElemCount: %d, VtxOffset: +%d, IdxOffset: +%d, Area: ~%0.f px", pcmd->ElemCount, pcmd->VtxOffset, pcmd->IdxOffset, total_area); ImGui::Selectable(buf); - if (fg_draw_list && ImGui::IsItemHovered() && show_drawcmd_details) - { - // Draw wire-frame version of everything - ImDrawListFlags backup_flags = fg_draw_list->Flags; - fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles. - ImRect clip_rect = pcmd->ClipRect; - fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255, 0, 255, 255)); - for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3) - { - ImVec2 triangle[3]; - for (int n = 0; n < 3; n++) - triangle[n] = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos; - fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); - } - fg_draw_list->Flags = backup_flags; - } + if (ImGui::IsItemHovered() && fg_draw_list) + NodeDrawCmdShowMeshAndBoundingBox(window, draw_list, pcmd, elem_offset, true, false); // Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted. ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible. @@ -10168,6 +10180,12 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::GetForegroundDrawList()->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255)); if (!open) return; + + if (!window->WasActive) + ImGui::TextDisabled("Note: window is not currently visible."); + if (window->MemoryCompacted) + ImGui::TextDisabled("Note: some memory buffers have been compacted/freed."); + ImGuiWindowFlags flags = window->Flags; NodeDrawList(window, window->DrawList, "DrawList"); ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y); @@ -10232,6 +10250,38 @@ void ImGui::ShowMetricsWindow(bool* p_open) } }; + + // Tools + if (ImGui::TreeNode("Tools")) + { + // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. + if (ImGui::Button("Item Picker..")) + ImGui::DebugStartItemPicker(); + ImGui::SameLine(); + MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); + + ImGui::Checkbox("Show windows begin order", &show_windows_begin_order); + ImGui::Checkbox("Show windows rectangles", &show_windows_rects); + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12); + show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count); + if (show_windows_rects && g.NavWindow) + { + ImGui::BulletText("'%s':", g.NavWindow->Name); + ImGui::Indent(); + for (int rect_n = 0; rect_n < WRT_Count; rect_n++) + { + ImRect r = Funcs::GetWindowRect(g.NavWindow, rect_n); + ImGui::Text("(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) %s", r.Min.x, r.Min.y, r.Max.x, r.Max.y, r.GetWidth(), r.GetHeight(), wrt_rects_names[rect_n]); + } + ImGui::Unindent(); + } + ImGui::Checkbox("Show mesh when hovering ImDrawCmd", &show_drawcmd_mesh); + ImGui::Checkbox("Show bounding boxes when hovering ImDrawCmd", &show_drawcmd_aabb); + ImGui::TreePop(); + } + + // Contents Funcs::NodeWindows(g.Windows, "Windows"); //Funcs::NodeWindows(g.WindowsFocusOrder, "WindowsFocusOrder"); if (ImGui::TreeNode("DrawLists", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size)) @@ -10302,35 +10352,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) ImGui::TreePop(); } - // Tools - if (ImGui::TreeNode("Tools")) - { - // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. - if (ImGui::Button("Item Picker..")) - ImGui::DebugStartItemPicker(); - ImGui::SameLine(); - MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); - - ImGui::Checkbox("Show windows begin order", &show_windows_begin_order); - ImGui::Checkbox("Show windows rectangles", &show_windows_rects); - ImGui::SameLine(); - ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12); - show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count); - if (show_windows_rects && g.NavWindow) - { - ImGui::BulletText("'%s':", g.NavWindow->Name); - ImGui::Indent(); - for (int rect_n = 0; rect_n < WRT_Count; rect_n++) - { - ImRect r = Funcs::GetWindowRect(g.NavWindow, rect_n); - ImGui::Text("(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) %s", r.Min.x, r.Min.y, r.Max.x, r.Max.y, r.GetWidth(), r.GetHeight(), wrt_rects_names[rect_n]); - } - ImGui::Unindent(); - } - ImGui::Checkbox("Show details when hovering ImDrawCmd node", &show_drawcmd_details); - ImGui::TreePop(); - } - // Overlay: Display windows Rectangles and Begin Order if (show_windows_rects || show_windows_begin_order) { From 00927105ba6b14f6d05a651b316428a8342fb4d3 Mon Sep 17 00:00:00 2001 From: OmarEmaraDev Date: Mon, 6 Apr 2020 20:23:57 +0200 Subject: [PATCH 359/384] Backends: Include imgui.h in implementation headers. (#3105) Currently, the implementation headers don't include the imgui.h header. Which means that the compilation will fail if the implementation header was included before the imgui.h header in the compilation unit. For instance, a compilation unit with the following will work: #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" But a compilation unit with the following will fail because IMGUI_IMPL_API and possibly other symbols will not be defined: #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include "imgui.h" This patch includes imgui.h in the implementation headers to make inclusions order-invariant, which is a recommended practice. --- examples/imgui_impl_allegro5.h | 2 ++ examples/imgui_impl_dx10.h | 2 ++ examples/imgui_impl_dx11.h | 2 ++ examples/imgui_impl_dx12.h | 2 ++ examples/imgui_impl_dx9.h | 2 ++ examples/imgui_impl_glfw.h | 2 ++ examples/imgui_impl_glut.h | 2 ++ examples/imgui_impl_marmalade.h | 2 ++ examples/imgui_impl_metal.h | 2 ++ examples/imgui_impl_opengl2.h | 2 ++ examples/imgui_impl_opengl3.h | 2 ++ examples/imgui_impl_osx.h | 2 ++ examples/imgui_impl_sdl.h | 2 ++ examples/imgui_impl_vulkan.h | 1 + examples/imgui_impl_win32.h | 2 ++ 15 files changed, 29 insertions(+) diff --git a/examples/imgui_impl_allegro5.h b/examples/imgui_impl_allegro5.h index 8b9a47d1..c105fea6 100644 --- a/examples/imgui_impl_allegro5.h +++ b/examples/imgui_impl_allegro5.h @@ -15,6 +15,8 @@ #pragma once +#include "imgui.h" + struct ALLEGRO_DISPLAY; union ALLEGRO_EVENT; diff --git a/examples/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h index 85281d79..341bd7df 100644 --- a/examples/imgui_impl_dx10.h +++ b/examples/imgui_impl_dx10.h @@ -11,6 +11,8 @@ #pragma once +#include "imgui.h" + struct ID3D10Device; IMGUI_IMPL_API bool ImGui_ImplDX10_Init(ID3D10Device* device); diff --git a/examples/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h index c54d4379..d7351644 100644 --- a/examples/imgui_impl_dx11.h +++ b/examples/imgui_impl_dx11.h @@ -11,6 +11,8 @@ #pragma once +#include "imgui.h" + struct ID3D11Device; struct ID3D11DeviceContext; diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index 8f307dc5..df95b205 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -13,6 +13,8 @@ #pragma once +#include "imgui.h" + enum DXGI_FORMAT; struct ID3D12Device; struct ID3D12DescriptorHeap; diff --git a/examples/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h index b36e95b2..f630eeaa 100644 --- a/examples/imgui_impl_dx9.h +++ b/examples/imgui_impl_dx9.h @@ -11,6 +11,8 @@ #pragma once +#include "imgui.h" + struct IDirect3DDevice9; IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device); diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index a86790b7..f7f6f8c2 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -18,6 +18,8 @@ #pragma once +#include "imgui.h" + struct GLFWwindow; IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); diff --git a/examples/imgui_impl_glut.h b/examples/imgui_impl_glut.h index 0c561207..68326dce 100644 --- a/examples/imgui_impl_glut.h +++ b/examples/imgui_impl_glut.h @@ -17,6 +17,8 @@ #pragma once +#include "imgui.h" + IMGUI_IMPL_API bool ImGui_ImplGLUT_Init(); IMGUI_IMPL_API void ImGui_ImplGLUT_InstallFuncs(); IMGUI_IMPL_API void ImGui_ImplGLUT_Shutdown(); diff --git a/examples/imgui_impl_marmalade.h b/examples/imgui_impl_marmalade.h index 01fbd0d2..6ff1cc23 100644 --- a/examples/imgui_impl_marmalade.h +++ b/examples/imgui_impl_marmalade.h @@ -10,6 +10,8 @@ #pragma once +#include "imgui.h" + IMGUI_IMPL_API bool ImGui_Marmalade_Init(bool install_callbacks); IMGUI_IMPL_API void ImGui_Marmalade_Shutdown(); IMGUI_IMPL_API void ImGui_Marmalade_NewFrame(); diff --git a/examples/imgui_impl_metal.h b/examples/imgui_impl_metal.h index f09a115d..bf43ef66 100644 --- a/examples/imgui_impl_metal.h +++ b/examples/imgui_impl_metal.h @@ -9,6 +9,8 @@ // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui +#include "imgui.h" + @class MTLRenderPassDescriptor; @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; diff --git a/examples/imgui_impl_opengl2.h b/examples/imgui_impl_opengl2.h index 009052d7..4e0185fc 100644 --- a/examples/imgui_impl_opengl2.h +++ b/examples/imgui_impl_opengl2.h @@ -18,6 +18,8 @@ #pragma once +#include "imgui.h" + IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame(); diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index a9a1e199..9a651dc4 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -23,6 +23,8 @@ #pragma once +#include "imgui.h" + // Backend API IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); diff --git a/examples/imgui_impl_osx.h b/examples/imgui_impl_osx.h index fe066eec..52b44a6d 100644 --- a/examples/imgui_impl_osx.h +++ b/examples/imgui_impl_osx.h @@ -8,6 +8,8 @@ // Issues: // [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters].. +#include "imgui.h" + @class NSEvent; @class NSView; diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index a672ca83..ae2261d5 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -16,6 +16,8 @@ #pragma once +#include "imgui.h" + struct SDL_Window; typedef union SDL_Event SDL_Event; diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h index a74cdb5a..ce02b4c2 100644 --- a/examples/imgui_impl_vulkan.h +++ b/examples/imgui_impl_vulkan.h @@ -22,6 +22,7 @@ #pragma once +#include "imgui.h" #include // Initialization data, for ImGui_ImplVulkan_Init() diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index 41bae701..328a3724 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -9,6 +9,8 @@ #pragma once +#include "imgui.h" + IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); From cc0e43e6314e977d10d034f030de478194a0dd70 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Apr 2020 11:02:29 +0200 Subject: [PATCH 360/384] Backends: Comments next to include, misc minor comments/tweaks, fix imgui_impl_osx.h using IMGUI_API instead of IMGUI_IMPL_API. (#3105) --- examples/imgui_impl_allegro5.h | 5 ++--- examples/imgui_impl_dx10.h | 5 ++--- examples/imgui_impl_dx11.h | 5 ++--- examples/imgui_impl_dx12.h | 5 ++--- examples/imgui_impl_dx9.h | 5 ++--- examples/imgui_impl_glfw.h | 3 +-- examples/imgui_impl_glut.h | 3 +-- examples/imgui_impl_marmalade.h | 5 ++--- examples/imgui_impl_metal.h | 2 +- examples/imgui_impl_opengl2.h | 3 +-- examples/imgui_impl_opengl3.h | 3 +-- examples/imgui_impl_osx.h | 10 +++++----- examples/imgui_impl_sdl.h | 3 +-- examples/imgui_impl_vulkan.h | 3 +-- examples/imgui_impl_win32.h | 6 +++--- 15 files changed, 27 insertions(+), 39 deletions(-) diff --git a/examples/imgui_impl_allegro5.h b/examples/imgui_impl_allegro5.h index c105fea6..f41e4c90 100644 --- a/examples/imgui_impl_allegro5.h +++ b/examples/imgui_impl_allegro5.h @@ -14,8 +14,7 @@ // https://github.com/ocornut/imgui, Original Allegro 5 code by @birthggd #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct ALLEGRO_DISPLAY; union ALLEGRO_EVENT; @@ -26,6 +25,6 @@ IMGUI_IMPL_API void ImGui_ImplAllegro5_NewFrame(); IMGUI_IMPL_API void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data); IMGUI_IMPL_API bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* event); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API bool ImGui_ImplAllegro5_CreateDeviceObjects(); IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects(); diff --git a/examples/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h index 341bd7df..d974ba8e 100644 --- a/examples/imgui_impl_dx10.h +++ b/examples/imgui_impl_dx10.h @@ -10,8 +10,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct ID3D10Device; @@ -20,6 +19,6 @@ IMGUI_IMPL_API void ImGui_ImplDX10_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX10_NewFrame(); IMGUI_IMPL_API void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API void ImGui_ImplDX10_InvalidateDeviceObjects(); IMGUI_IMPL_API bool ImGui_ImplDX10_CreateDeviceObjects(); diff --git a/examples/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h index d7351644..cccadcd2 100644 --- a/examples/imgui_impl_dx11.h +++ b/examples/imgui_impl_dx11.h @@ -10,8 +10,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct ID3D11Device; struct ID3D11DeviceContext; @@ -21,6 +20,6 @@ IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h index df95b205..52dab0ba 100644 --- a/examples/imgui_impl_dx12.h +++ b/examples/imgui_impl_dx12.h @@ -12,8 +12,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API enum DXGI_FORMAT; struct ID3D12Device; @@ -32,6 +31,6 @@ IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(); diff --git a/examples/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h index f630eeaa..b93c89f7 100644 --- a/examples/imgui_impl_dx9.h +++ b/examples/imgui_impl_dx9.h @@ -10,8 +10,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct IDirect3DDevice9; @@ -20,6 +19,6 @@ IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown(); IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame(); IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects(); IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects(); diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index f7f6f8c2..f62f44f3 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -17,8 +17,7 @@ // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct GLFWwindow; diff --git a/examples/imgui_impl_glut.h b/examples/imgui_impl_glut.h index 68326dce..9acb77fb 100644 --- a/examples/imgui_impl_glut.h +++ b/examples/imgui_impl_glut.h @@ -16,8 +16,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_ImplGLUT_Init(); IMGUI_IMPL_API void ImGui_ImplGLUT_InstallFuncs(); diff --git a/examples/imgui_impl_marmalade.h b/examples/imgui_impl_marmalade.h index 6ff1cc23..9e92d899 100644 --- a/examples/imgui_impl_marmalade.h +++ b/examples/imgui_impl_marmalade.h @@ -9,15 +9,14 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_Marmalade_Init(bool install_callbacks); IMGUI_IMPL_API void ImGui_Marmalade_Shutdown(); IMGUI_IMPL_API void ImGui_Marmalade_NewFrame(); IMGUI_IMPL_API void ImGui_Marmalade_RenderDrawData(ImDrawData* draw_data); -// Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing Dear ImGui state. IMGUI_IMPL_API void ImGui_Marmalade_InvalidateDeviceObjects(); IMGUI_IMPL_API bool ImGui_Marmalade_CreateDeviceObjects(); diff --git a/examples/imgui_impl_metal.h b/examples/imgui_impl_metal.h index bf43ef66..f6e8fd2b 100644 --- a/examples/imgui_impl_metal.h +++ b/examples/imgui_impl_metal.h @@ -9,7 +9,7 @@ // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API @class MTLRenderPassDescriptor; @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; diff --git a/examples/imgui_impl_opengl2.h b/examples/imgui_impl_opengl2.h index 4e0185fc..9b72cbba 100644 --- a/examples/imgui_impl_opengl2.h +++ b/examples/imgui_impl_opengl2.h @@ -17,8 +17,7 @@ // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 9a651dc4..d55935a1 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -22,8 +22,7 @@ // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API // Backend API IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); diff --git a/examples/imgui_impl_osx.h b/examples/imgui_impl_osx.h index 52b44a6d..dae5c0ce 100644 --- a/examples/imgui_impl_osx.h +++ b/examples/imgui_impl_osx.h @@ -8,12 +8,12 @@ // Issues: // [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters].. -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API @class NSEvent; @class NSView; -IMGUI_API bool ImGui_ImplOSX_Init(); -IMGUI_API void ImGui_ImplOSX_Shutdown(); -IMGUI_API void ImGui_ImplOSX_NewFrame(NSView *_Nullable view); -IMGUI_API bool ImGui_ImplOSX_HandleEvent(NSEvent *_Nonnull event, NSView *_Nullable view); +IMGUI_IMPL_API bool ImGui_ImplOSX_Init(); +IMGUI_IMPL_API void ImGui_ImplOSX_Shutdown(); +IMGUI_IMPL_API void ImGui_ImplOSX_NewFrame(NSView *_Nullable view); +IMGUI_IMPL_API bool ImGui_ImplOSX_HandleEvent(NSEvent *_Nonnull event, NSView *_Nullable view); diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index ae2261d5..bf207ba0 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -15,8 +15,7 @@ // https://github.com/ocornut/imgui #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API struct SDL_Window; typedef union SDL_Event SDL_Event; diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h index ce02b4c2..c85b5f28 100644 --- a/examples/imgui_impl_vulkan.h +++ b/examples/imgui_impl_vulkan.h @@ -21,8 +21,7 @@ // Read comments in imgui_impl_vulkan.h. #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API #include // Initialization data, for ImGui_ImplVulkan_Init() diff --git a/examples/imgui_impl_win32.h b/examples/imgui_impl_win32.h index 328a3724..8923bd63 100644 --- a/examples/imgui_impl_win32.h +++ b/examples/imgui_impl_win32.h @@ -8,14 +8,14 @@ // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. #pragma once - -#include "imgui.h" +#include "imgui.h" // IMGUI_IMPL_API IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); -// Configuration: Disable gamepad support or linking with xinput.lib +// Configuration +// - Disable gamepad support or linking with xinput.lib //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT From e9366b4c7375dd2cd88e2375d50fe218a20c7e87 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Apr 2020 11:40:29 +0200 Subject: [PATCH 361/384] Regretfully moved .gitignore file from examples/ into root directory because OSX keeps pooping its DS_Store/ artifacts everywhere. (#3088) --- .gitignore | 49 +++++++++++++++++++++++++++++++++++++++++++++ examples/.gitignore | 46 ------------------------------------------ 2 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 .gitignore delete mode 100644 examples/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..84014850 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +## OSX artifacts +.DS_Store + +## Dear ImGui artifacts +imgui.ini + +## General build artifacts +*.o +*.obj +*.exe +examples/build/* +examples/*/Debug/* +examples/*/Release/* +examples/*/x64/* + +## Visual Studio artifacts +.vs +ipch +*.opensdf +*.log +*.pdb +*.ilk +*.user +*.sdf +*.suo +*.VC.db +*.VC.VC.opendb + +## Xcode artifacts +project.xcworkspace +xcuserdata + +## Emscripten artifacts +examples/*.o.tmp +examples/*.out.js +examples/*.out.wasm +examples/example_emscripten/example_emscripten.* + +## JetBrains IDE artifacts +.idea +cmake-build-* + +## Unix executables from our example Makefiles +examples/example_glfw_opengl2/example_glfw_opengl2 +examples/example_glfw_opengl3/example_glfw_opengl3 +examples/example_glut_opengl2/example_glut_opengl2 +examples/example_null/example_null +examples/example_sdl_opengl2/example_sdl_opengl2 +examples/example_sdl_opengl3/example_sdl_opengl3 diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 2b5671a8..00000000 --- a/examples/.gitignore +++ /dev/null @@ -1,46 +0,0 @@ -build/* -*/Debug/* -*/Release/* -*/x64/* -*.o -*.obj -*.exe - -## Visual Studio cruft -.vs/* -*/ipch/* -*.opensdf -*.log -*.pdb -*.ilk -*.user -*.sdf -*.suo -*.VC.db -*.VC.VC.opendb - -## Xcode cruft -.DS_Store -project.xcworkspace -xcuserdata - -## Emscripten output -*.o.tmp -*.out.js -*.out.wasm -example_emscripten/example_emscripten.* - -## Unix executables -example_glfw_opengl2/example_glfw_opengl2 -example_glfw_opengl3/example_glfw_opengl3 -example_glut_opengl2/example_glut_opengl2 -example_null/example_null -example_sdl_opengl2/example_sdl_opengl2 -example_sdl_opengl3/example_sdl_opengl3 - -## Dear ImGui Ini files -imgui.ini - -## JetBrains IDEs -.idea -cmake-build-* From 4e7ceb5f903cf2de3adac1c10010a82460e193d0 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Apr 2020 12:11:06 +0200 Subject: [PATCH 362/384] Plot: Internals: Added hovered index to PlotEx() function. (#2670) --- imgui_internal.h | 2 +- imgui_widgets.cpp | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 06832ee7..2172c138 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1887,7 +1887,7 @@ namespace ImGui IMGUI_API void ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags); // Plot - IMGUI_API void PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size); + IMGUI_API int PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size); // Shade functions (write over already created vertices) IMGUI_API void ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a28fbdaa..4487f496 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5835,13 +5835,13 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v // - PlotHistogram() //------------------------------------------------------------------------- -void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size) +int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size) { + ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) - return; + return -1; - ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); @@ -5856,7 +5856,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); ItemSize(total_bb, style.FramePadding.y); if (!ItemAdd(total_bb, 0, &frame_bb)) - return; + return -1; const bool hovered = ItemHoverable(frame_bb, id); // Determine scale from values if not specified @@ -5881,13 +5881,13 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); const int values_count_min = (plot_type == ImGuiPlotType_Lines) ? 2 : 1; + int idx_hovered = -1; if (values_count >= values_count_min) { int res_w = ImMin((int)frame_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); // Tooltip on hover - int v_hovered = -1; if (hovered && inner_bb.Contains(g.IO.MousePos)) { const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); @@ -5900,7 +5900,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1); else if (plot_type == ImGuiPlotType_Histogram) SetTooltip("%d: %8.4g", v_idx, v0); - v_hovered = v_idx; + idx_hovered = v_idx; } const float t_step = 1.0f / (float)res_w; @@ -5927,13 +5927,13 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, histogram_zero_line_t)); if (plot_type == ImGuiPlotType_Lines) { - window->DrawList->AddLine(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); + window->DrawList->AddLine(pos0, pos1, idx_hovered == v1_idx ? col_hovered : col_base); } else if (plot_type == ImGuiPlotType_Histogram) { if (pos1.x >= pos0.x + 2.0f) pos1.x -= 1.0f; - window->DrawList->AddRectFilled(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); + window->DrawList->AddRectFilled(pos0, pos1, idx_hovered == v1_idx ? col_hovered : col_base); } t0 = t1; @@ -5947,6 +5947,10 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); + + // Return hovered index or -1 if none are hovered. + // This is currently not exposed in the public API because we need a larger redesign of the whole thing, but in the short-term we are making it available in PlotEx(). + return idx_hovered; } struct ImGuiPlotArrayGetterData From c142540705702623e0a60a866be60e9de5143491 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Thu, 26 Mar 2020 09:42:04 +0200 Subject: [PATCH 363/384] Viewports, Backends: GLFW: Avoid using window positioning workaround for glfw versions that have it fixed. Amend 09780b8. --- examples/imgui_impl_glfw.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index bcbee436..495796fd 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -57,6 +57,7 @@ #define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwFocusWindow #define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW #define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorWorkarea +#define GLFW_HAS_OSX_WINDOW_POS_FIX (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION * 10 >= 3310) // 3.3.1+ Fixed: Resizing window repositions it on MacOS #1553 #ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? #define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR #else @@ -671,7 +672,7 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport) static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) { ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; -#if __APPLE__ +#if __APPLE__ && !GLFW_HAS_OSX_WINDOW_POS_FIX // Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are // positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it // doesn't handle it when changing size. We are manually moving the window in order for changes of size to be based From 832fda848863f24b4bdf2b4323447e996a8c51f1 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 7 Apr 2020 14:46:46 +0200 Subject: [PATCH 364/384] Fixed stray end of line blanks, added comments in .editorconfig, tweaked some headers. --- .editorconfig | 4 +++- imgui.cpp | 2 +- imgui.h | 2 +- imgui_widgets.cpp | 6 +++--- misc/cpp/imgui_stdlib.cpp | 3 +-- misc/cpp/imgui_stdlib.h | 3 +-- misc/freetype/imgui_freetype.cpp | 2 +- misc/freetype/imgui_freetype.h | 2 +- misc/single_file/imgui_single_file.h | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3dd05d3d..284ba13f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,6 @@ -# editorconfig.org +# See http://editorconfig.org to read about the EditorConfig format. +# - Automatically supported by VS2017+ and most common IDE or text editors. +# - For older VS2010 to VS2015, install https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig # top-most EditorConfig file root = true diff --git a/imgui.cpp b/imgui.cpp index 9876cf92..42a7228e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4152,7 +4152,7 @@ void ImGui::EndFrame() { ImGuiContext& g = *GImGui; IM_ASSERT(g.Initialized); - + // Don't process EndFrame() multiple times. if (g.FrameCountEnded == g.FrameCount) return; diff --git a/imgui.h b/imgui.h index 53b2ccab..2d902022 100644 --- a/imgui.h +++ b/imgui.h @@ -1141,7 +1141,7 @@ enum ImGuiCol_ }; // Enumeration for PushStyleVar() / PopStyleVar() to temporarily modify the ImGuiStyle structure. -// - The enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. +// - The enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. // During initialization or between frames, feel free to just poke into ImGuiStyle directly. // - Tip: Use your programming IDE navigation facilities on the names in the _second column_ below to find the actual members and their description. // In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 4487f496..a0bfdd6c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5344,8 +5344,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // - Double-click on label = Toggle on MouseDoubleClick (when _OpenOnDoubleClick=1) // - Double-click on arrow = Toggle on MouseDoubleClick (when _OpenOnDoubleClick=1 and _OpenOnArrow=0) // This makes _OpenOnArrow have a subtle effect on _OpenOnDoubleClick: arrow click reacts on Down rather than Up. - // It is rather standard that arrow click react on Down rather than Up and we'd be tempted to make it the default - // (by removing the _OpenOnArrow test below), however this would have a perhaps surprising effect on CollapsingHeader()? + // It is rather standard that arrow click react on Down rather than Up and we'd be tempted to make it the default + // (by removing the _OpenOnArrow test below), however this would have a perhaps surprising effect on CollapsingHeader()? // So right now we are making this optional. May evolve later. if (is_mouse_x_over_arrow && (flags & ImGuiTreeNodeFlags_OpenOnArrow)) button_flags |= ImGuiButtonFlags_PressedOnClick; @@ -5948,7 +5948,7 @@ int ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_get if (label_size.x > 0.0f) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); - // Return hovered index or -1 if none are hovered. + // Return hovered index or -1 if none are hovered. // This is currently not exposed in the public API because we need a larger redesign of the whole thing, but in the short-term we are making it available in PlotEx(). return idx_hovered; } diff --git a/misc/cpp/imgui_stdlib.cpp b/misc/cpp/imgui_stdlib.cpp index fda60f4d..cb1fe174 100644 --- a/misc/cpp/imgui_stdlib.cpp +++ b/misc/cpp/imgui_stdlib.cpp @@ -1,5 +1,4 @@ -// imgui_stdlib.cpp -// Wrappers for C++ standard library (STL) types (std::string, etc.) +// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) // This is also an example of how you may wrap your own similar types. // Compatibility: diff --git a/misc/cpp/imgui_stdlib.h b/misc/cpp/imgui_stdlib.h index 5bccb032..f860b0c7 100644 --- a/misc/cpp/imgui_stdlib.h +++ b/misc/cpp/imgui_stdlib.h @@ -1,5 +1,4 @@ -// imgui_stdlib.h -// Wrappers for C++ standard library (STL) types (std::string, etc.) +// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) // This is also an example of how you may wrap your own similar types. // Compatibility: diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index b4ef795a..69108e3e 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -1,4 +1,4 @@ -// Wrapper to use FreeType (instead of stb_truetype) for Dear ImGui +// dear imgui: wrapper to use FreeType (instead of stb_truetype) // Get latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype // Original code by @vuhdo (Aleksei Skriabin). Improvements by @mikesart. Maintained and v0.60+ by @ocornut. diff --git a/misc/freetype/imgui_freetype.h b/misc/freetype/imgui_freetype.h index d65c7724..619735c4 100644 --- a/misc/freetype/imgui_freetype.h +++ b/misc/freetype/imgui_freetype.h @@ -1,4 +1,4 @@ -// Wrapper to use FreeType (instead of stb_truetype) for Dear ImGui +// dear imgui: wrapper to use FreeType (instead of stb_truetype) // Get latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype // Original code by @Vuhdo (Aleksei Skriabin), maintained by @ocornut diff --git a/misc/single_file/imgui_single_file.h b/misc/single_file/imgui_single_file.h index a556931c..6c849441 100644 --- a/misc/single_file/imgui_single_file.h +++ b/misc/single_file/imgui_single_file.h @@ -1,4 +1,4 @@ -// imgui_single_file.h +// dear imgui: single-file wrapper include // We use this to validate compiling all *.cpp files in a same compilation unit. // Users of that technique (also called "Unity builds") can generally provide this themselves, // so we don't really recommend you use this in your projects. From fb70d90fef176b24075bbaeb406612ab5f39fec6 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Apr 2020 13:34:39 +0200 Subject: [PATCH 365/384] Made default clipboard handlers for Win32 and OSX use a buffer inside the main context instead of a static buffer, so it can be freed properly on Shutdown. (#3110) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 34 ++++++++++++++++++---------------- imgui_internal.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6bdb7512..f274ba31 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,6 +73,8 @@ Other Changes: to a solution rather than encourage people to add braces in the codebase. - Misc: Added additional checks in EndFrame() to verify that io.KeyXXX values have not been tampered with between NewFrame() and EndFrame(). +- Misc: Made default clipboard handlers for Win32 and OSX use a buffer inside the main context + instead of a static buffer, so it can be freed properly on Shutdown. (#3110) - Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult] - Metrics: Made Tools section more prominent. Showing wire-frame mesh directly hovering the ImDrawCmd diff --git a/imgui.cpp b/imgui.cpp index 42a7228e..2aaddb67 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3985,7 +3985,7 @@ void ImGui::Shutdown(ImGuiContext* context) g.CurrentTabBarStack.clear(); g.ShrinkWidthBuffer.clear(); - g.PrivateClipboard.clear(); + g.ClipboardHandlerData.clear(); g.MenusIdSubmittedThisFrame.clear(); g.InputTextState.ClearFreeMemory(); @@ -9805,10 +9805,11 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl #endif // Win32 clipboard implementation +// We use g.ClipboardHandlerData for temporary storage to ensure it is freed on Shutdown() static const char* GetClipboardTextFn_DefaultImpl(void*) { - static ImVector buf_local; - buf_local.clear(); + ImGuiContext& g = *GImGui; + g.ClipboardHandlerData.clear(); if (!::OpenClipboard(NULL)) return NULL; HANDLE wbuf_handle = ::GetClipboardData(CF_UNICODETEXT); @@ -9820,12 +9821,12 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) if (const WCHAR* wbuf_global = (const WCHAR*)::GlobalLock(wbuf_handle)) { int buf_len = ::WideCharToMultiByte(CP_UTF8, 0, wbuf_global, -1, NULL, 0, NULL, NULL); - buf_local.resize(buf_len); - ::WideCharToMultiByte(CP_UTF8, 0, wbuf_global, -1, buf_local.Data, buf_len, NULL, NULL); + g.ClipboardHandlerData.resize(buf_len); + ::WideCharToMultiByte(CP_UTF8, 0, wbuf_global, -1, g.ClipboardHandlerData.Data, buf_len, NULL, NULL); } ::GlobalUnlock(wbuf_handle); ::CloseClipboard(); - return buf_local.Data; + return g.ClipboardHandlerData.Data; } static void SetClipboardTextFn_DefaultImpl(void*, const char* text) @@ -9887,13 +9888,14 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) CFDataRef cf_data; if (PasteboardCopyItemFlavorData(main_clipboard, item_id, CFSTR("public.utf8-plain-text"), &cf_data) == noErr) { - static ImVector clipboard_text; + ImGuiContext& g = *GImGui; + g.ClipboardHandlerData.clear(); int length = (int)CFDataGetLength(cf_data); - clipboard_text.resize(length + 1); - CFDataGetBytes(cf_data, CFRangeMake(0, length), (UInt8*)clipboard_text.Data); - clipboard_text[length] = 0; + g.ClipboardHandlerData.resize(length + 1); + CFDataGetBytes(cf_data, CFRangeMake(0, length), (UInt8*)g.ClipboardHandlerData.Data); + g.ClipboardHandlerData[length] = 0; CFRelease(cf_data); - return clipboard_text.Data; + return g.ClipboardHandlerData.Data; } } } @@ -9906,17 +9908,17 @@ static const char* GetClipboardTextFn_DefaultImpl(void*) static const char* GetClipboardTextFn_DefaultImpl(void*) { ImGuiContext& g = *GImGui; - return g.PrivateClipboard.empty() ? NULL : g.PrivateClipboard.begin(); + return g.ClipboardHandlerData.empty() ? NULL : g.ClipboardHandlerData.begin(); } static void SetClipboardTextFn_DefaultImpl(void*, const char* text) { ImGuiContext& g = *GImGui; - g.PrivateClipboard.clear(); + g.ClipboardHandlerData.clear(); const char* text_end = text + strlen(text); - g.PrivateClipboard.resize((int)(text_end - text) + 1); - memcpy(&g.PrivateClipboard[0], text, (size_t)(text_end - text)); - g.PrivateClipboard[(int)(text_end - text)] = 0; + g.ClipboardHandlerData.resize((int)(text_end - text) + 1); + memcpy(&g.ClipboardHandlerData[0], text, (size_t)(text_end - text)); + g.ClipboardHandlerData[(int)(text_end - text)] = 0; } #endif diff --git a/imgui_internal.h b/imgui_internal.h index 2172c138..7e744b3f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1189,7 +1189,7 @@ struct ImGuiContext float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? int TooltipOverrideCount; - ImVector PrivateClipboard; // If no custom clipboard handler is defined + ImVector ClipboardHandlerData; // If no custom clipboard handler is defined ImVector MenusIdSubmittedThisFrame; // A list of menu IDs that were rendered at least once // Platform support From f7852fa8e8175405f66cb4bce0cd0a85e4cebff8 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 10 Apr 2020 11:03:22 +0200 Subject: [PATCH 366/384] Internals: Extracted GetWindowScrollbarRect() out of Scrollbar() and tidying up code to make it more obvious how to draw over scrollbars. (#3114) --- imgui_internal.h | 3 +- imgui_widgets.cpp | 97 +++++++++++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 7e744b3f..61c1e5b7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1477,7 +1477,7 @@ struct IMGUI_API ImGuiWindow ImVec2 ScrollMax; ImVec2 ScrollTarget; // target scroll position. stored as cursor position with scrolling canceled out, so the highest point is always 0.0f. (FLT_MAX for no change) ImVec2 ScrollTargetCenterRatio; // 0.0f = scroll so that target position is at top, 0.5f = scroll so that target position is centered - ImVec2 ScrollbarSizes; // Size taken by scrollbars on each axis + ImVec2 ScrollbarSizes; // Size taken by each scrollbars on their smaller axis. Pay attention! ScrollbarSizes.x == width of the vertical scrollbar, ScrollbarSizes.y = height of the horizontal scrollbar. bool ScrollbarX, ScrollbarY; // Are scrollbars visible? bool Active; // Set to true on Begin(), unless Collapsed bool WasActive; @@ -1847,6 +1847,7 @@ namespace ImGui IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); IMGUI_API void Scrollbar(ImGuiAxis axis); IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawCornerFlags rounding_corners); + IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis); IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis); IMGUI_API ImGuiID GetWindowResizeID(ImGuiWindow* window, int n); // 0..3: corners, 4..7: borders IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a0bfdd6c..33a98635 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -391,8 +391,10 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // - ArrowButton() // - CloseButton() [Internal] // - CollapseButton() [Internal] -// - ScrollbarEx() [Internal] +// - GetWindowScrollbarID() [Internal] +// - GetWindowScrollbarRect() [Internal] // - Scrollbar() [Internal] +// - ScrollbarEx() [Internal] // - Image() // - ImageButton() // - Checkbox() @@ -812,6 +814,49 @@ ImGuiID ImGui::GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis) return window->GetIDNoKeepAlive(axis == ImGuiAxis_X ? "#SCROLLX" : "#SCROLLY"); } +// Return scrollbar rectangle, must only be called for corresponding axis if window->ScrollbarX/Y is set. +ImRect ImGui::GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis) +{ + const ImRect outer_rect = window->Rect(); + const ImRect inner_rect = window->InnerRect; + const float border_size = window->WindowBorderSize; + const float scrollbar_size = window->ScrollbarSizes[axis ^ 1]; // (ScrollbarSizes.x = width of Y scrollbar; ScrollbarSizes.y = height of X scrollbar) + IM_ASSERT(scrollbar_size > 0.0f); + if (axis == ImGuiAxis_X) + return ImRect(inner_rect.Min.x, ImMax(outer_rect.Min.y, outer_rect.Max.y - border_size - scrollbar_size), inner_rect.Max.x, outer_rect.Max.y); + else + return ImRect(ImMax(outer_rect.Min.x, outer_rect.Max.x - border_size - scrollbar_size), inner_rect.Min.y, outer_rect.Max.x, inner_rect.Max.y); +} + +void ImGui::Scrollbar(ImGuiAxis axis) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + + const ImGuiID id = GetWindowScrollbarID(window, axis); + KeepAliveID(id); + + // Calculate scrollbar bounding box + ImRect bb = GetWindowScrollbarRect(window, axis); + ImDrawCornerFlags rounding_corners = 0; + if (axis == ImGuiAxis_X) + { + rounding_corners |= ImDrawCornerFlags_BotLeft; + if (!window->ScrollbarY) + rounding_corners |= ImDrawCornerFlags_BotRight; + } + else + { + if ((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) + rounding_corners |= ImDrawCornerFlags_TopRight; + if (!window->ScrollbarX) + rounding_corners |= ImDrawCornerFlags_BotRight; + } + float size_avail = window->InnerRect.Max[axis] - window->InnerRect.Min[axis]; + float size_contents = window->ContentSize[axis] + window->WindowPadding[axis] * 2.0f; + ScrollbarEx(bb, id, axis, &window->Scroll[axis], size_avail, size_contents, rounding_corners); +} + // Vertical/Horizontal scrollbar // The entire piece of code below is rather confusing because: // - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab) @@ -830,7 +875,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa if (bb_frame_width <= 0.0f || bb_frame_height <= 0.0f) return false; - // When we are too small, start hiding and disabling the grab (this reduce visual noise on very small window and facilitate using the resize grab) + // When we are too small, start hiding and disabling the grab (this reduce visual noise on very small window and facilitate using the window resize grab) float alpha = 1.0f; if ((axis == ImGuiAxis_Y) && bb_frame_height < g.FontSize + g.Style.FramePadding.y * 2.0f) alpha = ImSaturate((bb_frame_height - g.FontSize) / (g.Style.FramePadding.y * 2.0f)); @@ -839,13 +884,12 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa const ImGuiStyle& style = g.Style; const bool allow_interaction = (alpha >= 1.0f); - const bool horizontal = (axis == ImGuiAxis_X); ImRect bb = bb_frame; bb.Expand(ImVec2(-ImClamp(IM_FLOOR((bb_frame_width - 2.0f) * 0.5f), 0.0f, 3.0f), -ImClamp(IM_FLOOR((bb_frame_height - 2.0f) * 0.5f), 0.0f, 3.0f))); // V denote the main, longer axis of the scrollbar (= height for a vertical scrollbar) - const float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight(); + const float scrollbar_size_v = (axis == ImGuiAxis_X) ? bb.GetWidth() : bb.GetHeight(); // Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount) // But we maintain a minimum size in pixel to allow for the user to still aim inside. @@ -861,11 +905,11 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa float scroll_max = ImMax(1.0f, size_contents_v - size_avail_v); float scroll_ratio = ImSaturate(*p_scroll_v / scroll_max); - float grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v; + float grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v; // Grab position in normalized space if (held && allow_interaction && grab_h_norm < 1.0f) { - float scrollbar_pos_v = horizontal ? bb.Min.x : bb.Min.y; - float mouse_pos_v = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y; + float scrollbar_pos_v = bb.Min[axis]; + float mouse_pos_v = g.IO.MousePos[axis]; // Click position in scrollbar normalized space (0.0f->1.0f) const float clicked_v_norm = ImSaturate((mouse_pos_v - scrollbar_pos_v) / scrollbar_size_v); @@ -882,7 +926,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa g.ScrollbarClickDeltaToGrabCenter = clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f; } - // Apply scroll + // Apply scroll (p_scroll_v will generally point on one member of window->Scroll) // It is ok to modify Scroll here because we are being called in Begin() after the calculation of ContentSize and before setting up our starting position const float scroll_v_norm = ImSaturate((clicked_v_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm * 0.5f) / (1.0f - grab_h_norm)); *p_scroll_v = IM_ROUND(scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v)); @@ -897,10 +941,11 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa } // Render - window->DrawList->AddRectFilled(bb_frame.Min, bb_frame.Max, GetColorU32(ImGuiCol_ScrollbarBg), window->WindowRounding, rounding_corners); + const ImU32 bg_col = GetColorU32(ImGuiCol_ScrollbarBg); const ImU32 grab_col = GetColorU32(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab, alpha); + window->DrawList->AddRectFilled(bb_frame.Min, bb_frame.Max, bg_col, window->WindowRounding, rounding_corners); ImRect grab_rect; - if (horizontal) + if (axis == ImGuiAxis_X) grab_rect = ImRect(ImLerp(bb.Min.x, bb.Max.x, grab_v_norm), bb.Min.y, ImLerp(bb.Min.x, bb.Max.x, grab_v_norm) + grab_h_pixels, bb.Max.y); else grab_rect = ImRect(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_v_norm), bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_v_norm) + grab_h_pixels); @@ -909,38 +954,6 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, floa return held; } -void ImGui::Scrollbar(ImGuiAxis axis) -{ - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - - const ImGuiID id = GetWindowScrollbarID(window, axis); - KeepAliveID(id); - - // Calculate scrollbar bounding box - const ImRect outer_rect = window->Rect(); - const ImRect inner_rect = window->InnerRect; - const float border_size = window->WindowBorderSize; - const float scrollbar_size = window->ScrollbarSizes[axis ^ 1]; - IM_ASSERT(scrollbar_size > 0.0f); - const float other_scrollbar_size = window->ScrollbarSizes[axis]; - ImDrawCornerFlags rounding_corners = (other_scrollbar_size <= 0.0f) ? ImDrawCornerFlags_BotRight : 0; - ImRect bb; - if (axis == ImGuiAxis_X) - { - bb.Min = ImVec2(inner_rect.Min.x, ImMax(outer_rect.Min.y, outer_rect.Max.y - border_size - scrollbar_size)); - bb.Max = ImVec2(inner_rect.Max.x, outer_rect.Max.y); - rounding_corners |= ImDrawCornerFlags_BotLeft; - } - else - { - bb.Min = ImVec2(ImMax(outer_rect.Min.x, outer_rect.Max.x - border_size - scrollbar_size), inner_rect.Min.y); - bb.Max = ImVec2(outer_rect.Max.x, window->InnerRect.Max.y); - rounding_corners |= ((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImDrawCornerFlags_TopRight : 0; - } - ScrollbarEx(bb, id, axis, &window->Scroll[axis], inner_rect.Max[axis] - inner_rect.Min[axis], window->ContentSize[axis] + window->WindowPadding[axis] * 2.0f, rounding_corners); -} - void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) { ImGuiWindow* window = GetCurrentWindow(); From 977ac53dd809ed41d4a9456d03d7ded0d0ee9bd4 Mon Sep 17 00:00:00 2001 From: SergeyN Date: Mon, 30 Mar 2020 21:43:21 +0200 Subject: [PATCH 367/384] Examples: Win32+DX12: Fixed resizing main window, enabled debug layer. (#3087, #3115) --- docs/CHANGELOG.txt | 1 + examples/example_win32_directx12/main.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f274ba31..43c70d33 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -94,6 +94,7 @@ Other Changes: - Backends: SDL: Added ImGui_ImplSDL2_InitForMetal() for API consistency (even though the function currently does nothing). - Backends: SDL: Fixed mapping for ImGuiKey_KeyPadEnter. (#3031) [@Davido71] +- Examples: Win32+DX12: Fixed resizing main window, enabled debug layer. (#3087, #3115) [@sergeyn] - Examples: SDL+DX11: Fixed resizing main window. (#3057) [@joeslay] - Examples: Added SDL+Metal example application. (#3017) [@coding-jackalope] diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index 139dea6e..8642ad45 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -9,7 +9,9 @@ #include #include -//#define DX12_ENABLE_DEBUG_LAYER +#ifdef _DEBUG +#define DX12_ENABLE_DEBUG_LAYER +#endif #ifdef DX12_ENABLE_DEBUG_LAYER #include @@ -441,6 +443,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SIZE: if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED) { + WaitForLastSubmittedFrame(); ImGui_ImplDX12_InvalidateDeviceObjects(); CleanupRenderTarget(); ResizeSwapChain(hWnd, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); From 71eb4034eba128f01aebc856e9ce65fd38edea86 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 12 Apr 2020 17:48:24 +0200 Subject: [PATCH 368/384] Viewports: Fixed viewport merge code not testing the Minimized flag correctly. (#3118) --- imgui.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4fcfd055..31d7a416 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3552,7 +3552,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame() if (g.NavWindow && g.NavWindow->Appearing) return; - // Click on void to focus window and start moving + // Click on void to focus window and start moving // (after we're done with all our widgets, so e.g. clicking on docking tab-bar which have set HoveredId already and not get us here!) if (g.IO.MouseClicked[0]) { @@ -4424,7 +4424,7 @@ void ImGui::EndFrame() { ImGuiContext& g = *GImGui; IM_ASSERT(g.Initialized); - + // Don't process EndFrame() multiple times. if (g.FrameCountEnded == g.FrameCount) return; @@ -10679,7 +10679,11 @@ static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window) static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport) { ImGuiContext& g = *GImGui; - if (!(viewport->Flags & (ImGuiViewportFlags_CanHostOtherWindows | ImGuiViewportFlags_Minimized)) || window->Viewport == viewport) + if (window->Viewport == viewport) + return false; + if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) == 0) + return false; + if ((viewport->Flags & ImGuiViewportFlags_Minimized) != 0) return false; if (!viewport->GetMainRect().Contains(window->Rect())) return false; @@ -10793,7 +10797,7 @@ static void ImGui::UpdateViewportsNewFrame() } } - // Create/update main viewport with current platform position. + // Create/update main viewport with current platform position. // FIXME-VIEWPORT: Size is driven by back-end/user code for backward-compatibility but we should aim to make this more consistent. ImGuiViewportP* main_viewport = g.Viewports[0]; IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID); From ec7294d890d7477047eccfdd5463df6cd72cb6dd Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 12 Apr 2020 18:01:10 +0200 Subject: [PATCH 369/384] Backends: OpenGL3: Fixed version check mistakenly testing for GL 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset, leaving 3.2 contexts without it. (#3119, #2866, #2852) --- docs/CHANGELOG.txt | 2 ++ examples/imgui_impl_opengl3.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 43c70d33..14f5c623 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -84,6 +84,8 @@ Other Changes: - CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building SDL+Metal example, building imgui_freetype.cpp, more compile-time imconfig.h settings: disabling obsolete functions, enabling 32-bit ImDrawIdx, enabling 32-bit ImWchar, disabling demo. [@rokups] +- Backends: OpenGL3: Fixed version check mistakenly testing for GL 4.0+ instead of 3.2+ to enable + ImGuiBackendFlags_RendererHasVtxOffset, leaving 3.2 contexts without it. (#3119, #2866) [@wolfpld] - Backends: OpenGL3: Added include support for older glbinding 2.x loader. (#3061) [@DonKult] - Backends: Win32: Added ImGui_ImplWin32_EnableDpiAwareness(), ImGui_ImplWin32_GetDpiScaleForHwnd(), ImGui_ImplWin32_GetDpiScaleForMonitor() helpers functions (backported from the docking branch). diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 2f908f46..40e531dd 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2020-04-12: OpenGL: Fixed context version check mistakenly testing for 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset. // 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader. // 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader. // 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders. @@ -141,7 +142,7 @@ using namespace gl; #endif // OpenGL Data -static GLuint g_GlVersion = 0; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries. +static GLuint g_GlVersion = 0; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2) static char g_GlslVersionString[32] = ""; // Specified by user or detected based on compile time GL settings. static GLuint g_FontTexture = 0; static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; @@ -152,21 +153,21 @@ static unsigned int g_VboHandle = 0, g_ElementsHandle = 0; // Functions bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { - // Query for GL version + // Query for GL version (e.g. 320 for GL 3.2) #if !defined(IMGUI_IMPL_OPENGL_ES2) GLint major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); - g_GlVersion = major * 1000 + minor; + g_GlVersion = major * 100 + minor * 10; #else - g_GlVersion = 2000; // GLES 2 + g_GlVersion = 200; // GLES 2 #endif // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = "imgui_impl_opengl3"; #if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET - if (g_GlVersion >= 3200) + if (g_GlVersion >= 320) io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. #endif @@ -378,7 +379,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) // Bind texture, Draw glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); #if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET - if (g_GlVersion >= 3200) + if (g_GlVersion >= 320) glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); else #endif From 7ee623d9b1385fffecc989b5a9fb371698bad060 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 12 Apr 2020 18:58:06 +0200 Subject: [PATCH 370/384] Internals: FocusScope not inherited by popups, modals. Amend a5041c88 2ebe08be) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 2aaddb67..5614f1e7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5902,7 +5902,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; - window->DC.NavFocusScopeIdCurrent = parent_window ? parent_window->DC.NavFocusScopeIdCurrent : 0; + window->DC.NavFocusScopeIdCurrent = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->DC.NavFocusScopeIdCurrent : 0; window->DC.NavHideHighlightOneFrame = false; window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); From 5503c0a12e0c929e84b3f61b2cb4bb9177ea3da1 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 12 Apr 2020 19:15:38 +0200 Subject: [PATCH 371/384] Version 1.76 + fixed PVS warning, update demo binaries, update readme image --- docs/CHANGELOG.txt | 11 +++++------ docs/README.md | 8 ++++---- examples/README.txt | 2 +- imgui.cpp | 4 ++-- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 14f5c623..c08d198c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -31,15 +31,13 @@ HOW TO UPDATE? ----------------------------------------------------------------------- - VERSION 1.76 WIP (In Progress) + VERSION 1.76 (Released 2020-04-12) ----------------------------------------------------------------------- Other Changes: - Drag and Drop, Nav: Disabling navigation arrow keys when drag and drop is active. In the docking branch pressing arrow keys while dragging a window from a tab could trigger an assert. (#3025) -- ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced - by default for standalone ColorButton. - BeginMenu: Using same ID multiple times appends content to a menu. (#1207) [@rokups] - BeginMenu: Fixed a bug where SetNextWindowXXX data before a BeginMenu() would not be cleared when the menu is not open. (#3030) @@ -49,6 +47,8 @@ Other Changes: - Selectable: Allow using ImGuiSelectableFlags_SpanAllColumns in other columns than first. (#125) - TreeNode: Made clicking on arrow with _OpenOnArrow toggle the open state on the Mouse Down event rather than the Mouse Down+Up sequence (this is rather standard behavior). +- ColorButton: Added ImGuiColorEditFlags_NoBorder flag to remove the border normally enforced + by default for standalone ColorButton. - Nav: Fixed interactions with ImGuiListClipper, so e.g. Home/End result would not clip the landing item on the landing frame. (#787) - Nav: Fixed currently focused item from ever being clipped by ItemAdd(). (#787) @@ -57,8 +57,7 @@ Other Changes: ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073) - Added optional support for Unicode plane 1-16 (#2538, #2541, #2815) [@cloudwu, @samhocevar] - Compile-time enable with '#define IMGUI_USE_WCHAR32' in imconfig.h. - - Generally more consistent support for unsupported codepoints (0xFFFD), in particular when - using the default, non-fitting characters will be turned into 0xFFFD instead of being ignored. + - More onsistent handling of unsupported code points (0xFFFD). - Surrogate pairs are supported when submitting UTF-16 data via io.AddInputCharacterUTF16(), allowing for more complete CJK input. - sizeof(ImWchar) goes from 2 to 4. IM_UNICODE_CODEPOINT_MAX goes from 0xFFFF to 0x10FFFF. @@ -68,7 +67,7 @@ Other Changes: to 64 columns with an assert. (#3037, #125) - Window: Fixed a bug with child window inheriting ItemFlags from their parent when the child window also manipulate the ItemFlags stack. (#3024) [@Stanbroek] -- Font: Fixed non-ASCII space occasionally creating unnecessary empty polygons. +- Font: Fixed non-ASCII space occasionally creating unnecessary empty looking polygons. - Misc: Added an explicit compile-time test for non-scoped IM_ASSERT() macros to redirect users to a solution rather than encourage people to add braces in the codebase. - Misc: Added additional checks in EndFrame() to verify that io.KeyXXX values have not been diff --git a/docs/README.md b/docs/README.md index 30c5d1a9..c7982c23 100644 --- a/docs/README.md +++ b/docs/README.md @@ -97,7 +97,7 @@ Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcas ![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, 1.72 WIP, built 2019/07/15, master branch, 5 executables) +- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20200412.zip) (Windows binaries, 1.76 WIP, built 2020/04/12, master branch, 5 executables) or [older demo binaries](http://www.dearimgui.org/binaries). The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your style with `style.ScaleAllSizes()`. @@ -140,7 +140,7 @@ Custom engine [![screenshot tool](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white_preview.jpg)](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v160/editor_white.png) [Tracy Profiler](https://bitbucket.org/wolfpld/tracy) -![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v173/tracy_profiler.jpg) +![tracy profiler](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v176/tracy_profiler.png) ### Support, Frequently Asked Questions (FAQ) @@ -196,7 +196,7 @@ Ongoing Dear ImGui development is financially supported by users and private spo *Double-chocolate and Salty caramel sponsors* - [Activision](https://careers.activision.com/c/programmingsoftware-engineering-jobs), [DotEmu](http://www.dotemu.com), [Framefield](http://framefield.com), [Hexagon](https://hexagonxalt.com/the-technology/xalt-visualization), [Kylotonn](https://www.kylotonn.com), [Media Molecule](http://www.mediamolecule.com), [Mesh Consultants](https://www.meshconsultants.ca), [Mobigame](http://www.mobigame.net), [Nadeo](https://www.nadeo.com), [Supercell](http://www.supercell.com), [Remedy Entertainment](https://www.remedygames.com/), [Unit 2 Games](https://unit2games.com/) -From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. Please see [detailed list of Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors). +From November 2014 to December 2019, ongoing development has also been financially supported by its users on Patreon and through individual donations. Please see [detailed list of Dear ImGui supporters](https://github.com/ocornut/imgui/wiki/Sponsors). **THANK YOU to all past and present supporters for helping to keep this project alive and thriving!** @@ -208,7 +208,7 @@ Dear ImGui is using software and services provided free of charge for open sourc Credits ------- -Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com) (Vita). +Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com) (PS Vita). I first discovered the IMGUI paradigm at [Q-Games](http://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it. diff --git a/examples/README.txt b/examples/README.txt index 355d616c..1408585b 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.76 WIP + dear imgui, v1.76 ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index 5614f1e7..b57bb195 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (main code and documentation) // Help: @@ -5902,7 +5902,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main); window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext; window->DC.NavLayerActiveMaskNext = 0x00; - window->DC.NavFocusScopeIdCurrent = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->DC.NavFocusScopeIdCurrent : 0; + window->DC.NavFocusScopeIdCurrent = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->DC.NavFocusScopeIdCurrent : 0; // -V595 window->DC.NavHideHighlightOneFrame = false; window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f); diff --git a/imgui.h b/imgui.h index 2d902022..92c56740 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (headers) // Help: @@ -59,8 +59,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.76 WIP" -#define IMGUI_VERSION_NUM 17502 +#define IMGUI_VERSION "1.76" +#define IMGUI_VERSION_NUM 17600 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 28a5940e..1e110ded 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index f02c7a90..1e08bfd0 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index 61c1e5b7..cef0f9a9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 33a98635..27d9e455 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 WIP +// dear imgui, v1.76 // (widgets code) /* From 013013737fa729619534ade16915619b2683e91f Mon Sep 17 00:00:00 2001 From: SergeyN Date: Mon, 13 Apr 2020 15:22:27 +0200 Subject: [PATCH 372/384] Viewports, Backends: DX12: Fix for crash caused by early resource release. (#3121) --- examples/imgui_impl_dx12.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index 3ead29c5..446546fb 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -815,7 +815,8 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; desc.NodeMask = 1; - IM_ASSERT(g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap)) == S_OK); + HRESULT hr = g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap)); + IM_ASSERT(hr == S_OK); SIZE_T rtv_descriptor_size = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = data->RtvDescHeap->GetCPUDescriptorHandleForHeapStart(); @@ -847,12 +848,24 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport) // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData) { + // Wait for pending operations to complete to safely release objects below + HRESULT hr; + if (data->CommandQueue && data->Fence && data->FenceEvent) + { + hr = data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue); + IM_ASSERT(hr == S_OK); + ::WaitForSingleObject(data->FenceEvent, 0); // Reset any forgotten waits + hr = data->Fence->SetEventOnCompletion(data->FenceSignaledValue, data->FenceEvent); + IM_ASSERT(hr == S_OK); + ::WaitForSingleObject(data->FenceEvent, INFINITE); + } + SafeRelease(data->CommandQueue); SafeRelease(data->CommandList); SafeRelease(data->SwapChain); SafeRelease(data->RtvDescHeap); SafeRelease(data->Fence); - ::CloseHandle(data->FenceEvent); + ::CloseHandle(data->FenceEvent); data->FenceEvent = NULL; for (UINT i = 0; i < g_numFramesInFlight; i++) From e8c986b34ea5664688d1126eed784a5e297e7e11 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Apr 2020 14:55:50 +0200 Subject: [PATCH 373/384] Version 1.77 WIP --- docs/CHANGELOG.txt | 5 +++++ docs/README.md | 4 ++-- examples/README.txt | 2 +- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_widgets.cpp | 2 +- 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c08d198c..af8eb05f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -30,6 +30,11 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.77 WIP (In Progress) +----------------------------------------------------------------------- + + ----------------------------------------------------------------------- VERSION 1.76 (Released 2020-04-12) ----------------------------------------------------------------------- diff --git a/docs/README.md b/docs/README.md index c7982c23..72ebea3d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -97,7 +97,7 @@ Calling the `ImGui::ShowDemoWindow()` function will create a demo window showcas ![screenshot demo](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v167/v167-misc.png) You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: -- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20200412.zip) (Windows binaries, 1.76 WIP, built 2020/04/12, master branch, 5 executables) or [older demo binaries](http://www.dearimgui.org/binaries). +- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20200412.zip) (Windows binaries, 1.76, built 2020/04/12, master branch) or [older demo binaries](http://www.dearimgui.org/binaries). The demo applications are not DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your style with `style.ScaleAllSizes()`. @@ -114,7 +114,7 @@ Officially maintained bindings (in repository): Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): - Languages: C, C#/.Net, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... -- Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, Nim Game Lib, Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, px_render, Qt/QtDirect3D, SFML, Sokol, Unreal Engine 4, vtk, Win32 GDI. +- Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, Nim Game Lib, Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, SFML, Sokol, Unity, Unreal Engine 4, vtk, Win32 GDI, WxWidgets. - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. diff --git a/examples/README.txt b/examples/README.txt index 1408585b..3356b546 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1,5 +1,5 @@ ----------------------------------------------------------------------- - dear imgui, v1.76 + dear imgui, v1.77 WIP ----------------------------------------------------------------------- examples/README.txt (This is the README file for the examples/ folder. See docs/ for more documentation) diff --git a/imgui.cpp b/imgui.cpp index b57bb195..1161a580 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index 92c56740..5ac453c4 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (headers) // Help: @@ -59,8 +59,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.76" -#define IMGUI_VERSION_NUM 17600 +#define IMGUI_VERSION "1.77 WIP" +#define IMGUI_VERSION_NUM 17601 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) // Define attributes of all API symbols declarations (e.g. for DLL under Windows) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 1e110ded..d31a4ca1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1e08bfd0..d0d6a1e7 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index cef0f9a9..3f35b8c2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 27d9e455..584dc39a 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.76 +// dear imgui, v1.77 WIP // (widgets code) /* From 54b38d88f75a7b3a54cb1552e97199fc714cc2cf Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 15 Apr 2020 12:31:51 +0200 Subject: [PATCH 374/384] TreeNode: Fixed bug where BeginDragDropSource() failed when the _OpenOnDoubleClick flag is set. Added basic demo code. (Amend 05420ea) --- docs/CHANGELOG.txt | 10 ++++++++++ imgui_demo.cpp | 14 ++++++++++++++ imgui_widgets.cpp | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index af8eb05f..d6d9f2c3 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -34,11 +34,21 @@ HOW TO UPDATE? VERSION 1.77 WIP (In Progress) ----------------------------------------------------------------------- +Breaking Changes: + +Other Changes: + +- TreeNode: Fixed bug where BeginDragDropSource() failed when the _OpenOnDoubleClick flag is + enabled (bug introduced in 1.76, but pre-1.76 it would also fail unless the _OpenOnArrow + flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick). + ----------------------------------------------------------------------- VERSION 1.76 (Released 2020-04-12) ----------------------------------------------------------------------- +Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.76 + Other Changes: - Drag and Drop, Nav: Disabling navigation arrow keys when drag and drop is active. In the docking diff --git a/imgui_demo.cpp b/imgui_demo.cpp index d31a4ca1..e9652ef7 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -641,11 +641,13 @@ static void ShowDemoWindowWidgets() HelpMarker("This is a more typical looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open."); static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; static bool align_label_with_current_x_position = false; + static bool test_drag_and_drop = false; ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnArrow", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnArrow); ImGui::CheckboxFlags("ImGuiTreeNodeFlags_OpenOnDoubleClick", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_OpenOnDoubleClick); ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanAvailWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanAvailWidth); ImGui::SameLine(); HelpMarker("Extend hit area to all available width instead of allowing more items to be layed out after the node."); ImGui::CheckboxFlags("ImGuiTreeNodeFlags_SpanFullWidth", (unsigned int*)&base_flags, ImGuiTreeNodeFlags_SpanFullWidth); ImGui::Checkbox("Align label with current X position", &align_label_with_current_x_position); + ImGui::Checkbox("Test tree node as drag source", &test_drag_and_drop); ImGui::Text("Hello!"); if (align_label_with_current_x_position) ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing()); @@ -665,6 +667,12 @@ static void ShowDemoWindowWidgets() bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Node %d", i); if (ImGui::IsItemClicked()) node_clicked = i; + if (test_drag_and_drop && ImGui::BeginDragDropSource()) + { + ImGui::SetDragDropPayload("_TREENODE", NULL, 0); + ImGui::Text("This is a drag and drop source"); + ImGui::EndDragDropSource(); + } if (node_open) { ImGui::BulletText("Blah blah\nBlah Blah"); @@ -680,6 +688,12 @@ static void ShowDemoWindowWidgets() ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i); if (ImGui::IsItemClicked()) node_clicked = i; + if (test_drag_and_drop && ImGui::BeginDragDropSource()) + { + ImGui::SetDragDropPayload("_TREENODE", NULL, 0); + ImGui::Text("This is a drag and drop source"); + ImGui::EndDragDropSource(); + } } } if (node_clicked != -1) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 584dc39a..aca6d796 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5360,10 +5360,11 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // It is rather standard that arrow click react on Down rather than Up and we'd be tempted to make it the default // (by removing the _OpenOnArrow test below), however this would have a perhaps surprising effect on CollapsingHeader()? // So right now we are making this optional. May evolve later. + // We set ImGuiButtonFlags_PressedOnClickRelease on OpenOnDoubleClick because we want the item to be active on the initial MouseDown in order for drag and drop to work. if (is_mouse_x_over_arrow && (flags & ImGuiTreeNodeFlags_OpenOnArrow)) button_flags |= ImGuiButtonFlags_PressedOnClick; else if (flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) - button_flags |= ImGuiButtonFlags_PressedOnDoubleClick; + button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; else button_flags |= ImGuiButtonFlags_PressedOnClickRelease; From 1fd9e131e4ca7d61602e976fd85b88ce8118b9dd Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 15 Apr 2020 13:06:05 +0200 Subject: [PATCH 375/384] TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick or _OpenOnArrow would open the node. (#143) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 1 + imgui_internal.h | 2 ++ imgui_widgets.cpp | 14 ++++++++++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d6d9f2c3..fca9b189 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,8 @@ Other Changes: - TreeNode: Fixed bug where BeginDragDropSource() failed when the _OpenOnDoubleClick flag is enabled (bug introduced in 1.76, but pre-1.76 it would also fail unless the _OpenOnArrow flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick). +- TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick + or _OpenOnArrow would open the node. (#143) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 1161a580..a1cdfe50 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3795,6 +3795,7 @@ void ImGui::NewFrame() g.DragDropAcceptIdCurrRectSurface = FLT_MAX; g.DragDropWithinSource = false; g.DragDropWithinTarget = false; + g.DragDropHoldJustPressedId = 0; // Update keyboard input state // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools diff --git a/imgui_internal.h b/imgui_internal.h index 3f35b8c2..0735d727 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1165,6 +1165,7 @@ struct ImGuiContext ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source + ImGuiID DragDropHoldJustPressedId; // Set when holding a payload just made ButtonBehavior() return a press. ImVector DragDropPayloadBufHeap; // We don't expose the ImVector<> directly, ImGuiPayload only holds pointer+size unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads @@ -1320,6 +1321,7 @@ struct ImGuiContext DragDropAcceptIdCurrRectSurface = 0.0f; DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; DragDropAcceptFrameCount = -1; + DragDropHoldJustPressedId = 0; memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal)); CurrentTabBar = NULL; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index aca6d796..124e0122 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -500,11 +500,13 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) { + const float DRAG_DROP_HOLD_TIMER = 0.70f; hovered = true; SetHoveredID(id); - if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, 0.70f, 0.00f)) + if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, DRAG_DROP_HOLD_TIMER, 0.00f)) { pressed = true; + g.DragDropHoldJustPressedId = id; FocusWindow(window); } } @@ -5376,7 +5378,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l bool toggled = false; if (!is_leaf) { - if (pressed) + if (pressed && g.DragDropHoldJustPressedId != id) { if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) toggled = true; @@ -5384,8 +5386,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l toggled |= is_mouse_x_over_arrow && !g.NavDisableMouseHover; // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0]) toggled = true; - if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. - toggled = false; + } + else if (pressed && g.DragDropHoldJustPressedId == id) + { + IM_ASSERT(button_flags & ImGuiButtonFlags_PressedOnDragDropHold); + if (!is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. + toggled = true; } if (g.NavId == id && g.NavMoveRequest && g.NavMoveDir == ImGuiDir_Left && is_open) From 3233fbff0e6d92b86624c733dbb2309d5673f45e Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 16 Apr 2020 14:07:40 +0200 Subject: [PATCH 376/384] Internals: Added SetNextWindowScroll() (#1526) --- imgui.cpp | 21 +++++++++++++++++++++ imgui_internal.h | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index a1cdfe50..b2a1953e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5488,6 +5488,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) UpdateWindowParentAndRootLinks(window, flags, parent_window); // Process SetNextWindow***() calls + // (FIXME: Consider splitting the HasXXX flags into X/Y components bool window_pos_set_by_api = false; bool window_size_x_set_by_api = false, window_size_y_set_by_api = false; if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) @@ -5512,6 +5513,19 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindowData.SizeCond) != 0 && (g.NextWindowData.SizeVal.y > 0.0f); SetWindowSize(window, g.NextWindowData.SizeVal, g.NextWindowData.SizeCond); } + if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasScroll) + { + if (g.NextWindowData.ScrollVal.x >= 0.0f) + { + window->ScrollTarget.x = g.NextWindowData.ScrollVal.x; + window->ScrollTargetCenterRatio.x = 0.0f; + } + if (g.NextWindowData.ScrollVal.y >= 0.0f) + { + window->ScrollTarget.y = g.NextWindowData.ScrollVal.y; + window->ScrollTargetCenterRatio.y = 0.0f; + } + } if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasContentSize) window->ContentSizeExplicit = g.NextWindowData.ContentSizeVal; else if (first_begin_of_the_frame) @@ -6513,6 +6527,13 @@ void ImGui::SetNextWindowContentSize(const ImVec2& size) g.NextWindowData.ContentSizeVal = size; } +void ImGui::SetNextWindowScroll(const ImVec2& scroll) +{ + ImGuiContext& g = *GImGui; + g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasScroll; + g.NextWindowData.ScrollVal = scroll; +} + void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond) { ImGuiContext& g = *GImGui; diff --git a/imgui_internal.h b/imgui_internal.h index 0735d727..8a561e51 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -948,7 +948,8 @@ enum ImGuiNextWindowDataFlags_ ImGuiNextWindowDataFlags_HasCollapsed = 1 << 3, ImGuiNextWindowDataFlags_HasSizeConstraint = 1 << 4, ImGuiNextWindowDataFlags_HasFocus = 1 << 5, - ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6 + ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6, + ImGuiNextWindowDataFlags_HasScroll = 1 << 7 }; // Storage for SetNexWindow** functions @@ -962,6 +963,7 @@ struct ImGuiNextWindowData ImVec2 PosPivotVal; ImVec2 SizeVal; ImVec2 ContentSizeVal; + ImVec2 ScrollVal; bool CollapsedVal; ImRect SizeConstraintRect; ImGuiSizeCallback SizeCallback; @@ -1703,6 +1705,7 @@ namespace ImGui IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); // Scrolling + IMGUI_API void SetNextWindowScroll(const ImVec2& scroll); // Use -1.0f on one axis to leave as-is IMGUI_API void SetScrollX(ImGuiWindow* window, float new_scroll_x); IMGUI_API void SetScrollY(ImGuiWindow* window, float new_scroll_y); IMGUI_API void SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x_ratio = 0.5f); From b0e9092d6f16c4e45f58879a319055663cedc2b6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 15 Apr 2020 17:39:49 +0200 Subject: [PATCH 377/384] TestEngine: Added extra storage and global enable flag. Added missing ItemInfo hooks. --- imgui_internal.h | 18 +++++++++++------- imgui_widgets.cpp | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 8a561e51..fbf3e1cc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1034,6 +1034,8 @@ struct ImGuiContext bool WithinFrameScope; // Set by NewFrame(), cleared by EndFrame() bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed bool WithinEndChild; // Set within EndChild() + bool TestEngineHookItems; // Will call test engine hooks ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() + void* TestEngine; // Test engine user data // Windows state ImVector Windows; // Windows, sorted in display order, back to front @@ -1233,14 +1235,16 @@ struct ImGuiContext ImGuiContext(ImFontAtlas* shared_font_atlas) : BackgroundDrawList(&DrawListSharedData), ForegroundDrawList(&DrawListSharedData) { Initialized = false; + FontAtlasOwnedByContext = shared_font_atlas ? false : true; Font = NULL; FontSize = FontBaseSize = 0.0f; - FontAtlasOwnedByContext = shared_font_atlas ? false : true; IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); Time = 0.0f; FrameCount = 0; FrameCountEnded = FrameCountRendered = -1; WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; + TestEngineHookItems = false; + TestEngine = NULL; WindowsActiveCount = 0; CurrentWindow = NULL; @@ -1938,13 +1942,13 @@ extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags); extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); -#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB, _ID) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box -#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) -#define IMGUI_TEST_ENGINE_LOG(_FMT, ...) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log +#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box +#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) +#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log #else -#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB, _ID) do { } while (0) -#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS) do { } while (0) -#define IMGUI_TEST_ENGINE_LOG(_FMT, ...) do { } while (0) +#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0) +#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0) +#define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0) #endif #if defined(__clang__) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 124e0122..5a3fa4c3 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -486,7 +486,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool #ifdef IMGUI_ENABLE_TEST_ENGINE if (id != 0 && window->DC.LastItemId != id) - ImGuiTestEngineHook_ItemAdd(&g, bb, id); + IMGUI_TEST_ENGINE_ITEM_ADD(bb, id); #endif bool pressed = false; @@ -1134,6 +1134,7 @@ bool ImGui::RadioButton(const char* label, bool active) if (label_size.x > 0.0f) RenderText(ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y), label); + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); return pressed; } @@ -7030,6 +7031,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, const ImGuiID id = TabBarCalcTabID(tab_bar, label); // If the user called us with *p_open == false, we early out and don't render. We make a dummy call to ItemAdd() so that attempts to use a contextual popup menu with an implicit ID won't use an older ID. + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags); if (p_open && !*p_open) { PushItemFlag(ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus, true); From 9f9ff84ba145d30b21641deca34055b18b183cf3 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 16 Apr 2020 16:57:17 +0200 Subject: [PATCH 378/384] TestEngine: Added PushID() hooks. --- imgui.cpp | 33 ++++++++++++++++++++++++--------- imgui_internal.h | 16 ++++++++++++++++ imgui_widgets.cpp | 4 +++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b2a1953e..5ef24b47 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6597,6 +6597,7 @@ void ImGui::PushFocusScope(ImGuiID id) ImGuiWindow* window = g.CurrentWindow; window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent); window->DC.NavFocusScopeIdCurrent = id; + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::PopFocusScope() @@ -6648,33 +6649,47 @@ ImGuiStorage* ImGui::GetStateStorage() void ImGui::PushID(const char* str_id) { - ImGuiWindow* window = GImGui->CurrentWindow; - window->IDStack.push_back(window->GetIDNoKeepAlive(str_id)); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetIDNoKeepAlive(str_id); + window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_String, str_id); } void ImGui::PushID(const char* str_id_begin, const char* str_id_end) { - ImGuiWindow* window = GImGui->CurrentWindow; - window->IDStack.push_back(window->GetIDNoKeepAlive(str_id_begin, str_id_end)); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetIDNoKeepAlive(str_id_begin, str_id_end); + window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID2(id, ImGuiDataType_String, str_id_begin, str_id_end); } void ImGui::PushID(const void* ptr_id) { - ImGuiWindow* window = GImGui->CurrentWindow; - window->IDStack.push_back(window->GetIDNoKeepAlive(ptr_id)); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetIDNoKeepAlive(ptr_id); + window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_Pointer, ptr_id); } void ImGui::PushID(int int_id) { - ImGuiWindow* window = GImGui->CurrentWindow; - window->IDStack.push_back(window->GetIDNoKeepAlive(int_id)); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetIDNoKeepAlive(int_id); + window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_S32, (intptr_t)int_id); } // Push a given id value ignoring the ID stack as a seed. void ImGui::PushOverrideID(ImGuiID id) { - ImGuiWindow* window = GImGui->CurrentWindow; + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::PopID() diff --git a/imgui_internal.h b/imgui_internal.h index fbf3e1cc..407b77cc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -723,6 +723,14 @@ struct ImGuiDataTypeInfo const char* ScanFmt; // Default scanf format for the type }; +// Extend ImGuiDataType_ +enum ImGuiDataTypePrivate_ +{ + ImGuiDataType_String = ImGuiDataType_COUNT + 1, + ImGuiDataType_Pointer, + ImGuiDataType_ID +}; + // Stacked color modifier, backup of modified data so we can restore it struct ImGuiColorMod { @@ -1035,6 +1043,7 @@ struct ImGuiContext bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed bool WithinEndChild; // Set within EndChild() bool TestEngineHookItems; // Will call test engine hooks ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() + ImGuiID TestEngineHookPushId; void* TestEngine; // Test engine user data // Windows state @@ -1244,6 +1253,7 @@ struct ImGuiContext FrameCountEnded = FrameCountRendered = -1; WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; TestEngineHookItems = false; + TestEngineHookPushId = 0; TestEngine = NULL; WindowsActiveCount = 0; @@ -1941,14 +1951,20 @@ extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags); +extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id); +extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id, const void* data_id_end); extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log +#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA)); +#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2)); #else #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0) #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0) +#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) do { } while (0) +#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) do { } while (0) #endif #if defined(__clang__) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5a3fa4c3..14489f5b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5493,10 +5493,12 @@ void ImGui::TreePush(const void* ptr_id) void ImGui::TreePushOverrideID(ImGuiID id) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; Indent(); window->DC.TreeDepth++; window->IDStack.push_back(id); + IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::TreePop() From 388bf66247bc17cddb704d6e6421cf872bc3f964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kucsma?= Date: Fri, 17 Apr 2020 18:50:33 +0200 Subject: [PATCH 379/384] Fix missing comma in FAQ.md (#3134) --- docs/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 3d73a0f4..6c140760 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -168,7 +168,7 @@ Unique ID are implicitly built from the hash of multiple elements that identify - Unique ID are often derived from a string label and at minimum scoped within their host window: ```c Begin("MyWindow"); -Button("OK"); // Label = "OK", ID = hash of ("MyWindow" "OK") +Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "OK") Button("Cancel"); // Label = "Cancel", ID = hash of ("MyWindow", "Cancel") End(); ``` From 36ac557df077530f540e58778fedd8e3ef24cd31 Mon Sep 17 00:00:00 2001 From: Patryk Czachurski Date: Sat, 18 Apr 2020 11:09:44 +0200 Subject: [PATCH 380/384] Docking: Fix unused variable warning. (#3135) --- imgui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui.cpp b/imgui.cpp index 4ca0c92f..23ce906c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -14222,6 +14222,7 @@ void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_persi if (want_removal) { const ImGuiID backup_dock_id = window->DockId; + IM_UNUSED(backup_dock_id); DockContextProcessUndockWindow(ctx, window, clear_persistent_docking_references); if (!clear_persistent_docking_references) IM_ASSERT(window->DockId == backup_dock_id); From 7f8b076f2b5042aa88a95e0d334e599051176e44 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 15 Apr 2020 15:00:37 +0300 Subject: [PATCH 381/384] Viewports, Backends: GLFW: Fix windows resizing incorrectly due to GLFW firing window positioning callbacks on next frame after window is resized manually. (#2117) + Docking fixed PVS warning --- examples/imgui_impl_glfw.cpp | 27 +++++++++++++++++++-------- imgui.cpp | 4 ++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 495796fd..f1d38701 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -491,9 +491,10 @@ struct ImGuiViewportDataGlfw { GLFWwindow* Window; bool WindowOwned; + int IgnoreWindowPosEventFrame; int IgnoreWindowSizeEventFrame; - ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = -1; } + ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = IgnoreWindowPosEventFrame = -1; } ~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); } }; @@ -503,10 +504,25 @@ static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window) viewport->PlatformRequestClose = true; } +// GLFW may dispatch window pos/size events after calling glfwSetWindowPos()/glfwSetWindowSize(). +// However: depending on the platform the callback may be invoked at different time: +// - on Windows it appears to be called within the glfwSetWindowPos()/glfwSetWindowSize() call +// - on Linux it is queued and invoked during glfwPollEvents() +// Because the event doesn't always fire on glfwSetWindowXXX() we use a frame counter tag to only +// ignore recent glfwSetWindowXXX() calls. static void ImGui_ImplGlfw_WindowPosCallback(GLFWwindow* window, int, int) { if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window)) + { + if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData) + { + bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowPosEventFrame + 1); + //data->IgnoreWindowPosEventFrame = -1; + if (ignore_event) + return; + } viewport->PlatformRequestMove = true; + } } static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int) @@ -515,14 +531,8 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int) { if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData) { - // GLFW may dispatch window size event after calling glfwSetWindowSize(). - // However depending on the platform the callback may be invoked at different time: on Windows it - // appears to be called within the glfwSetWindowSize() call whereas on Linux it is queued and invoked - // during glfwPollEvents(). - // Because the event doesn't always fire on glfwSetWindowSize() we use a frame counter tag to only - // ignore recent glfwSetWindowSize() calls. bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1); - data->IgnoreWindowSizeEventFrame = -1; + //data->IgnoreWindowSizeEventFrame = -1; if (ignore_event) return; } @@ -658,6 +668,7 @@ static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport) static void ImGui_ImplGlfw_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos) { ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData; + data->IgnoreWindowPosEventFrame = ImGui::GetFrameCount(); glfwSetWindowPos(data->Window, (int)pos.x, (int)pos.y); } diff --git a/imgui.cpp b/imgui.cpp index 23ce906c..54743e34 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13350,8 +13350,8 @@ static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockN // Build a tentative future node (reuse same structure because it is practical. Shape will be readjusted when previewing a split) data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton); data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0); - data->FutureNode.Pos = host_node ? ref_node_for_rect->Pos : host_window->Pos; - data->FutureNode.Size = host_node ? ref_node_for_rect->Size : host_window->Size; + data->FutureNode.Pos = ref_node_for_rect ? ref_node_for_rect->Pos : host_window->Pos; + data->FutureNode.Size = ref_node_for_rect ? ref_node_for_rect->Size : host_window->Size; // Calculate drop shapes geometry for allowed splitting directions IM_ASSERT(ImGuiDir_None == -1); From 37f665b619946b1651d120b063a537a694f4ab2d Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 19 Apr 2020 17:52:09 +0200 Subject: [PATCH 382/384] Backends: Win32: Support for #define NOGDI, won't try to call GetDeviceCaps(). (#3137, #2327) --- docs/CHANGELOG.txt | 1 + examples/imgui_impl_win32.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fca9b189..81cb3bab 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,6 +43,7 @@ Other Changes: flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick). - TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick or _OpenOnArrow would open the node. (#143) +- Backends: Win32: Support for #define NOGDI, won't try to call GetDeviceCaps(). (#3137, #2327) ----------------------------------------------------------------------- diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index f8868ce6..aa00a1f9 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -408,7 +408,7 @@ void ImGui_ImplWin32_EnableDpiAwareness() SetProcessDPIAware(); } -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(NOGDI) #pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps() #endif @@ -421,6 +421,7 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) if (PFN_GetDpiForMonitor GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor")) GetDpiForMonitorFn((HMONITOR)monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); } +#ifndef NOGDI else { const HDC dc = ::GetDC(NULL); @@ -428,6 +429,7 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor) ydpi = ::GetDeviceCaps(dc, LOGPIXELSY); ::ReleaseDC(NULL, dc); } +#endif IM_ASSERT(xdpi == ydpi); // Please contact me if you hit this assert! return xdpi / 96.0f; } From c0283c128975d4cc3edb595a0bc30f407f801d30 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 20 Apr 2020 11:31:30 +0200 Subject: [PATCH 383/384] TestEngine: Changed PushID hooks into GetID(), makes more sense and catches more information. --- imgui.cpp | 39 ++++++++++++++++++++++++++++++--------- imgui_internal.h | 18 +++++++++--------- imgui_widgets.cpp | 1 - 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5ef24b47..0d4d9780 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2889,6 +2889,10 @@ ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) ImGuiID seed = IDStack.back(); ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); ImGui::KeepAliveID(id); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO2(id, ImGuiDataType_String, str, str_end); +#endif return id; } @@ -2897,6 +2901,10 @@ ImGuiID ImGuiWindow::GetID(const void* ptr) ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); ImGui::KeepAliveID(id); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO(id, ImGuiDataType_Pointer, ptr); +#endif return id; } @@ -2905,25 +2913,44 @@ ImGuiID ImGuiWindow::GetID(int n) ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&n, sizeof(n), seed); ImGui::KeepAliveID(id); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO(id, ImGuiDataType_S32, (intptr_t)n); +#endif return id; } ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end) { ImGuiID seed = IDStack.back(); - return ImHashStr(str, str_end ? (str_end - str) : 0, seed); + ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO2(id, ImGuiDataType_String, str, str_end); +#endif + return id; } ImGuiID ImGuiWindow::GetIDNoKeepAlive(const void* ptr) { ImGuiID seed = IDStack.back(); - return ImHashData(&ptr, sizeof(void*), seed); + ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO(id, ImGuiDataType_Pointer, ptr); +#endif + return id; } ImGuiID ImGuiWindow::GetIDNoKeepAlive(int n) { ImGuiID seed = IDStack.back(); - return ImHashData(&n, sizeof(n), seed); + ImGuiID id = ImHashData(&n, sizeof(n), seed); +#ifdef IMGUI_ENABLE_TEST_ENGINE + ImGuiContext& g = *GImGui; + IMGUI_TEST_ENGINE_ID_INFO(id, ImGuiDataType_S32, (intptr_t)n); +#endif + return id; } // This is only used in rare/specific situations to manufacture an ID out of nowhere. @@ -6597,7 +6624,6 @@ void ImGui::PushFocusScope(ImGuiID id) ImGuiWindow* window = g.CurrentWindow; window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent); window->DC.NavFocusScopeIdCurrent = id; - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::PopFocusScope() @@ -6653,7 +6679,6 @@ void ImGui::PushID(const char* str_id) ImGuiWindow* window = g.CurrentWindow; ImGuiID id = window->GetIDNoKeepAlive(str_id); window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_String, str_id); } void ImGui::PushID(const char* str_id_begin, const char* str_id_end) @@ -6662,7 +6687,6 @@ void ImGui::PushID(const char* str_id_begin, const char* str_id_end) ImGuiWindow* window = g.CurrentWindow; ImGuiID id = window->GetIDNoKeepAlive(str_id_begin, str_id_end); window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID2(id, ImGuiDataType_String, str_id_begin, str_id_end); } void ImGui::PushID(const void* ptr_id) @@ -6671,7 +6695,6 @@ void ImGui::PushID(const void* ptr_id) ImGuiWindow* window = g.CurrentWindow; ImGuiID id = window->GetIDNoKeepAlive(ptr_id); window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_Pointer, ptr_id); } void ImGui::PushID(int int_id) @@ -6680,7 +6703,6 @@ void ImGui::PushID(int int_id) ImGuiWindow* window = g.CurrentWindow; ImGuiID id = window->GetIDNoKeepAlive(int_id); window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_S32, (intptr_t)int_id); } // Push a given id value ignoring the ID stack as a seed. @@ -6689,7 +6711,6 @@ void ImGui::PushOverrideID(ImGuiID id) ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::PopID() diff --git a/imgui_internal.h b/imgui_internal.h index 407b77cc..d6ef765d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1042,8 +1042,8 @@ struct ImGuiContext bool WithinFrameScope; // Set by NewFrame(), cleared by EndFrame() bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed bool WithinEndChild; // Set within EndChild() - bool TestEngineHookItems; // Will call test engine hooks ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() - ImGuiID TestEngineHookPushId; + bool TestEngineHookItems; // Will call test engine hooks: ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() + ImGuiID TestEngineHookIdInfo; // Will call test engine hooks: ImGuiTestEngineHook_IdInfo() from GetID() void* TestEngine; // Test engine user data // Windows state @@ -1253,7 +1253,7 @@ struct ImGuiContext FrameCountEnded = FrameCountRendered = -1; WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; TestEngineHookItems = false; - TestEngineHookPushId = 0; + TestEngineHookIdInfo = 0; TestEngine = NULL; WindowsActiveCount = 0; @@ -1951,20 +1951,20 @@ extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags); -extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id); -extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id, const void* data_id_end); +extern void ImGuiTestEngineHook_IdInfo(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id); +extern void ImGuiTestEngineHook_IdInfo(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id, const void* data_id_end); extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log -#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA)); -#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2)); +#define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA)); +#define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2)); #else #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0) #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0) -#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) do { } while (0) -#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) do { } while (0) +#define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) do { } while (0) +#define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) do { } while (0) #endif #if defined(__clang__) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 14489f5b..02ac3cd5 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5498,7 +5498,6 @@ void ImGui::TreePushOverrideID(ImGuiID id) Indent(); window->DC.TreeDepth++; window->IDStack.push_back(id); - IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL); } void ImGui::TreePop() From 7ddc1adefbdca94e7de350653def7a647ff45612 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 22 Apr 2020 16:30:22 +0200 Subject: [PATCH 384/384] Internals: FIxed commented out IMGUI_DEBUG_LOG_xxx macros, added extra. Revert incorrect 103c5edaa. --- imgui.cpp | 4 +++- imgui_internal.h | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8a2b3f69..970fc9cc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12154,7 +12154,8 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref) { - (void)ctx; + IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); + IM_UNUSED(ctx); if (window->DockNode) DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId); else @@ -12167,6 +12168,7 @@ void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* windo void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) { + IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockNode node %08X\n", node->ID); IM_ASSERT(node->IsLeafNode()); IM_ASSERT(node->Windows.Size >= 1); diff --git a/imgui_internal.h b/imgui_internal.h index dd0ea528..13abd67a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -158,9 +158,12 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #endif // Debug Logging for selected systems. Remove the '((void)0) //' to enable. -#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) -#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) -#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // IMGUI_DEBUG_LOG(__VA_ARGS__) +//#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log +//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log +//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log +#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log +#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log +#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log // Static Asserts #if (__cplusplus >= 201100) @@ -1751,7 +1754,7 @@ struct IMGUI_API ImGuiWindow ImGuiItemStatusFlags DockTabItemStatusFlags; ImRect DockTabItemRect; short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. - bool DockIsActive :1; // When docking artifacts are actually visible. When this is set, DockNode is guaranteed to be != NULL. ~~ (DockNode != NULL) && (DockNode->Windows.Size > 1). + bool DockIsActive :1; // When docking artifacts are actually visible. When this is set, DockNode is guaranteed to be != NULL. ~~ (DockNode != NULL) && (DockNode->Windows.Size > 1). bool DockTabIsVisible :1; // Is our window visible this frame? ~~ is the corresponding tab selected? bool DockTabWantClose :1;