UI: Improve search layout #112422
|
@ -1651,6 +1651,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.
|
||||
*/
|
||||
|
|
|
@ -1229,6 +1229,8 @@ enum uiMenuItemSeparatorType {
|
|||
/**
|
||||
* Helper call to draw a menu item without a button.
|
||||
*
|
||||
* \param back_rect: Used to draw/leave out the backdrop of the menu item. Useful when layering
|
||||
* multiple items with different formatting like in search menus.
|
||||
* \param but_flag: Button flags (#uiBut.flag) indicating the state of the item, typically
|
||||
* #UI_HOVER, #UI_BUT_DISABLED, #UI_BUT_INACTIVE.
|
||||
* \param separator_type: The kind of separator which controls if and how the string is clipped.
|
||||
|
@ -1237,6 +1239,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,
|
||||
|
@ -1244,6 +1249,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,
|
||||
|
|
|
@ -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()
|
||||
|
@ -231,34 +231,39 @@ static void ui_searchbox_select(bContext *C, ARegion *region, uiBut *but, int st
|
|||
ED_region_tag_redraw(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the bounding rectangle \a r_rect around the visible search result item \a itemnr.
|
||||
*/
|
||||
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 float 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;
|
||||
}
|
||||
}
|
||||
|
@ -546,9 +551,56 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *region, uiBut *but, char *st
|
|||
return match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a downwards facing triangle.
|
||||
* \param rect: Rectangle under which the triangle icon is drawn. Usually from the last result item
|
||||
* that can be displayed.
|
||||
*/
|
||||
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 - (0.5f * zoom * (UI_SEARCHBOX_TRIA_H - UI_ICON_SIZE) - U.pixelsize) -
|
||||
zoom * UI_ICON_SIZE;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an upwards facing triangle.
|
||||
* \param rect: Rectangle above which the triangle icon is drawn. Usually from the first result
|
||||
* item that can be displayed.
|
||||
*/
|
||||
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);
|
||||
|
@ -574,24 +626,31 @@ 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_first_item;
|
||||
ui_searchbox_butrect(&rect_first_item, data, 0);
|
||||
rcti rect_max_item;
|
||||
ui_searchbox_butrect(&rect_max_item, data, data->items.maxitem - 1);
|
||||
|
||||
if (data->items.offset) {
|
||||
/* The first item is in the top left corner. Adjust width so the icon is centered. */
|
||||
rect_first_item.xmax = rect_max_item.xmax;
|
||||
ui_searchbox_draw_clip_tri_up(&rect_first_item, zoom);
|
||||
}
|
||||
|
||||
if (data->items.more) {
|
||||
/* The last item is in the bottom right corner. Adjust width so the icon is centered. */
|
||||
rect_max_item.xmin = rect_first_item.xmin;
|
||||
ui_searchbox_draw_clip_tri_down(&rect_max_item, zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -624,7 +683,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. */
|
||||
|
@ -640,8 +708,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);
|
||||
|
@ -651,26 +722,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);
|
||||
/* No backdrop. The previous menu item draws the active selection. */
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -679,6 +756,9 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region)
|
|||
ui_searchbox_butrect(&rect, data, 0);
|
||||
ui_draw_menu_item(&data->fstyle,
|
||||
&rect,
|
||||
&rect,
|
||||
zoom,
|
||||
use_unpadded,
|
||||
IFACE_("No results found"),
|
||||
0,
|
||||
0,
|
||||
|
@ -748,17 +828,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;
|
||||
|
||||
/* In this case the search menu is inside another menu, so we copy region size. */
|
||||
region->winrct = butregion->winrct;
|
||||
|
||||
/* widget rect, in region coords */
|
||||
data->bbox.xmin = margin;
|
||||
data->bbox.xmax = BLI_rcti_size_x(®ion->winrct) - margin;
|
||||
/* Widget rect, in region coordinates. */
|
||||
data->bbox.xmin = margin + padding;
|
||||
data->bbox.xmax = BLI_rcti_size_x(®ion->winrct) - (margin + padding);
|
||||
data->bbox.ymin = margin;
|
||||
data->bbox.ymax = BLI_rcti_size_y(®ion->winrct) - margin;
|
||||
data->bbox.ymax = BLI_rcti_size_y(®ion->winrct) - UI_POPUP_MENU_TOP;
|
||||
|
||||
/* check if button is lower half */
|
||||
if (but->rect.ymax < BLI_rctf_cent_y(&but->block->rect)) {
|
||||
|
@ -777,8 +859,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();
|
||||
|
||||
|
@ -883,6 +965,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,
|
||||
|
@ -962,6 +1046,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);
|
||||
|
@ -1005,9 +1091,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,
|
||||
|
@ -1015,6 +1103,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,
|
||||
|
@ -1026,15 +1117,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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1042,6 +1129,9 @@ static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegio
|
|||
ui_searchbox_butrect(&rect, data, 0);
|
||||
ui_draw_menu_item(&data->fstyle,
|
||||
&rect,
|
||||
&rect,
|
||||
zoom,
|
||||
use_unpadded,
|
||||
IFACE_("No results found"),
|
||||
0,
|
||||
0,
|
||||
|
|
|
@ -403,7 +403,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;
|
||||
|
|
|
@ -254,28 +254,30 @@ 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, nullptr);
|
||||
/* Fake button holds space for search items. */
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 0, UI_UNIT_Y, w, h, nullptr, 0, 0, nullptr);
|
||||
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y, "");
|
||||
but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, w, UI_UNIT_Y, "");
|
||||
UI_but_search_preview_grid_size_set(but, preview_rows, preview_cols);
|
||||
}
|
||||
/* list view */
|
||||
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 */
|
||||
/* 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,
|
||||
|
@ -285,10 +287,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,
|
||||
"");
|
||||
}
|
||||
UI_but_func_search_set(but,
|
||||
|
@ -301,7 +303,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 */
|
||||
|
|
|
@ -1222,7 +1222,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)
|
||||
{
|
||||
|
@ -5557,13 +5557,16 @@ 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);
|
||||
uiWidgetType *wt = widget_type(use_unpadded ? UI_WTYPE_MENU_ITEM_UNPADDED : UI_WTYPE_MENU_ITEM);
|
||||
const rcti _rect = *rect;
|
||||
const int row_height = BLI_rcti_size_y(rect);
|
||||
int max_hint_width = INT_MAX;
|
||||
|
@ -5574,7 +5577,9 @@ 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);
|
||||
}
|
||||
|
||||
UI_fontstyle_set(fstyle);
|
||||
|
||||
|
@ -5646,17 +5651,19 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -5681,7 +5688,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, ¶ms);
|
||||
|
@ -5755,6 +5762,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,
|
||||
|
@ -5767,7 +5775,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);
|
||||
}
|
||||
|
|
|
@ -443,8 +443,8 @@ static uiBlock *create_search_popup_block(bContext *C, ARegion *region, void *ar
|
|||
0,
|
||||
ICON_VIEWZOOM,
|
||||
sizeof(storage.search),
|
||||
storage.in_out() == SOCK_OUT ? 10 : 10 - UI_searchbox_size_x(),
|
||||
10,
|
||||
storage.in_out() == SOCK_OUT ? 0 : -UI_searchbox_size_x(),
|
||||
0,
|
||||
UI_searchbox_size_x(),
|
||||
UI_UNIT_Y,
|
||||
"");
|
||||
|
|
|
@ -1390,8 +1390,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,
|
||||
"");
|
||||
|
@ -1400,14 +1400,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,
|
||||
|
@ -1415,7 +1416,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;
|
||||
}
|
||||
|
|
|
@ -834,7 +834,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, "");
|
||||
block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, menu_width, UI_UNIT_Y, "");
|
||||
UI_but_func_search_set(but,
|
||||
nullptr,
|
||||
merged_element_search_update_fn,
|
||||
|
@ -845,23 +845,13 @@ 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,
|
||||
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, 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;
|
||||
}
|
||||
|
|
|
@ -1103,8 +1103,8 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
|
|||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
WM_operatortype_name(op->type, op->ptr),
|
||||
10,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
UI_searchbox_size_x(),
|
||||
UI_UNIT_Y,
|
||||
nullptr,
|
||||
|
@ -1119,28 +1119,17 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
|
|||
0,
|
||||
ICON_VIEWZOOM,
|
||||
sizeof(search),
|
||||
10,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
UI_UNIT_Y,
|
||||
"");
|
||||
|
||||
/* 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,
|
||||
nullptr);
|
||||
/* Fake button holds space for search items. */
|
||||
uiDefBut(block, UI_BTYPE_LABEL, 0, "", 0, -height, width, height, nullptr, 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);
|
||||
|
||||
|
@ -1918,8 +1907,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,
|
||||
"");
|
||||
|
@ -1941,21 +1930,22 @@ 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. */
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue