Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double-click on resize grip)
| 7200 | // Handle resize for: Resize Grips, Borders, Gamepad |
| 7201 | // Return true when using auto-fit (double-click on resize grip) |
| 7202 | static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect) |
| 7203 | { |
| 7204 | ImGuiContext& g = *GImGui; |
| 7205 | ImGuiWindowFlags flags = window->Flags; |
| 7206 | |
| 7207 | if ((flags & ImGuiWindowFlags_NoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) |
| 7208 | return false; |
| 7209 | if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && (window->ChildFlags & (ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY)) == 0) |
| 7210 | return false; |
| 7211 | if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window. |
| 7212 | return false; |
| 7213 | |
| 7214 | int ret_auto_fit_mask = 0x00; |
| 7215 | const float grip_draw_size = IM_TRUNC(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); |
| 7216 | const float grip_hover_inner_size = (resize_grip_count > 0) ? IM_TRUNC(grip_draw_size * 0.75f) : 0.0f; |
| 7217 | const float grip_hover_outer_size = g.WindowsBorderHoverPadding; |
| 7218 | |
| 7219 | ImRect clamp_rect = visibility_rect; |
| 7220 | const bool window_move_from_title_bar = !(window->BgClickFlags & ImGuiWindowBgClickFlags_Move) && !(window->Flags & ImGuiWindowFlags_NoTitleBar); |
| 7221 | if (window_move_from_title_bar) |
| 7222 | clamp_rect.Min.y -= window->TitleBarHeight; |
| 7223 | |
| 7224 | ImVec2 pos_target(FLT_MAX, FLT_MAX); |
| 7225 | ImVec2 size_target(FLT_MAX, FLT_MAX); |
| 7226 | |
| 7227 | // Clip mouse interaction rectangles within the viewport rectangle (in practice the narrowing is going to happen most of the time). |
| 7228 | // - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits. |
| 7229 | // This is however not the case with current backends under Win32, but a custom borderless window implementation would benefit from it. |
| 7230 | // - 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. |
| 7231 | // - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold). |
| 7232 | // We only clip interaction so we overwrite window->ClipRect, cannot call PushClipRect() yet as DrawList is not yet setup. |
| 7233 | const bool clip_with_viewport_rect = !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration); |
| 7234 | if (clip_with_viewport_rect) |
| 7235 | window->ClipRect = window->Viewport->GetMainRect(); |
| 7236 | |
| 7237 | // Resize grips and borders are on layer 1 |
| 7238 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 7239 | |
| 7240 | // Manual resize grips |
| 7241 | PushID("#RESIZE"); |
| 7242 | for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) |
| 7243 | { |
| 7244 | const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n]; |
| 7245 | const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN); |
| 7246 | |
| 7247 | // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window |
| 7248 | bool hovered, held; |
| 7249 | ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size); |
| 7250 | if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); |
| 7251 | if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); |
| 7252 | ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() |
| 7253 | ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav); |
| 7254 | ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); |
| 7255 | //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); |
| 7256 | if (hovered || held) |
| 7257 | SetMouseCursor((resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE); |
| 7258 | |
| 7259 | if (held && g.IO.MouseDoubleClicked[0]) |
nothing calls this directly
no test coverage detected