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