Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double click on resize grip)
| 5365 | // Handle resize for: Resize Grips, Borders, Gamepad |
| 5366 | // Return true when using auto-fit (double click on resize grip) |
| 5367 | 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) |
| 5368 | { |
| 5369 | ImGuiContext& g = *GImGui; |
| 5370 | ImGuiWindowFlags flags = window->Flags; |
| 5371 | |
| 5372 | if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) |
| 5373 | return false; |
| 5374 | if (window->WasActive == false) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window. |
| 5375 | return false; |
| 5376 | |
| 5377 | bool ret_auto_fit = false; |
| 5378 | const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0; |
| 5379 | const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); |
| 5380 | const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f); |
| 5381 | const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f; |
| 5382 | |
| 5383 | ImVec2 pos_target(FLT_MAX, FLT_MAX); |
| 5384 | ImVec2 size_target(FLT_MAX, FLT_MAX); |
| 5385 | |
| 5386 | // Resize grips and borders are on layer 1 |
| 5387 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 5388 | |
| 5389 | // Manual resize grips |
| 5390 | PushID("#RESIZE"); |
| 5391 | for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) |
| 5392 | { |
| 5393 | const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n]; |
| 5394 | const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN); |
| 5395 | |
| 5396 | // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window |
| 5397 | bool hovered, held; |
| 5398 | ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size); |
| 5399 | if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); |
| 5400 | if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); |
| 5401 | ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() |
| 5402 | ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); |
| 5403 | //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); |
| 5404 | if (hovered || held) |
| 5405 | g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; |
| 5406 | |
| 5407 | if (held && g.IO.MouseDoubleClicked[0] && resize_grip_n == 0) |
| 5408 | { |
| 5409 | // Manual auto-fit when double-clicking |
| 5410 | size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 5411 | ret_auto_fit = true; |
| 5412 | ClearActiveID(); |
| 5413 | } |
| 5414 | else if (held) |
| 5415 | { |
| 5416 | // Resize from any of the four corners |
| 5417 | // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position |
| 5418 | ImVec2 clamp_min = ImVec2(def.CornerPosN.x == 1.0f ? visibility_rect.Min.x : -FLT_MAX, def.CornerPosN.y == 1.0f ? visibility_rect.Min.y : -FLT_MAX); |
| 5419 | ImVec2 clamp_max = ImVec2(def.CornerPosN.x == 0.0f ? visibility_rect.Max.x : +FLT_MAX, def.CornerPosN.y == 0.0f ? visibility_rect.Max.y : +FLT_MAX); |
| 5420 | ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + ImLerp(def.InnerDir * grip_hover_outer_size, def.InnerDir * -grip_hover_inner_size, def.CornerPosN); // Corner of the window corresponding to our corner grip |
| 5421 | corner_target = ImClamp(corner_target, clamp_min, clamp_max); |
| 5422 | CalcResizePosSizeFromAnyCorner(window, corner_target, def.CornerPosN, &pos_target, &size_target); |
| 5423 | } |
| 5424 |
nothing calls this directly
no test coverage detected