Blender V5.0
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
8
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"
20
22
23#include "UI_interface.hh"
24#include "UI_resources.hh"
25#include "UI_string_search.hh"
26
27#include <fmt/format.h>
28
30
31namespace blender::ui {
32
34{
35 const char *name = nullptr;
37 return StringRef(IFACE_(name));
38}
39
41{
42 const char *name = nullptr;
44 return StringRef(IFACE_(name));
45}
46
48{
49 std::string search_item_text = fmt::format(
50 "{} " UI_MENU_ARROW_SEP "{}" UI_SEP_CHAR_S "{}",
52 item.name,
54 return UI_search_item_add(
55 items, search_item_text, (void *)&item, ICON_NONE, UI_BUT_HAS_SEP_CHAR, 0);
56}
57
59 const bool can_create_attribute,
61 uiSearchItems *seach_items,
62 const bool is_first)
63{
64 static GeometryAttributeInfo dummy_info;
65
66 /* Any string may be valid, so add the current search string along with the hints. */
67 if (!str.is_empty()) {
68 bool contained = false;
69 for (const GeometryAttributeInfo *attribute_info : infos) {
70 if (attribute_info->name == str) {
71 contained = true;
72 break;
73 }
74 }
75 if (!contained) {
76 dummy_info.name = str;
78 seach_items, str, &dummy_info, can_create_attribute ? ICON_ADD : ICON_NONE, 0, 0);
79 }
80 }
81
82 if (str.is_empty() && !is_first) {
83 /* Allow clearing the text field when the string is empty, but not on the first pass,
84 * or opening an attribute field for the first time would show this search item. */
85 dummy_info.name = str;
86 UI_search_item_add(seach_items, str, &dummy_info, ICON_X, 0, 0);
87 }
88
89 /* Don't filter when the menu is first opened, but still run the search
90 * so the items are in the same order they will appear in while searching. */
91 const StringRef string = is_first ? "" : str;
92
94 for (const GeometryAttributeInfo *item : infos) {
96 continue;
97 }
98 search.add(item->name, item);
99 }
100
101 const Vector<const GeometryAttributeInfo *> filtered_items = search.query(string);
102
103 for (const GeometryAttributeInfo *item : filtered_items) {
104 if (!attribute_search_item_add(seach_items, *item)) {
105 break;
106 }
107 }
108}
109
110} // namespace blender::ui
#define IFACE_(msgid)
#define UI_SEP_CHAR_S
@ UI_BUT_HAS_SEP_CHAR
bool UI_search_item_add(uiSearchItems *items, blender::StringRef name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
#define str(s)
std::optional< eCustomDataType > attr_type_to_custom_data_type(AttrType attr_type)
bool allow_procedural_attribute_access(StringRef attribute_name)
static bool attribute_search_item_add(uiSearchItems *items, const GeometryAttributeInfo &item)
void attribute_search_add_items(StringRef 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)
const char * name
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