diff options
author | Hans Goudey <h.goudey@me.com> | 2020-08-12 21:19:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-08-12 21:19:05 +0300 |
commit | 31705201dddebf7e3be5c4533b89f380aad1ede1 (patch) | |
tree | 53c8be86b15e9ebd96dd60cad52e6acac8ce2324 /source/blender/editors/interface/interface_layout.c | |
parent | ea4c327c977223922c41c889fa2bd51403409dca (diff) | |
parent | 337b6d075880ea44ff5183804a387dc98673ffb9 (diff) |
Merge branch 'master' into active-fcurve-keyframe
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 181 |
1 files changed, 119 insertions, 62 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index f027a62cbfd..888cacb64eb 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -674,7 +674,7 @@ static void ui_item_array(uiLayout *layout, /* show checkboxes for rna on a non-emboss block (menu for eg) */ if (type == PROP_BOOLEAN && - ELEM(layout->root->block->dt, UI_EMBOSS_NONE, UI_EMBOSS_PULLDOWN)) { + ELEM(layout->root->block->emboss, UI_EMBOSS_NONE, UI_EMBOSS_PULLDOWN)) { boolarr = MEM_callocN(sizeof(bool) * len, __func__); RNA_property_boolean_get_array(ptr, prop, boolarr); } @@ -937,7 +937,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, int h, int flag) { - uiLayout *sub; + uiLayout *sub = layout; uiBut *but = NULL; PropertyType type; PropertySubType subtype; @@ -945,14 +945,20 @@ static uiBut *ui_item_with_label(uiLayout *layout, #ifdef UI_PROP_DECORATE uiLayout *layout_prop_decorate = NULL; const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0); + const bool use_prop_decorate = use_prop_sep && (layout->item.flag & UI_ITEM_PROP_DECORATE) && + (layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0; #endif - /* Previously 'align' was enabled to make sure the label is spaced closely to the button. - * Set the space to zero instead as aligning a large number of labels can end up aligning - * thousands of buttons when displaying key-map search (a heavy operation), see: T78636. */ - sub = uiLayoutRow(layout, false); - sub->space = 0; - UI_block_layout_set_current(block, sub); + UI_block_layout_set_current(block, layout); + + /* Only add new row if more than 1 item will be added. */ + if (name[0] || use_prop_decorate) { + /* Also avoid setting 'align' if possible. Set the space to zero instead as aligning a large + * number of labels can end up aligning thousands of buttons when displaying key-map search (a + * heavy operation), see: T78636. */ + sub = uiLayoutRow(layout, layout->align); + sub->space = 0; + } #ifdef UI_PROP_DECORATE if (name[0]) { @@ -1050,11 +1056,8 @@ static uiBut *ui_item_with_label(uiLayout *layout, #ifdef UI_PROP_DECORATE /* Only for alignment. */ - if (use_prop_sep) { /* Flag may have been unset meanwhile. */ - if ((layout->item.flag & UI_ITEM_PROP_DECORATE) && - (layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0) { - uiItemL(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1); - } + if (use_prop_decorate) { /* Note that sep flag may have been unset meanwhile. */ + uiItemL(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1); } #endif /* UI_PROP_DECORATE */ @@ -2275,7 +2278,7 @@ void uiItemFullR(uiLayout *layout, /* property with separate label */ else if (type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) { but = ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h, flag); - ui_but_add_search(but, ptr, prop, NULL, NULL); + but = ui_but_add_search(but, ptr, prop, NULL, NULL); if (layout->redalert) { UI_but_flag_enable(but, UI_BUT_REDALERT); @@ -2330,7 +2333,7 @@ void uiItemFullR(uiLayout *layout, /* 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)) { + (but->emboss & UI_EMBOSS_NONE)) { UI_but_flag_enable(but, UI_BUT_LIST_ITEM); } @@ -2648,7 +2651,10 @@ static void ui_rna_collection_search_arg_free_fn(void *ptr) MEM_freeN(ptr); } -void ui_but_add_search( +/** + * \note May reallocate \a but, so the possibly new address is returned. + */ +uiBut *ui_but_add_search( uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop) { StructRNA *ptype; @@ -2666,11 +2672,13 @@ void ui_but_add_search( /* turn button into search button */ if (searchprop) { uiRNACollectionSearch *coll_search = MEM_mallocN(sizeof(*coll_search), __func__); + uiButSearch *search_but; - but->type = UI_BTYPE_SEARCH_MENU; + but = ui_but_change_type(but, UI_BTYPE_SEARCH_MENU); + search_but = (uiButSearch *)but; + search_but->rnasearchpoin = *searchptr; + search_but->rnasearchprop = searchprop; but->hardmax = MAX2(but->hardmax, 256.0f); - but->rnasearchpoin = *searchptr; - but->rnasearchprop = searchprop; but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; if (RNA_property_is_unlink(prop)) { but->flag |= UI_BUT_VALUE_CLEAR; @@ -2704,6 +2712,8 @@ void ui_but_add_search( * so other code might have already set but->type to search menu... */ but->flag |= UI_BUT_DISABLED; } + + return but; } void uiItemPointerR_prop(uiLayout *layout, @@ -2936,29 +2946,28 @@ void uiItemMContents(uiLayout *layout, const char *menuname) void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index) { uiBlock *block = layout->root->block; - uiBut *but = NULL; - uiLayout *col; + UI_block_layout_set_current(block, layout); col = uiLayoutColumn(layout, false); col->space = 0; col->emboss = UI_EMBOSS_NONE; if (ELEM(NULL, ptr, prop) || !RNA_property_animateable(ptr, prop)) { - but = uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_BLANK1, - 0, - 0, - UI_UNIT_X, - UI_UNIT_Y, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - ""); + uiBut *but = uiDefIconBut(block, + UI_BTYPE_DECORATOR, + 0, + ICON_BLANK1, + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + ""); but->flag |= UI_BUT_DISABLED; return; } @@ -2968,27 +2977,28 @@ void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, /* Loop for the array-case, but only do in case of an expanded array. */ for (int i = 0; i < (is_expand ? RNA_property_array_length(ptr, prop) : 1); i++) { - but = uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_DOT, - 0, - 0, - UI_UNIT_X, - UI_UNIT_Y, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - TIP_("Animate property")); - UI_but_func_set(but, ui_but_anim_decorate_cb, but, NULL); - but->flag |= UI_BUT_UNDO | UI_BUT_DRAG_LOCK; + uiButDecorator *decorator_but = (uiButDecorator *)uiDefIconBut(block, + UI_BTYPE_DECORATOR, + 0, + ICON_DOT, + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + TIP_("Animate property")); + + UI_but_func_set(&decorator_but->but, ui_but_anim_decorate_cb, decorator_but, NULL); + decorator_but->but.flag |= UI_BUT_UNDO | UI_BUT_DRAG_LOCK; /* Reusing RNA search members, setting actual RNA data has many side-effects. */ - but->rnasearchpoin = *ptr; - but->rnasearchprop = prop; + decorator_but->rnapoin = *ptr; + decorator_but->rnaprop = prop; /* ui_def_but_rna() sets non-array buttons to have a RNA index of 0. */ - but->custom_data = POINTER_FROM_INT((!is_array || is_expand) ? i : index); + decorator_but->rnaindex = (!is_array || is_expand) ? i : index; } } @@ -3828,7 +3838,7 @@ static void ui_litem_layout_radial(uiLayout *litem) bitem->but->rect.xmax += 1.5f * UI_UNIT_X; /* enable drawing as pie item if supported by widget */ if (ui_item_is_radial_drawable(bitem)) { - bitem->but->dt = UI_EMBOSS_RADIAL; + bitem->but->emboss = UI_EMBOSS_RADIAL; bitem->but->drawflag |= UI_BUT_ICON_LEFT; } } @@ -4816,8 +4826,6 @@ void ui_layout_list_set_labels_active(uiLayout *layout) uiLayout *uiLayoutListBox(uiLayout *layout, uiList *ui_list, - PointerRNA *ptr, - PropertyRNA *prop, PointerRNA *actptr, PropertyRNA *actprop) { @@ -4826,8 +4834,6 @@ uiLayout *uiLayoutListBox(uiLayout *layout, but->custom_data = ui_list; - but->rnasearchpoin = *ptr; - but->rnasearchprop = prop; but->rnapoin = *actptr; but->rnaprop = actprop; @@ -5036,7 +5042,7 @@ float uiLayoutGetUnitsY(uiLayout *layout) int uiLayoutGetEmboss(uiLayout *layout) { if (layout->emboss == UI_EMBOSS_UNDEFINED) { - return layout->root->block->dt; + return layout->root->block->emboss; } return layout->emboss; } @@ -5404,6 +5410,7 @@ void ui_layout_add_but(uiLayout *layout, uiBut *but) else { BLI_addtail(&layout->items, bitem); } + but->layout = layout; if (layout->context) { but->context = layout->context; @@ -5411,8 +5418,32 @@ void ui_layout_add_but(uiLayout *layout, uiBut *but) } if (layout->emboss != UI_EMBOSS_UNDEFINED) { - but->dt = layout->emboss; + but->emboss = layout->emboss; + } +} + +bool ui_layout_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but) +{ + ListBase *child_list = layout->child_items_layout ? &layout->child_items_layout->items : + &layout->items; + + LISTBASE_FOREACH (uiItem *, item, child_list) { + if (item->type == ITEM_BUTTON) { + uiButtonItem *bitem = (uiButtonItem *)item; + + if (bitem->but == old_but_ptr) { + bitem->but = new_but; + return true; + } + } + else { + if (ui_layout_replace_but_ptr((uiLayout *)item, old_but_ptr, new_but)) { + return true; + } + } } + + return false; } void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size) @@ -5540,6 +5571,26 @@ void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout) } } +static bool ui_layout_has_panel_label(const uiLayout *layout, const PanelType *pt) +{ + LISTBASE_FOREACH (uiItem *, subitem, &layout->items) { + if (subitem->type == ITEM_BUTTON) { + uiButtonItem *bitem = (uiButtonItem *)subitem; + if (!(bitem->but->flag & UI_HIDDEN) && STREQ(bitem->but->str, pt->label)) { + return true; + } + } + else { + uiLayout *litem = (uiLayout *)subitem; + if (ui_layout_has_panel_label(litem, pt)) { + return true; + } + } + } + + return false; +} + static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout, bool show_header) { Panel *panel = MEM_callocN(sizeof(Panel), "popover panel"); @@ -5556,7 +5607,13 @@ static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout, pt->draw_header(C, panel); panel->layout = NULL; } - uiItemL(row, CTX_IFACE_(pt->translation_context, pt->label), ICON_NONE); + + /* draw_header() is often used to add a checkbox to the header. If we add the label like below + * the label is disconnected from the checkbox, adding a weird looking gap. As workaround, let + * the checkbox add the label instead. */ + if (!ui_layout_has_panel_label(row, pt)) { + uiItemL(row, CTX_IFACE_(pt->translation_context, pt->label), ICON_NONE); + } } panel->layout = layout; |