UI Code Quality: Use derived structs for search buttons and decorators
The current on-size-fits-all `uiBut` creates quite a mess, where it's hard to reason about which members are free for use, under which conditions they are used and how. `uiBut` also has members that aren't used at times, violating the "don't pay for what you don't use" principle. To address this, we want to move to typed buttons, where `uiBut` is just a base struct and each type extends it as needed. That structures data better and type specific data is only available if it's actually used by a button type. Two trade-offs: * Many casts to the derived type have to be done. * Sometimes we change the button type after it's created. So I had to add logic to reallocate the button for use with the new, possibly derived struct. Ideally that wouldn't be needed, but for now that's what we have. Part of T74432. Differential Revision: https://developer.blender.org/D7610 Reviewed by: Brecht Van Lommel, Campbell Barton
This commit is contained in:
@@ -1148,10 +1148,11 @@ static bool jump_to_target_button(bContext *C, bool poll)
|
||||
/* For string properties with prop_search, look up the search collection item. */
|
||||
if (type == PROP_STRING) {
|
||||
const uiBut *but = UI_context_active_but_get(C);
|
||||
const uiButSearch *search_but = (but->type == UI_BTYPE_SEARCH_MENU) ? (uiButSearch *)but :
|
||||
NULL;
|
||||
|
||||
if (but->type == UI_BTYPE_SEARCH_MENU && but->search &&
|
||||
but->search->update_fn == ui_rna_collection_search_update_fn) {
|
||||
uiRNACollectionSearch *coll_search = but->search->arg;
|
||||
if (search_but && search_but->items_update_fn == ui_rna_collection_search_update_fn) {
|
||||
uiRNACollectionSearch *coll_search = search_but->arg;
|
||||
|
||||
char str_buf[MAXBONENAME];
|
||||
char *str_ptr = RNA_property_string_get_alloc(&ptr, prop, str_buf, sizeof(str_buf), NULL);
|
||||
|
||||
Reference in New Issue
Block a user