UI: allow off/on icons to be in reverse order.
The same icons are reused for "hide" and "show" properties, which need to be in reverse order compared to each other.
This commit is contained in:
parent
4c7f08e5eb
commit
b5667c2ca7
|
@ -236,6 +236,8 @@ enum {
|
|||
UI_BUT_ACTIVE_RIGHT = (1 << 22), /* Active right part of number button */
|
||||
|
||||
UI_BUT_HAS_SHORTCUT = (1 << 23), /* Button has shortcut text */
|
||||
|
||||
UI_BUT_ICON_REVERSE = (1 << 24), /* Reverse order of consecutive off/on icons */
|
||||
};
|
||||
|
||||
/* scale fixed button widths by this to account for DPI */
|
||||
|
|
|
@ -2985,7 +2985,11 @@ void ui_but_update_ex(uiBut *but, const bool validate)
|
|||
|
||||
case UI_BTYPE_ICON_TOGGLE:
|
||||
case UI_BTYPE_ICON_TOGGLE_N:
|
||||
if (!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
|
||||
if ((but->rnaprop == NULL) || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) {
|
||||
if (but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ICONS_REVERSE) {
|
||||
but->drawflag |= UI_BUT_ICON_REVERSE;
|
||||
}
|
||||
|
||||
but->iconadd = (but->flag & UI_SELECT) ? 1 : 0;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -2016,6 +2016,21 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
|
|||
}
|
||||
}
|
||||
|
||||
static BIFIconID widget_icon_id(uiBut *but)
|
||||
{
|
||||
if (!(but->flag & UI_HAS_ICON)) {
|
||||
return ICON_NONE;
|
||||
}
|
||||
|
||||
/* Consecutive icons can be toggle between. */
|
||||
if (but->drawflag & UI_BUT_ICON_REVERSE) {
|
||||
return but->icon - but->iconadd;
|
||||
}
|
||||
else {
|
||||
return but->icon + but->iconadd;
|
||||
}
|
||||
}
|
||||
|
||||
/* draws text and icons for buttons */
|
||||
static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
|
||||
{
|
||||
|
@ -2039,7 +2054,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
|
|||
|
||||
/* Big previews with optional text label below */
|
||||
if (but->flag & UI_BUT_ICON_PREVIEW && ui_block_is_menu(but->block)) {
|
||||
const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE;
|
||||
const BIFIconID icon = widget_icon_id(but);
|
||||
int icon_size = BLI_rcti_size_y(rect);
|
||||
int text_size = 0;
|
||||
|
||||
|
@ -2076,7 +2091,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
|
|||
}
|
||||
#endif
|
||||
|
||||
const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE;
|
||||
const BIFIconID icon = widget_icon_id(but);
|
||||
int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
|
||||
const float icon_size = icon_size_init / (but->block->aspect / UI_DPI_FAC);
|
||||
const float icon_padding = 2 * UI_DPI_FAC;
|
||||
|
|
|
@ -175,7 +175,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value);
|
|||
|
||||
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description);
|
||||
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision);
|
||||
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive);
|
||||
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive);
|
||||
|
||||
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *updatefunc);
|
||||
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable);
|
||||
|
|
|
@ -184,6 +184,7 @@ typedef enum PropertyFlag {
|
|||
|
||||
/* icon */
|
||||
PROP_ICONS_CONSECUTIVE = (1 << 12),
|
||||
PROP_ICONS_REVERSE = (1 << 8),
|
||||
|
||||
/* hidden in the user interface */
|
||||
PROP_HIDDEN = (1 << 19),
|
||||
|
|
|
@ -1426,11 +1426,13 @@ void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *d
|
|||
prop->description = description;
|
||||
}
|
||||
|
||||
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive)
|
||||
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
|
||||
{
|
||||
prop->icon = icon;
|
||||
if (consecutive)
|
||||
if (consecutive != 0)
|
||||
prop->flag |= PROP_ICONS_CONSECUTIVE;
|
||||
if (consecutive < 0)
|
||||
prop->flag |= PROP_ICONS_REVERSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue