Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_layout.c
| Show First 20 Lines • Show All 2,272 Lines • ▼ Show 20 Lines | #endif /* UI_PROP_DECORATE */ | ||||
| } | } | ||||
| /* expanded enum */ | /* expanded enum */ | ||||
| else if (type == PROP_ENUM && expand) { | else if (type == PROP_ENUM && expand) { | ||||
| ui_item_enum_expand(layout, block, ptr, prop, name, h, icon_only); | ui_item_enum_expand(layout, block, ptr, prop, name, h, icon_only); | ||||
| } | } | ||||
| /* property with separate label */ | /* property with separate label */ | ||||
| else if (type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) { | 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); | 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) { | if (layout->redalert) { | ||||
| UI_but_flag_enable(but, UI_BUT_REDALERT); | UI_but_flag_enable(but, UI_BUT_REDALERT); | ||||
| } | } | ||||
| if (layout->activate_init) { | if (layout->activate_init) { | ||||
| UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); | UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 357 Lines • ▼ Show 20 Lines | |||||
| static void ui_rna_collection_search_free_cb(void *ptr) | static void ui_rna_collection_search_free_cb(void *ptr) | ||||
| { | { | ||||
| uiRNACollectionSearch *coll_search = ptr; | uiRNACollectionSearch *coll_search = ptr; | ||||
| UI_butstore_free(coll_search->butstore_block, coll_search->butstore); | UI_butstore_free(coll_search->butstore_block, coll_search->butstore); | ||||
| MEM_freeN(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) | uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop) | ||||
| { | { | ||||
| StructRNA *ptype; | StructRNA *ptype; | ||||
| PointerRNA sptr; | PointerRNA sptr; | ||||
| /* for ID's we do automatic lookup */ | /* for ID's we do automatic lookup */ | ||||
| if (!searchprop) { | if (!searchprop) { | ||||
| if (RNA_property_type(prop) == PROP_POINTER) { | if (RNA_property_type(prop) == PROP_POINTER) { | ||||
| ptype = RNA_property_pointer_type(ptr, prop); | ptype = RNA_property_pointer_type(ptr, prop); | ||||
| search_id_collection(ptype, &sptr, &searchprop); | search_id_collection(ptype, &sptr, &searchprop); | ||||
| searchptr = &sptr; | searchptr = &sptr; | ||||
| } | } | ||||
| } | } | ||||
| /* turn button into search button */ | /* turn button into search button */ | ||||
| if (searchprop) { | if (searchprop) { | ||||
| uiRNACollectionSearch *coll_search = MEM_mallocN(sizeof(*coll_search), __func__); | 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->hardmax = MAX2(but->hardmax, 256.0f); | ||||
| but->rnasearchpoin = *searchptr; | |||||
| but->rnasearchprop = searchprop; | |||||
| but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | ||||
| if (RNA_property_is_unlink(prop)) { | if (RNA_property_is_unlink(prop)) { | ||||
| but->flag |= UI_BUT_VALUE_CLEAR; | but->flag |= UI_BUT_VALUE_CLEAR; | ||||
| } | } | ||||
| coll_search->target_ptr = *ptr; | coll_search->target_ptr = *ptr; | ||||
| coll_search->target_prop = prop; | coll_search->target_prop = prop; | ||||
| coll_search->search_ptr = *searchptr; | coll_search->search_ptr = *searchptr; | ||||
| Show All 18 Lines | UI_but_func_search_set(but, | ||||
| NULL, | NULL, | ||||
| NULL); | NULL); | ||||
| } | } | ||||
| else if (but->type == UI_BTYPE_SEARCH_MENU) { | else if (but->type == UI_BTYPE_SEARCH_MENU) { | ||||
| /* In case we fail to find proper searchprop, | /* In case we fail to find proper searchprop, | ||||
| * so other code might have already set but->type to search menu... */ | * so other code might have already set but->type to search menu... */ | ||||
| but->flag |= UI_BUT_DISABLED; | but->flag |= UI_BUT_DISABLED; | ||||
| } | } | ||||
| return but; | |||||
| } | } | ||||
| void uiItemPointerR_prop(uiLayout *layout, | void uiItemPointerR_prop(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| PointerRNA *searchptr, | PointerRNA *searchptr, | ||||
| PropertyRNA *searchprop, | PropertyRNA *searchprop, | ||||
| const char *name, | const char *name, | ||||
| ▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Insert a decorator item for a button with the same property as \a prop. | * Insert a decorator item for a button with the same property as \a prop. | ||||
| * To force inserting a blank dummy element, NULL can be passed for \a ptr and \a prop. | * To force inserting a blank dummy element, NULL can be passed for \a ptr and \a prop. | ||||
| */ | */ | ||||
| void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index) | void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index) | ||||
| { | { | ||||
| uiBlock *block = layout->root->block; | uiBlock *block = layout->root->block; | ||||
| uiBut *but = NULL; | |||||
| uiLayout *col; | uiLayout *col; | ||||
| UI_block_layout_set_current(block, layout); | UI_block_layout_set_current(block, layout); | ||||
| col = uiLayoutColumn(layout, false); | col = uiLayoutColumn(layout, false); | ||||
| col->space = 0; | col->space = 0; | ||||
| col->emboss = UI_EMBOSS_NONE; | col->emboss = UI_EMBOSS_NONE; | ||||
| if (ELEM(NULL, ptr, prop) || !RNA_property_animateable(ptr, prop)) { | if (ELEM(NULL, ptr, prop) || !RNA_property_animateable(ptr, prop)) { | ||||
| but = uiDefIconBut(block, | uiBut *but = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_DECORATOR, | ||||
| 0, | 0, | ||||
| ICON_BLANK1, | ICON_BLANK1, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | NULL, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| ""); | ""); | ||||
| but->flag |= UI_BUT_DISABLED; | but->flag |= UI_BUT_DISABLED; | ||||
| return; | return; | ||||
| } | } | ||||
| const bool is_expand = ui_item_rna_is_expand(prop, index, 0); | const bool is_expand = ui_item_rna_is_expand(prop, index, 0); | ||||
| const bool is_array = RNA_property_array_check(prop); | const bool is_array = RNA_property_array_check(prop); | ||||
| /* Loop for the array-case, but only do in case of an expanded array. */ | /* 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++) { | for (int i = 0; i < (is_expand ? RNA_property_array_length(ptr, prop) : 1); i++) { | ||||
| but = uiDefIconBut(block, | uiButDecorator *decorator_but = (uiButDecorator *)uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_DECORATOR, | ||||
| 0, | 0, | ||||
| ICON_DOT, | ICON_DOT, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | NULL, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Animate property")); | TIP_("Animate property")); | ||||
| UI_but_func_set(but, ui_but_anim_decorate_cb, but, NULL); | |||||
| but->flag |= UI_BUT_UNDO | UI_BUT_DRAG_LOCK; | 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. */ | /* Reusing RNA search members, setting actual RNA data has many side-effects. */ | ||||
| but->rnasearchpoin = *ptr; | decorator_but->rnapoin = *ptr; | ||||
| but->rnasearchprop = prop; | decorator_but->rnaprop = prop; | ||||
| /* ui_def_but_rna() sets non-array buttons to have a RNA index of 0. */ | /* 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; | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Insert a decorator item for a button with the same property as \a prop. | * Insert a decorator item for a button with the same property as \a prop. | ||||
| * To force inserting a blank dummy element, NULL can be passed for \a ptr and \a propname. | * To force inserting a blank dummy element, NULL can be passed for \a ptr and \a propname. | ||||
| */ | */ | ||||
| void uiItemDecoratorR(uiLayout *layout, PointerRNA *ptr, const char *propname, int index) | void uiItemDecoratorR(uiLayout *layout, PointerRNA *ptr, const char *propname, int index) | ||||
| ▲ Show 20 Lines • Show All 1,812 Lines • ▼ Show 20 Lines | for (bitem = layout->items.first; bitem; bitem = bitem->item.next) { | ||||
| else if (bitem->but->flag & UI_BUT_LIST_ITEM) { | else if (bitem->but->flag & UI_BUT_LIST_ITEM) { | ||||
| UI_but_flag_enable(bitem->but, UI_SELECT); | UI_but_flag_enable(bitem->but, UI_SELECT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| uiLayout *uiLayoutListBox(uiLayout *layout, | uiLayout *uiLayoutListBox(uiLayout *layout, | ||||
| uiList *ui_list, | uiList *ui_list, | ||||
| PointerRNA *ptr, | |||||
| PropertyRNA *prop, | |||||
| PointerRNA *actptr, | PointerRNA *actptr, | ||||
| PropertyRNA *actprop) | PropertyRNA *actprop) | ||||
| { | { | ||||
| uiLayoutItemBx *box = ui_layout_box(layout, UI_BTYPE_LISTBOX); | uiLayoutItemBx *box = ui_layout_box(layout, UI_BTYPE_LISTBOX); | ||||
| uiBut *but = box->roundbox; | uiBut *but = box->roundbox; | ||||
| but->custom_data = ui_list; | but->custom_data = ui_list; | ||||
| but->rnasearchpoin = *ptr; | |||||
| but->rnasearchprop = prop; | |||||
| but->rnapoin = *actptr; | but->rnapoin = *actptr; | ||||
| but->rnaprop = actprop; | but->rnaprop = actprop; | ||||
| /* only for the undo string */ | /* only for the undo string */ | ||||
| if (but->flag & UI_BUT_UNDO) { | if (but->flag & UI_BUT_UNDO) { | ||||
| but->tip = RNA_property_description(actprop); | but->tip = RNA_property_description(actprop); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Lines | void ui_layout_add_but(uiLayout *layout, uiBut *but) | ||||
| } | } | ||||
| if (layout->child_items_layout) { | if (layout->child_items_layout) { | ||||
| BLI_addtail(&layout->child_items_layout->items, bitem); | BLI_addtail(&layout->child_items_layout->items, bitem); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_addtail(&layout->items, bitem); | BLI_addtail(&layout->items, bitem); | ||||
| } | } | ||||
| but->layout = layout; | |||||
| if (layout->context) { | if (layout->context) { | ||||
| but->context = layout->context; | but->context = layout->context; | ||||
| but->context->used = true; | but->context->used = true; | ||||
| } | } | ||||
| if (layout->emboss != UI_EMBOSS_UNDEFINED) { | if (layout->emboss != UI_EMBOSS_UNDEFINED) { | ||||
| but->dt = layout->emboss; | but->dt = 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) | void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size) | ||||
| { | { | ||||
| if (fixed_size) { | if (fixed_size) { | ||||
| layout->item.flag |= UI_ITEM_FIXED_SIZE; | layout->item.flag |= UI_ITEM_FIXED_SIZE; | ||||
| } | } | ||||
| else { | else { | ||||
| layout->item.flag &= ~UI_ITEM_FIXED_SIZE; | layout->item.flag &= ~UI_ITEM_FIXED_SIZE; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines | |||||