102#define SEARCH_ITEMS 10
109 const uint8_t name_prefix_offset)
123 if (poin == items->
active) {
151 if (name_prefix_offset != 0) {
186 for (const int i : range) {
187 const StringRefNull name = items.names[i];
188 const int icon = items.icons ? items.icons[i] : ICON_NONE;
189 const float text_width = BLF_width(BLF_default(), name.c_str(), name.size(), nullptr);
190 const float icon_with_padding = icon == ICON_NONE ? 0.0f : UI_ICON_SIZE + UI_UNIT_X;
191 const float padding = UI_UNIT_X;
192 item_widths[i] = int(text_width + padding + icon_with_padding);
198 for (
const int width : item_widths) {
199 box_width = std::max(box_width, width);
224 update_fn(
C, arg,
"", &items,
true);
235 for (
int i = 0; i < items->
totitem; i++) {
242 for (
int i = 0; i < items->
totitem; i++) {
259 if (
data->items.totitem == 0) {
262 else if (
data->active >=
data->items.totitem) {
263 if (
data->items.more) {
264 data->items.offset++;
265 data->active =
data->items.totitem - 1;
269 data->active =
data->items.totitem - 1;
272 else if (
data->active < 0) {
273 if (
data->items.offset) {
274 data->items.offset--;
297 *r_rect =
data->bbox;
299 col = itemnr %
data->prv_cols;
300 row = itemnr /
data->prv_cols;
302 r_rect->
xmin += col * butw;
305 r_rect->
ymax -= tria_h + row * buth;
312 *r_rect =
data->bbox;
317 r_rect->
ymax =
data->bbox.ymax - tria_h - itemnr * buth;
344 if (
data->active != -1) {
345 const char *name =
data->items.names[
data->active] +
347 (
data->items.name_prefix_offsets ?
348 data->items.name_prefix_offsets[
data->active] :
351 const char *name_sep =
data->use_shortcut_sep ? strrchr(name,
UI_SEP_CHAR) :
nullptr;
371 *r_exit_on_event =
true;
404 int type =
event->
type, val =
event->val;
405 bool handled =
false;
406 bool tooltip_timer_started =
false;
428 if (
data->active != -1) {
437 void *active =
data->items.pointers[
data->active];
455 bool is_inside =
false;
461 for (a = 0; a <
data->items.totitem; a++) {
467 if (
data->active != a) {
479 if (
data->active != -1) {
483 tooltip_timer_started =
true;
492 if (handled && (tooltip_timer_started ==
false)) {
511 const bool is_first_search = !but->
changed;
523 data->items.totitem = 0;
524 data->items.more = 0;
526 data->items.offset_i =
data->items.offset;
529 data->items.offset_i =
data->items.offset = 0;
533 const bool is_first_search = !but->
changed;
537 data->items.active =
nullptr;
540 if (
data->items.totitem) {
542 if (
data->items.offset_i <
data->items.maxitem) {
543 data->active =
data->items.offset_i;
544 data->items.offset_i = 0;
548 if (
data->items.totitem -
data->items.offset_i <=
data->items.maxitem) {
549 data->active =
data->items.offset_i -
data->items.totitem +
data->items.maxitem;
550 data->items.offset_i =
data->items.totitem -
data->items.maxitem;
554 data->items.offset_i -=
data->items.maxitem / 2;
555 data->active =
data->items.maxitem / 2;
559 data->items.offset =
data->items.offset_i;
560 data->items.totitem = 0;
571 for (
int a = 0; a <
data->items.totitem; a++) {
572 const char *name =
data->items.names[a] +
574 (
data->items.name_prefix_offsets ?
data->items.name_prefix_offsets[a] :
576 const char *name_sep =
data->use_shortcut_sep ? strrchr(name,
UI_SEP_CHAR) :
nullptr;
588 if (
data->active == -1 &&
data->search_but &&
data->search_but->editstr[0] ==
'\0') {
595 for (
int a = 0; a <
data->items.totitem; a++) {
626 maxncpy = strlen(
str) + 1024;
633 data->items.autocpl =
nullptr;
649 const float aspect =
U.inv_scale_factor / zoom;
664 const float aspect =
U.inv_scale_factor / zoom;
677 if (
data->noback ==
false) {
682 if (
data->items.totitem) {
687 for (
int a = 0; a <
data->items.totitem; a++) {
699 data->items.names[a],
700 data->items.icons[a],
706 if (
data->items.more ||
data->items.offset) {
707 rcti rect_first_item;
712 if (
data->items.offset) {
714 rect_first_item.
xmax = rect_max_item.
xmax;
718 if (
data->items.more) {
720 rect_max_item.
xmin = rect_first_item.
xmin;
726 const int search_sep_len =
data->sep_string ? strlen(
data->sep_string) : 0;
728 for (
int a = 0; a <
data->items.totitem; a++) {
730 const char *name =
data->items.names[a];
731 int icon =
data->items.icons[a];
732 char *name_sep_test =
nullptr;
735 if (
data->use_shortcut_sep) {
746 if ((search_sep_len == 0) ||
747 !(name_sep_test = strstr(
data->items.names[a],
data->sep_string)))
749 if (!icon &&
data->items.has_icon) {
768 char *name_sep =
nullptr;
770 name_sep = name_sep_test;
771 name_sep_test = strstr(name_sep + search_sep_len,
data->sep_string);
772 }
while (name_sep_test !=
nullptr);
774 name_sep += search_sep_len;
775 const char name_sep_prev = *name_sep;
788 *name_sep = name_sep_prev;
789 rect.
xmin += name_width;
792 if (icon == ICON_BLANK1) {
795 if (icon != ICON_NONE) {
813 if (
data->items.more) {
817 if (
data->items.offset) {
831 IFACE_(
"No results found"),
844 for (
int a = 0; a <
data->items.maxitem; a++) {
845 MEM_delete(
data->items.names[a]);
847 MEM_delete(
data->items.names);
848 MEM_delete(
data->items.pointers);
849 MEM_delete(
data->items.icons);
850 MEM_delete(
data->items.but_flags);
852 if (
data->items.name_prefix_offsets !=
nullptr) {
853 MEM_delete(
data->items.name_prefix_offsets);
863 if (
data->search_listener) {
864 data->search_listener(params,
data->search_arg);
872 if (
data->size_set) {
890 const float zoom =
data->zoom;
897 data->bbox.ymin = margin;
902 data->bbox.ymin += search_but_h;
905 data->bbox.ymax -= search_but_h;
924 rect_fl.
xmax = rect_fl.
xmin + searchbox_width;
941 if (rect_i.
xmax > winx) {
943 if (rect_i.
xmax > winx + rect_i.
xmin) {
953 if (rect_i.
ymin < 0) {
967 data->bbox.xmin = margin;
969 data->bbox.ymin = margin;
982 data->size_set =
true;
988 const bool use_shortcut_sep)
1007 data->search_arg = but->
arg.get();
1008 data->search_but = but;
1009 data->butregion = butregion;
1010 data->size_set =
false;
1012 data->zoom = 1.0f / aspect;
1024 data->noback =
true;
1028 data->preview =
true;
1033 if (but->
optype !=
nullptr || use_shortcut_sep) {
1034 data->use_shortcut_sep =
true;
1045 if (
data->preview) {
1053 data->items.totitem = 0;
1058 data->items.name_prefix_offsets =
nullptr;
1059 for (
int i = 0; i <
data->items.maxitem; i++) {
1079 bool prev_delim =
true;
1081 for (
size_t i = 0; (i <
len) &&
str[i]; i++) {
1082 if (
str[i] >=
'A' &&
str[i] <=
'Z') {
1083 if (prev_delim ==
false) {
1084 str[i] +=
'a' -
'A';
1087 else if (
str[i] ==
'_') {
1091 prev_delim =
ELEM(
str[i],
' ') || (
str[i] >=
'0' &&
str[i] <=
'9');
1102 if (
data->noback ==
false) {
1107 if (
data->items.totitem) {
1111 for (
int a = 0; a <
data->items.totitem; a++) {
1112 rcti rect_pre, rect_post;
1127 const char *text_pre_p = strstr(ot->
idname,
"_OT_");
1128 if (text_pre_p ==
nullptr) {
1136 text_pre[text_pre_len] =
':';
1137 text_pre[text_pre_len + 1] =
'\0';
1147 data->items.icons[a],
1156 data->items.names[a],
1165 if (
data->items.more) {
1169 if (
data->items.offset) {
1182 IFACE_(
"No results found"),
1228 SearchItems *items = MEM_new<SearchItems>(__func__);
1234 for (
int i = 0; i < items->
maxitem; i++) {
1246 else if (items->
more == 0) {
1253 for (
int i = 0; i < items->
maxitem; i++) {
1254 MEM_delete(items->
names[i]);
1256 MEM_delete(items->
names);
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
Read Blender memory allocation and freeing.
#define AUTOCOMPLETE_NO_MATCH
#define UI_SEARCHBOX_BOUNDS
#define UI_SEARCHBOX_TRIA_H
#define UI_NO_ICON_OVERLAY_TEXT
#define STREQLEN(a, b, n)
IndexRange index_range() const
constexpr StringRef drop_prefix(int64_t n) const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define UI_POPUP_MENU_TOP
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
@ UI_MENU_ITEM_SEPARATOR_SHORTCUT
@ UI_MENU_ITEM_SEPARATOR_NONE
@ UI_MENU_ITEM_SEPARATOR_HINT
void draw_preview_item(const uiFontStyle *fstyle, rcti *rect, float zoom, const char *name, int iconid, int64_t but_flag, FontStyleAlign text_align)
static void searchbox_region_layout_fn(const bContext *C, ARegion *region)
void button_search_refresh(ButtonSearch *but)
int button_string_get_maxncpy(Button *but)
ARegion * searchbox_create_menu(bContext *C, ARegion *butregion, ButtonSearch *search_but)
static ARegion * searchbox_create_generic_ex(bContext *C, ARegion *butregion, ButtonSearch *but, const bool use_shortcut_sep)
static void searchbox_region_draw_cb__menu(const bContext *, ARegion *)
void draw_widget_menu_back(const rcti *rect, bool use_shadow)
const uiStyle * style_get()
void searchbox_update(bContext *C, ARegion *region, Button *but, bool reset)
static void searchbox_draw_clip_tri_up(rcti *rect, const float zoom)
static void searchbox_update_fn(bContext *C, ButtonSearch *but, const char *str, SearchItems *items)
bool searchbox_event(bContext *C, ARegion *region, Button *but, ARegion *butregion, const wmEvent *event)
float view2d_view_to_region_y(const View2D *v2d, float y)
void region_temp_remove(bContext *C, bScreen *screen, ARegion *region)
void icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false, float scale=1.0f)
void fontstyle_set(const uiFontStyle *fs)
void autocomplete_update_name(AutoComplete *autocpl, StringRef name)
static void searchbox_region_draw_fn(const bContext *C, ARegion *region)
void view2d_view_to_region_rcti(const View2D *v2d, const rctf *rect_src, rcti *rect_dst) ATTR_NONNULL()
ARegion * region_searchbox_region_get(const ARegion *button_region)
void searchbox_free(bContext *C, ARegion *region)
void fontscale(float *points, float aspect)
int searchbox_size_x_guess(const bContext *C, const ButtonSearchUpdateFn update_fn, void *arg)
static void searchbox_region_free_fn(ARegion *region)
static void searchbox_region_draw_cb__operator(const bContext *, ARegion *region)
ARegion * region_temp_add(bScreen *screen)
void button_flag_enable(Button *but, int64_t flag)
ARegion * searchbox_create_operator(bContext *C, ARegion *butregion, ButtonSearch *search_but)
int search_items_find_index(const SearchItems *items, const char *name)
static void str_tolower_titlecaps_ascii(char *str, const size_t len)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
static ARegion * wm_searchbox_tooltip_init(bContext *C, ARegion *region, int *, double *, bool *r_exit_on_event)
static int searchbox_size_x_from_items(const SearchItems &items)
bool searchbox_inside(ARegion *region, const int xy[2]) ATTR_NONNULL(1
void pan_to_scroll(const wmEvent *event, int *type, int *val)
bool searchbox_apply(Button *but, ARegion *region)
static void searchbox_draw_clip_tri_down(rcti *rect, const float zoom)
ARegion * searchbox_create_generic(bContext *C, ARegion *butregion, ButtonSearch *search_but)
static void searchbox_select(bContext *C, ARegion *region, Button *but, int step)
int searchbox_autocomplete(bContext *C, ARegion *region, Button *but, char *str)
void(*)(const bContext *C, void *arg, const char *str, SearchItems *items, bool is_first) ButtonSearchUpdateFn
static void searchbox_butrect(rcti *r_rect, uiSearchboxData *data, int itemnr)
bool int searchbox_find_index(ARegion *region, const char *name)
AutoComplete * autocomplete_begin(const char *startname, size_t maxncpy)
void icon_ensure_deferred(const bContext *C, int icon_id, bool big)
static void searchbox_region_listen_fn(const wmRegionListenerParams *params)
void draw_menu_item(const uiFontStyle *fstyle, rcti *rect, rcti *back_rect, float zoom, bool use_unpadded, const char *name, int iconid, int64_t but_flag, MenuItemSeparatorType separator_type, int *r_xmax)
void(*)(const wmRegionListenerParams *params, void *arg) ButtonSearchListenFn
int autocomplete_end(AutoComplete *autocpl, char *autoname)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ScrArea * CTX_wm_area(const bContext *C)
void wmOrtho2_region_pixelspace(const ARegion *region)
uint padding(uint offset, uint alignment)
char size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src)
wmWindow * CTX_wm_window(const bContext *C)
int WM_window_native_pixel_x(const wmWindow *win)
void WM_tooltip_clear(bContext *C, wmWindow *win)
void ED_region_tag_redraw(ARegion *region)
void WM_tooltip_timer_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
PropertyType RNA_property_type(PropertyRNA *prop)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
BMesh const char void * data
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
void ED_region_floating_init(ARegion *region)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
void BLI_rctf_translate(struct rctf *rect, float x, float y)
bScreen * CTX_wm_screen(const bContext *C)
void GPU_blend(GPUBlend blend)
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
BLI_INLINE int BLI_rcti_cent_x(const struct rcti *rct)
MINLINE int min_ii(int a, int b)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void(*) draw(const bContext *C, ARegion *region)
void(*) listener(const wmRegionListenerParams *params)
void(*) layout(const bContext *C, ARegion *region)
bke::ARegionRuntime * runtime
ListBaseT< ui::Block > uiblocks
struct ARegionType * type
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
uint8_t * name_prefix_offsets
ButtonSearch * search_but
ButtonSearchListenFn search_listener
bke::WindowRuntime * runtime