mirror of https://github.com/ocornut/imgui
DragScalarN, SliderScalarN, InputScalarN, PushMultiItemsWidths: improve multi-components width computation to better distribute the error. (#7120, #7121)
This commit is contained in:
parent
03298fe875
commit
86512eac06
|
@ -64,6 +64,8 @@ Other changes:
|
|||
- Drag and Drop: Fixed drop target highlight on items temporarily pushing a widened clip rect
|
||||
(namely Selectables and Treenodes using SpanAllColumn flag) so the highlight properly covers
|
||||
all columns. (#7049, #4281, #3272)
|
||||
- DragScalarN, SliderScalarN, InputScalarN, PushMultiItemsWidths: improve multi-components
|
||||
width computation to better distribute the error. (#7120, #7121) [@Nahor]
|
||||
- Menus: Tweaked hover slack logic, adding a timer to avoid situations where a slow vertical
|
||||
movements toward another parent BeginMenu() can keep the wrong child menu open. (#6671, #6926)
|
||||
- Debug Tools: Added DebugFlashStyleColor() to identify a style color. Added to Style Editor.
|
||||
|
|
16
imgui.cpp
16
imgui.cpp
|
@ -9862,14 +9862,16 @@ void ImGui::PushMultiItemsWidths(int components, float w_full)
|
|||
ImGuiWindow* window = g.CurrentWindow;
|
||||
IM_ASSERT(components > 0);
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const float w_item_one = ImMax(1.0f, IM_TRUNC((w_full - (style.ItemInnerSpacing.x) * (components - 1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, IM_TRUNC(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components - 1)));
|
||||
window->DC.ItemWidthStack.push_back(window->DC.ItemWidth); // Backup current width
|
||||
if (components > 1)
|
||||
window->DC.ItemWidthStack.push_back(w_item_last);
|
||||
for (int i = 0; i < components - 2; i++)
|
||||
window->DC.ItemWidthStack.push_back(w_item_one);
|
||||
window->DC.ItemWidth = (components == 1) ? w_item_last : w_item_one;
|
||||
float w_items = w_full - style.ItemInnerSpacing.x * (components - 1);
|
||||
float prev_split = w_items;
|
||||
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);
|
||||
prev_split = next_split;
|
||||
}
|
||||
window->DC.ItemWidth = prev_split;
|
||||
g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue