Skip to content

Useful API improvements #8570

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

Open
tpecholt opened this issue Apr 15, 2025 · 0 comments
Open

Useful API improvements #8570

tpecholt opened this issue Apr 15, 2025 · 0 comments

Comments

@tpecholt
Copy link

Version/Branch of Dear ImGui:

1.91.6 docking

Back-ends:

opengl3, glfw

Compiler, OS:

windows 10 + msvc 2022

Full config/build information:

No response

Details:

Please consider to include these API improvements which I think are generally useful.

1. Negative size calculation

I often use the negative size feature to request size expansion to the right/bottom edge. Some widgets (such as Table or Selectable/sizeY) already expand when specifying zero size because it's their default behavior. But zero value often means different behavior for other widgets such as Button or InputText. So if one wants to request expansion reliably the best way is to pass -1. Unfortunately -1 will leave one pixel gap. That may not be noticeable by the user but I wonder why the size calculation doesn't use +1 term to compensate for it?

2. IsItemContextMenuClicked

Simple helper to implement context menus. This would be a shortcut to
ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonDefault_) && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup); which I find too long to remember.

3. IsCurrentItemDisabled

It's useful to know we are inside a ImGuiItemFlags_Disabled block. For example the property grid shows modified properties in bold font but if the property is disabled it should use a regular font. This currently requires internal API usage: ImGui::GetCurrentContext()->CurrentItemFlags & ImGuiItemFlags_Disabled

4. Spacing(value = 0)

Both SameLine() and Indent() allow to specify the exact gap value. It would be nice for Spacing to allow the same so one doesn't need to call it repeatedly for spacing multiplies. There isn't a way to specify non-default spacing other than use SetCursorY.

5. SetNextWindowIgnorePadding / Push/Pop/IgnoreWindowPadding

Sometimes there is a need to ignore window padding for few items but not all. For example a ModalPopup may contain a Child with different color in the middle but all widgets in Child and outside should otherwise respect same window padding values. It would be easier to Push/Pop instead of setting ModalPopup WindowPadding to zero then lay down 3 Children which specify original WindowPading again. I have implemented it but instead of simply pushing the StyleVar value the code modifies ClipRect, WorkRect, CursorScreenPos directly.

6. GetFontByName(name)

I find it easier to give loaded fonts names through ImFontConfig::Name then access the font by its name e.g. GetFontByName("H1") instead of keeping ImFont pointers somewhere and pass them around.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

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

No branches or pull requests

1 participant