From 0bd6489721328ba28b2bb19088f988ca54a881da Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Dec 2023 20:50:17 +0100 Subject: [PATCH] DragScalarN, SliderScalarN, InputScalarN, PushMultiItemsWidths: fixed multi-components width in tight space (#7120, #7121) + extra tweak color ColorEdit4() label. Amend 86512ea, 3464662 --- imgui.cpp | 4 ++-- imgui_widgets.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index af1f2381..d89e7e26 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9872,10 +9872,10 @@ void ImGui::PushMultiItemsWidths(int components, float w_full) for (int i = components - 1; i > 0; i--) { float next_split = IM_TRUNC(w_items * i / components); - window->DC.ItemWidthStack.push_back(prev_split - next_split); + window->DC.ItemWidthStack.push_back(ImMax(prev_split - next_split, 1.0f)); prev_split = next_split; } - window->DC.ItemWidth = prev_split; + window->DC.ItemWidth = ImMax(prev_split, 1.0f); g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth; } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 8d486d48..abf1f0c1 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5128,8 +5128,6 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag const ImGuiStyle& style = g.Style; const float square_sz = GetFrameHeight(); const float w_full = CalcItemWidth(); - const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x); - const float w_inputs = w_full - w_button; const char* label_display_end = FindRenderedTextEnd(label); g.NextItemData.ClearFlags(); @@ -5164,6 +5162,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag const bool alpha = (flags & ImGuiColorEditFlags_NoAlpha) == 0; const bool hdr = (flags & ImGuiColorEditFlags_HDR) != 0; const int components = alpha ? 4 : 3; + const float w_button = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x); + const float w_inputs = ImMax(w_full - w_button, 1.0f * components); // Convert to the formats we need float f[4] = { col[0], col[1], col[2], alpha ? col[3] : 1.0f }; @@ -5211,7 +5211,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (n > 0) SameLine(0, style.ItemInnerSpacing.x); float next_split = IM_TRUNC(w_items * (n + 1) / components); - SetNextItemWidth(next_split - prev_split); + SetNextItemWidth(ImMax(next_split - prev_split, 1.0f)); prev_split = next_split; // FIXME: When ImGuiColorEditFlags_HDR flag is passed HS values snap in weird ways when SV values go below 0.