UI: Improve search layout #112422

Open
Leon Schittek wants to merge 17 commits from lone_noel/blender:ui-search-box-layout into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
10 changed files with 196 additions and 128 deletions
Showing only changes of commit a960b87911 - Show all commits

View File

@ -1708,6 +1708,8 @@ void UI_but_func_search_set_listen(uiBut *but, uiButSearchListenFn listen_fn);
void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string);
void UI_but_func_search_set_results_are_suggestions(uiBut *but, bool value);
#define UI_SEARCHBOX_BOUNDS (6.0f * UI_SCALE_FAC)
#define UI_SEARCHBOX_TRIA_H (12.0f * UI_SCALE_FAC)
/**
* Height in pixels, it's using hard-coded values still.
*/

View File

@ -1186,6 +1186,7 @@ enum uiMenuItemSeparatorType {
/**
* Helper call to draw a menu item without a button.
*
* \param use_unpadded: TODO (LEON): Document what these are for!
* \param but_flag: Button flags (#uiBut.flag) indicating the state of the item, typically
* #UI_ACTIVE, #UI_BUT_DISABLED, #UI_BUT_INACTIVE.
* \param separator_type: The kind of separator which controls if and how the string is clipped.
@ -1194,6 +1195,9 @@ enum uiMenuItemSeparatorType {
*/
void ui_draw_menu_item(const uiFontStyle *fstyle,
rcti *rect,
rcti *back_rect,
float zoom,
bool use_unpadded,
const char *name,
int iconid,
int but_flag,
@ -1201,6 +1205,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
int *r_xmax);
void ui_draw_preview_item(const uiFontStyle *fstyle,
rcti *rect,
float zoom,
const char *name,
int iconid,
int but_flag,

View File

@ -43,8 +43,6 @@
#include "interface_intern.hh"
#include "interface_regions_intern.hh"
#define MENU_BORDER int(0.3f * U.widget_unit)
/* -------------------------------------------------------------------- */
/** \name Search Box Creation
* \{ */
@ -71,6 +69,8 @@ struct uiSearchItems {
struct uiSearchboxData {
rcti bbox;
uiFontStyle fstyle;
/** Region zoom level. */
float zoom;
uiSearchItems items;
bool size_set;
ARegion *butregion;
@ -168,7 +168,7 @@ bool UI_search_item_add(uiSearchItems *items,
int UI_searchbox_size_y()
{
return SEARCH_ITEMS * UI_UNIT_Y + 2 * UI_POPUP_MENU_TOP;
return SEARCH_ITEMS * UI_UNIT_Y + 2 * UI_SEARCHBOX_TRIA_H;
}
int UI_searchbox_size_x()
@ -233,32 +233,34 @@ static void ui_searchbox_select(bContext *C, ARegion *region, uiBut *but, int st
static void ui_searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr)
{
const float zoom = data->zoom;
const float tria_h = zoom * UI_SEARCHBOX_TRIA_H;
/* thumbnail preview */
if (data->preview) {
const int butw = (BLI_rcti_size_x(&data->bbox) - 2 * MENU_BORDER) / data->prv_cols;
const int buth = (BLI_rcti_size_y(&data->bbox) - 2 * MENU_BORDER) / data->prv_rows;
int row, col;
const int butw = BLI_rcti_size_x(&data->bbox) / data->prv_cols;
const int buth = (BLI_rcti_size_y(&data->bbox) - 2.0f * tria_h) / data->prv_rows;
const int col = itemnr % data->prv_cols;
const int row = itemnr / data->prv_cols;
*r_rect = data->bbox;
col = itemnr % data->prv_cols;
row = itemnr / data->prv_cols;
r_rect->xmin += MENU_BORDER + (col * butw);
r_rect->xmin += col * butw;
r_rect->xmax = r_rect->xmin + butw;
r_rect->ymax -= MENU_BORDER + (row * buth);
r_rect->ymax -= tria_h + row * buth;
r_rect->ymin = r_rect->ymax - buth;
}
/* list view */
else {
const int buth = (BLI_rcti_size_y(&data->bbox) - 2 * UI_POPUP_MENU_TOP) / SEARCH_ITEMS;
const int buth = (BLI_rcti_size_y(&data->bbox) - 2.0f * tria_h) / SEARCH_ITEMS;
*r_rect = data->bbox;
r_rect->xmin = data->bbox.xmin + 3.0f;
r_rect->xmax = data->bbox.xmax - 3.0f;
r_rect->ymax = data->bbox.ymax - UI_POPUP_MENU_TOP - itemnr * buth;
r_rect->xmin = data->bbox.xmin;
r_rect->xmax = data->bbox.xmax;
r_rect->ymax = data->bbox.ymax - tria_h - itemnr * buth;
r_rect->ymin = r_rect->ymax - buth;
}
}
@ -544,9 +546,46 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *region, uiBut *but, char *st
return match;
}
static void ui_searchbox_draw_clip_tri_down(rcti *rect, const float zoom)
{
const float x = BLI_rcti_cent_x(rect) - 0.5f * zoom * UI_ICON_SIZE;
const float y = rect->ymin - zoom * UI_ICON_SIZE -
0.5f * zoom * (UI_SEARCHBOX_TRIA_H - UI_ICON_SIZE) + U.pixelsize;
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw_ex(x,
y,
ICON_TRIA_DOWN,
U.inv_scale_factor / zoom,
1.0f,
0.0f,
NULL,
false,
UI_NO_ICON_OVERLAY_TEXT);
GPU_blend(GPU_BLEND_NONE);
}
static void ui_searchbox_draw_clip_tri_up(rcti *rect, const float zoom)
{
const float x = BLI_rcti_cent_x(rect) - 0.5f * zoom * UI_ICON_SIZE;
const float y = rect->ymax + 0.5f * zoom * (UI_SEARCHBOX_TRIA_H - UI_ICON_SIZE) - U.pixelsize;
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw_ex(x,
y,
ICON_TRIA_UP,
U.inv_scale_factor / zoom,
1.0f,
0.0f,
NULL,
false,
UI_NO_ICON_OVERLAY_TEXT);
GPU_blend(GPU_BLEND_NONE);
}
static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
{
uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
const float zoom = data->zoom;
const bool use_unpadded = data->noback;
/* pixel space */
wmOrtho2_region_pixelspace(region);
@ -572,24 +611,29 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
/* widget itself */
ui_draw_preview_item(&data->fstyle,
&rect,
zoom,
data->items.names[a],
data->items.icons[a],
but_flag,
UI_STYLE_TEXT_LEFT);
}
/* indicate more */
if (data->items.more) {
ui_searchbox_butrect(&rect, data, data->items.maxitem - 1);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(rect.xmax - 18, rect.ymin - 7, ICON_TRIA_DOWN);
GPU_blend(GPU_BLEND_NONE);
}
if (data->items.offset) {
ui_searchbox_butrect(&rect, data, 0);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(rect.xmin, rect.ymax - 9, ICON_TRIA_UP);
GPU_blend(GPU_BLEND_NONE);
/* Indicate more. */
if (data->items.more || data->items.offset) {
rcti rect_min;
ui_searchbox_butrect(&rect_min, data, 0);
rcti rect_max;
ui_searchbox_butrect(&rect_max, data, data->items.maxitem - 1);
if (data->items.offset) {
rect_min.xmax = rect_max.xmax;
ui_searchbox_draw_clip_tri_up(&rect_min, zoom);
}
if (data->items.more) {
rect_max.xmin = rect_min.xmin;
ui_searchbox_draw_clip_tri_down(&rect_max, zoom);
}
}
}
else {
@ -621,7 +665,16 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
}
/* Simple menu item. */
ui_draw_menu_item(&data->fstyle, &rect, name, icon, but_flag, separator_type, nullptr);
ui_draw_menu_item(&data->fstyle,
&rect,
&rect,
zoom,
use_unpadded,
name,
icon,
but_flag,
separator_type,
nullptr);
}
else {
/* Split menu item, faded text before the separator. */
@ -637,8 +690,11 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
int name_width = 0;
ui_draw_menu_item(&data->fstyle,
&rect,
&rect,
zoom,
use_unpadded,
name,
0,
ICON_NONE,
but_flag | UI_BUT_INACTIVE,
UI_MENU_ITEM_SEPARATOR_NONE,
&name_width);
@ -648,26 +704,32 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
if (icon == ICON_BLANK1) {
icon = ICON_NONE;
rect.xmin -= UI_ICON_SIZE / 4;
}
if (icon != ICON_NONE) {
rect.xmin += UI_UNIT_X / 8;
}
/* The previous menu item draws the active selection. */
ui_draw_menu_item(
&data->fstyle, &rect, name_sep, icon, but_flag, separator_type, nullptr);
ui_draw_menu_item(&data->fstyle,
&rect,
nullptr,
zoom,
use_unpadded,
name_sep,
icon,
but_flag,
separator_type,
nullptr);
}
}
/* indicate more */
if (data->items.more) {
ui_searchbox_butrect(&rect, data, data->items.maxitem - 1);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(BLI_rcti_size_x(&rect) / 2, rect.ymin - 9, ICON_TRIA_DOWN);
GPU_blend(GPU_BLEND_NONE);
ui_searchbox_draw_clip_tri_down(&rect, zoom);
}
if (data->items.offset) {
ui_searchbox_butrect(&rect, data, 0);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(BLI_rcti_size_x(&rect) / 2, rect.ymax - 7, ICON_TRIA_UP);
GPU_blend(GPU_BLEND_NONE);
ui_searchbox_draw_clip_tri_up(&rect, zoom);
}
}
}
@ -734,17 +796,19 @@ static void ui_searchbox_region_layout_fn(const bContext *C, ARegion *region)
/* compute position */
if (but->block->flag & UI_BLOCK_SEARCH_MENU) {
const int search_but_h = BLI_rctf_size_y(&but->rect) + 10;
/* this case is search menu inside other menu */
/* we copy region size */
/* Align menu items with the search button. */
const float zoom = data->zoom;
const int padding = zoom * UI_SEARCHBOX_BOUNDS - (data->preview ? 0 : U.pixelsize);
const int search_but_h = BLI_rctf_size_y(&but->rect) + zoom * UI_SEARCHBOX_BOUNDS;
/* This case is search menu inside other menu, we copy region size. */
region->winrct = butregion->winrct;
/* widget rect, in region coords */
data->bbox.xmin = margin;
data->bbox.xmax = BLI_rcti_size_x(&region->winrct) - margin;
/* Widget rect, in region coordinates. */
data->bbox.xmin = margin + padding;
data->bbox.xmax = BLI_rcti_size_x(&region->winrct) - margin - padding;
data->bbox.ymin = margin;
data->bbox.ymax = BLI_rcti_size_y(&region->winrct) - margin;
data->bbox.ymax = BLI_rcti_size_y(&region->winrct) - UI_POPUP_MENU_TOP;
/* check if button is lower half */
if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) {
@ -763,8 +827,8 @@ static void ui_searchbox_region_layout_fn(const bContext *C, ARegion *region)
}
rctf rect_fl;
rect_fl.xmin = but->rect.xmin - 5; /* align text with button */
rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */
rect_fl.xmin = but->rect.xmin;
rect_fl.xmax = but->rect.xmax;
rect_fl.ymax = but->rect.ymin;
rect_fl.ymin = rect_fl.ymax - UI_searchbox_size_y();
@ -869,6 +933,8 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C,
ui_fontscale(&data->fstyle.points, aspect);
UI_fontstyle_set(&data->fstyle);
data->zoom = 1.0f / aspect;
region->regiondata = data;
/* Special case, hard-coded feature, not draw backdrop when called from menus,
@ -948,6 +1014,8 @@ static void str_tolower_titlecaps_ascii(char *str, const size_t len)
static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegion *region)
{
uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata);
const float zoom = data->zoom;
const bool use_unpadded = data->noback;
/* pixel space */
wmOrtho2_region_pixelspace(region);
@ -991,9 +1059,11 @@ static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegio
str_tolower_titlecaps_ascii(text_pre, sizeof(text_pre));
}
rect_pre.xmax += 4; /* sneaky, avoid showing ugly margin */
ui_draw_menu_item(&data->fstyle,
&rect_pre,
&rect,
zoom,
use_unpadded,
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, text_pre),
data->items.icons[a],
but_flag,
@ -1001,6 +1071,9 @@ static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegio
nullptr);
ui_draw_menu_item(&data->fstyle,
&rect_post,
nullptr,
zoom,
use_unpadded,
data->items.names[a],
0,
but_flag,
@ -1012,15 +1085,11 @@ static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegio
/* indicate more */
if (data->items.more) {
ui_searchbox_butrect(&rect, data, data->items.maxitem - 1);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(BLI_rcti_size_x(&rect) / 2, rect.ymin - 9, ICON_TRIA_DOWN);
GPU_blend(GPU_BLEND_NONE);
ui_searchbox_draw_clip_tri_down(&rect, zoom);
}
if (data->items.offset) {
ui_searchbox_butrect(&rect, data, 0);
GPU_blend(GPU_BLEND_ALPHA);
UI_icon_draw(BLI_rcti_size_x(&rect) / 2, rect.ymax - 7, ICON_TRIA_UP);
GPU_blend(GPU_BLEND_NONE);
ui_searchbox_draw_clip_tri_up(&rect, zoom);
}
}
}

View File

@ -406,7 +406,7 @@ static void menu_items_from_all_operators(bContext *C, MenuSearch_Data *data)
char uiname[256];
WM_operator_py_idname(idname_as_py, ot->idname);
SNPRINTF(uiname, "%s " UI_MENU_ARROW_SEP "%s", idname_as_py, ot_ui_name);
SNPRINTF(uiname, "%s " UI_MENU_ARROW_SEP " %s", idname_as_py, ot_ui_name);
item->drawwstr_full = strdup_memarena(memarena, uiname);
item->drawstr = ot_ui_name;

View File

@ -251,17 +251,18 @@ static uiBlock *template_common_search_menu(const bContext *C,
/* preview thumbnails */
if (preview_rows > 0 && preview_cols > 0) {
const int w = 4 * U.widget_unit * preview_cols * scale;
const int h = 5 * U.widget_unit * preview_rows * scale;
const int h = 5 * U.widget_unit * preview_rows * scale + 2 * UI_SEARCHBOX_TRIA_H -
UI_SEARCHBOX_BOUNDS;
/* fake button, it holds space for search items */
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 26, w, h, nullptr, 0, 0, 0, 0, nullptr);
/* Fake button holds space for search items. */
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 0, UI_UNIT_Y, w, h, nullptr, 0, 0, 0, 0, nullptr);
but = uiDefSearchBut(block,
search,
0,
ICON_VIEWZOOM,
sizeof(search),
10,
0,
0,
w,
UI_UNIT_Y,
@ -273,16 +274,17 @@ static uiBlock *template_common_search_menu(const bContext *C,
else {
const int searchbox_width = UI_searchbox_size_x();
const int searchbox_height = UI_searchbox_size_y();
const int search_but_height = UI_UNIT_Y - 1.0f * UI_SCALE_FAC;
/* fake button, it holds space for search items */
uiDefBut(block,
UI_BTYPE_LABEL,
0,
"",
10,
15,
0,
search_but_height,
searchbox_width,
searchbox_height,
searchbox_height - UI_SEARCHBOX_BOUNDS,
nullptr,
0,
0,
@ -294,10 +296,10 @@ static uiBlock *template_common_search_menu(const bContext *C,
0,
ICON_VIEWZOOM,
sizeof(search),
10,
0,
0,
searchbox_width,
UI_UNIT_Y - 1,
search_but_height,
0,
0,
"");
@ -312,7 +314,7 @@ static uiBlock *template_common_search_menu(const bContext *C,
active_item);
UI_but_func_search_set_tooltip(but, item_tooltip_fn);
UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
UI_block_bounds_set_normal(block, UI_SEARCHBOX_BOUNDS);
UI_block_direction_set(block, UI_DIR_DOWN);
/* give search-field focus */

View File

@ -1301,7 +1301,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, const uiWidgetColors *wcol)
#define UI_TEXT_CLIP_MARGIN (0.25f * U.widget_unit / but->block->aspect)
#define PREVIEW_PAD 4
#define PREVIEW_PAD (4.0f * UI_SCALE_FAC)
static float widget_alpha_factor(const uiWidgetStateInfo *state)
{
@ -5457,14 +5457,17 @@ void ui_draw_tooltip_background(const uiStyle * /*style*/, uiBlock * /*block*/,
void ui_draw_menu_item(const uiFontStyle *fstyle,
rcti *rect,
rcti *back_rect,
const float zoom,
const bool use_unpadded,
const char *name,
int iconid,
int but_flag,
uiMenuItemSeparatorType separator_type,
int *r_xmax)
{
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
const rcti _rect = *rect;
uiWidgetType *wt = widget_type(use_unpadded ? UI_WTYPE_MENU_ITEM_UNPADDED : UI_WTYPE_MENU_ITEM);
const int row_height = BLI_rcti_size_y(rect);
int max_hint_width = INT_MAX;
int padding = 0.25f * row_height;
@ -5474,7 +5477,12 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
state.but_flag = but_flag;
wt->state(wt, &state, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, 1.0f);
if (back_rect != nullptr) {
wt->draw(&wt->wcol, back_rect, &STATE_INFO_NULL, 0, zoom);
}
/* Draw first, in case UI_WTYPE_MENU_ITEM padding will be added, rect = back_rect. */
const rcti _rect = *rect;
UI_fontstyle_set(fstyle);
@ -5546,17 +5554,20 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
*rect = _rect;
if (iconid) {
float height, aspect;
const int xs = rect->xmin + 0.2f * UI_UNIT_X;
const int ys = rect->ymin + 0.1f * BLI_rcti_size_y(rect);
height = ICON_SIZE_FROM_BUTRECT(rect);
aspect = ICON_DEFAULT_HEIGHT / height;
const int xs = rect->xmin + 0.2f * UI_UNIT_X * zoom;
const int ys = rect->ymin + 0.5f * (BLI_rcti_size_y(rect) - UI_ICON_SIZE * zoom);
GPU_blend(GPU_BLEND_ALPHA);
/* XXX scale weak get from fstyle? */
UI_icon_draw_ex(
xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text, false, UI_NO_ICON_OVERLAY_TEXT);
UI_icon_draw_ex(xs,
ys,
iconid,
U.inv_scale_factor / zoom,
1.0f,
0.0f,
wt->wcol.text,
false,
UI_NO_ICON_OVERLAY_TEXT);
GPU_blend(GPU_BLEND_NONE);
}
@ -5581,7 +5592,7 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
}
}
rect->xmax = _rect.xmax - 5;
rect->xmax = _rect.xmax - padding;
uiFontStyleDraw_Params params{};
params.align = UI_STYLE_TEXT_RIGHT;
UI_fontstyle_draw(fstyle, rect, hint_drawstr, sizeof(hint_drawstr), wt->wcol.text, &params);
@ -5654,6 +5665,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
void ui_draw_preview_item(const uiFontStyle *fstyle,
rcti *rect,
const float zoom,
const char *name,
int iconid,
int but_flag,
@ -5666,7 +5678,7 @@ void ui_draw_preview_item(const uiFontStyle *fstyle,
/* drawing button background */
wt->state(wt, &state, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, 1.0f);
wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, zoom);
ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align);
}

View File

@ -1406,8 +1406,8 @@ static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_op)
0,
ICON_VIEWZOOM,
sizeof(search),
10,
10,
0,
0,
UI_searchbox_size_x(),
UI_UNIT_Y,
0,
@ -1418,14 +1418,15 @@ static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_op)
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
/* Fake button holds space for search items. */
const int height = UI_searchbox_size_y() - UI_SEARCHBOX_BOUNDS;
uiDefBut(block,
UI_BTYPE_LABEL,
0,
"",
10,
10 - UI_searchbox_size_y(),
0,
-height,
UI_searchbox_size_x(),
UI_searchbox_size_y(),
height,
nullptr,
0,
0,
@ -1435,7 +1436,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_op)
/* Move it downwards, mouse over button. */
std::array<int, 2> bounds_offset = {0, -UI_UNIT_Y};
UI_block_bounds_set_popup(block, 0.3f * U.widget_unit, bounds_offset.data());
UI_block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, bounds_offset.data());
return block;
}

View File

@ -854,7 +854,7 @@ static uiBlock *merged_element_search_menu(bContext *C, ARegion *region, void *d
short menu_width = 10 * UI_UNIT_X;
but = uiDefSearchBut(
block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, menu_width, UI_UNIT_Y, 0, 0, "");
block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, menu_width, UI_UNIT_Y, 0, 0, "");
UI_but_func_search_set(but,
nullptr,
merged_element_search_update_fn,
@ -865,25 +865,14 @@ static uiBlock *merged_element_search_menu(bContext *C, ARegion *region, void *d
nullptr);
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
/* Fake button to hold space for search items */
uiDefBut(block,
UI_BTYPE_LABEL,
0,
"",
10,
10 - UI_searchbox_size_y(),
menu_width,
UI_searchbox_size_y(),
nullptr,
0,
0,
0,
0,
nullptr);
/* Fake button holds space for search items. */
const int height = UI_searchbox_size_y() - UI_SEARCHBOX_BOUNDS;
uiDefBut(
block, UI_BTYPE_LABEL, 0, "", 0, -height, menu_width, height, nullptr, 0, 0, 0, 0, nullptr);
/* Center the menu on the cursor */
/* Center the menu on the cursor. */
const int offset[2] = {-(menu_width / 2), 0};
UI_block_bounds_set_popup(block, 6, offset);
UI_block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, offset);
return block;
}

View File

@ -2442,7 +2442,7 @@ static int wm_userpref_read_exec(bContext *C, wmOperator *op)
BKE_callback_exec_null(bmain, BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST);
/* Needed to recalculate UI scaling values (eg, #UserDef.inv_dpi_fac). */
/* Needed to recalculate UI scaling values (eg, #UserDef.inv_scale_fac). */
wm_window_clear_drawable(static_cast<wmWindowManager *>(bmain->wm.first));
WM_event_add_notifier(C, NC_WINDOW, nullptr);

View File

@ -1090,7 +1090,7 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
const int width = search_menu->use_previews ? 5 * U.widget_unit * search_menu->prv_cols :
UI_searchbox_size_x();
const int height = search_menu->use_previews ? 5 * U.widget_unit * search_menu->prv_rows :
UI_searchbox_size_y();
UI_searchbox_size_y() - UI_SEARCHBOX_BOUNDS;
static char search[256] = "";
uiBlock *block = UI_block_begin(C, region, "_popup", UI_EMBOSS);
@ -1131,24 +1131,11 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
search_menu->prv_cols,
"");
/* fake button, it holds space for search items */
uiDefBut(block,
UI_BTYPE_LABEL,
0,
"",
10,
10 - UI_searchbox_size_y(),
width,
height,
nullptr,
0,
0,
0,
0,
nullptr);
/* Fake button holds space for search items. */
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 0, -height, width, height, nullptr, 0, 0, 0, 0, nullptr);
/* Move it downwards, mouse over button. */
UI_block_bounds_set_popup(block, 0.3f * U.widget_unit, blender::int2{0, -UI_UNIT_Y});
UI_block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, blender::int2{0, -UI_UNIT_Y});
UI_but_focus_on_enter_event(win, but);
@ -1765,8 +1752,8 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *region, void *userdat
0,
ICON_VIEWZOOM,
sizeof(g_search_text),
10,
10,
0,
0,
init_data->size[0],
UI_UNIT_Y,
0,
@ -1789,15 +1776,16 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *region, void *userdat
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
/* fake button, it holds space for search items */
/* Fake button holds space for search items. */
const int height = init_data->size[1] - UI_SEARCHBOX_BOUNDS;
uiDefBut(block,
UI_BTYPE_LABEL,
0,
"",
10,
10 - init_data->size[1],
0,
-height,
init_data->size[0],
init_data->size[1],
height,
nullptr,
0,
0,
@ -1806,7 +1794,7 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *region, void *userdat
nullptr);
/* Move it downwards, mouse over button. */
UI_block_bounds_set_popup(block, 0.3f * U.widget_unit, blender::int2{0, -UI_UNIT_Y});
UI_block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, blender::int2{0, -UI_UNIT_Y});
return block;
}