guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text_field.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/text_field.hpp"
24
26{
27 const std::string &TextField::getPlaceholder(void) const
28 {
29 return _placeholder;
30 }
31
32 TextField &TextField::setPlaceholder(const std::string &placeholder)
33 {
34 if (_placeholder == placeholder) {
35 return *this;
36 }
37 _placeholder = placeholder;
38 setHasChanged(true);
39 return *this;
40 }
41
42 const std::string &TextField::getLabel(void) const
43 {
44 return _label;
45 }
46
47 TextField &TextField::setLabel(const std::string &label)
48 {
49 if (_label == label) {
50 return *this;
51 }
52 _label = label;
53 setHasChanged(true);
54 return *this;
55 }
56
57 const std::string &TextField::getSupportingText(void) const
58 {
59 return _supportingText;
60 }
61
62 TextField &TextField::setSupportingText(const std::string &supportingText)
63 {
64 if (_supportingText == supportingText) {
65 return *this;
66 }
67 _supportingText = supportingText;
68 setHasChanged(true);
69 return *this;
70 }
71
72 const std::string &TextField::getPrefix(void) const
73 {
74 return _prefix;
75 }
76
77 TextField &TextField::setPrefix(const std::string &prefix)
78 {
79 if (_prefix == prefix) {
80 return *this;
81 }
82 _prefix = prefix;
83 setHasChanged(true);
84 return *this;
85 }
86
87 const std::string &TextField::getSuffix(void) const
88 {
89 return _suffix;
90 }
91
92 TextField &TextField::setSuffix(const std::string &suffix)
93 {
94 if (_suffix == suffix) {
95 return *this;
96 }
97 _suffix = suffix;
98 setHasChanged(true);
99 return *this;
100 }
101
102 const std::string &TextField::getErrorText(void) const
103 {
104 return _errorText;
105 }
106
107 TextField &TextField::setErrorText(const std::string &errorText)
108 {
109 if (_errorText == errorText) {
110 return *this;
111 }
112 _errorText = errorText;
113 setHasChanged(true);
114 return *this;
115 }
116
117 bool TextField::isError(void) const
118 {
119 return _error;
120 }
121
123 {
124 if (_error == error) {
125 return *this;
126 }
127 _error = error;
128 setHasChanged(true);
129 return *this;
130 }
131
133 {
134 return _labelFloating;
135 }
136
138 {
139 if (_labelFloating == floating) {
140 return *this;
141 }
142 _labelFloating = floating;
143 setHasChanged(true);
144 return *this;
145 }
146} // namespace guillaume::components
bool isLabelFloating(void) const
Tell whether the label is drawn small, above the input.
bool isError(void) const
Tell whether the field is in error.
TextField & setPlaceholder(const std::string &placeholder)
Set the placeholder: the text that names the field, such as "Email".
TextField & setError(bool error)
Put the field in error or clear the error.
const std::string & getErrorText(void) const
Get the message shown under the field while it is in error.
TextField & setErrorText(const std::string &errorText)
Set the message shown under the field while it is in error.
const std::string & getPrefix(void) const
Get the fixed text shown before the input.
TextField & setLabel(const std::string &label)
Store the label.
const std::string & getSupportingText(void) const
Get the helper text shown under the field.
TextField(void)=default
Create a field with no text and no error.
const std::string & getSuffix(void) const
Get the fixed text shown after the input.
const std::string & getPlaceholder(void) const
Get the placeholder: the text that names the field.
TextField & setSupportingText(const std::string &supportingText)
Set the helper text shown under the field, such as "Atleast 8 characters".
TextField & setLabelFloating(bool floating)
Store whether the label floats above the input.
const std::string & getLabel(void) const
Get the label.
TextField & setPrefix(const std::string &prefix)
Set the fixed text shown before the input, such as "$".
TextField & setSuffix(const std::string &suffix)
Set the fixed text shown after the input, such as "kg".
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.