mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-16 20:07:18 +01:00
Viewport: Fixed issue where resize grip would display hovered (before of extruded hit rectangle) while mouse is still off the OS bounds so click would miss it and focus the OS window behind expected one. (#1542)
This commit is contained in:
parent
72090b646f
commit
d8f9f6ba2a
21
imgui.cpp
21
imgui.cpp
@ -5398,6 +5398,15 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
|||||||
ImVec2 pos_target(FLT_MAX, FLT_MAX);
|
ImVec2 pos_target(FLT_MAX, FLT_MAX);
|
||||||
ImVec2 size_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).
|
||||||
|
// - 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();
|
||||||
|
|
||||||
// Resize grips and borders are on layer 1
|
// Resize grips and borders are on layer 1
|
||||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
|
window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
|
||||||
window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
|
window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
|
||||||
@ -5413,6 +5422,7 @@ 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);
|
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.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);
|
if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
|
||||||
|
resize_rect.ClipWith(clip_viewport_rect);
|
||||||
bool hovered, held;
|
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((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
|
||||||
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
|
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
|
||||||
@ -5440,8 +5450,9 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
|||||||
{
|
{
|
||||||
bool hovered, held;
|
bool hovered, held;
|
||||||
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS);
|
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS);
|
||||||
|
border_rect.ClipWith(clip_viewport_rect);
|
||||||
ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren);
|
ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren);
|
||||||
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
|
//GetForegroundDrawList(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)
|
if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held)
|
||||||
{
|
{
|
||||||
g.MouseCursor = (border_n & 1) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
|
g.MouseCursor = (border_n & 1) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
|
||||||
@ -5461,6 +5472,10 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
|||||||
}
|
}
|
||||||
PopID();
|
PopID();
|
||||||
|
|
||||||
|
// Resize nav layer
|
||||||
|
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
||||||
|
window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
|
||||||
|
|
||||||
// Navigation resize (keyboard/gamepad)
|
// Navigation resize (keyboard/gamepad)
|
||||||
if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window)
|
if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window)
|
||||||
{
|
{
|
||||||
@ -5493,10 +5508,6 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
|||||||
MarkIniSettingsDirty(window);
|
MarkIniSettingsDirty(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize nav layer
|
|
||||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
|
||||||
window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
|
|
||||||
|
|
||||||
window->Size = window->SizeFull;
|
window->Size = window->SizeFull;
|
||||||
return ret_auto_fit;
|
return ret_auto_fit;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user