Blender
V5.0
source
blender
editors
interface
templates
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
11
#include "
DNA_customdata_types.h
"
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_geometry_nodes_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
28
namespace
blender::ui
{
29
30
void
grease_pencil_layer_search_add_items
(
const
StringRef
str
,
31
const
Span<const std::string *>
layer_names,
32
uiSearchItems
&seach_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
UI_search_item_add
(&seach_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
UI_search_item_add
(&seach_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
62
ui::string_search::StringSearch<const std::string>
search;
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
(!
UI_search_item_add
(&seach_items, *
name
, (
void
*)
name
, ICON_NONE,
UI_BUT_HAS_SEP_CHAR
, 0))
70
{
71
break
;
72
}
73
}
74
}
75
76
}
// namespace blender::ui
BKE_attribute.hh
BLI_string_ref.hh
BLT_translation.hh
DNA_customdata_types.h
NOD_geometry_nodes_log.hh
RNA_access.hh
RNA_enum_types.hh
UI_interface.hh
UI_BUT_HAS_SEP_CHAR
@ UI_BUT_HAS_SEP_CHAR
Definition
UI_interface_c.hh:254
UI_search_item_add
bool UI_search_item_add(uiSearchItems *items, blender::StringRef name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
Definition
interface_region_search.cc:104
UI_resources.hh
UI_string_search.hh
blender::Span
Definition
BLI_span.hh:74
blender::StringRef
Definition
BLI_string_ref.hh:150
blender::Vector
Definition
BLI_vector.hh:76
blender::string_search::StringSearch::add
void add(const StringRef str, T *user_data, const int weight=0)
Definition
BLI_string_search.hh:104
blender::string_search::StringSearch::query
Vector< T * > query(const StringRef query) const
Definition
BLI_string_search.hh:113
blender::ui::string_search::StringSearch
Definition
UI_string_search.hh:29
str
#define str(s)
Definition
ffmpeg_codecs.cc:103
blender::ui
Definition
UI_abstract_view.hh:45
blender::ui::grease_pencil_layer_search_add_items
void grease_pencil_layer_search_add_items(StringRef str, Span< const std::string * > layer_names, uiSearchItems &items, bool is_first)
name
const char * name
Definition
python_compat.hh:32
uiSearchItems
Definition
interface_region_search.cc:54
Generated on
for Blender by
doxygen
1.16.1