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

Sizing of ComboAutoSelect in table cells #8066

Open
merravid opened this issue Oct 16, 2024 · 1 comment
Open

Sizing of ComboAutoSelect in table cells #8066

merravid opened this issue Oct 16, 2024 · 1 comment

Comments

@merravid
Copy link

merravid commented Oct 16, 2024

Version/Branch of Dear ImGui:

Version 1.90.9, Branch: Docking

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 11 + MSVC 2022

Full config/build information:

No response

Details:

I am trying to use ImGui::ComboAutoSelect() element within a table cell. What I want to achieve is that the combo box auto-resizes to fit the preview text and the table column resizes to fit the size of that combo box. I assume this is what ImGuiComboFlags_WidthFitPreview does, at least at the combo level.

Issue 1:
The behaviour I am seeing instead is that the combo sizes proportionally to around 70% of the column width. If I stretch the column width, the combo box width also changes.

The table has ImGuiTableFlags_NoSavedSettings.

I tried setting SetNextItemWidth to -1 before the ComboAutoSelect call. What this did was stretch the combo infinitely. If I set next item width to constant, the combo doesn't auto-stretch to fit the preview.

Issue 2:
In no case does the table column auto-resize to fit the content. I guess this is not default behaviour, but is there a flag or a call I can use to have it mimick the "Size All Columns To Fit" menu option?

Issue 3:
How do I remove ALL padding from the table cell so that the combo rectangle sits tightly along the table grid lines. I tried setting ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 0,0 }) but that didn't work.

Thanks.

@ocornut
Copy link
Owner

ocornut commented Oct 16, 2024

ComboAutoSelect() is not a function I know or wrote or heard for.

The behaviour I am seeing instead is that the combo sizes proportionally to around 70% of the column width. If I stretch the column width, the combo box width also changes.

See Demo->Tables->Item Width.
(or more generally Demo->Layout & Scrolling->Widgets Width)

TL;DR; you can use ImGui::SetNextItemWidth(-FLT_MIN) to right align framed items. Or ImGui::PushItemWidth(-FLT_MIN); ... ImGui::PopItemWidth() if you want the state to be reused for a several widgets. This is common for framed widgets and makes sense if you use hidden label (given the absence of code I am assuming you are).

In no case does the table column auto-resize to fit the content. I guess this is not default behaviour, but is there a flag or a call I can use to have it mimick the "Size All Columns To Fit" menu option?

Define "fit the content" ? Do you mean fit so the combo width would fit exactly the preview text? In this case, it means that changing the combo selection would resize the table, which seems bizarre. It seems to make sense that the contents of previewed label doesn't feed back into ideal width width.

(It generally depends how the widgets in question reports its ideal size. Since I don't know what ComboAutoSelect() i am assuming it work like a regular BeginCombo)

How do I remove ALL padding from the table cell so that the combo rectangle sits tightly along the table grid lines. I tried setting ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, { 0,0 }) but that didn't work.

I cannot reply to unrelated questions in the same thread. They are less searchable for other users. And as proven by this, the more unrelated question you ask the less likely you are going to actually provide enough details to make it possible for us to answer the question. Please refer to the tables demo contents and refer to guidelines when asking questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants