MCPcopy Create free account
hub / github.com/RenderKit/embree / UpdateWindowManualResize

Method UpdateWindowManualResize

tutorials/common/imgui/imgui.cpp:5905–6043  ·  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

5903// Handle resize for: Resize Grips, Borders, Gamepad
5904// Return true when using auto-fit (double-click on resize grip)
5905static 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)
5906{
5907 ImGuiContext& g = *GImGui;
5908 ImGuiWindowFlags flags = window->Flags;
5909
5910 if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0)
5911 return false;
5912 if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window.
5913 return false;
5914
5915 bool ret_auto_fit = false;
5916 const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0;
5917 const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
5918 const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f);
5919 const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f;
5920
5921 ImVec2 pos_target(FLT_MAX, FLT_MAX);
5922 ImVec2 size_target(FLT_MAX, FLT_MAX);
5923
5924 // Resize grips and borders are on layer 1
5925 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
5926
5927 // Manual resize grips
5928 PushID("#RESIZE");
5929 for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
5930 {
5931 const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n];
5932 const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN);
5933
5934 // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window
5935 bool hovered, held;
5936 ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size);
5937 if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
5938 if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
5939 ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID()
5940 ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav);
5941 ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
5942 //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
5943 if (hovered || held)
5944 g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
5945
5946 if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0)
5947 {
5948 // Manual auto-fit when double-clicking
5949 size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5950 ret_auto_fit = true;
5951 ClearActiveID();
5952 }
5953 else if (held)
5954 {
5955 // Resize from any of the four corners
5956 // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
5957 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);
5958 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);
5959 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
5960 corner_target = ImClamp(corner_target, clamp_min, clamp_max);
5961 CalcResizePosSizeFromAnyCorner(window, corner_target, def.CornerPosN, &pos_target, &size_target);
5962 }

Callers

nothing calls this directly

Calls 11

ImMaxFunction · 0.85
ImLerpFunction · 0.85
ImSwapFunction · 0.85
ImVec2Function · 0.85
ImClampFunction · 0.85
GetResizeBorderRectFunction · 0.85
ImMinFunction · 0.85
ImFloorFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected