Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Nahor opened this issue Dec 7, 2023 · 3 comments
Labels

Comments

@Nahor
Copy link
Contributor

Nahor commented Dec 7, 2023

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 #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
@ocornut ocornut added the bug label Dec 7, 2023
ocornut added a commit that referenced this issue Dec 7, 2023
… incorrect pushes into ItemWidth stack when number of components is 1. [#7095]
@ocornut
Copy link
Owner

ocornut commented Dec 7, 2023

Thank you for the report! I have pushed a fix as 1fade35.
Given the fix itself was fairly simple I have used your name in the changelog.

@ocornut ocornut closed this as completed Dec 7, 2023
@Nahor
Copy link
Contributor Author

Nahor commented Dec 7, 2023

Still breaks if there are 0 (or negative) components. "foo" widget won't show, but "bar" is still the wrong size and will have double the vertical spacing with the last visible component.
(Probably an assert would be a good enough option for that since it doesn't make much sense as a use case but it would avoid a lot of head scratching if someone triggers it anyway)

@ocornut ocornut reopened this Dec 7, 2023
ocornut added a commit that referenced this issue Dec 8, 2023
@ocornut
Copy link
Owner

ocornut commented Dec 8, 2023

Added an assert for it.

@ocornut ocornut closed this as completed Dec 8, 2023
Madspark-Studios added a commit to Madspark-Studios/imguiForSparkEngine that referenced this issue Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants