ListBoxHeader: In version taking height in number of items, made vertical padding consistent regardless of if (items_count <= height_in_items) or not.

Demo: Tweaks.
This commit is contained in:
ocornut 2021-02-03 14:55:17 +01:00
parent e5cbf60def
commit 6f6d4e0b70
3 changed files with 12 additions and 15 deletions

View File

@ -56,6 +56,8 @@ Other Changes:
- InputText: Multiline: Fixed padding/cliprect not precisely matching single-line version. (#3781)
- InputText: Multiline: Fixed FramePadding.y worth of vertical offset when aiming with mouse.
- ListBox: Tweaked default height calculation.
- ListBoxHeader: In version taking height in number of items, made vertical padding consistent regardless
of if (items_count <= height_in_items) or not.
- Fonts: imgui_freetype: Facilitated using FreeType integration: [@Xipiryon, @ocornut]
- Use '#define IMGUI_ENABLE_FREETYPE' in imconfig.h should make it work with no other modifications
other than compiling misc/freetype/imgui_freetype.cpp and linking with FreeType.

View File

@ -7475,19 +7475,20 @@ void ShowExampleAppDocuments(bool* p_open)
{
if (!ImGui::IsPopupOpen("Save?"))
ImGui::OpenPopup("Save?");
if (ImGui::BeginPopupModal("Save?"))
if (ImGui::BeginPopupModal("Save?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Save change to the following items?");
ImGui::SetNextItemWidth(-FLT_MIN);
if (ImGui::ListBoxHeader("##", close_queue_unsaved_documents, 6))
float item_height = ImGui::GetTextLineHeightWithSpacing();
if (ImGui::BeginChildFrame(ImGui::GetID("frame"), ImVec2(-FLT_MIN, 6.25f * item_height)))
{
for (int n = 0; n < close_queue.Size; n++)
if (close_queue[n]->Dirty)
ImGui::Text("%s", close_queue[n]->Name);
ImGui::ListBoxFooter();
ImGui::EndChildFrame();
}
if (ImGui::Button("Yes", ImVec2(80, 0)))
ImVec2 button_size(ImGui::GetFontSize() * 7.0f, 0.0f);
if (ImGui::Button("Yes", button_size))
{
for (int n = 0; n < close_queue.Size; n++)
{
@ -7499,7 +7500,7 @@ void ShowExampleAppDocuments(bool* p_open)
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("No", ImVec2(80, 0)))
if (ImGui::Button("No", button_size))
{
for (int n = 0; n < close_queue.Size; n++)
close_queue[n]->DoForceClose();
@ -7507,7 +7508,7 @@ void ShowExampleAppDocuments(bool* p_open)
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(80, 0)))
if (ImGui::Button("Cancel", button_size))
{
close_queue.clear();
ImGui::CloseCurrentPopup();

View File

@ -6177,15 +6177,9 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
// FIXME: In principle this function should be called BeginListBox(). 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.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 == -1, default height is maximum 7.
ImGuiContext& g = *GImGui;
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.25f) : (height_in_items + 0.00f);
float height_in_items_f = (height_in_items < 0 ? ImMin(items_count, 7) : height_in_items) + 0.25f;
ImVec2 size;
size.x = 0.0f;
size.y = GetTextLineHeightWithSpacing() * height_in_items_f + g.Style.FramePadding.y * 2.0f;