MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / UpdateWindowManualResize

Method UpdateWindowManualResize

KBotExt/imgui/imgui.cpp:5791–5934  ·  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

5789// Handle resize for: Resize Grips, Borders, Gamepad
5790// Return true when using auto-fit (double-click on resize grip)
5791static 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)
5792{
5793 ImGuiContext& g = *GImGui;
5794 ImGuiWindowFlags flags = window->Flags;
5795
5796 if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0)
5797 return false;
5798 if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window.
5799 return false;
5800
5801 bool ret_auto_fit = false;
5802 const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0;
5803 const float grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
5804 const float grip_hover_inner_size = IM_FLOOR(grip_draw_size * 0.75f);
5805 const float grip_hover_outer_size = g.IO.ConfigWindowsResizeFromEdges ? WINDOWS_HOVER_PADDING : 0.0f;
5806
5807 ImRect clamp_rect = visibility_rect;
5808 const bool window_move_from_title_bar = g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar);
5809 if (window_move_from_title_bar)
5810 clamp_rect.Min.y -= window->TitleBarHeight();
5811
5812 ImVec2 pos_target(FLT_MAX, FLT_MAX);
5813 ImVec2 size_target(FLT_MAX, FLT_MAX);
5814
5815 // Resize grips and borders are on layer 1
5816 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
5817
5818 // Manual resize grips
5819 PushID("#RESIZE");
5820 for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
5821 {
5822 const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n];
5823 const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN);
5824
5825 // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window
5826 bool hovered, held;
5827 ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size);
5828 if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
5829 if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
5830 ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID()
5831 ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav);
5832 ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
5833 //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
5834 if (hovered || held)
5835 g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
5836
5837 if (held && g.IO.MouseClickedCount[0] == 2 && resize_grip_n == 0)
5838 {
5839 // Manual auto-fit when double-clicking
5840 size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
5841 ret_auto_fit = true;
5842 ClearActiveID();
5843 }
5844 else if (held)
5845 {
5846 // Resize from any of the four corners
5847 // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
5848 ImVec2 clamp_min = ImVec2(def.CornerPosN.x == 1.0f ? clamp_rect.Min.x : -FLT_MAX, (def.CornerPosN.y == 1.0f || (def.CornerPosN.y == 0.0f && window_move_from_title_bar)) ? clamp_rect.Min.y : -FLT_MAX);

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