godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Allow unpressing all buttons in a ButtonGroup #6722

Closed TheSecondReal0 closed 1 year ago

TheSecondReal0 commented 1 year ago

Describe the project you are working on

User interface

Describe the problem or limitation you are having in your project

I consistently find myself wanting to have a group of buttons where only one can be pressed at a time but you can also unpress all of them.

For instance, a map editor. When you press a button to select what object to place, you want the other buttons to unpress. Extremely easy with button groups. But what if you want to press that same button again to have no object selected? Currently this behavior is impossible without creating your own ButtonGroup-like system.

Example of map editor:

https://user-images.githubusercontent.com/66881186/233255596-2628799a-c8b0-4bfb-ba43-44140f3ad2a7.mp4

You would hit the same road block developing a UI with categories and dropdowns like this:

https://user-images.githubusercontent.com/66881186/233254988-65b61cd7-0888-4999-ae09-305e42809e22.mp4

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Solution 1: Add a toggle to ButtonGroup for whether or not all buttons can become unpressed Solution 2: Create a child class of ButtonGroup that allows all buttons to become unpressed

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Current behavior:

https://user-images.githubusercontent.com/66881186/233247341-db02d893-0e6c-4c0f-b8a5-3c4b39fc6f29.mp4

Proposed behavior:

https://user-images.githubusercontent.com/66881186/233247374-e427a3d4-36d3-4a4e-88e4-071b99a5efbd.mp4

Possible feature UI (allow_unpress disabled by default to maintain compatibility): image

PR with implementation: https://github.com/godotengine/godot/pull/76279

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can be worked around, but the workaround is creating an entire system yourself that copies the behavior of ButtonGroup with one minor tweak. While it's not that hard, it seems unnecessary given the engine already has a system that's 99% of the way there.

Is there a reason why this should be core and not an add-on in the asset library?

This seems like a useful enough feature to be part of the engine and it can be added without breaking compatibility. It would resolve a pain point that I'm sure many developers have run into and would make it even easier to create responsive UIs.

arkology commented 1 year ago

Related issues: https://github.com/godotengine/godot/issues/3610 https://github.com/godotengine/godot/issues/9789