Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-08-07 15:34:11 +0300
committerJulian Eisel <julian@blender.org>2020-08-07 16:17:52 +0300
commit49f088e2d0936ed3b5f08881a14ad83c19951791 (patch)
treee0d64f096345e3cda1e18a248a09a52869e37407 /source/blender/editors/interface/interface_intern.h
parent48e089375ebe4aeb30d60e9d8ef6f467280cf07d (diff)
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
Diffstat (limited to 'source/blender/editors/interface/interface_intern.h')
-rw-r--r--source/blender/editors/interface/interface_intern.h72
1 files changed, 46 insertions, 26 deletions
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index bf2971f93df..0dfa23a4332 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -147,19 +147,11 @@ enum {
/* max amount of items a radial menu (pie menu) can contain */
#define PIE_MAX_ITEMS 8
-struct uiButSearchData {
- uiButSearchCreateFn create_fn;
- uiButSearchUpdateFn update_fn;
- void *arg;
- uiButSearchArgFreeFn arg_free_fn;
- uiButSearchContextMenuFn context_menu_fn;
- uiButSearchTooltipFn tooltip_fn;
-
- const char *sep_string;
-};
-
struct uiBut {
struct uiBut *next, *prev;
+
+ /* Pointer back to the layout item holding this button. */
+ uiLayout *layout;
int flag, drawflag;
eButType type;
eButPointerType pointype;
@@ -214,8 +206,6 @@ struct uiBut {
uiButCompleteFunc autocomplete_func;
void *autofunc_arg;
- struct uiButSearchData *search;
-
uiButHandleRenameFunc rename_func;
void *rename_arg1;
void *rename_orig;
@@ -256,9 +246,6 @@ struct uiBut {
struct PropertyRNA *rnaprop;
int rnaindex;
- struct PointerRNA rnasearchpoin;
- struct PropertyRNA *rnasearchprop;
-
/* Operator data */
struct wmOperatorType *optype;
struct PointerRNA *opptr;
@@ -294,11 +281,41 @@ struct uiBut {
uiBlock *block;
};
+/** Derived struct for #UI_BTYPE_TAB */
typedef struct uiButTab {
uiBut but;
struct MenuType *menu;
} uiButTab;
+/** Derived struct for #UI_BTYPE_SEARCH_MENU */
+typedef struct uiButSearch {
+ uiBut but;
+
+ uiButSearchCreateFn popup_create_fn;
+ uiButSearchUpdateFn items_update_fn;
+ void *item_active;
+
+ void *arg;
+ uiButSearchArgFreeFn arg_free_fn;
+
+ uiButSearchContextMenuFn item_context_menu_fn;
+ uiButSearchTooltipFn item_tooltip_fn;
+
+ const char *item_sep_string;
+
+ struct PointerRNA rnasearchpoin;
+ struct PropertyRNA *rnasearchprop;
+} uiButSearch;
+
+/** Derived struct for #UI_BTYPE_DECORATOR */
+typedef struct uiButDecorator {
+ uiBut but;
+
+ struct PointerRNA rnapoin;
+ struct PropertyRNA *rnaprop;
+ int rnaindex;
+} uiButDecorator;
+
/**
* Additional, superimposed icon for a button, invoking an operator.
*/
@@ -493,6 +510,8 @@ extern void ui_window_to_region_rcti(const struct ARegion *region,
extern void ui_region_to_window(const struct ARegion *region, int *x, int *y);
extern void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r_rect);
+uiBut *ui_but_change_type(uiBut *but, eButType new_type);
+
extern double ui_but_value_get(uiBut *but);
extern void ui_but_value_set(uiBut *but, double value);
extern void ui_but_hsv_set(uiBut *but);
@@ -662,13 +681,13 @@ ColorPicker *ui_block_colorpicker_create(struct uiBlock *block);
/* Searchbox for string button */
struct ARegion *ui_searchbox_create_generic(struct bContext *C,
struct ARegion *butregion,
- uiBut *but);
+ uiButSearch *search_but);
struct ARegion *ui_searchbox_create_operator(struct bContext *C,
struct ARegion *butregion,
- uiBut *but);
+ uiButSearch *search_but);
struct ARegion *ui_searchbox_create_menu(struct bContext *C,
struct ARegion *butregion,
- uiBut *but);
+ uiButSearch *search_but);
bool ui_searchbox_inside(struct ARegion *region, int x, int y);
int ui_searchbox_find_index(struct ARegion *region, const char *name);
@@ -681,7 +700,7 @@ bool ui_searchbox_event(struct bContext *C,
const struct wmEvent *event);
bool ui_searchbox_apply(uiBut *but, struct ARegion *region);
void ui_searchbox_free(struct bContext *C, struct ARegion *region);
-void ui_but_search_refresh(uiBut *but);
+void ui_but_search_refresh(uiButSearch *but);
/* interface_region_menu_popup.c */
int ui_but_menu_step(uiBut *but, int step);
@@ -925,11 +944,12 @@ void ui_resources_free(void);
/* interface_layout.c */
void ui_layout_add_but(uiLayout *layout, uiBut *but);
-void ui_but_add_search(uiBut *but,
- PointerRNA *ptr,
- PropertyRNA *prop,
- PointerRNA *searchptr,
- PropertyRNA *searchprop);
+bool ui_layout_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but);
+uiBut *ui_but_add_search(uiBut *but,
+ PointerRNA *ptr,
+ PropertyRNA *prop,
+ PointerRNA *searchptr,
+ PropertyRNA *searchprop);
void ui_layout_list_set_labels_active(uiLayout *layout);
/* menu callback */
void ui_item_menutype_func(struct bContext *C, struct uiLayout *layout, void *arg_mt);
@@ -950,7 +970,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str);
void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra);
void ui_but_anim_decorate_cb(struct bContext *C, void *arg_but, void *arg_dummy);
-void ui_but_anim_decorate_update_from_flag(uiBut *but);
+void ui_but_anim_decorate_update_from_flag(uiButDecorator *but);
/* interface_query.c */
bool ui_but_is_editable(const uiBut *but) ATTR_WARN_UNUSED_RESULT;