Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double click on resize grip)
| 5551 | // Handle resize for: Resize Grips, Borders, Gamepad |
| 5552 | // Return true when using auto-fit (double click on resize grip) |
| 5553 | 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) |
| 5554 | { |
| 5555 | ImGuiContext& g = *GImGui; |
| 5556 | ImGuiWindowFlags flags = window->Flags; |
| 5557 | |
| 5558 | if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) |
| 5559 | return false; |
| 5560 | if (window->WasActive == false) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window. |
| 5561 | return false; |
| 5562 | |
| 5563 | bool ret_auto_fit = false; |
| 5564 | const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0; |
| 5565 | const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); |
| 5566 | const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f); |
| 5567 | const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f; |
| 5568 | |
| 5569 | ImVec2 pos_target(FLT_MAX, FLT_MAX); |
| 5570 | ImVec2 size_target(FLT_MAX, FLT_MAX); |
| 5571 | |
| 5572 | // Resize grips and borders are on layer 1 |
| 5573 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 5574 | |
| 5575 | // Manual resize grips |
| 5576 | PushID("#RESIZE"); |
| 5577 | for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) |
| 5578 | { |
| 5579 | const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n]; |
| 5580 | const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN); |
| 5581 | |
| 5582 | // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window |
| 5583 | bool hovered, held; |
| 5584 | ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size); |
| 5585 | if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); |
| 5586 | if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); |
| 5587 | ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() |
| 5588 | ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); |
| 5589 | //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); |
| 5590 | if (hovered || held) |
| 5591 | g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; |
| 5592 | |
| 5593 | if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0) |
| 5594 | { |
| 5595 | // Manual auto-fit when double-clicking |
| 5596 | size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 5597 | ret_auto_fit = true; |
| 5598 | ClearActiveID(); |
| 5599 | } |
| 5600 | else if (held) |
| 5601 | { |
| 5602 | // Resize from any of the four corners |
| 5603 | // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position |
| 5604 | 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); |
| 5605 | 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); |
| 5606 | 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 |
| 5607 | corner_target = ImClamp(corner_target, clamp_min, clamp_max); |
| 5608 | CalcResizePosSizeFromAnyCorner(window, corner_target, def.CornerPosN, &pos_target, &size_target); |
| 5609 | } |
| 5610 |
nothing calls this directly
no test coverage detected