godotengine / godot-proposals

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

Consistent Display of Checkbox Outer Box for Both Checked and Unchecked States #10491

Open nongvantinh opened 1 month ago

nongvantinh commented 1 month ago

Describe the project you are working on

I am working on a project in the Godot Engine that involves creating a user interface where checkboxes are a key component. The project requires a consistent and clear visual representation of checkboxes, regardless of whether they are in a checked or unchecked state.

Describe the problem or limitation you are having in your project

In the current implementation of Godot, when a checkbox is checked, it only displays the "on" icon. Conversely, when the checkbox is unchecked, it only displays the "off" icon. This behavior poses a challenge when using asset store resources, where the "on" icon (checked state) lacks the outer box that is present in the "off" icon (unchecked state). The asset creators expect users to manually combine the "off" icon (outer box) with the "on" icon, but Godot does not natively support displaying both icons simultaneously when the checkbox is checked.

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

The proposed feature is an enhancement to the Godot checkbox control that allows the "off" icon (outer box) to be displayed consistently, regardless of the checkbox's state. When the checkbox is checked, the "on" icon (checked mark) should be layered on top of the "off" icon (outer box), ensuring that the outer box is always visible. This feature would provide a more consistent and visually clear user interface, eliminating the need for manual icon combination.

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

The enhancement could be implemented by modifying the checkbox control to render the "off" icon (outer box) as a background image, with the "on" icon (checked mark) rendered on top when the checkbox is in the checked state.

 GDScript pseudo-code example
func _draw():
    if is_checked():
        draw_texture(off_icon, position)
        draw_texture(on_icon, position)
    else:
        draw_texture(off_icon, position)

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

A workaround could involve manually drawing both the "off" and "on" icons using custom drawing logic in the checkbox control, but this approach would be cumbersome for users who are not comfortable with scripting. Additionally, it would require redundant code across multiple checkboxes, making the process inefficient.

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

This enhancement should be integrated into the core engine because checkboxes are a fundamental UI element used in various projects. Having a consistent and reliable visual representation of checkboxes is crucial for user interfaces, and this feature would benefit a wide range of developers who rely on asset store resources or require a similar visual effect. Making this a core feature would streamline development and improve the overall usability of the Godot Engine.

KoBeWi commented 4 weeks ago

As I already commented in the PR, it falls on the asset creator to create the asset to work properly with the systems it's designed for. It the asset doesn't work with Godot's UI, it wasn't designed specifically for Godot. That's common with assets, personally I never expect them to work properly out-of-the-box and make some adjustments myself. In your case you can either edit the image or overlay the icons in code (by creating a new texture resource dynamically).

That aside, this change will affect how CheckBox icons are displayed, which breaks compatibility and some themes will no longer look correctly.

nongvantinh commented 4 weeks ago

Eventually, it will not be accepted. I will change the PR to add a variable to the theme (off_icon_always_visible) to indicate that the background should always be visible to ensure compability with the old behavior.