mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-10-26 12:27:30 +00:00 
			
		
		
		
	ListBox(): Fixed frame sizing when items_count==1 unnecessarily showing a scrollbar. (#2173). Tweaked frame sizing so list boxes will look more consistent when FramePadding is far from ItemSpacing.
This commit is contained in:
		@@ -4973,7 +4973,7 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags
 | 
			
		||||
// - Selectable()
 | 
			
		||||
//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
// Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image.
 | 
			
		||||
// Tip: pass a non-visible label (e.g. "##dummy") then you can use the space to draw other text or image.
 | 
			
		||||
// But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID or use ##unique_id.
 | 
			
		||||
bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg)
 | 
			
		||||
{
 | 
			
		||||
@@ -5084,9 +5084,9 @@ bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags
 | 
			
		||||
// - ListBoxFooter()
 | 
			
		||||
//-------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
// FIXME: Rename to BeginListBox()
 | 
			
		||||
// FIXME: In principle this function should be called BeginListBox(). We should rename it after re-evaluating if we want to keep the same signature.
 | 
			
		||||
// Helper to calculate the size of a listbox and display a label on the right.
 | 
			
		||||
// Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty"
 | 
			
		||||
// Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an non-visible label e.g. "##empty"
 | 
			
		||||
bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiWindow* window = GetCurrentWindow();
 | 
			
		||||
@@ -5112,24 +5112,26 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FIXME: Rename to BeginListBox()
 | 
			
		||||
// FIXME: In principle this function should be called EndListBox(). We should rename it after re-evaluating if we want to keep the same signature.
 | 
			
		||||
bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_items)
 | 
			
		||||
{
 | 
			
		||||
    // Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
 | 
			
		||||
    // We don't add +0.40f if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
 | 
			
		||||
    // Size default to hold ~7.25 items.
 | 
			
		||||
    // We add +25% worth of item height to allow the user to see at a glance if there are more items up/down, without looking at the scrollbar.
 | 
			
		||||
    // We don't add this extra bit if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
 | 
			
		||||
    // I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution.
 | 
			
		||||
    if (height_in_items < 0)
 | 
			
		||||
        height_in_items = ImMin(items_count, 7);
 | 
			
		||||
    float height_in_items_f = height_in_items < items_count ? (height_in_items + 0.40f) : (height_in_items + 0.00f);
 | 
			
		||||
    const ImGuiStyle& style = GetStyle();
 | 
			
		||||
    float height_in_items_f = (height_in_items < items_count) ? (height_in_items + 0.25f) : (height_in_items + 0.00f);
 | 
			
		||||
 | 
			
		||||
    // We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild().
 | 
			
		||||
    ImVec2 size;
 | 
			
		||||
    size.x = 0.0f;
 | 
			
		||||
    size.y = GetTextLineHeightWithSpacing() * height_in_items_f + GetStyle().ItemSpacing.y;
 | 
			
		||||
    size.y = GetTextLineHeightWithSpacing() * height_in_items_f + style.FramePadding.y * 2.0f;
 | 
			
		||||
    return ListBoxHeader(label, size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FIXME: Rename to EndListBox()
 | 
			
		||||
// FIXME: In principle this function should be called EndListBox(). We should rename it after re-evaluating if we want to keep the same signature.
 | 
			
		||||
void ImGui::ListBoxFooter()
 | 
			
		||||
{
 | 
			
		||||
    ImGuiWindow* parent_window = GetCurrentWindow()->ParentWindow;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user