Blender V4.3
interface_template_attribute_search.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_string_ref.hh"
10
12
13#include "RNA_access.hh"
14#include "RNA_enum_types.hh"
15
16#include "BLT_translation.hh"
17
18#include "BKE_attribute.hh"
19
21
22#include "UI_interface.hh"
23#include "UI_resources.hh"
24#include "UI_string_search.hh"
25
27
28namespace blender::ui {
29
31{
32 const char *name = nullptr;
34 return StringRef(IFACE_(name));
35}
36
38{
39 const char *name = nullptr;
41 return StringRef(IFACE_(name));
42}
43
45{
46 const StringRef data_type_name = attribute_data_type_string(*item.data_type);
47 const StringRef domain_name = attribute_domain_string(*item.domain);
48 std::string search_item_text = domain_name + " " + UI_MENU_ARROW_SEP + item.name + UI_SEP_CHAR +
49 data_type_name;
50
51 return UI_search_item_add(
52 items, search_item_text.c_str(), (void *)&item, ICON_NONE, UI_BUT_HAS_SEP_CHAR, 0);
53}
54
56 const bool can_create_attribute,
58 uiSearchItems *seach_items,
59 const bool is_first)
60{
61 static GeometryAttributeInfo dummy_info;
62
63 /* Any string may be valid, so add the current search string along with the hints. */
64 if (str[0] != '\0') {
65 bool contained = false;
66 for (const GeometryAttributeInfo *attribute_info : infos) {
67 if (attribute_info->name == str) {
68 contained = true;
69 break;
70 }
71 }
72 if (!contained) {
73 dummy_info.name = str;
74 UI_search_item_add(seach_items,
75 str.c_str(),
76 &dummy_info,
77 can_create_attribute ? ICON_ADD : ICON_NONE,
78 0,
79 0);
80 }
81 }
82
83 if (str[0] == '\0' && !is_first) {
84 /* Allow clearing the text field when the string is empty, but not on the first pass,
85 * or opening an attribute field for the first time would show this search item. */
86 dummy_info.name = str;
87 UI_search_item_add(seach_items, str.c_str(), &dummy_info, ICON_X, 0, 0);
88 }
89
90 /* Don't filter when the menu is first opened, but still run the search
91 * so the items are in the same order they will appear in while searching. */
92 const char *string = is_first ? "" : str.c_str();
93
95 for (const GeometryAttributeInfo *item : infos) {
97 continue;
98 }
99 search.add(item->name, item);
100 }
101
102 const Vector<const GeometryAttributeInfo *> filtered_items = search.query(string);
103
104 for (const GeometryAttributeInfo *item : filtered_items) {
105 if (!attribute_search_item_add(seach_items, *item)) {
106 break;
107 }
108 }
109}
110
111} // namespace blender::ui
#define IFACE_(msgid)
#define UI_SEP_CHAR
bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
@ UI_BUT_HAS_SEP_CHAR
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
#define str(s)
bool allow_procedural_attribute_access(StringRef attribute_name)
static bool attribute_search_item_add(uiSearchItems *items, const GeometryAttributeInfo &item)
void attribute_search_add_items(StringRefNull str, bool can_create_attribute, Span< const nodes::geo_eval_log::GeometryAttributeInfo * > infos, uiSearchItems *items, bool is_first)
static StringRef attribute_domain_string(const bke::AttrDomain domain)
static StringRef attribute_data_type_string(const eCustomDataType type)
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
const EnumPropertyItem rna_enum_attribute_domain_items[]
const EnumPropertyItem rna_enum_attribute_type_items[]
#define UI_MENU_ARROW_SEP