From 13208038da6a8dbdc2282a43d52d1179dd8ac552 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 20 Dec 2023 20:53:48 +0100 Subject: [PATCH] UI: Show "No results found" for empty searches For menu and operator searches, and for File and Asset Browser filtering, show "No Results Found" when there is nothing to show. Pull Request: https://projects.blender.org/blender/blender/pulls/116201 --- .../interface/interface_region_search.cc | 22 ++++++++++++++++++ .../blender/editors/space_file/file_draw.cc | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/source/blender/editors/interface/interface_region_search.cc b/source/blender/editors/interface/interface_region_search.cc index 3f8f5264845..aa0899af0e9 100644 --- a/source/blender/editors/interface/interface_region_search.cc +++ b/source/blender/editors/interface/interface_region_search.cc @@ -673,6 +673,17 @@ static void ui_searchbox_region_draw_fn(const bContext *C, ARegion *region) } } } + else { + rcti rect; + ui_searchbox_butrect(&rect, data, 0); + ui_draw_menu_item(&data->fstyle, + &rect, + IFACE_("No results found"), + 0, + 0, + UI_MENU_ITEM_SEPARATOR_NONE, + nullptr); + } } static void ui_searchbox_region_free_fn(ARegion *region) @@ -1025,6 +1036,17 @@ static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegio GPU_blend(GPU_BLEND_NONE); } } + else { + rcti rect; + ui_searchbox_butrect(&rect, data, 0); + ui_draw_menu_item(&data->fstyle, + &rect, + IFACE_("No results found"), + 0, + 0, + UI_MENU_ITEM_SEPARATOR_NONE, + nullptr); + } } ARegion *ui_searchbox_create_operator(bContext *C, ARegion *butregion, uiButSearch *search_but) diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 4265a86b3d3..a0b450e4627 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -1166,6 +1166,29 @@ void file_draw_list(const bContext *C, ARegion *region) } } + if (numfiles == 0) { + const rcti tile_draw_rect = tile_draw_rect_get( + v2d, layout, eFileDisplayType(params->display), 0, 0); + const uiStyle *style = UI_style_get(); + + const bool is_filtered = params->filter_search[0] != '\0'; + + uchar text_col[4]; + UI_GetThemeColor4ubv(TH_TEXT, text_col); + if (!is_filtered) { + text_col[3] /= 2; + } + + const char *message = is_filtered ? IFACE_("No results match the search filter") : + IFACE_("No items"); + + UI_fontstyle_draw_simple(&style->widget, + tile_draw_rect.xmin + UI_UNIT_X, + tile_draw_rect.ymax - UI_UNIT_Y, + message, + text_col); + } + BLF_batch_draw_end(); UI_block_end(C, block);