Added SetNextItemWidth() helper to avoid using PushItemWidth/PopItemWidth() for single items.
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 511e381..39f0da9 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -46,6 +46,10 @@
- InputText: Work-around for buggy standard libraries where isprint('\t') returns true. (#2467, #1336)
- InputText: Fixed ImGuiInputTextFlags_AllowTabInput leading to two tabs characters being inserted
if the back-end provided both Key and Character input. (#2467, #1336)
+- Added SetNextItemWidth() helper to avoid using PushItemWidth/PopItemWidth() for single items.
+ Note that SetNextItemWidth() currently only affect the same subset of items as PushItemWidth(),
+ generally referred to as the large framed+labeled items.
+ Because the new SetNextItemWidth() function is explicit
- GetMouseDragDelta(): also returns the delta on the mouse button released frame. (#2419)
- GetMouseDragDelta(): verify that mouse positions are valid otherwise returns zero.
- Inputs: Also add support for horizontal scroll with Shift+Mouse Wheel. (#2424, #1463) [@LucaRood]
diff --git a/imgui.cpp b/imgui.cpp
index 2b4b7a8..8f56ab6 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -2068,10 +2068,8 @@
bool ImGuiTextFilter::Draw(const char* label, float width)
{
if (width != 0.0f)
- ImGui::PushItemWidth(width);
+ ImGui::SetNextItemWidth(width);
bool value_changed = ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
- if (width != 0.0f)
- ImGui::PopItemWidth();
if (value_changed)
Build();
return value_changed;
@@ -5744,6 +5742,12 @@
}
}
+void ImGui::SetNextItemWidth(float item_width)
+{
+ ImGuiWindow* window = GetCurrentWindow();
+ window->DC.NextItemWidth = item_width;
+}
+
void ImGui::PushItemWidth(float item_width)
{
ImGuiWindow* window = GetCurrentWindow();
@@ -5755,8 +5759,6 @@
{
ImGuiWindow* window = GetCurrentWindow();
const ImGuiStyle& style = GImGui->Style;
- if (w_full <= 0.0f)
- w_full = CalcItemWidth();
const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components));
const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1)));
window->DC.ItemWidthStack.push_back(w_item_last);
@@ -5772,11 +5774,21 @@
window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
}
-// Calculate default item width given value passed to PushItemWidth()
-float ImGui::CalcItemWidth()
+// Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth(),
+// Then consume the
+float ImGui::GetNextItemWidth()
{
ImGuiWindow* window = GImGui->CurrentWindow;
- float w = window->DC.ItemWidth;
+ float w;
+ if (window->DC.NextItemWidth != FLT_MAX)
+ {
+ w = window->DC.NextItemWidth;
+ window->DC.NextItemWidth = FLT_MAX;
+ }
+ else
+ {
+ w = window->DC.ItemWidth;
+ }
if (w < 0.0f)
{
float region_max_x = GetContentRegionMaxScreen().x;
@@ -5786,10 +5798,21 @@
return w;
}
-// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth().
+// Calculate item width *without* popping/consuming NextItemWidth if it was set.
+// (rarely used, which is why we avoid calling this from GetNextItemWidth() and instead do a backup/restore here)
+float ImGui::CalcItemWidth()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ float backup_next_item_width = window->DC.NextItemWidth;
+ float w = GetNextItemWidth();
+ window->DC.NextItemWidth = backup_next_item_width;
+ return w;
+}
+
+// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == GetNextItemWidth().
// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical.
// Note that only CalcItemWidth() is publicly exposed.
-// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable)
+// The 4.0f here may be changed to match GetNextItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable)
ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
{
ImGuiWindow* window = GImGui->CurrentWindow;
@@ -9147,11 +9170,10 @@
const bool log_to_tty = Button("Log To TTY"); SameLine();
const bool log_to_file = Button("Log To File"); SameLine();
const bool log_to_clipboard = Button("Log To Clipboard"); SameLine();
- PushItemWidth(80.0f);
PushAllowKeyboardFocus(false);
+ SetNextItemWidth(80.0f);
SliderInt("Default Depth", &g.LogDepthToExpandDefault, 0, 9, NULL);
PopAllowKeyboardFocus();
- PopItemWidth();
PopID();
// Start logging at the end of the function so that the buttons don't appear in the log
@@ -9739,9 +9761,8 @@
ImGui::Checkbox("Show windows begin order", &show_windows_begin_order);
ImGui::Checkbox("Show windows rectangles", &show_windows_rects);
ImGui::SameLine();
- ImGui::PushItemWidth(ImGui::GetFontSize() * 12);
+ ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
show_windows_rects |= ImGui::Combo("##rects_type", &show_windows_rect_type, "OuterRect\0" "OuterRectClipped\0" "InnerMainRect\0" "InnerClipRect\0" "ContentsRegionRect\0");
- ImGui::PopItemWidth();
ImGui::Checkbox("Show clipping rectangle when hovering ImDrawCmd node", &show_drawcmd_clip_rects);
ImGui::TreePop();
}
diff --git a/imgui.h b/imgui.h
index f597e07..53e1725 100644
--- a/imgui.h
+++ b/imgui.h
@@ -321,8 +321,9 @@
IMGUI_API ImU32 GetColorU32(ImU32 col); // retrieve given color with style alpha applied
// Parameters stacks (current window)
- IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side)
+ IMGUI_API void PushItemWidth(float item_width); // set width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width,
IMGUI_API void PopItemWidth();
+ IMGUI_API void SetNextItemWidth(float item_width); // set width of the _next_ common large "item+label" widget. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side)
IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position
IMGUI_API void PushTextWrapPos(float wrap_local_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space
IMGUI_API void PopTextWrapPos();
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 6dd69bd..2233eab 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -550,9 +550,8 @@
ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
//static int listbox_item_current2 = 2;
- //ImGui::PushItemWidth(-1);
+ //ImGui::SetNextItemWidth(-1);
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
- //ImGui::PopItemWidth();
}
ImGui::TreePop();
@@ -1052,7 +1051,8 @@
};
static int func_type = 0, display_count = 70;
ImGui::Separator();
- ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth();
+ ImGui::SetNextItemWidth(100);
+ ImGui::Combo("func", &func_type, "Sin\0Saw\0");
ImGui::SameLine();
ImGui::SliderInt("Sample count", &display_count, 1, 400);
float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw;
@@ -1667,9 +1667,8 @@
static int line = 50;
bool goto_line = ImGui::Button("Goto");
ImGui::SameLine();
- ImGui::PushItemWidth(100);
+ ImGui::SetNextItemWidth(100);
goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
- ImGui::PopItemWidth();
// Child 1: no border, enable horizontal scrollbar
{
@@ -1740,35 +1739,36 @@
if (ImGui::TreeNode("Widgets Width"))
{
+ // Use SetNextItemWidth() to set the width of a single upcoming item.
+ // Use PushItemWidth()/PopItemWidth() to set the width of a group of items.
static float f = 0.0f;
- ImGui::Text("PushItemWidth(100)");
+ ImGui::Text("SetNextItemWidth/PushItemWidth(100)");
ImGui::SameLine(); HelpMarker("Fixed width.");
- ImGui::PushItemWidth(100);
+ ImGui::SetNextItemWidth(100);
ImGui::DragFloat("float##1", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(GetWindowWidth() * 0.5f)");
+ ImGui::Text("SetNextItemWidth/PushItemWidth(GetWindowWidth() * 0.5f)");
ImGui::SameLine(); HelpMarker("Half of window width.");
- ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
+ ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.5f);
ImGui::DragFloat("float##2", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
+ ImGui::Text("SetNextItemWidth/PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
ImGui::SameLine(); HelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
- ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
+ ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
ImGui::DragFloat("float##3", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(-100)");
+ ImGui::Text("SetNextItemWidth/PushItemWidth(-100)");
ImGui::SameLine(); HelpMarker("Align to right edge minus 100");
- ImGui::PushItemWidth(-100);
+ ImGui::SetNextItemWidth(-100);
ImGui::DragFloat("float##4", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(-1)");
+ // Demonstrate using PushItemWidth to surround three items. Calling SetNextItemWidth() before each of them would have the same effect.
+ ImGui::Text("SetNextItemWidth/PushItemWidth(-1)");
ImGui::SameLine(); HelpMarker("Align to right edge");
ImGui::PushItemWidth(-1);
- ImGui::DragFloat("float##5", &f);
+ ImGui::DragFloat("float##5a", &f);
+ ImGui::DragFloat("float##5b", &f);
+ ImGui::DragFloat("float##5c", &f);
ImGui::PopItemWidth();
ImGui::TreePop();
@@ -2241,9 +2241,8 @@
{
if (ImGui::Selectable("Set to zero")) value = 0.0f;
if (ImGui::Selectable("Set to PI")) value = 3.1415f;
- ImGui::PushItemWidth(-1);
+ ImGui::SetNextItemWidth(-1);
ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f);
- ImGui::PopItemWidth();
ImGui::EndPopup();
}
@@ -2968,7 +2967,7 @@
}
ImGui::LogFinish();
}
- ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth();
+ ImGui::SameLine(); ImGui::SetNextItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0");
ImGui::SameLine(); ImGui::Checkbox("Only Modified Colors", &output_only_modified);
static ImGuiTextFilter filter;
@@ -3807,12 +3806,11 @@
ImGui::AlignTextToFramePadding();
ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet, "Field_%d", i);
ImGui::NextColumn();
- ImGui::PushItemWidth(-1);
+ ImGui::SetNextItemWidth(-1);
if (i >= 5)
ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
else
ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
- ImGui::PopItemWidth();
ImGui::NextColumn();
}
ImGui::PopID();
@@ -3952,10 +3950,10 @@
if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine();
if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine();
if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); }
- ImGui::PushItemWidth(200);
+ ImGui::SetNextItemWidth(200);
ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc));
+ ImGui::SetNextItemWidth(200);
ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100);
- ImGui::PopItemWidth();
ImGui::Checkbox("Auto-resize", &auto_resize);
for (int i = 0; i < display_lines; i++)
ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, "");
@@ -4401,7 +4399,7 @@
if (ImGui::BeginPopupModal("Save?"))
{
ImGui::Text("Save change to the following items?");
- ImGui::PushItemWidth(-1.0f);
+ ImGui::SetNextItemWidth(-1.0f);
if (ImGui::ListBoxHeader("##", close_queue_unsaved_documents, 6))
{
for (int n = 0; n < close_queue.Size; n++)
diff --git a/imgui_internal.h b/imgui_internal.h
index b399bec..9107cfe 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1146,6 +1146,7 @@
// We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
ImGuiItemFlags ItemFlags; // == ItemFlagsStack.back() [empty == ImGuiItemFlags_Default]
float ItemWidth; // == ItemWidthStack.back(). 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
+ float NextItemWidth;
float TextWrapPos; // == TextWrapPosStack.back() [empty == -1.0f]
ImVector<ImGuiItemFlags>ItemFlagsStack;
ImVector<float> ItemWidthStack;
@@ -1181,6 +1182,7 @@
ItemFlags = ImGuiItemFlags_Default_;
ItemWidth = 0.0f;
+ NextItemWidth = +FLT_MAX;
TextWrapPos = -1.0f;
memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
@@ -1438,9 +1440,10 @@
IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id); // Return true if focus is requested
IMGUI_API void FocusableItemUnregister(ImGuiWindow* window);
+ IMGUI_API float GetNextItemWidth();
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h);
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
- IMGUI_API void PushMultiItemsWidths(int components, float width_full = 0.0f);
+ IMGUI_API void PushMultiItemsWidths(int components, float width_full);
IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled);
IMGUI_API void PopItemFlag();
IMGUI_API bool IsItemToggledSelection(); // was the last item selection toggled? (after Selectable(), TreeNode() etc. We only returns toggle _event_ in order to handle clipping correctly)
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 6812808..d1ecf3b 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -325,7 +325,7 @@
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
- const float w = CalcItemWidth();
+ const float w = GetNextItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2));
@@ -1089,7 +1089,7 @@
const ImGuiStyle& style = g.Style;
ImVec2 pos = window->DC.CursorPos;
- ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y*2.0f);
+ ImVec2 size = CalcItemSize(size_arg, GetNextItemWidth(), g.FontSize + style.FramePadding.y*2.0f);
ImRect bb(pos, pos + size);
ItemSize(size, style.FramePadding.y);
if (!ItemAdd(bb, 0))
@@ -1353,7 +1353,8 @@
const float arrow_size = (flags & ImGuiComboFlags_NoArrowButton) ? 0.0f : GetFrameHeight();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
- const float w = (flags & ImGuiComboFlags_NoPreview) ? arrow_size : CalcItemWidth();
+ const float expected_w = GetNextItemWidth();
+ const float w = (flags & ImGuiComboFlags_NoPreview) ? arrow_size : expected_w;
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
ItemSize(total_bb, style.FramePadding.y);
@@ -1978,7 +1979,7 @@
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
- const float w = CalcItemWidth();
+ const float w = GetNextItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
@@ -2052,7 +2053,7 @@
bool value_changed = false;
BeginGroup();
PushID(label);
- PushMultiItemsWidths(components);
+ PushMultiItemsWidths(components, GetNextItemWidth());
size_t type_size = GDataTypeInfo[data_type].Size;
for (int i = 0; i < components; i++)
{
@@ -2099,7 +2100,7 @@
ImGuiContext& g = *GImGui;
PushID(label);
BeginGroup();
- PushMultiItemsWidths(2);
+ PushMultiItemsWidths(2, GetNextItemWidth());
bool value_changed = DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format, power);
PopItemWidth();
@@ -2144,7 +2145,7 @@
ImGuiContext& g = *GImGui;
PushID(label);
BeginGroup();
- PushMultiItemsWidths(2);
+ PushMultiItemsWidths(2, GetNextItemWidth());
bool value_changed = DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format);
PopItemWidth();
@@ -2422,7 +2423,7 @@
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
- const float w = CalcItemWidth();
+ const float w = GetNextItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
@@ -2501,7 +2502,7 @@
bool value_changed = false;
BeginGroup();
PushID(label);
- PushMultiItemsWidths(components);
+ PushMultiItemsWidths(components, GetNextItemWidth());
size_t type_size = GDataTypeInfo[data_type].Size;
for (int i = 0; i < components; i++)
{
@@ -2790,10 +2791,9 @@
BeginGroup(); // The only purpose of the group here is to allow the caller to query item data e.g. IsItemActive()
PushID(label);
- PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2));
+ SetNextItemWidth(ImMax(1.0f, GetNextItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2));
if (InputText("", buf, IM_ARRAYSIZE(buf), flags)) // PushId(label) + "" gives us the expected ID from outside point of view
value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, data_ptr, format);
- PopItemWidth();
// Step buttons
const ImVec2 backup_frame_padding = style.FramePadding;
@@ -2839,7 +2839,7 @@
bool value_changed = false;
BeginGroup();
PushID(label);
- PushMultiItemsWidths(components);
+ PushMultiItemsWidths(components, GetNextItemWidth());
size_t type_size = GDataTypeInfo[data_type].Size;
for (int i = 0; i < components; i++)
{
@@ -3289,7 +3289,7 @@
BeginGroup();
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
- ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
+ ImVec2 size = CalcItemSize(size_arg, GetNextItemWidth(), (is_multiline ? GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
@@ -4047,7 +4047,7 @@
const ImGuiStyle& style = g.Style;
const float square_sz = GetFrameHeight();
const float w_extra = (flags & ImGuiColorEditFlags_NoSmallPreview) ? 0.0f : (square_sz + style.ItemInnerSpacing.x);
- const float w_items_all = CalcItemWidth() - w_extra;
+ const float w_items_all = GetNextItemWidth() - w_extra;
const char* label_display_end = FindRenderedTextEnd(label);
BeginGroup();
@@ -4112,13 +4112,11 @@
};
const int fmt_idx = hide_prefix ? 0 : (flags & ImGuiColorEditFlags_DisplayHSV) ? 2 : 1;
- PushItemWidth(w_item_one);
for (int n = 0; n < components; n++)
{
if (n > 0)
SameLine(0, style.ItemInnerSpacing.x);
- if (n + 1 == components)
- PushItemWidth(w_item_last);
+ SetNextItemWidth((n + 1 < components) ? w_item_one : w_item_last);
if (flags & ImGuiColorEditFlags_Float)
{
value_changed |= DragFloat(ids[n], &f[n], 1.0f/255.0f, 0.0f, hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]);
@@ -4131,8 +4129,6 @@
if (!(flags & ImGuiColorEditFlags_NoOptions))
OpenPopupOnItemClick("context");
}
- PopItemWidth();
- PopItemWidth();
}
else if ((flags & ImGuiColorEditFlags_DisplayHex) != 0 && (flags & ImGuiColorEditFlags_NoInputs) == 0)
{
@@ -4142,7 +4138,7 @@
ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X%02X", ImClamp(i[0],0,255), ImClamp(i[1],0,255), ImClamp(i[2],0,255), ImClamp(i[3],0,255));
else
ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", ImClamp(i[0],0,255), ImClamp(i[1],0,255), ImClamp(i[2],0,255));
- PushItemWidth(w_items_all);
+ SetNextItemWidth(w_items_all);
if (InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
{
value_changed = true;
@@ -4157,7 +4153,6 @@
}
if (!(flags & ImGuiColorEditFlags_NoOptions))
OpenPopupOnItemClick("context");
- PopItemWidth();
}
ImGuiWindow* picker_active_window = NULL;
@@ -4190,9 +4185,8 @@
}
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags__InputMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
- PushItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
+ SetNextItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
- PopItemWidth();
EndPopup();
}
}
@@ -4360,7 +4354,7 @@
ImVec2 picker_pos = window->DC.CursorPos;
float square_sz = GetFrameHeight();
float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars
- float sv_picker_size = ImMax(bars_width * 1, CalcItemWidth() - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box
+ float sv_picker_size = ImMax(bars_width * 1, GetNextItemWidth() - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box
float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x;
float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x;
float bars_triangles_half_sz = (float)(int)(bars_width * 0.20f);
@@ -5458,7 +5452,7 @@
const ImVec2 label_size = CalcTextSize(label, NULL, true);
// Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
- ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y);
+ ImVec2 size = CalcItemSize(size_arg, GetNextItemWidth(), GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y);
ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
@@ -5575,7 +5569,7 @@
const ImVec2 label_size = CalcTextSize(label, NULL, true);
if (frame_size.x == 0.0f)
- frame_size.x = CalcItemWidth();
+ frame_size.x = GetNextItemWidth();
if (frame_size.y == 0.0f)
frame_size.y = label_size.y + (style.FramePadding.y * 2);