mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01: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:
		| @@ -66,6 +66,8 @@ Other Changes: | |||||||
|   introduced in 1.50 and broken in 1.60. (#1698, #894, #713). |   introduced in 1.50 and broken in 1.60. (#1698, #894, #713). | ||||||
| - TextUnformatted(): Fixed a case where large-text path would read bytes past the text_end marker depending | - TextUnformatted(): Fixed a case where large-text path would read bytes past the text_end marker depending | ||||||
|   on the position of new lines in the buffer (it wasn't affecting the output but still not the right thing to do!)  |   on the position of new lines in the buffer (it wasn't affecting the output but still not the right thing to do!)  | ||||||
|  | - ListBox(): Fixed frame sizing when items_count==1 unnecessarily showing a scrollbar. (#2173) [@luk1337, @ocornut]   | ||||||
|  | - ListBox(): Tweaked frame sizing so list boxes will look more consistent when FramePadding is far from ItemSpacing.  | ||||||
| - RenderText(): Some optimization for very large text buffers, useful for non-optimized builds. | - RenderText(): Some optimization for very large text buffers, useful for non-optimized builds. | ||||||
| - BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f. | - BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f. | ||||||
| - ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different. | - ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different. | ||||||
|   | |||||||
| @@ -4973,7 +4973,7 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags | |||||||
| // - Selectable() | // - 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. | // 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) | 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() | // - 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. | // 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) | bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) | ||||||
| { | { | ||||||
|     ImGuiWindow* window = GetCurrentWindow(); |     ImGuiWindow* window = GetCurrentWindow(); | ||||||
| @@ -5112,24 +5112,26 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) | |||||||
|     return true; |     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) | 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. |     // Size default to hold ~7.25 items. | ||||||
|     // 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. |     // 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. |     // 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) |     if (height_in_items < 0) | ||||||
|         height_in_items = ImMin(items_count, 7); |         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(). |     // 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; |     ImVec2 size; | ||||||
|     size.x = 0.0f; |     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); |     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() | void ImGui::ListBoxFooter() | ||||||
| { | { | ||||||
|     ImGuiWindow* parent_window = GetCurrentWindow()->ParentWindow; |     ImGuiWindow* parent_window = GetCurrentWindow()->ParentWindow; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user