Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double-click on resize grip)
| 6263 | // Handle resize for: Resize Grips, Borders, Gamepad |
| 6264 | // Return true when using auto-fit (double-click on resize grip) |
| 6265 | static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect) |
| 6266 | { |
| 6267 | ImGuiContext& g = *GImGui; |
| 6268 | ImGuiWindowFlags flags = window->Flags; |
| 6269 | |
| 6270 | if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) |
| 6271 | return false; |
| 6272 | if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window. |
| 6273 | return false; |
| 6274 | |
| 6275 | bool ret_auto_fit = false; |
| 6276 | const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0; |
| 6277 | const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); |
| 6278 | const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f); |
| 6279 | const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f; |
| 6280 | |
| 6281 | ImVec2 pos_target(FLT_MAX, FLT_MAX); |
| 6282 | ImVec2 size_target(FLT_MAX, FLT_MAX); |
| 6283 | |
| 6284 | // Clip mouse interaction rectangles within the viewport rectangle (in practice the narrowing is going to happen most of the time). |
| 6285 | // - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits. |
| 6286 | // This is however not the case with current backends under Win32, but a custom borderless window implementation would benefit from it. |
| 6287 | // - 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. |
| 6288 | // - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold). |
| 6289 | // We only clip interaction so we overwrite window->ClipRect, cannot call PushClipRect() yet as DrawList is not yet setup. |
| 6290 | const bool clip_with_viewport_rect = !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration); |
| 6291 | if (clip_with_viewport_rect) |
| 6292 | window->ClipRect = window->Viewport->GetMainRect(); |
| 6293 | |
| 6294 | // Resize grips and borders are on layer 1 |
| 6295 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 6296 | |
| 6297 | // Manual resize grips |
| 6298 | PushID("#RESIZE"); |
| 6299 | for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) |
| 6300 | { |
| 6301 | const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n]; |
| 6302 | const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN); |
| 6303 | |
| 6304 | // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window |
| 6305 | bool hovered, held; |
| 6306 | ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size); |
| 6307 | if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); |
| 6308 | if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); |
| 6309 | ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() |
| 6310 | ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav); |
| 6311 | ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); |
| 6312 | //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); |
| 6313 | if (hovered || held) |
| 6314 | g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; |
| 6315 | |
| 6316 | if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0) |
| 6317 | { |
| 6318 | // Manual auto-fit when double-clicking |
| 6319 | size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 6320 | ret_auto_fit = true; |
| 6321 | ClearActiveID(); |
| 6322 | } |
nothing calls this directly
no test coverage detected