InputScalarN/DragScalarN/SliderScalarN can mess up the layout when called with only one component #7095

Closed
opened 2023-12-07 00:14:37 +00:00 by Nahor · 0 comments
Nahor commented 2023-12-07 00:14:37 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: v1.90
Branch: docking

My Issue/Question:

XxxScalarN, through PushMultiItemsWidths, pushes a minimum of two entries into ItemWidthStack, but only pops as many as there are components. If one (or less) component is used, there will be one (or more) leftover entry in the stack, which can then mess up the layout of subsequent widgets.

Screenshots/Video

Expected result:
image

Actual result:
image

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)

ImGui::PushItemWidth(100);

float f[2] = {0.0f, 0.0f};
float min = 0, max = 1;
ImGui::InputScalarN("foo", ImGuiDataType_Float, f, 1, &min, &max); // DO NOT WORK (1 component)
//ImGui::InputScalarN("foo", ImGuiDataType_Float, f, 2, &min, &max); // WORKS (2 components)
//ImGui::InputScalar("foo", ImGuiDataType_Float, f); // WORKS (single-scalar-only version)

ImGui::PopItemWidth();  // should pop the 100 from above, but pops the leftover entry instead

char buf[10];
ImGui::InputFloat("bar", f); // width of 100 instead of being automatically computed
**Version/Branch of Dear ImGui:** Version: v1.90 Branch: docking **My Issue/Question:** `XxxScalarN`, through `PushMultiItemsWidths`, pushes a minimum of two entries into `ItemWidthStack`, but only pops as many as there are components. If one (or less) component is used, there will be one (or more) leftover entry in the stack, which can then mess up the layout of subsequent widgets. **Screenshots/Video** Expected result: ![image](https://github.com/ocornut/imgui/assets/1198364/cdd893eb-1ee6-48c8-a681-fb96275b9434) Actual result: ![image](https://github.com/ocornut/imgui/assets/1198364/62001323-7e10-4b59-abfa-fcb705a9bc72) **Standalone, minimal, complete and verifiable example:** _(see https://github.com/ocornut/imgui/issues/2261)_ ```C++ ImGui::PushItemWidth(100); float f[2] = {0.0f, 0.0f}; float min = 0, max = 1; ImGui::InputScalarN("foo", ImGuiDataType_Float, f, 1, &min, &max); // DO NOT WORK (1 component) //ImGui::InputScalarN("foo", ImGuiDataType_Float, f, 2, &min, &max); // WORKS (2 components) //ImGui::InputScalar("foo", ImGuiDataType_Float, f); // WORKS (single-scalar-only version) ImGui::PopItemWidth(); // should pop the 100 from above, but pops the leftover entry instead char buf[10]; ImGui::InputFloat("bar", f); // width of 100 instead of being automatically computed ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#7095
No description provided.