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/editors/interface/interface_layout.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/editors/interface/interface_layout.c')
-rw-r--r--source/blender/editors/interface/interface_layout.c99
1 files changed, 60 insertions, 39 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 9632bcd35e4..a3906879fd7 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -484,7 +484,7 @@ static void ui_item_array(uiLayout *layout,
int UNUSED(h),
bool expand,
bool slider,
- bool toggle,
+ int toggle,
bool icon_only,
bool compact,
bool show_text)
@@ -691,7 +691,7 @@ static void ui_item_array(uiLayout *layout,
if (slider && but->type == UI_BTYPE_NUM) {
but->type = UI_BTYPE_NUM_SLIDER;
}
- if (toggle && but->type == UI_BTYPE_CHECKBOX) {
+ if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
but->type = UI_BTYPE_TOGGLE;
}
if ((a == 0) && (subtype == PROP_AXISANGLE)) {
@@ -1889,6 +1889,10 @@ void uiItemFullR(uiLayout *layout,
const bool icon_only = (flag & UI_ITEM_R_ICON_ONLY) != 0;
+ /* Boolean with -1 to signify that the value depends on the presence of an icon. */
+ const int toggle = ((flag & UI_ITEM_R_TOGGLE) ? 1 : ((flag & UI_ITEM_R_ICON_NEVER) ? 0 : -1));
+ const bool no_icon = (toggle == 0);
+
/* set name and icon */
if (!name) {
if (!icon_only) {
@@ -1903,10 +1907,6 @@ void uiItemFullR(uiLayout *layout,
flag &= ~UI_ITEM_R_CHECKBOX_INVERT;
}
- if (icon == ICON_NONE) {
- icon = RNA_property_ui_icon(prop);
- }
-
if (flag & UI_ITEM_R_ICON_ONLY) {
/* pass */
}
@@ -1931,51 +1931,60 @@ void uiItemFullR(uiLayout *layout,
}
}
-#ifdef UI_PROP_SEP_ICON_WIDTH_EXCEPTION
- if (use_prop_sep) {
- if (type == PROP_BOOLEAN && (icon == ICON_NONE) && !icon_only) {
- use_prop_sep_split_label = false;
+ if (no_icon == false) {
+ if (icon == ICON_NONE) {
+ icon = RNA_property_ui_icon(prop);
}
- }
-#endif
- /* menus and pie-menus don't show checkbox without this */
- if ((layout->root->type == UI_LAYOUT_MENU) ||
- /* use checkboxes only as a fallback in pie-menu's, when no icon is defined */
- ((layout->root->type == UI_LAYOUT_PIEMENU) && (icon == ICON_NONE))) {
- int prop_flag = RNA_property_flag(prop);
- if (type == PROP_BOOLEAN && ((is_array == false) || (index != RNA_NO_INDEX))) {
- if (prop_flag & PROP_ICONS_CONSECUTIVE) {
- icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
- }
- else if (is_array) {
- icon = (RNA_property_boolean_get_index(ptr, prop, index)) ? ICON_CHECKBOX_HLT :
- ICON_CHECKBOX_DEHLT;
+ /* Menus and pie-menus don't show checkbox without this. */
+ if ((layout->root->type == UI_LAYOUT_MENU) ||
+ /* Use checkboxes only as a fallback in pie-menu's, when no icon is defined. */
+ ((layout->root->type == UI_LAYOUT_PIEMENU) && (icon == ICON_NONE))) {
+ int prop_flag = RNA_property_flag(prop);
+ if (type == PROP_BOOLEAN) {
+ if ((is_array == false) || (index != RNA_NO_INDEX)) {
+ if (prop_flag & PROP_ICONS_CONSECUTIVE) {
+ icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
+ }
+ else if (is_array) {
+ icon = (RNA_property_boolean_get_index(ptr, prop, index)) ? ICON_CHECKBOX_HLT :
+ ICON_CHECKBOX_DEHLT;
+ }
+ else {
+ icon = (RNA_property_boolean_get(ptr, prop)) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
+ }
+ }
}
- else {
- icon = (RNA_property_boolean_get(ptr, prop)) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
+ else if (type == PROP_ENUM) {
+ if (index == RNA_ENUM_VALUE) {
+ int enum_value = RNA_property_enum_get(ptr, prop);
+ if (prop_flag & PROP_ICONS_CONSECUTIVE) {
+ icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
+ }
+ else if (prop_flag & PROP_ENUM_FLAG) {
+ icon = (enum_value & value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
+ }
+ else {
+ icon = (enum_value == value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
+ }
+ }
}
}
- else if (type == PROP_ENUM && index == RNA_ENUM_VALUE) {
- int enum_value = RNA_property_enum_get(ptr, prop);
- if (prop_flag & PROP_ICONS_CONSECUTIVE) {
- icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
- }
- else if (prop_flag & PROP_ENUM_FLAG) {
- icon = (enum_value & value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
- }
- else {
- icon = (enum_value == value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
- }
+ }
+
+#ifdef UI_PROP_SEP_ICON_WIDTH_EXCEPTION
+ if (use_prop_sep) {
+ if (type == PROP_BOOLEAN && (icon == ICON_NONE) && !icon_only) {
+ use_prop_sep_split_label = false;
}
}
+#endif
if ((type == PROP_ENUM) && (RNA_property_flag(prop) & PROP_ENUM_FLAG)) {
flag |= UI_ITEM_R_EXPAND;
}
const bool slider = (flag & UI_ITEM_R_SLIDER) != 0;
- const bool toggle = (flag & UI_ITEM_R_TOGGLE) != 0;
const bool expand = (flag & UI_ITEM_R_EXPAND) != 0;
const bool no_bg = (flag & UI_ITEM_R_NO_BG) != 0;
const bool compact = (flag & UI_ITEM_R_COMPACT) != 0;
@@ -2164,7 +2173,7 @@ void uiItemFullR(uiLayout *layout,
}
}
- if (toggle && but->type == UI_BTYPE_CHECKBOX) {
+ if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
but->type = UI_BTYPE_TOGGLE;
}
@@ -2183,6 +2192,18 @@ void uiItemFullR(uiLayout *layout,
}
}
+ /* The resulting button may have the icon set since boolean button drawing
+ * is being 'helpful' and adding an icon for us.
+ * In this case we want the ability not to have an icon.
+ *
+ * We could pass an argument not to set the icon to begin with however this is the one case
+ * the functionality is needed. */
+ if (but && no_icon) {
+ if ((icon == ICON_NONE) && (but->icon != ICON_NONE)) {
+ ui_def_but_icon_clear(but);
+ }
+ }
+
/* Mark non-embossed textfields inside a listbox. */
if (but && (block->flag & UI_BLOCK_LIST_ITEM) && (but->type == UI_BTYPE_TEXT) &&
(but->dt & UI_EMBOSS_NONE)) {