Blender V5.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
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
21#include "NOD_eval_log.hh"
22
23#include "UI_interface.hh"
24#include "UI_resources.hh"
25#include "UI_string_search.hh"
26
27#include <fmt/format.h>
28
29namespace blender {
30
32
33namespace ui {
34
36{
37 const char *name = nullptr;
39 return StringRef(IFACE_(name));
40}
41
43{
44 const char *name = nullptr;
46 return StringRef(IFACE_(name));
47}
48
50{
51 std::string search_item_text = fmt::format(
52 "{} " UI_MENU_ARROW_SEP "{}" UI_SEP_CHAR_S "{}",
54 item.name,
56 return search_item_add(items, search_item_text, (void *)&item, ICON_NONE, BUT_HAS_SEP_CHAR, 0);
57}
58
60 const bool can_create_attribute,
62 SearchItems *search_items,
63 const bool is_first)
64{
65 static GeometryAttributeInfo dummy_info;
66
67 /* Any string may be valid, so add the current search string along with the hints. */
68 if (!str.is_empty()) {
69 bool contained = false;
70 for (const GeometryAttributeInfo *attribute_info : infos) {
71 if (attribute_info->name == str) {
72 contained = true;
73 break;
74 }
75 }
76 if (!contained) {
77 dummy_info.name = str;
79 search_items, str, &dummy_info, can_create_attribute ? ICON_ADD : ICON_NONE, 0, 0);
80 }
81 }
82
83 if (str.is_empty() && !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 search_item_add(search_items, 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 StringRef string = is_first ? "" : 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(search_items, *item)) {
106 break;
107 }
108 }
109}
110
111} // namespace ui
112} // namespace blender
#define IFACE_(msgid)
#define UI_SEP_CHAR_S
constexpr StringRef()
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)
void attribute_search_add_items(StringRef str, bool can_create_attribute, Span< const nodes::eval_log::GeometryAttributeInfo * > infos, SearchItems *items, bool is_first)
static bool attribute_search_item_add(SearchItems *items, const GeometryAttributeInfo &item)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
static StringRef attribute_domain_string(const bke::AttrDomain domain)
static StringRef attribute_data_type_string(const eCustomDataType type)
BMesh Iterators.
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
const EnumPropertyItem rna_enum_attribute_type_items[]
const EnumPropertyItem rna_enum_attribute_domain_items[]
#define UI_MENU_ARROW_SEP
std::optional< bke::AttrDomain > domain