mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 09:44:29 +00:00 
			
		
		
		
	Window: Shrink close button hit-testing region when it covers an abnormally high portion of the window visible area (e.g. when window is collapsed and moved in a corner)to facilitate moving the window away. (#3825)
This commit is contained in:
		@@ -45,6 +45,8 @@ Other Changes:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- DragScalar: Fixed crash when using DragScalar() directly (not via common wrapper like DragFloat() etc.)
 | 
					- DragScalar: Fixed crash when using DragScalar() directly (not via common wrapper like DragFloat() etc.)
 | 
				
			||||||
  with ImGuiSliderFlags_AlwaysClamp + only one of either p_min or p_max set. (#3824) [@harry75369]
 | 
					  with ImGuiSliderFlags_AlwaysClamp + only one of either p_min or p_max set. (#3824) [@harry75369]
 | 
				
			||||||
 | 
					- Window: Shrink close button hit-testing region when it covers an abnormally high portion of the window visible
 | 
				
			||||||
 | 
					  area (e.g. when window is collapsed + moved in a corner) to facilitate moving the window away. (#3825)
 | 
				
			||||||
- ImDrawList: AddCircle, AddCircleFilled(): Tweaked default segment count calculation to honor MaxError
 | 
					- ImDrawList: AddCircle, AddCircleFilled(): Tweaked default segment count calculation to honor MaxError
 | 
				
			||||||
  with more accuracy. Made default segment count always even for better looking result. (#3808) [@thedmd]
 | 
					  with more accuracy. Made default segment count always even for better looking result. (#3808) [@thedmd]
 | 
				
			||||||
- ImDrawList: AddCircle, AddCircleFilled(): New default for style.
 | 
					- ImDrawList: AddCircle, AddCircleFilled(): New default for style.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -448,6 +448,7 @@ struct IMGUI_API ImRect
 | 
				
			|||||||
    ImVec2      GetSize() const                     { return ImVec2(Max.x - Min.x, Max.y - Min.y); }
 | 
					    ImVec2      GetSize() const                     { return ImVec2(Max.x - Min.x, Max.y - Min.y); }
 | 
				
			||||||
    float       GetWidth() const                    { return Max.x - Min.x; }
 | 
					    float       GetWidth() const                    { return Max.x - Min.x; }
 | 
				
			||||||
    float       GetHeight() const                   { return Max.y - Min.y; }
 | 
					    float       GetHeight() const                   { return Max.y - Min.y; }
 | 
				
			||||||
 | 
					    float       GetArea() const                     { return (Max.x - Min.x) * (Max.y - Min.y); }
 | 
				
			||||||
    ImVec2      GetTL() const                       { return Min; }                   // Top-left
 | 
					    ImVec2      GetTL() const                       { return Min; }                   // Top-left
 | 
				
			||||||
    ImVec2      GetTR() const                       { return ImVec2(Max.x, Min.y); }  // Top-right
 | 
					    ImVec2      GetTR() const                       { return ImVec2(Max.x, Min.y); }  // Top-right
 | 
				
			||||||
    ImVec2      GetBL() const                       { return ImVec2(Min.x, Max.y); }  // Bottom-left
 | 
					    ImVec2      GetBL() const                       { return ImVec2(Min.x, Max.y); }  // Bottom-left
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -782,22 +782,30 @@ bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Button to close a window
 | 
					// Button to close a window
 | 
				
			||||||
bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)//, float size)
 | 
					bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    ImGuiWindow* window = g.CurrentWindow;
 | 
					    ImGuiWindow* window = g.CurrentWindow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // We intentionally allow interaction when clipped so that a mechanical Alt,Right,Validate sequence close a window.
 | 
					    // Tweak 1: Shrink hit-testing area if button covers an abnormally large proportion of the visible region. That's in order to facilitate moving the window away. (#3825)
 | 
				
			||||||
    // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible).
 | 
					    // This may better be applied as a general hit-rect reduction mechanism for all widgets to ensure the area to move window is always accessible?
 | 
				
			||||||
    const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
 | 
					    const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
 | 
				
			||||||
    bool is_clipped = !ItemAdd(bb, id);
 | 
					    ImRect bb_interact = bb;
 | 
				
			||||||
 | 
					    const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
 | 
				
			||||||
 | 
					    if (area_to_visible_ratio < 1.5f)
 | 
				
			||||||
 | 
					        bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
 | 
				
			||||||
 | 
					    // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible).
 | 
				
			||||||
 | 
					    bool is_clipped = !ItemAdd(bb_interact, id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool hovered, held;
 | 
					    bool hovered, held;
 | 
				
			||||||
    bool pressed = ButtonBehavior(bb, id, &hovered, &held);
 | 
					    bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
 | 
				
			||||||
    if (is_clipped)
 | 
					    if (is_clipped)
 | 
				
			||||||
        return pressed;
 | 
					        return pressed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Render
 | 
					    // Render
 | 
				
			||||||
 | 
					    // FIXME: Clarify this mess
 | 
				
			||||||
    ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
 | 
					    ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
 | 
				
			||||||
    ImVec2 center = bb.GetCenter();
 | 
					    ImVec2 center = bb.GetCenter();
 | 
				
			||||||
    if (hovered)
 | 
					    if (hovered)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user