UI: Change menu icons of single-choice enums to radio buttons #111796

Merged
Harley Acheson merged 1 commits from Mysteryem/blender:ui_enum_menu_item_radio_icons into main 2023-09-13 19:24:25 +02:00
Member

Checkboxes are usually used when multiple choices can be made from
multiple options.

Radio buttons are usually used when only a single choice can be made
from multiple options.

Enum properties that do not have PROP_ENUM_FLAG can only have a single
chosen value, so this patch changes their menu icons from checkboxes to
radio buttons.

Affected UI primarily includes use of UILayout.prop_menu_enum in Python-
defined UI, such as View>Display Size in the Asset Browser and File
Browser, and the menu for changing a Brush's tool in the Brush Specials
menu.


It was questionable whether single-choice enums being displayed as checkboxes was considered a bug (#111768), but it turned out to be a single-line change, so I thought I may as well submit the change myself.

I don't know if there are any places other than UILayout.prop_menu_enum that this is used. The code mentions pie menus too, but I don't know of any enum properties displayed through pie menus that were displaying with checkboxes.

Before

image
image
image

After

image
image
image

Panel script

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        row = self.layout.row()
        ts = context.scene.tool_settings
        # Multiple-choice enum
        row.prop_menu_enum(ts, "snap_elements")
        # Single-choice enum
        row.prop_menu_enum(ts, "proportional_edit_falloff")

def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()
Checkboxes are usually used when multiple choices can be made from multiple options. Radio buttons are usually used when only a single choice can be made from multiple options. Enum properties that do not have PROP_ENUM_FLAG can only have a single chosen value, so this patch changes their menu icons from checkboxes to radio buttons. Affected UI primarily includes use of UILayout.prop_menu_enum in Python- defined UI, such as View>Display Size in the Asset Browser and File Browser, and the menu for changing a Brush's tool in the Brush Specials menu. --- It was questionable whether single-choice enums being displayed as checkboxes was considered a bug (#111768), but it turned out to be a single-line change, so I thought I may as well submit the change myself. I don't know if there are any places other than UILayout.prop_menu_enum that this is used. The code mentions pie menus too, but I don't know of any enum properties displayed through pie menus that were displaying with checkboxes. ## Before ![image](/attachments/df0d05be-6722-4dce-a90b-fd20ffac9c56) ![image](/attachments/765bc8d9-3a33-4fc2-a0d7-a42e4614f60a) ![image](/attachments/7c25fef9-3975-4fdc-9bf8-1bc2faea7b62) ## After ![image](/attachments/b920a856-91ba-4f96-9b55-37f14ee221f0) ![image](/attachments/09b9f0d5-61bd-4edf-a94f-247378511497) ![image](/attachments/39e0ca97-4003-46e7-9d16-c0438cfc6508) ## Panel script ```py import bpy class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object" def draw(self, context): row = self.layout.row() ts = context.scene.tool_settings # Multiple-choice enum row.prop_menu_enum(ts, "snap_elements") # Single-choice enum row.prop_menu_enum(ts, "proportional_edit_falloff") def register(): bpy.utils.register_class(HelloWorldPanel) def unregister(): bpy.utils.unregister_class(HelloWorldPanel) if __name__ == "__main__": register() ```
Thomas Barlow added 1 commit 2023-09-01 17:31:32 +02:00
bbc1a5393a UI: Change menu icons of single-choice enums to radio buttons
Checkboxes are usually used when multiple choices can be made from
multiple options.

Radio buttons are usually used when only a single choice can be made
from multiple options.

Enum properties that do not have PROP_ENUM_FLAG can only have a single
chosen value, so this patch changes their menu icons from checkboxes to
radio buttons.

Affected UI primarily includes use of UILayout.prop_menu_enum in Python-
defined UI, such as View>Display Size in the Asset Browser and File
Browser, and the menu for changing a Brush's tool in the Brush Specials
menu.
Pablo Vazquez added this to the User Interface project 2023-09-01 20:48:45 +02:00
Pablo Vazquez added the
Module
User Interface
label 2023-09-01 20:48:54 +02:00
Harley Acheson requested review from Pablo Vazquez 2023-09-02 18:15:35 +02:00
Pablo Vazquez approved these changes 2023-09-02 18:17:08 +02:00
Pablo Vazquez left a comment
Member

Such a useful one liner. Thank you!

Such a useful one liner. Thank you!
Member

@Mysteryem

Love this!

However I can think of some ways where our current code could be incorrect regarding this flag. Can you go through each editor with this PR applied looking at each menu for anything that looks wrong? Obviously I am concerned about the possibility of showing a single item alone as a radio button because the ON state just looks like a filled ball.

If you find any errors they would just need to have some RNA_def_property_flag(prop, PROP_ENUM_FLAG); sprinkled here and there. I can certainly help if you need it.

@Mysteryem Love this! However I can think of some ways where our current code could be incorrect regarding this flag. Can you go through each editor with this PR applied looking at each menu for anything that looks wrong? Obviously I am concerned about the possibility of showing a single item alone as a radio button because the ON state just looks like a filled ball. If you find any errors they would just need to have some `RNA_def_property_flag(prop, PROP_ENUM_FLAG);` sprinkled here and there. I can certainly help if you need it.
Harley Acheson requested review from Harley Acheson 2023-09-02 18:33:28 +02:00
Author
Member

I think an enum property that only has a single option and only allows a single choice would be a little odd with either checkboxes or radio buttons, mainly because that single option should always be selected and selecting it again will do nothing (technically for custom properties defined by addons, the current index can be set out-of-bounds which deselects that single option, but I'm not sure if that also applies for RNA enum properties).

Though, enabling PROP_ENUM_FLAG for enum properties that do not have the flag already would need some care because it would be a breaking Python API change. An enum property with PROP_ENUM_FLAG being exposed through the Python API as a set of str strings, and enum property without PROP_ENUM_FLAG being exposed through the Python API as a single str string.

I would anticipate that the only RNA enum properties that allow only a single choice and might have only a single option would be dynamic enums. A static enum with only a single choice and a single option would make more sense to be a read-only string property instead.

I've checked every use of prop_menu_enum that I could find in Blender's python-defined UI, and those enums all have more than one option.

I had a look at the C functions called by UILayout.prop_menu_enum too, but I couldn't find any other uses until the UI functions got generic, supporting any kind of property rather than only enums.

I think an enum property that only has a single option and only allows a single choice would be a little odd with either checkboxes or radio buttons, mainly because that single option should always be selected and selecting it again will do nothing (technically for custom properties defined by addons, the current index can be set out-of-bounds which deselects that single option, but I'm not sure if that also applies for RNA enum properties). Though, enabling `PROP_ENUM_FLAG` for enum properties that do not have the flag already would need some care because it would be a breaking Python API change. An enum property with `PROP_ENUM_FLAG` being exposed through the Python API as a `set` of `str` strings, and enum property without `PROP_ENUM_FLAG` being exposed through the Python API as a single `str` string. I would anticipate that the only RNA enum properties that allow only a single choice and might have only a single option would be dynamic enums. A static enum with only a single choice and a single option would make more sense to be a read-only string property instead. I've checked every use of `prop_menu_enum` that I could find in Blender's python-defined UI, and those enums all have more than one option. I had a look at the C functions called by `UILayout.prop_menu_enum` too, but I couldn't find any other uses until the UI functions got generic, supporting any kind of property rather than only enums.
Member

@Mysteryem - I think an enum property that only has a single option and only allows a single choice would be a little odd...

Oh, sorry that I was not clear. I have no problems with your PR itself. My only concern is that our codebase might contain some errors that could be exposed by this. I'll do a quick check around to make sure.

Thanks for posting this PR. We should be able to discuss it very soon.

> @Mysteryem - I think an enum property that only has a single option and only allows a single choice would be a little odd... Oh, sorry that I was not clear. I have no problems with your PR itself. My only concern is that our codebase might contain some errors that could be exposed by this. I'll do a quick check around to make sure. Thanks for posting this PR. We should be able to discuss it very soon.
Harley Acheson approved these changes 2023-09-13 19:19:46 +02:00
Member

Thanks for this!

Thanks for this!
Harley Acheson merged commit 6dd3c90185 into main 2023-09-13 19:24:25 +02:00
Thomas Barlow deleted branch ui_enum_menu_item_radio_icons 2024-01-09 23:07:56 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111796
No description provided.