ocornut / imgui

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

Is it possible to change widget's active area? #8134

Closed nikitablack closed 2 weeks ago

nikitablack commented 2 weeks ago

Version/Branch of Dear ImGui:

Version v1.90.7, Branch: docking

Back-ends:

Custom

Compiler, OS:

Ubuntu 20.04

Details:

I'm making a timeline and I want each frame marker to be a button widget - it should interact on hover, mouse press, etc. Something like this: Screenshot from 2024-11-07 10-31-19 Here I hovered over a frame 20 button (though the capture software moved mouse a bit to the left).

Now I want the markers to stay the same size, but capture mouse below them: Screenshot from 2024-11-07 10-31-39 Here I hold the mouse cursor under the frame 20 button and want it to be hovered. Also, when I press the button, I want it to look pressed.

I can draw rectangles and assign a color depending on a mouse positions, but is there maybe a simper recommended way? For example, expand the active area of a button somehow?

ocornut commented 2 weeks ago

Typically you would create your own widget by calling either InvisibleButton() or ButtonBehavior() (slightly lower level) And then draw the visuals yourself (here it would be two calls).

For a timeline like this, I often found it even more practical to submit a single button from ImGui point of view and do the geometry hit-testing yourself based on mouse position. But both ways would work.

nikitablack commented 2 weeks ago

Thank you. I implemented this with multiple InvisibleButtons.