Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-05-21 07:39:09 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-05-21 08:06:44 +0300
commit6640bcca742210fa3dc9c8a0675ebf71a9e9e7f6 (patch)
tree0798bbbc04b0f175a5b0284d5537246ed44ceaf7 /source/blender/makesrna/intern/rna_ui_api.c
parent87fda5bc608322dbddbe57303ad3ae5d737216e0 (diff)
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_ui_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_ui_api.c21
1 files changed, 18 insertions, 3 deletions
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(