[Bf-blender-cvs] [c470620c169] topbar: Rework tab data storing to fix glitches & get rid of hacks
Julian Eisel
noreply at git.blender.org
Sun Oct 15 15:20:53 CEST 2017
Commit: c470620c169953e5c45ce3221d7f3dc3638814b9
Author: Julian Eisel
Date: Sun Oct 15 15:06:13 2017 +0200
Branches: topbar
https://developer.blender.org/rBc470620c169953e5c45ce3221d7f3dc3638814b9
Rework tab data storing to fix glitches & get rid of hacks
Fixes glitch where hovering an active tab would make the tab appear like
a hovered non-active one.
Still not the most beautiful solution, but it's as good as it can get
with our current UI code I'm afraid.
===================================================================
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/interface/interface_widgets.c
===================================================================
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 35c69ea855f..c7d9cb27149 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1484,6 +1484,18 @@ int ui_but_is_pushed_ex(uiBut *but, double *value)
if (*value == (double)but->hardmax) is_push = true;
}
break;
+ case UI_BTYPE_TAB:
+ if (but->rnaprop && but->custom_data) {
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ if (RNA_property_type(but->rnaprop) == PROP_POINTER) {
+ PointerRNA active_ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
+ if (active_ptr.data == but->custom_data) {
+ is_push = true;
+ }
+ }
+ }
+ break;
default:
is_push = -1;
break;
@@ -2173,14 +2185,23 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
*r_use_exp_float = false;
}
- if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
+ if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
PropertyType type;
const char *buf = NULL;
int buf_len;
type = RNA_property_type(but->rnaprop);
- if (type == PROP_STRING) {
+ if ((but->type == UI_BTYPE_TAB) && (but->custom_data)) {
+ StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop);
+ PointerRNA ptr;
+
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr);
+ buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len);
+ }
+ else if (type == PROP_STRING) {
/* RNA string */
buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len);
}
@@ -2216,7 +2237,7 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
MEM_freeN((void *)buf);
}
}
- else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
+ else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
/* string */
BLI_strncpy(str, but->poin, maxlen);
return;
@@ -2426,18 +2447,16 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
return true;
}
else if (type == PROP_POINTER) {
- /* RNA pointer */
- PointerRNA ptr, rptr;
- PropertyRNA *prop;
-
if (str[0] == '\0') {
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
return true;
}
else {
- ptr = but->rnasearchpoin;
- prop = but->rnasearchprop;
-
+ /* RNA pointer */
+ PointerRNA rptr;
+ PointerRNA ptr = but->rnasearchpoin;
+ PropertyRNA *prop = but->rnasearchprop;
+
if (prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
@@ -2459,6 +2478,21 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
}
}
}
+ else if (but->type == UI_BTYPE_TAB) {
+ if (but->rnaprop && but->custom_data) {
+ StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop);
+ PointerRNA ptr;
+ PropertyRNA *prop;
+
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr);
+ prop = RNA_struct_name_property(ptr_type);
+ if (RNA_property_editable(&ptr, prop)) {
+ RNA_property_string_set(&ptr, prop, str);
+ }
+ }
+ }
else if (but->type == UI_BTYPE_TEXT) {
/* string */
if (!but->poin || (str[0] == '\0')) {
@@ -2473,7 +2507,7 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
return true;
}
- else if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
+ else if (but->type == UI_BTYPE_SEARCH_MENU) {
/* string */
BLI_strncpy(but->poin, str, but->hardmax);
return true;
@@ -3010,6 +3044,7 @@ void ui_but_update_ex(uiBut *but, const bool validate)
case UI_BTYPE_TEXT:
case UI_BTYPE_SEARCH_MENU:
+ case UI_BTYPE_TAB:
if (!but->editstr) {
char str[UI_MAX_DRAW_STR];
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 6ce399b4b39..ce1aad370d5 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -941,13 +941,12 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data)
{
if (data->str) {
- ui_apply_but_TEX(C, but, data);
- return;
+ ui_but_string_set(C, but, data->str);
+ ui_but_update_edited(but);
+ }
+ else {
+ ui_apply_but_func(C, but);
}
-
- ui_but_value_set(but, but->hardmax);
-
- ui_apply_but_func(C, but);
data->retval = but->retval;
data->applied = true;
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index b1e3ed27e01..0a32b1febf4 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -235,7 +235,7 @@ typedef struct TemplateID {
} TemplateID;
/* Search browse menu, assign */
-static void id_search_call_cb(bContext *C, void *arg_template, void *item)
+static void template_ID_set_property_cb(bContext *C, void *arg_template, void *item)
{
TemplateID *template = (TemplateID *)arg_template;
@@ -249,15 +249,6 @@ static void id_search_call_cb(bContext *C, void *arg_template, void *item)
}
}
-static void id_rename_cb(bContext *C, void *arg, char *origstr)
-{
- ID *id = arg;
-
- if (origstr && !STREQ(id->name + 2, origstr)) {
- BLI_libblock_ensure_unique_name(CTX_data_main(C), id->name);
- }
-}
-
/* ID Search browse menu, do the search */
static void id_search_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
{
@@ -311,7 +302,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
active_item_ptr = RNA_property_pointer_get(&template.ptr, template.prop);
return template_common_search_menu(
- C, ar, id_search_cb, &template, id_search_call_cb, active_item_ptr.data,
+ C, ar, id_search_cb, &template, template_ID_set_property_cb, active_item_ptr.data,
template.prv_rows, template.prv_cols);
}
@@ -716,23 +707,21 @@ static void template_ID_tabs(
for (ID *id = template->idlb->first; id; id = id->next) {
wmOperatorType *unlink_ot = WM_operatortype_find(unlinkop, false);
- const char *id_name = id->name + 2;
const bool is_active = active_ptr.data == id;
- const unsigned int but_width = UI_fontstyle_string_width(&style->widgetlabel, id_name) + UI_UNIT_X +
+ const unsigned int but_width = UI_fontstyle_string_width(&style->widgetlabel, id->name + 2) + UI_UNIT_X +
(is_active ? ICON_DEFAULT_WIDTH_SCALE : 0);
uiButTab *tab;
tab = (uiButTab *)uiDefButR_prop(
- block, UI_BTYPE_TAB, 0, id_name, 0, 0, but_width, UI_UNIT_Y,
+ block, UI_BTYPE_TAB, 0, "", 0, 0, but_width, UI_UNIT_Y,
&template->ptr, template->prop, 0, 0.0f,
sizeof(id->name) - 2, 0.0f, 0.0f, "");
- UI_but_funcN_set(&tab->but, id_search_call_cb, MEM_dupallocN(template), id);
- tab->but.poin = &id->name[2];
+ UI_but_funcN_set(&tab->but, template_ID_set_property_cb, MEM_dupallocN(template), id);
+ tab->but.custom_data = (void *)id;
tab->unlink_ot = unlink_ot;
- UI_but_func_rename_set(&tab->but, id_rename_cb, id);
if (is_active) {
- UI_but_flag_enable(&tab->but, UI_SELECT | UI_BUT_VALUE_CLEAR);
+ UI_but_flag_enable(&tab->but, UI_BUT_VALUE_CLEAR);
}
UI_but_drawflag_enable(&tab->but, but_align);
}
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index dfdd65bb386..532b98990f3 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -3607,8 +3607,8 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
break;
case UI_WTYPE_TAB:
- wt.draw = widget_tab;
wt.wcol_theme = &btheme->tui.wcol_tab;
+ wt.draw = widget_tab;
break;
case UI_WTYPE_TOOLTIP:
More information about the Bf-blender-cvs
mailing list