guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
search.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/search.hpp"
24
25#include <utility>
26
28{
30 {
31 return _variant;
32 }
33
35 {
36 return assign(_variant, variant);
37 }
38
39 const std::string &Search::getPlaceholder(void) const noexcept
40 {
41 return _placeholder;
42 }
43
44 Search &Search::setPlaceholder(const std::string &placeholder)
45 {
46 return assign(_placeholder, placeholder);
47 }
48
49 const std::string &Search::getText(void) const noexcept
50 {
51 return _text;
52 }
53
54 Search &Search::setText(const std::string &text)
55 {
56 return assign(_text, text);
57 }
58
59 const std::string &Search::getIconGlyph(void) const noexcept
60 {
61 return _iconGlyph;
62 }
63
64 Search &Search::setIconGlyph(const std::string &glyph)
65 {
66 return assign(_iconGlyph, glyph);
67 }
68
69 const std::string &Search::getTrailingGlyph(void) const noexcept
70 {
71 return _trailingGlyph;
72 }
73
74 Search &Search::setTrailingGlyph(const std::string &glyph)
75 {
76 return assign(_trailingGlyph, glyph);
77 }
78
79 bool Search::isLoading(void) const noexcept
80 {
81 return _loading;
82 }
83
85 {
86 return assign(_loading, loading);
87 }
88
89 const std::function<void(void)> &Search::getOnIconPress(void) const noexcept
90 {
91 return _onIconPress;
92 }
93
94 Search &Search::setOnIconPress(std::function<void(void)> handler)
95 {
96 _onIconPress = std::move(handler);
97 return *this;
98 }
99
100 const std::function<void(void)> &
101 Search::getOnClearIconPress(void) const noexcept
102 {
103 return _onClearIconPress;
104 }
105
106 Search &Search::setOnClearIconPress(std::function<void(void)> handler)
107 {
108 _onClearIconPress = std::move(handler);
109 return *this;
110 }
111
112 const std::function<void(void)> &
114 {
115 return _onTrailingIconPress;
116 }
117
118 Search &Search::setOnTrailingIconPress(std::function<void(void)> handler)
119 {
120 _onTrailingIconPress = std::move(handler);
121 return *this;
122 }
123
125 {
126 return _searchIcon;
127 }
128
130 {
131 return assign(_searchIcon, identifier);
132 }
133
135 {
136 return _textEntity;
137 }
138
140 {
141 return assign(_textEntity, identifier);
142 }
143
145 {
146 return _placeholderEntity;
147 }
148
150 {
151 return assign(_placeholderEntity, identifier);
152 }
153
155 {
156 return _clearIcon;
157 }
158
160 {
161 return assign(_clearIcon, identifier);
162 }
163
165 {
166 return _loadingIcon;
167 }
168
170 {
171 return assign(_loadingIcon, identifier);
172 }
173
175 {
176 return _trailingIcon;
177 }
178
180 {
181 return assign(_trailingIcon, identifier);
182 }
183} // namespace guillaume::components
Search & setTextEntity(ecs::Entity::Identifier identifier)
Record the child the user types the query in.
Definition search.cpp:139
ecs::Entity::Identifier getLoadingIcon(void) const noexcept
Get the child that draws the loading glyph.
Definition search.cpp:164
const std::function< void(void)> & getOnIconPress(void) const noexcept
Get the callback run when the leading icon is pressed.
Definition search.cpp:89
Variant getVariant(void) const noexcept
Get the shape of the field.
Definition search.cpp:29
const std::string & getIconGlyph(void) const noexcept
Get the icon at the leading edge of the field.
Definition search.cpp:59
ecs::Entity::Identifier getClearIcon(void) const noexcept
Get the pressable child that draws the clear button.
Definition search.cpp:154
Search & setLoadingIcon(ecs::Entity::Identifier identifier)
Record the child that draws the loading glyph.
Definition search.cpp:169
Search & setClearIcon(ecs::Entity::Identifier identifier)
Record the pressable child that draws the clear button.
Definition search.cpp:159
Variant
Shape of the search field.
Definition search.hpp:64
const std::string & getText(void) const noexcept
Get the query.
Definition search.cpp:49
ecs::Entity::Identifier getSearchIcon(void) const noexcept
Get the pressable child that draws the leading icon.
Definition search.cpp:124
Search & setLoading(bool loading)
Show or hide the loading glyph.
Definition search.cpp:84
const std::function< void(void)> & getOnTrailingIconPress(void) const noexcept
Get the callback run when the trailing icon is pressed.
Definition search.cpp:113
Search & setText(const std::string &text)
Store the query.
Definition search.cpp:54
Search & setPlaceholderEntity(ecs::Entity::Identifier identifier)
Record the child that draws the placeholder.
Definition search.cpp:149
Search & setTrailingIcon(ecs::Entity::Identifier identifier)
Record the pressable child that draws the trailing icon.
Definition search.cpp:179
const std::string & getPlaceholder(void) const noexcept
Get the hint shown while the query is empty.
Definition search.cpp:39
Search & setOnIconPress(std::function< void(void)> handler)
Set the callback run when the leading icon is pressed.
Definition search.cpp:94
Search & setIconGlyph(const std::string &glyph)
Set the icon at the leading edge of the field, such as "arrow_back".
Definition search.cpp:64
Search & setOnTrailingIconPress(std::function< void(void)> handler)
Set the callback run when the trailing icon is pressed.
Definition search.cpp:118
const std::string & getTrailingGlyph(void) const noexcept
Get the icon at the trailing edge of the field.
Definition search.cpp:69
Search & setSearchIcon(ecs::Entity::Identifier identifier)
Record the pressable child that draws the leading icon.
Definition search.cpp:129
ecs::Entity::Identifier getTrailingIcon(void) const noexcept
Get the pressable child that draws the trailing icon.
Definition search.cpp:174
ecs::Entity::Identifier getPlaceholderEntity(void) const noexcept
Get the child that draws the placeholder.
Definition search.cpp:144
ecs::Entity::Identifier getTextEntity(void) const noexcept
Get the child the user types the query in.
Definition search.cpp:134
Search & setPlaceholder(const std::string &placeholder)
Set the hint shown while the query is empty, such as "Search".
Definition search.cpp:44
Search(void)=default
Create the configuration of an empty search bar with the "search" leading icon.
Search & setTrailingGlyph(const std::string &glyph)
Set the icon at the trailing edge of the field, such as "mic".
Definition search.cpp:74
Search & setVariant(Variant variant)
Set the shape of the field.
Definition search.cpp:34
bool isLoading(void) const noexcept
Tell whether the field shows its loading glyph.
Definition search.cpp:79
const std::function< void(void)> & getOnClearIconPress(void) const noexcept
Get the callback run when the clear button is pressed.
Definition search.cpp:101
Search & setOnClearIconPress(std::function< void(void)> handler)
Set the callback run when the clear button is pressed.
Definition search.cpp:106
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
State. Every class here is plain data attached to an entity.