From 6640bcca742210fa3dc9c8a0675ebf71a9e9e7f6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 21 May 2019 14:39:09 +1000 Subject: UI: support drawing booleans with icons as check-boxes Previously, if a boolean happened to use an icon there was no way to make it display as a check-box from Python scripts. The previous logic meant we ended up having to edit the RNA. Since booleans with icons don't work well with the split-property layout (now used for most of the interface). Icons were being removed from RNA then added back using awkward Python ternary expressions in the interface scripts. The toggle argument now has an unset state (-1). - toggle=True: no checkbox (emboss). - toggle=False: always use a checkbox (no icon). - toggle=(unset/-1): depends on the icon status, default as before. Since toggle=False was default, this isn't used in existing UI logic. --- source/blender/makesrna/intern/rna_ui_api.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'source/blender/makesrna/intern/rna_ui_api.c') diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 5a001f05b53..d50f97e88ca 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -95,7 +95,7 @@ static void rna_uiItemR(uiLayout *layout, int icon, bool expand, bool slider, - bool toggle, + int toggle, bool icon_only, bool event, bool full_event, @@ -121,7 +121,12 @@ static void rna_uiItemR(uiLayout *layout, flag |= (slider) ? UI_ITEM_R_SLIDER : 0; flag |= (expand) ? UI_ITEM_R_EXPAND : 0; - flag |= (toggle) ? UI_ITEM_R_TOGGLE : 0; + if (toggle == 1) { + flag |= UI_ITEM_R_TOGGLE; + } + else if (toggle == 0) { + flag |= UI_ITEM_R_ICON_NEVER; + } flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0; flag |= (event) ? UI_ITEM_R_EVENT : 0; flag |= (full_event) ? UI_ITEM_R_FULL_EVENT : 0; @@ -773,7 +778,17 @@ void RNA_api_ui_layout(StructRNA *srna) api_ui_item_common(func); RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail"); RNA_def_boolean(func, "slider", false, "", "Use slider widget for numeric values"); - RNA_def_boolean(func, "toggle", false, "", "Use toggle widget for boolean values"); + RNA_def_int(func, + "toggle", + -1, + -1, + 1, + "", + "Use toggle widget for boolean values, " + "or a checkbox when disabled " + "(the default is -1 which uses toggle only when an icon is displayed)", + -1, + 1); RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in buttons, no text"); RNA_def_boolean(func, "event", false, "", "Use button to input key events"); RNA_def_boolean( -- cgit v1.2.3