Blender V5.3
interface_template_grease_pencil_layer_search.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 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
20#include "NOD_eval_log.hh"
21
22#include "UI_interface.hh"
23#include "UI_resources.hh"
24#include "UI_string_search.hh"
25
26#include <fmt/format.h>
27
28namespace blender::ui {
29
31 const Span<const std::string *> layer_names,
32 SearchItems &search_items,
33 const bool is_first)
34{
35 static std::string dummy_str;
36
37 /* Any string may be valid, so add the current search string along with the hints. */
38 if (!str.is_empty()) {
39 bool contained = false;
40 for (const std::string *name : layer_names) {
41 if (name != nullptr && str == *name) {
42 contained = true;
43 }
44 }
45 if (!contained) {
46 dummy_str = str;
47 search_item_add(&search_items, str, &dummy_str, ICON_NONE, 0, 0);
48 }
49 }
50
51 if (str.is_empty() && !is_first) {
52 /* Allow clearing the text field when the string is empty, but not on the first pass,
53 * or opening a layer name field for the first time would show this search item. */
54 dummy_str = str;
55 search_item_add(&search_items, str, &dummy_str, ICON_X, 0, 0);
56 }
57
58 /* Don't filter when the menu is first opened, but still run the search
59 * so the items are in the same order they will appear in while searching. */
60 const StringRef string = is_first ? "" : str;
61
63 for (const std::string *name : layer_names) {
64 search.add(*name, name);
65 }
66
67 const Vector<const std::string *> filtered_names = search.query(string);
68 for (const std::string *name : filtered_names) {
69 if (!search_item_add(&search_items, *name, (void *)name, ICON_NONE, BUT_HAS_SEP_CHAR, 0)) {
70 break;
71 }
72 }
73}
74
75} // namespace blender::ui
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
#define str(s)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
void grease_pencil_layer_search_add_items(StringRef str, Span< const std::string * > layer_names, SearchItems &items, bool is_first)