From 10b7d4f601ca05e055896e7743d3ccc63f54f558 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 14 Apr 2023 20:11:59 +1000 Subject: [PATCH] WM: support separators when generating tools from enums & icon map Currently this is disabled for sculpt, we may want to enable this in the future. Also add an icon map argument for brushes to use generic icons. --- .../startup/bl_ui/space_toolsystem_toolbar.py | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 1e33c2f92ee..265608530cd 100644 --- a/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -32,20 +32,43 @@ def generate_from_enum_ex( attr, cursor='DEFAULT', tooldef_keywords=None, + icon_map=None, + use_separators=True, ): if tooldef_keywords is None: tooldef_keywords = {} tool_defs = [] - for enum in type.bl_rna.properties[attr].enum_items_static: - name = enum.name - idname = enum.identifier + + enum_items = getattr( + type.bl_rna.properties[attr], + "enum_items_static_ui" if use_separators else + "enum_items_static", + ) + + for enum in enum_items: + if use_separators: + if not (name := enum.name): + # Empty string for a UI Separator. + tool_defs.append(None) + continue + if not (idname := enum.identifier): + # This is a heading, there is no purpose in showing headings here. + continue + else: + name = enum.name + idname = enum.identifier + + icon = icon_prefix + idname.lower() + if icon_map is not None: + icon = icon_map.get(icon, icon) + tool_defs.append( ToolDef.from_dict( dict( idname=idname_prefix + name, label=name, - icon=icon_prefix + idname.lower(), + icon=icon, cursor=cursor, data_block=idname, **tooldef_keywords, @@ -1316,6 +1339,9 @@ class _defs_sculpt: icon_prefix="brush.sculpt.", type=bpy.types.Brush, attr="sculpt_tool", + # TODO(@ideasman42): we may want to enable this, + # it causes awkward grouping with 2x column button layout. + use_separators=False, ) @ToolDef.from_fn