Useful API improvements
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
Sorry for not answering this but processing 6 unrelated requests is to difficult for me.
- It's not a good idea because it hinder future discoverability. Case in point, the title for this topic is vague and generic.
- Honestly each individual topic could easily lead to a whole design discussion. And the last thing I want is to have 6 different discussions in a same location.
I'd really prefer different issues for them.
For (2) IsItemContextMenuClicked() it seems like BeginPopupContextItem() would cover this already?
For (6) GetFontByName() I don't think it's a good idea to promote searching fonts by name, but it is something you could freely add in your app code. That said, I can imagine that a future rework of the text and style systems would favor standardized storage for accessing font type/size and text color by semantic (e.g. "error color", "h1 font+size").