Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_region_search.cc
| Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | struct uiSearchboxData { | ||||
| * Show the active icon and text after the last instance of this string. | * Show the active icon and text after the last instance of this string. | ||||
| * Used so we can show leading text to menu items less prominently (not related to 'use_sep'). | * Used so we can show leading text to menu items less prominently (not related to 'use_sep'). | ||||
| */ | */ | ||||
| const char *sep_string; | const char *sep_string; | ||||
| }; | }; | ||||
| #define SEARCH_ITEMS 10 | #define SEARCH_ITEMS 10 | ||||
| /** | |||||
| * Public function exported for functions that use #UI_BTYPE_SEARCH_MENU. | |||||
| * | |||||
| * \param items: Stores the items. | |||||
| * \param name: Text to display for the item. | |||||
| * \param poin: Opaque pointer (for use by the caller). | |||||
| * \param iconid: The icon, #ICON_NONE for no icon. | |||||
| * \param state: The buttons state flag, compatible with #uiBut.flag, | |||||
| * typically #UI_BUT_DISABLED / #UI_BUT_INACTIVE. | |||||
| * \return false if there is nothing to add. | |||||
| */ | |||||
| bool UI_search_item_add(uiSearchItems *items, | bool UI_search_item_add(uiSearchItems *items, | ||||
| const char *name, | const char *name, | ||||
| void *poin, | void *poin, | ||||
| int iconid, | int iconid, | ||||
| int state, | int state, | ||||
| const uint8_t name_prefix_offset) | const uint8_t name_prefix_offset) | ||||
| { | { | ||||
| /* hijack for autocomplete */ | /* hijack for autocomplete */ | ||||
| if (items->autocpl) { | if (items->autocpl) { | ||||
| UI_autocomplete_update_name(items->autocpl, name); | UI_autocomplete_update_name(items->autocpl, name + name_prefix_offset); | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (iconid) { | if (iconid) { | ||||
| items->has_icon = true; | items->has_icon = true; | ||||
| } | } | ||||
| /* hijack for finding active item */ | /* hijack for finding active item */ | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (items->states) { | ||||
| items->states[items->totitem] = state; | items->states[items->totitem] = state; | ||||
| } | } | ||||
| items->totitem++; | items->totitem++; | ||||
| return true; | return true; | ||||
| } | } | ||||
| int UI_searchbox_size_y(void) | int UI_searchbox_size_y() | ||||
| { | { | ||||
| return SEARCH_ITEMS * UI_UNIT_Y + 2 * UI_POPUP_MENU_TOP; | return SEARCH_ITEMS * UI_UNIT_Y + 2 * UI_POPUP_MENU_TOP; | ||||
| } | } | ||||
| int UI_searchbox_size_x(void) | int UI_searchbox_size_x() | ||||
| { | { | ||||
| return 12 * UI_UNIT_X; | return 12 * UI_UNIT_X; | ||||
| } | } | ||||
| int UI_search_items_find_index(uiSearchItems *items, const char *name) | int UI_search_items_find_index(uiSearchItems *items, const char *name) | ||||
| { | { | ||||
| if (items->name_prefix_offsets != nullptr) { | if (items->name_prefix_offsets != nullptr) { | ||||
| for (int i = 0; i < items->totitem; i++) { | for (int i = 0; i < items->totitem; i++) { | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| int ui_searchbox_find_index(ARegion *region, const char *name) | int ui_searchbox_find_index(ARegion *region, const char *name) | ||||
| { | { | ||||
| uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | ||||
| return UI_search_items_find_index(&data->items, name); | return UI_search_items_find_index(&data->items, name); | ||||
| } | } | ||||
| /* x and y in screen-coords. */ | |||||
| bool ui_searchbox_inside(ARegion *region, const int xy[2]) | bool ui_searchbox_inside(ARegion *region, const int xy[2]) | ||||
| { | { | ||||
| uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | ||||
| return BLI_rcti_isect_pt(&data->bbox, xy[0] - region->winrct.xmin, xy[1] - region->winrct.ymin); | return BLI_rcti_isect_pt(&data->bbox, xy[0] - region->winrct.xmin, xy[1] - region->winrct.ymin); | ||||
| } | } | ||||
| /* string validated to be of correct length (but->hardmax) */ | |||||
| bool ui_searchbox_apply(uiBut *but, ARegion *region) | bool ui_searchbox_apply(uiBut *but, ARegion *region) | ||||
| { | { | ||||
| uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | ||||
| uiButSearch *search_but = (uiButSearch *)but; | uiButSearch *search_but = (uiButSearch *)but; | ||||
| BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | ||||
| search_but->item_active = nullptr; | search_but->item_active = nullptr; | ||||
| Show All 12 Lines | if (data->active != -1) { | ||||
| if (but->hardmax != 0) { | if (but->hardmax != 0) { | ||||
| BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); | BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); | ||||
| } | } | ||||
| search_but->item_active = data->items.pointers[data->active]; | search_but->item_active = data->items.pointers[data->active]; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (but->flag & UI_BUT_VALUE_CLEAR) { | |||||
| /* It is valid for _VALUE_CLEAR flavor to have no active element | |||||
| * (it's a valid way to unlink). */ | |||||
| but->editstr[0] = '\0'; | |||||
| return true; | |||||
| } | |||||
| return false; | return false; | ||||
| } | } | ||||
| static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C, | static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C, | ||||
| struct ARegion *region, | struct ARegion *region, | ||||
| int *UNUSED(r_pass), | int *UNUSED(r_pass), | ||||
| double *UNUSED(pass_delay), | double *UNUSED(pass_delay), | ||||
| bool *r_exit_on_event) | bool *r_exit_on_event) | ||||
| ▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | static void ui_searchbox_update_fn(bContext *C, | ||||
| if (search_but->but.editstr) { | if (search_but->but.editstr) { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| WM_tooltip_clear(C, win); | WM_tooltip_clear(C, win); | ||||
| } | } | ||||
| const bool is_first_search = !search_but->but.changed; | const bool is_first_search = !search_but->but.changed; | ||||
| search_but->items_update_fn(C, search_but->arg, str, items, is_first_search); | search_but->items_update_fn(C, search_but->arg, str, items, is_first_search); | ||||
| } | } | ||||
| /* region is the search box itself */ | |||||
| void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool reset) | void ui_searchbox_update(bContext *C, ARegion *region, uiBut *but, const bool reset) | ||||
| { | { | ||||
| uiButSearch *search_but = (uiButSearch *)but; | uiButSearch *search_but = (uiButSearch *)but; | ||||
| uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); | ||||
| BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | ||||
| /* reset vars */ | /* reset vars */ | ||||
| ▲ Show 20 Lines • Show All 538 Lines • ▼ Show 20 Lines | ARegion *ui_searchbox_create_menu(bContext *C, ARegion *butregion, uiButSearch *search_but) | ||||
| if (false) { | if (false) { | ||||
| region->type->draw = ui_searchbox_region_draw_cb__menu; | region->type->draw = ui_searchbox_region_draw_cb__menu; | ||||
| } | } | ||||
| return region; | return region; | ||||
| } | } | ||||
| /* sets red alert if button holds a string it can't find */ | |||||
| /* XXX weak: search_func adds all partial matches... */ | |||||
| void ui_but_search_refresh(uiButSearch *search_but) | void ui_but_search_refresh(uiButSearch *search_but) | ||||
| { | { | ||||
| uiBut *but = &search_but->but; | uiBut *but = &search_but->but; | ||||
| /* possibly very large lists (such as ID datablocks) only | /* possibly very large lists (such as ID datablocks) only | ||||
| * only validate string RNA buts (not pointers) */ | * only validate string RNA buts (not pointers) */ | ||||
| if (but->rnaprop && RNA_property_type(but->rnaprop) != PROP_STRING) { | if (but->rnaprop && RNA_property_type(but->rnaprop) != PROP_STRING) { | ||||
| return; | return; | ||||
| Show All 34 Lines | |||||