MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / UpdateManualResize

Method UpdateManualResize

lib/imgui/imgui.cpp:4973–5093  ·  view source on GitHub ↗

Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double click on resize grip)

Source from the content-addressed store, hash-verified

4971// Handle resize for: Resize Grips, Borders, Gamepad
4972// Return true when using auto-fit (double click on resize grip)
4973static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
4974{
4975 ImGuiContext& g = *GImGui;
4976 ImGuiWindowFlags flags = window->Flags;
4977
4978 if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0)
4979 return false;
4980 if (window->WasActive == false) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window.
4981 return false;
4982
4983 bool ret_auto_fit = false;
4984 const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0;
4985 const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
4986 const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f);
4987 const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS : 0.0f;
4988
4989 ImVec2 pos_target(FLT_MAX, FLT_MAX);
4990 ImVec2 size_target(FLT_MAX, FLT_MAX);
4991
4992 // Resize grips and borders are on layer 1
4993 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
4994 window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
4995
4996 // Manual resize grips
4997 PushID("#RESIZE");
4998 for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
4999 {
5000 const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
5001 const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
5002
5003 // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window
5004 ImRect resize_rect(corner - grip.InnerDir * grip_hover_outer_size, corner + grip.InnerDir * grip_hover_inner_size);
5005 if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
5006 if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
5007 bool hovered, held;
5008 ButtonBehavior(resize_rect, window->GetID(resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
5009 //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
5010 if (hovered || held)
5011 g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
5012
5013 if (held && g.IO.MouseDoubleClicked[0] && resize_grip_n == 0)
5014 {
5015 // Manual auto-fit when double-clicking
5016 size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5017 ret_auto_fit = true;
5018 ClearActiveID();
5019 }
5020 else if (held)
5021 {
5022 // Resize from any of the four corners
5023 // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
5024 ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + ImLerp(grip.InnerDir * grip_hover_outer_size, grip.InnerDir * -grip_hover_inner_size, grip.CornerPosN); // Corner of the window corresponding to our corner grip
5025 CalcResizePosSizeFromAnyCorner(window, corner_target, grip.CornerPosN, &pos_target, &size_target);
5026 }
5027 if (resize_grip_n == 0 || held || hovered)
5028 resize_grip_col[resize_grip_n] = GetColorU32(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
5029 }
5030 for (int border_n = 0; border_n < resize_border_count; border_n++)

Callers

nothing calls this directly

Calls 10

ImMaxFunction · 0.85
ImLerpFunction · 0.85
ImSwapFunction · 0.85
GetResizeBorderRectFunction · 0.85
ImVec2Class · 0.85
ImFloorFunction · 0.85
ImMinFunction · 0.85
GetIDMethod · 0.45

Tested by

no test coverage detected