ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.11k stars 10.3k forks source link

Selectable doesn't accept negative size values #7010

Open tpecholt opened 1 year ago

tpecholt commented 1 year ago

Version/Branch of Dear ImGui:

Version: 1.90 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Compiler: VS 2022 Operating System: Windows 10

My Issue/Question: Selectable currently doesn't honor negative size values so its size can't be made relative to right or bottom edge of the window. I am currently calling CalcItemSize in place of the size parameter to fix it but that is inconsistent with how other widgets work (InputTextMultiline, Child, Table).

Screenshots/Video

Standalone, minimal, complete and verifiable example:

ImGui::Selectable("Example Bug", false, 0, { -1, -1 }); // will not expand to the right & bottom edge
ocornut commented 1 year ago

Hello,

I am not sure I remember if there was a good reason.

Selectable() has various sizing subtleties (some I wish I didn't had), but the extra padding it adds would make the use of CalcItemSize() misleading. e.g. if you use -FLT_MIN (or -1) to right-align it would still add half ItemSpacing.x*0.5f over this, making the thing looks unaligned.

If I have to be honest, removing this extra padding from Selectable() would be a great move but it'll require carefull maneuvering and documentation.

tpecholt commented 12 months ago

I see what you mean. It looks like Selectable frame gets extended but unless it's hovered or pressed the extension is not visible and the label stays aligned with other -1 widgets on the next line. Also there is NoPadWithHalfSpacing to disable this behavior. So to me enabling negative size would still make sense but feel free to close this ticket how you wish.

ocornut commented 12 months ago

I'll leave it open for now. I might introduce support for this sooner but most I want to eventually remove that extra padding.