UI: Widen Search Boxes When Necessary #104603
@ -73,6 +73,9 @@ struct uiSearchboxData {
|
||||
rcti bbox;
|
||||
uiFontStyle fstyle;
|
||||
uiSearchItems items;
|
||||
bool size_set;
|
||||
ARegion *butregion;
|
||||
uiButSearch *search_but;
|
||||
/** index in items array */
|
||||
int active;
|
||||
/** when menu opened with enough space for this */
|
||||
@ -702,55 +705,35 @@ static void ui_searchbox_region_listen_fn(const wmRegionListenerParams *params)
|
||||
}
|
||||
}
|
||||
|
||||
static ARegion *ui_searchbox_create_generic_ex(bContext *C,
|
||||
ARegion *butregion,
|
||||
uiButSearch *but,
|
||||
const bool use_shortcut_sep)
|
||||
static uiMenuItemSeparatorType ui_searchbox_item_separator(uiSearchboxData *data)
|
||||
{
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
const uiStyle *style = UI_style_get();
|
||||
const float aspect = but->block->aspect;
|
||||
uiMenuItemSeparatorType separator_type = data->use_shortcut_sep ?
|
||||
UI_MENU_ITEM_SEPARATOR_SHORTCUT :
|
||||
UI_MENU_ITEM_SEPARATOR_NONE;
|
||||
if (separator_type == UI_MENU_ITEM_SEPARATOR_NONE && !data->preview) {
|
||||
for (int a = 0; a < data->items.totitem; a++) {
|
||||
Harley marked this conversation as resolved
|
||||
if (data->items.but_flags[a] & UI_BUT_HAS_SEP_CHAR) {
|
||||
separator_type = UI_MENU_ITEM_SEPARATOR_HINT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return separator_type;
|
||||
}
|
||||
|
||||
static void ui_searchbox_region_layout_fn(const struct bContext *C, struct ARegion *region)
|
||||
{
|
||||
uiSearchboxData *data = (uiSearchboxData *)region->regiondata;
|
||||
|
||||
if (data->size_set) {
|
||||
/* Already set. */
|
||||
return;
|
||||
}
|
||||
|
||||
uiButSearch *but = data->search_but;
|
||||
ARegion *butregion = data->butregion;
|
||||
const int margin = UI_POPUP_MARGIN;
|
||||
|
||||
/* create area region */
|
||||
ARegion *region = ui_region_temp_add(CTX_wm_screen(C));
|
||||
|
||||
static ARegionType type;
|
||||
memset(&type, 0, sizeof(ARegionType));
|
||||
type.draw = ui_searchbox_region_draw_fn;
|
||||
type.free = ui_searchbox_region_free_fn;
|
||||
type.listener = ui_searchbox_region_listen_fn;
|
||||
type.regionid = RGN_TYPE_TEMPORARY;
|
||||
region->type = &type;
|
||||
|
||||
/* Create search-box data. */
|
||||
uiSearchboxData *data = MEM_cnew<uiSearchboxData>(__func__);
|
||||
data->search_arg = but->arg;
|
||||
data->search_listener = but->listen_fn;
|
||||
|
||||
/* Set font, get the bounding-box. */
|
||||
data->fstyle = style->widget; /* copy struct */
|
||||
ui_fontscale(&data->fstyle.points, aspect);
|
||||
UI_fontstyle_set(&data->fstyle);
|
||||
|
||||
region->regiondata = data;
|
||||
|
||||
/* Special case, hard-coded feature, not draw backdrop when called from menus,
|
||||
* assume for design that popup already added it. */
|
||||
if (but->block->flag & UI_BLOCK_SEARCH_MENU) {
|
||||
data->noback = true;
|
||||
}
|
||||
|
||||
if (but->a1 > 0 && but->a2 > 0) {
|
||||
data->preview = true;
|
||||
data->prv_rows = but->a1;
|
||||
data->prv_cols = but->a2;
|
||||
}
|
||||
|
||||
if (but->optype != nullptr || use_shortcut_sep) {
|
||||
data->use_shortcut_sep = true;
|
||||
}
|
||||
data->sep_string = but->item_sep_string;
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
|
||||
/* compute position */
|
||||
if (but->block->flag & UI_BLOCK_SEARCH_MENU) {
|
||||
@ -775,7 +758,12 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C,
|
||||
}
|
||||
}
|
||||
else {
|
||||
const int searchbox_width = UI_searchbox_size_x();
|
||||
int searchbox_width = UI_searchbox_size_x();
|
||||
|
||||
/* We should make this wider if there is a path or hint on the right. */
|
||||
if (ui_searchbox_item_separator(data) != UI_MENU_ITEM_SEPARATOR_NONE) {
|
||||
searchbox_width += 12 * data->fstyle.points * U.dpi_fac;
|
||||
}
|
||||
|
||||
rctf rect_fl;
|
||||
rect_fl.xmin = but->rect.xmin - 5; /* align text with button */
|
||||
@ -845,6 +833,64 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C,
|
||||
region->winrct.ymax = rect_i.ymax;
|
||||
}
|
||||
|
||||
region->winx = region->winrct.xmax - region->winrct.xmin;
|
||||
region->winy = region->winrct.ymax - region->winrct.ymin;
|
||||
|
||||
data->size_set = true;
|
||||
}
|
||||
|
||||
static ARegion *ui_searchbox_create_generic_ex(bContext *C,
|
||||
ARegion *butregion,
|
||||
uiButSearch *but,
|
||||
const bool use_shortcut_sep)
|
||||
{
|
||||
const uiStyle *style = UI_style_get();
|
||||
const float aspect = but->block->aspect;
|
||||
|
||||
/* create area region */
|
||||
ARegion *region = ui_region_temp_add(CTX_wm_screen(C));
|
||||
|
||||
static ARegionType type;
|
||||
memset(&type, 0, sizeof(ARegionType));
|
||||
type.layout = ui_searchbox_region_layout_fn;
|
||||
type.draw = ui_searchbox_region_draw_fn;
|
||||
type.free = ui_searchbox_region_free_fn;
|
||||
type.listener = ui_searchbox_region_listen_fn;
|
||||
type.regionid = RGN_TYPE_TEMPORARY;
|
||||
region->type = &type;
|
||||
|
||||
/* Create search-box data. */
|
||||
uiSearchboxData *data = MEM_cnew<uiSearchboxData>(__func__);
|
||||
data->search_arg = but->arg;
|
||||
data->search_but = but;
|
||||
data->butregion = butregion;
|
||||
data->size_set = false;
|
||||
data->search_listener = but->listen_fn;
|
||||
|
||||
/* Set font, get the bounding-box. */
|
||||
data->fstyle = style->widget; /* copy struct */
|
||||
ui_fontscale(&data->fstyle.points, aspect);
|
||||
UI_fontstyle_set(&data->fstyle);
|
||||
|
||||
region->regiondata = data;
|
||||
|
||||
/* Special case, hard-coded feature, not draw backdrop when called from menus,
|
||||
* assume for design that popup already added it. */
|
||||
if (but->block->flag & UI_BLOCK_SEARCH_MENU) {
|
||||
data->noback = true;
|
||||
}
|
||||
|
||||
if (but->a1 > 0 && but->a2 > 0) {
|
||||
data->preview = true;
|
||||
data->prv_rows = but->a1;
|
||||
data->prv_cols = but->a2;
|
||||
}
|
||||
|
||||
if (but->optype != nullptr || use_shortcut_sep) {
|
||||
data->use_shortcut_sep = true;
|
||||
}
|
||||
data->sep_string = but->item_sep_string;
|
||||
|
||||
/* adds subwindow */
|
||||
ED_region_floating_init(region);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
I don't think we should limit this to 30. There's no particular reason to expect the user to need to select an item from the first 30 more often than the others.