mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Tables: Fixed PopItemWidth() or multi-components items not restoring per-colum ItemWidth correctly. (#3760) rework local stacks to facilitate modifying current value without altering the stack.
May consider doing the same for ItemFlags and moving to g.ItemFlags...
This commit is contained in:
14
imgui.cpp
14
imgui.cpp
@ -6428,15 +6428,15 @@ void ImGui::PopButtonRepeat()
|
||||
void ImGui::PushTextWrapPos(float wrap_pos_x)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.TextWrapPosStack.push_back(window->DC.TextWrapPos);
|
||||
window->DC.TextWrapPos = wrap_pos_x;
|
||||
window->DC.TextWrapPosStack.push_back(wrap_pos_x);
|
||||
}
|
||||
|
||||
void ImGui::PopTextWrapPos()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.TextWrapPos = window->DC.TextWrapPosStack.back();
|
||||
window->DC.TextWrapPosStack.pop_back();
|
||||
window->DC.TextWrapPos = window->DC.TextWrapPosStack.empty() ? -1.0f : window->DC.TextWrapPosStack.back();
|
||||
}
|
||||
|
||||
bool ImGui::IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent)
|
||||
@ -7393,12 +7393,13 @@ void ImGui::SetNextItemWidth(float item_width)
|
||||
g.NextItemData.Width = item_width;
|
||||
}
|
||||
|
||||
// FIXME: Remove the == 0.0f behavior?
|
||||
void ImGui::PushItemWidth(float item_width)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); // Backup current width
|
||||
window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width);
|
||||
window->DC.ItemWidthStack.push_back(window->DC.ItemWidth);
|
||||
g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth;
|
||||
}
|
||||
|
||||
@ -7409,18 +7410,19 @@ void ImGui::PushMultiItemsWidths(int components, float w_full)
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const float w_item_one = ImMax(1.0f, IM_FLOOR((w_full - (style.ItemInnerSpacing.x) * (components - 1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, IM_FLOOR(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components - 1)));
|
||||
window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); // Backup current width
|
||||
window->DC.ItemWidthStack.push_back(w_item_last);
|
||||
for (int i = 0; i < components - 1; i++)
|
||||
for (int i = 0; i < components - 2; i++)
|
||||
window->DC.ItemWidthStack.push_back(w_item_one);
|
||||
window->DC.ItemWidth = window->DC.ItemWidthStack.back();
|
||||
window->DC.ItemWidth = (components == 1) ? w_item_last : w_item_one;
|
||||
g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth;
|
||||
}
|
||||
|
||||
void ImGui::PopItemWidth()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.ItemWidth = window->DC.ItemWidthStack.back();
|
||||
window->DC.ItemWidthStack.pop_back();
|
||||
window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
|
||||
}
|
||||
|
||||
// Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth().
|
||||
|
Reference in New Issue
Block a user