From eb7849b477ff96d8d0cc9f2f4a304b5fc0f3ac1a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 31 May 2019 20:48:52 +0200 Subject: [PATCH 1/3] Nav: Fixed gamepad/keyboard moving of window affecting contents size incorrectly, sometimes leading to scrollbars appearing during the movement. + minor fix with the mostly dead Ctrl+wheel scaling. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 6 +++--- imgui_internal.h | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 010fc805..83af7f48 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -53,6 +53,8 @@ Other Changes: options. (#2587, broken in 1.69 by #2384). - CollapsingHeader: Better clipping when a close button is enabled and it overlaps the label. (#600) - Scrollbar: Very minor bounding box adjustment to cope with various border size. +- Nav: Fixed gamepad/keyboard moving of window affecting contents size incorrectly, sometimes leading + to scrollbars appearing during the movement. - Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the collapsing/docking button to the other side of the title bar. - Style: Made window close button cross slightly smaller. diff --git a/imgui.cpp b/imgui.cpp index e42f3ae0..1be33f96 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3330,7 +3330,7 @@ void ImGui::UpdateMouseWheel() // Zoom / Scale window // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. - if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) + if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling && !window->Collapsed) { const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); const float scale = new_font_scale / window->FontWindowScale; @@ -3338,7 +3338,7 @@ void ImGui::UpdateMouseWheel() if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) { const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; - window->Pos = ImFloor(window->Pos + offset); + SetWindowPos(window, window->Pos + offset, 0); window->Size = ImFloor(window->Size * scale); window->SizeFull = ImFloor(window->SizeFull * scale); } @@ -8398,7 +8398,7 @@ static void ImGui::NavUpdateWindowing() { const float NAV_MOVE_SPEED = 800.0f; const float move_speed = ImFloor(NAV_MOVE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); // FIXME: Doesn't code variable framerate very well - g.NavWindowingTarget->RootWindow->Pos += move_delta * move_speed; + SetWindowPos(g.NavWindowingTarget->RootWindow, g.NavWindowingTarget->RootWindow->Pos + move_delta * move_speed, ImGuiCond_Always); g.NavDisableMouseHover = true; MarkIniSettingsDirty(g.NavWindowingTarget); } diff --git a/imgui_internal.h b/imgui_internal.h index 0af4a5ed..2ad53b24 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1450,9 +1450,9 @@ namespace ImGui IMGUI_API float GetWindowScrollMaxX(ImGuiWindow* window); IMGUI_API float GetWindowScrollMaxY(ImGuiWindow* window); IMGUI_API ImRect GetWindowAllowedExtentRect(ImGuiWindow* window); - IMGUI_API void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond); - IMGUI_API void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond); - IMGUI_API void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond); + 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 SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } From 6614bab883268778db8490f1282d7cfb8fdac1bf Mon Sep 17 00:00:00 2001 From: DucaRii <24766710+DucaRii@users.noreply.github.com> Date: Tue, 4 Jun 2019 16:37:45 +0200 Subject: [PATCH 2/3] Combo: Fixed rounding not applying with the ImGuiComboFlags_NoArrowButton flag. (#2606, #2607) --- 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 83af7f48..8a38612e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -53,6 +53,7 @@ Other Changes: options. (#2587, broken in 1.69 by #2384). - CollapsingHeader: Better clipping when a close button is enabled and it overlaps the label. (#600) - Scrollbar: Very minor bounding box adjustment to cope with various border size. +- Combo: Fixed rounding not applying with the ImGuiComboFlags_NoArrowButton flag. (#2607) [@DucaRii] - Nav: Fixed gamepad/keyboard moving of window affecting contents size incorrectly, sometimes leading to scrollbars appearing during the movement. - Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 08c936fd..24c7b3e3 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1411,7 +1411,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF const float value_x2 = ImMax(frame_bb.Min.x, frame_bb.Max.x - arrow_size); RenderNavHighlight(frame_bb, id); if (!(flags & ImGuiComboFlags_NoPreview)) - window->DrawList->AddRectFilled(frame_bb.Min, ImVec2(value_x2, frame_bb.Max.y), frame_col, style.FrameRounding, ImDrawCornerFlags_Left); + window->DrawList->AddRectFilled(frame_bb.Min, ImVec2(value_x2, frame_bb.Max.y), frame_col, style.FrameRounding, (flags & ImGuiComboFlags_NoArrowButton) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Left); if (!(flags & ImGuiComboFlags_NoArrowButton)) { window->DrawList->AddRectFilled(ImVec2(value_x2, frame_bb.Min.y), frame_bb.Max, GetColorU32((popup_open || hovered) ? ImGuiCol_ButtonHovered : ImGuiCol_Button), style.FrameRounding, (w <= arrow_size) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Right); From 57d8ab62f4c0c28e24b099c61ebee911b1aa7e7e Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 5 Jun 2019 00:25:21 +0200 Subject: [PATCH 3/3] Nav: Fixed rare crash when e.g. releasing Alt-key while focusing a window with a menu at the same frame as clearing the focus. This was in most noticeable in some back-ends with emits key release events when focusing another viewport. (#2609) --- docs/CHANGELOG.txt | 4 ++++ imgui.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8a38612e..09152b43 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -56,6 +56,10 @@ Other Changes: - Combo: Fixed rounding not applying with the ImGuiComboFlags_NoArrowButton flag. (#2607) [@DucaRii] - Nav: Fixed gamepad/keyboard moving of window affecting contents size incorrectly, sometimes leading to scrollbars appearing during the movement. +- Nav: Fixed rare crash when e.g. releasing Alt-key while focusing a window with a menu at the same + frame as clearing the focus. This was in most noticeable in back-ends such as Glfw and SDL which + emits key release events when focusing another viewport, leading to Alt+clicking on void on another + viewport triggering the issue. (#2609) - Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the collapsing/docking button to the other side of the title bar. - Style: Made window close button cross slightly smaller. diff --git a/imgui.cpp b/imgui.cpp index 1be33f96..99fb8c2e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7933,10 +7933,10 @@ static void ImGui::NavUpdate() g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f; // Process navigation init request (select first/default focus) - if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove)) + // In very rare cases g.NavWindow may be null (e.g. clearing focus after requesting an init request, which does happen when releasing Alt while clicking on void) + 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) - IM_ASSERT(g.NavWindow); if (g.NavInitRequestFromMove) SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel); else