Handle resize for: Resize Grips, Borders, Gamepad Return true when using auto-fit (double-click on resize grip)
| 6728 | // Handle resize for: Resize Grips, Borders, Gamepad |
| 6729 | // Return true when using auto-fit (double-click on resize grip) |
| 6730 | static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_hovered, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect) |
| 6731 | { |
| 6732 | ImGuiContext& g = *GImGui; |
| 6733 | ImGuiWindowFlags flags = window->Flags; |
| 6734 | |
| 6735 | if ((flags & ImGuiWindowFlags_NoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0) |
| 6736 | return false; |
| 6737 | if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && (window->ChildFlags & (ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY)) == 0) |
| 6738 | return false; |
| 6739 | if (window->WasActive == false) // Early out to avoid running this code for e.g. a hidden implicit/fallback Debug window. |
| 6740 | return false; |
| 6741 | |
| 6742 | int ret_auto_fit_mask = 0x00; |
| 6743 | const float grip_draw_size = IM_TRUNC(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); |
| 6744 | const float grip_hover_inner_size = (resize_grip_count > 0) ? IM_TRUNC(grip_draw_size * 0.75f) : 0.0f; |
| 6745 | const float grip_hover_outer_size = g.WindowsBorderHoverPadding; |
| 6746 | |
| 6747 | ImRect clamp_rect = visibility_rect; |
| 6748 | const bool window_move_from_title_bar = g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar); |
| 6749 | if (window_move_from_title_bar) |
| 6750 | clamp_rect.Min.y -= window->TitleBarHeight; |
| 6751 | |
| 6752 | ImVec2 pos_target(FLT_MAX, FLT_MAX); |
| 6753 | ImVec2 size_target(FLT_MAX, FLT_MAX); |
| 6754 | |
| 6755 | // Resize grips and borders are on layer 1 |
| 6756 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 6757 | |
| 6758 | // Manual resize grips |
| 6759 | PushID("#RESIZE"); |
| 6760 | for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) |
| 6761 | { |
| 6762 | const ImGuiResizeGripDef& def = resize_grip_def[resize_grip_n]; |
| 6763 | const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, def.CornerPosN); |
| 6764 | |
| 6765 | // Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window |
| 6766 | bool hovered, held; |
| 6767 | ImRect resize_rect(corner - def.InnerDir * grip_hover_outer_size, corner + def.InnerDir * grip_hover_inner_size); |
| 6768 | if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); |
| 6769 | if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); |
| 6770 | ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() |
| 6771 | ItemAdd(resize_rect, resize_grip_id, NULL, ImGuiItemFlags_NoNav); |
| 6772 | ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); |
| 6773 | //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); |
| 6774 | if (hovered || held) |
| 6775 | SetMouseCursor((resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE); |
| 6776 | |
| 6777 | if (held && g.IO.MouseDoubleClicked[0]) |
| 6778 | { |
| 6779 | // Auto-fit when double-clicking |
| 6780 | size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit); |
| 6781 | ret_auto_fit_mask = 0x03; // Both axes |
| 6782 | ClearActiveID(); |
| 6783 | } |
| 6784 | else if (held) |
| 6785 | { |
| 6786 | // Resize from any of the four corners |
| 6787 | // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position |
nothing calls this directly
no test coverage detected