Windows: fixed double-clicked border from showing highlighted at the new position.

Amend c95fbb4 + misc tidying up, comments of grip/border resizing struct.
This commit is contained in:
ocornut 2023-10-19 17:40:32 +02:00
parent e2035a514c
commit bc3c6e74e6

View File

@ -5779,7 +5779,7 @@ static void CalcResizePosSizeFromAnyCorner(ImGuiWindow* window, const ImVec2& co
*out_size = size_constrained; *out_size = size_constrained;
} }
// Data for resizing from corner // Data for resizing from resize grip / corner
struct ImGuiResizeGripDef struct ImGuiResizeGripDef
{ {
ImVec2 CornerPosN; ImVec2 CornerPosN;
@ -5797,9 +5797,9 @@ static const ImGuiResizeGripDef resize_grip_def[4] =
// Data for resizing from borders // Data for resizing from borders
struct ImGuiResizeBorderDef struct ImGuiResizeBorderDef
{ {
ImVec2 InnerDir; ImVec2 InnerDir; // Normal toward inside
ImVec2 SegmentN1, SegmentN2; ImVec2 SegmentN1, SegmentN2; // End positions, normalized (0,0: upper left)
float OuterAngle; float OuterAngle; // Angle toward outside
}; };
static const ImGuiResizeBorderDef resize_border_def[4] = static const ImGuiResizeBorderDef resize_border_def[4] =
{ {
@ -5927,14 +5927,10 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
ItemAdd(border_rect, border_id, NULL, ImGuiItemFlags_NoNav); ItemAdd(border_rect, border_id, NULL, ImGuiItemFlags_NoNav);
ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); //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) if (hovered && g.HoveredIdTimer <= WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER)
{ hovered = false;
if (hovered || held)
g.MouseCursor = (axis == ImGuiAxis_X) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS; g.MouseCursor = (axis == ImGuiAxis_X) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
if (hovered)
*border_hovered = border_n;
if (held)
*border_held = border_n;
}
if (held && g.IO.MouseDoubleClicked[0]) if (held && g.IO.MouseDoubleClicked[0])
{ {
// Double-clicking bottom or right border auto-fit on this axis // Double-clicking bottom or right border auto-fit on this axis
@ -5943,6 +5939,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
{ {
size_target[axis] = CalcWindowSizeAfterConstraint(window, size_auto_fit)[axis]; size_target[axis] = CalcWindowSizeAfterConstraint(window, size_auto_fit)[axis];
ret_auto_fit_mask |= (1 << axis); ret_auto_fit_mask |= (1 << axis);
hovered = held = false; // So border doesn't show highlighted at new position
} }
ClearActiveID(); ClearActiveID();
} }
@ -5955,6 +5952,10 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
border_target = ImClamp(border_target, clamp_min, clamp_max); border_target = ImClamp(border_target, clamp_min, clamp_max);
CalcResizePosSizeFromAnyCorner(window, border_target, ImMin(def.SegmentN1, def.SegmentN2), &pos_target, &size_target); CalcResizePosSizeFromAnyCorner(window, border_target, ImMin(def.SegmentN1, def.SegmentN2), &pos_target, &size_target);
} }
if (hovered)
*border_hovered = border_n;
if (held)
*border_held = border_n;
} }
PopID(); PopID();
@ -5999,7 +6000,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
window->Pos.x = ImTrunc(pos_target.x); window->Pos.x = ImTrunc(pos_target.x);
if (pos_target.y != FLT_MAX) if (pos_target.y != FLT_MAX)
window->Pos.y = ImTrunc(pos_target.y); window->Pos.y = ImTrunc(pos_target.y);
if (size_target.x != FLT_MAX || size_target.y != FLT_MAX || pos_target.x != FLT_MAX|| pos_target.y != FLT_MAX) if (size_target.x != FLT_MAX || size_target.y != FLT_MAX || pos_target.x != FLT_MAX || pos_target.y != FLT_MAX)
MarkIniSettingsDirty(window); MarkIniSettingsDirty(window);
return ret_auto_fit_mask; return ret_auto_fit_mask;