UI: Add search-create callback
Needed to support alternate search UI's, no functional changes.
This commit is contained in:
parent
aefb68c84d
commit
69b66d549b
Notes:
blender-bot
2023-02-14 07:31:35 +01:00
Referenced by issue #49601, Material menu length problem
|
@ -354,6 +354,7 @@ typedef void (*uiButHandleFunc)(struct bContext *C, void *arg1, void *arg2);
|
|||
typedef void (*uiButHandleRenameFunc)(struct bContext *C, void *arg, char *origstr);
|
||||
typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
|
||||
typedef int (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
|
||||
typedef struct ARegion *(*uiButSearchCreateFunc)(struct bContext *C, struct ARegion *butregion, uiBut *but);
|
||||
typedef void (*uiButSearchFunc)(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
|
||||
/* Must return allocated string. */
|
||||
typedef char *(*uiButToolTipFunc)(struct bContext *C, void *argN, const char *tip);
|
||||
|
@ -680,7 +681,9 @@ uiBut *UI_block_links_find_inlink(uiBlock *block, void *poin);
|
|||
/* use inside searchfunc to add items */
|
||||
bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid);
|
||||
/* bfunc gets search item *poin as arg2, or if NULL the old string */
|
||||
void UI_but_func_search_set(uiBut *but, uiButSearchFunc sfunc, void *arg1, uiButHandleFunc bfunc, void *active);
|
||||
void UI_but_func_search_set(
|
||||
uiBut *but, uiButSearchCreateFunc cfunc, uiButSearchFunc sfunc,
|
||||
void *arg1, uiButHandleFunc bfunc, void *active);
|
||||
/* height in pixels, it's using hardcoded values still */
|
||||
int UI_searchbox_size_y(void);
|
||||
int UI_searchbox_size_x(void);
|
||||
|
|
|
@ -4320,9 +4320,19 @@ uiBut *uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxle
|
|||
* \param arg: user value,
|
||||
* \param active: when set, button opens with this item visible and selected.
|
||||
*/
|
||||
void UI_but_func_search_set(uiBut *but, uiButSearchFunc sfunc, void *arg, uiButHandleFunc bfunc, void *active)
|
||||
void UI_but_func_search_set(
|
||||
uiBut *but,
|
||||
uiButSearchCreateFunc search_create_func,
|
||||
uiButSearchFunc search_func, void *arg,
|
||||
uiButHandleFunc bfunc, void *active)
|
||||
{
|
||||
but->search_func = sfunc;
|
||||
/* needed since callers don't have access to internal functions (as an alternative we could expose it) */
|
||||
if (search_create_func == NULL) {
|
||||
search_create_func = ui_searchbox_create_generic;
|
||||
}
|
||||
|
||||
but->search_create_func = search_create_func;
|
||||
but->search_func = search_func;
|
||||
but->search_arg = arg;
|
||||
|
||||
UI_but_func_set(but, bfunc, arg, active);
|
||||
|
@ -4400,7 +4410,9 @@ uiBut *uiDefSearchButO_ptr(
|
|||
uiBut *but;
|
||||
|
||||
but = uiDefSearchBut(block, arg, retval, icon, maxlen, x, y, width, height, a1, a2, tip);
|
||||
UI_but_func_search_set(but, operator_enum_search_cb, but, operator_enum_call_cb, NULL);
|
||||
UI_but_func_search_set(
|
||||
but, ui_searchbox_create_generic, operator_enum_search_cb,
|
||||
but, operator_enum_call_cb, NULL);
|
||||
|
||||
but->optype = ot;
|
||||
but->opcontext = WM_OP_EXEC_DEFAULT;
|
||||
|
|
|
@ -3066,7 +3066,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
|
|||
|
||||
/* optional searchbox */
|
||||
if (but->type == UI_BTYPE_SEARCH_MENU) {
|
||||
data->searchbox = ui_searchbox_create(C, data->region, but);
|
||||
data->searchbox = but->search_create_func(C, data->region, but);
|
||||
ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,7 @@ struct uiBut {
|
|||
uiButCompleteFunc autocomplete_func;
|
||||
void *autofunc_arg;
|
||||
|
||||
uiButSearchCreateFunc search_create_func;
|
||||
uiButSearchFunc search_func;
|
||||
void *search_arg;
|
||||
|
||||
|
@ -591,7 +592,7 @@ void ui_color_picker_to_rgb_v(const float r_cp[3], float rgb[3]);
|
|||
void ui_color_picker_to_rgb(float r_cp0, float r_cp1, float r_cp2, float *r, float *g, float *b);
|
||||
|
||||
/* searchbox for string button */
|
||||
ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
|
||||
ARegion *ui_searchbox_create_generic(struct bContext *C, struct ARegion *butregion, uiBut *but);
|
||||
bool ui_searchbox_inside(struct ARegion *ar, int x, int y);
|
||||
int ui_searchbox_find_index(struct ARegion *ar, const char *name);
|
||||
void ui_searchbox_update(struct bContext *C, struct ARegion *ar, uiBut *but, const bool reset);
|
||||
|
|
|
@ -1672,7 +1672,7 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
|
|||
but->str[0] = 0;
|
||||
}
|
||||
|
||||
UI_but_func_search_set(but, rna_search_cb, but, NULL, NULL);
|
||||
UI_but_func_search_set(but, ui_searchbox_create_generic, rna_search_cb, but, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -829,7 +829,7 @@ int UI_searchbox_size_y(void)
|
|||
|
||||
int UI_searchbox_size_x(void)
|
||||
{
|
||||
return 12 * UI_UNIT_X;
|
||||
return 10 * UI_UNIT_X;
|
||||
}
|
||||
|
||||
int UI_search_items_find_index(uiSearchItems *items, const char *name)
|
||||
|
@ -1164,7 +1164,7 @@ static void ui_searchbox_region_free_cb(ARegion *ar)
|
|||
ar->regiondata = NULL;
|
||||
}
|
||||
|
||||
ARegion *ui_searchbox_create(bContext *C, ARegion *butregion, uiBut *but)
|
||||
ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiBut *but)
|
||||
{
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
uiStyle *style = UI_style_get();
|
||||
|
|
|
@ -197,7 +197,9 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
|
|||
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y,
|
||||
template.prv_rows, template.prv_cols, "");
|
||||
UI_but_func_search_set(but, id_search_cb, &template, id_search_call_cb, idptr.data);
|
||||
UI_but_func_search_set(
|
||||
but, ui_searchbox_create_generic, id_search_cb,
|
||||
&template, id_search_call_cb, idptr.data);
|
||||
}
|
||||
/* list view */
|
||||
else {
|
||||
|
@ -207,7 +209,9 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
|
|||
/* fake button, it holds space for search items */
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 15, searchbox_width, searchbox_height, NULL, 0, 0, 0, 0, NULL);
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, searchbox_width, UI_UNIT_Y - 1, 0, 0, "");
|
||||
UI_but_func_search_set(but, id_search_cb, &template, id_search_call_cb, idptr.data);
|
||||
UI_but_func_search_set(
|
||||
but, ui_searchbox_create_generic, id_search_cb,
|
||||
&template, id_search_call_cb, idptr.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3303,7 +3307,9 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
|
|||
|
||||
void UI_but_func_operator_search(uiBut *but)
|
||||
{
|
||||
UI_but_func_search_set(but, operator_search_cb, NULL, operator_call_cb, NULL);
|
||||
UI_but_func_search_set(
|
||||
but, ui_searchbox_create_generic, operator_search_cb,
|
||||
NULL, operator_call_cb, NULL);
|
||||
}
|
||||
|
||||
void uiTemplateOperatorSearch(uiLayout *layout)
|
||||
|
|
|
@ -1018,7 +1018,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op)
|
|||
UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
|
||||
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, "");
|
||||
UI_but_func_search_set(but, node_find_cb, op->type, node_find_call_cb, NULL);
|
||||
UI_but_func_search_set(but, NULL, node_find_cb, op->type, node_find_call_cb, NULL);
|
||||
|
||||
/* fake button, it holds space for search items */
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);
|
||||
|
|
|
@ -185,7 +185,7 @@ static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase)
|
|||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 15, UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);
|
||||
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, 150, 19, 0, 0, "");
|
||||
UI_but_func_search_set(but, operator_search_cb, arg_listbase, operator_call_cb, NULL);
|
||||
UI_but_func_search_set(but, NULL, operator_search_cb, arg_listbase, operator_call_cb, NULL);
|
||||
|
||||
UI_block_bounds_set_normal(block, 6);
|
||||
UI_block_direction_set(block, UI_DIR_DOWN);
|
||||
|
|
|
@ -1900,8 +1900,14 @@ static void WM_OT_splash(wmOperatorType *ot)
|
|||
|
||||
|
||||
/* ***************** Search menu ************************* */
|
||||
static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *UNUSED(arg_op))
|
||||
|
||||
struct SearchPopupInit_Data {
|
||||
int size[2];
|
||||
};
|
||||
|
||||
static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *userdata)
|
||||
{
|
||||
const struct SearchPopupInit_Data *init_data = userdata;
|
||||
static char search[256] = "";
|
||||
wmEvent event;
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
|
@ -1911,11 +1917,12 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *UNUSED(arg_
|
|||
block = UI_block_begin(C, ar, "_popup", UI_EMBOSS);
|
||||
UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
|
||||
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, UI_searchbox_size_x(), UI_UNIT_Y, 0, 0, "");
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, init_data->size[0], UI_UNIT_Y, 0, 0, "");
|
||||
UI_but_func_operator_search(but);
|
||||
|
||||
/* fake button, it holds space for search items */
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - init_data->size[1],
|
||||
init_data->size[0], init_data->size[1], NULL, 0, 0, 0, 0, NULL);
|
||||
|
||||
UI_block_bounds_set_popup(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
|
||||
|
||||
|
@ -1934,9 +1941,16 @@ static int wm_search_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
|
|||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int wm_search_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
|
||||
{
|
||||
UI_popup_block_invoke(C, wm_block_search_menu, op);
|
||||
struct SearchPopupInit_Data data = {
|
||||
.size = {
|
||||
UI_searchbox_size_x(),
|
||||
UI_searchbox_size_y(),
|
||||
},
|
||||
};
|
||||
|
||||
UI_popup_block_invoke(C, wm_block_search_menu, &data);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue