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

getting tightest possible horizontal spacing #7601

Closed
tenpn opened this issue May 18, 2024 · 7 comments
Closed

getting tightest possible horizontal spacing #7601

tenpn opened this issue May 18, 2024 · 7 comments
Labels

Comments

@tenpn
Copy link

tenpn commented May 18, 2024

Version/Branch of Dear ImGui:

1.90.1

Back-ends:

Psydack's UImGui port v4.1.0

Compiler, OS:

Windows 10, Unity 2023.2.13

Full config/build information:

No response

Details:

I've got a collection of mostly Labels under Collapsible Headers. Something about my layout means I have to have much wider windows than seem necessary.

In the first screenshot below, this is the narrowest I can have this window and still read everything in the right-hand column. If I go narrower, as in the second screenshot, the right-hand column starts to get cut off. This is despite there still being plenty of space in the middle to eat up.

Am I missing an option to let Dear ImGui prioritise shrinking empty space before it cuts off content?

Screenshots/Video:

image
image

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented May 18, 2024

If by labels you mean LabelText() its a widget that follows the current value of ItemWidth to match the width of a Slider or any other framed widget. You can control that width with PushItemWidth() or SetNextItemWidth() and there’s a section in Demo>Layout detailing it. It defaults to something like 2/3 of the window and its a bit awkward because it doesn’t lend itself to manual resizing (i have some ideas in mind to improve it). There’s not calculation of either side contents in that situation.

However, it seems like you should be using a table and set column policy to fit/stretch or make the table resizable.

@ocornut
Copy link
Owner

ocornut commented May 18, 2024

To clarify if you were submitting eg Drags or Sliders or Inputs you would see the frame on the left and this frame’s width is derived from ItemWidth, and it would make a little bit more sense as to why the left side is not best-fit.

(It’s a recurrent question/wonder in the sense that both the order and lack of manual resizing is not ideal. What people do nowadays if they want the best-fit is to use a two columns table, add label in one column and widgets without label filling the other column (using -FLT_MIN you right align frames to available bounds).

it’s probably good to browse the Examples in Demo for some references.

@tenpn
Copy link
Author

tenpn commented May 18, 2024

my GUI is constructed dynamically, so it's awkward to know if you're in a run of labels that could share a table or not.

I could do Text--SameLine--Text but what would really make it sing is some way of tabstopping. If the first Text was < some width, then pass an offset to SameLine. CalcItemWidth isn't what I need according to the docs. I've been digging in the excellent manual demo https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html but not found anything yet.

@ocornut
Copy link
Owner

ocornut commented May 18, 2024

my GUI is constructed dynamically, so it's awkward to know if you're in a run of labels that could share a table or not.

I believe every fields should share the same table, why wouldn’t they?

@tenpn
Copy link
Author

tenpn commented May 18, 2024

I've got collapsing headers and tree nodes all mixed up in there, it's callbacks all over the place. I think I figured out a way to table runs of labels tho, will give that a go.

@tenpn
Copy link
Author

tenpn commented May 18, 2024

😤
image
using a cached CalcTextSize for the label key to pass a minimum offset to SameLine()

@tenpn tenpn closed this as completed May 18, 2024
@ocornut
Copy link
Owner

ocornut commented May 18, 2024

You can call EndTable() when using a collapsing header and reopen it immediately, that’s also a solution.

@ocornut ocornut added the layout label May 18, 2024
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