guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::TextField Class Reference

The texts around the input of a text field, and its error state: placeholder, label, supporting text, prefix, suffix and error text. More...

#include <headers/guillaume/components/text_field.hpp>

Inheritance diagram for guillaume::components::TextField:
Collaboration diagram for guillaume::components::TextField:

Public Member Functions

 TextField (void)=default
 Create a field with no text and no error.
 ~TextField (void)=default
 Default destructor.
const std::string & getPlaceholder (void) const
 Get the placeholder: the text that names the field.
TextField & setPlaceholder (const std::string &placeholder)
 Set the placeholder: the text that names the field, such as "Email".
const std::string & getLabel (void) const
 Get the label.
TextField & setLabel (const std::string &label)
 Store the label.
const std::string & getSupportingText (void) const
 Get the helper text shown under the field.
TextField & setSupportingText (const std::string &supportingText)
 Set the helper text shown under the field, such as "At least 8 characters".
const std::string & getPrefix (void) const
 Get the fixed text shown before the input.
TextField & setPrefix (const std::string &prefix)
 Set the fixed text shown before the input, such as "$".
const std::string & getSuffix (void) const
 Get the fixed text shown after the input.
TextField & setSuffix (const std::string &suffix)
 Set the fixed text shown after the input, such as "kg".
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.
bool isError (void) const
 Tell whether the field is in error.
TextField & setError (bool error)
 Put the field in error or clear the error.
bool isLabelFloating (void) const
 Tell whether the label is drawn small, above the input.
TextField & setLabelFloating (bool floating)
 Store whether the label floats above the input.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

The texts around the input of a text field, and its error state: placeholder, label, supporting text, prefix, suffix and error text.

It is shared by the two widgets that contain an input: entities::TextField (together with components::TextFieldConfiguration) and entities::Search. The widget writes the texts and the error flag. systems::TextField reads them in the Layout phase to fill and color the label, affix and supporting text children.

Two members are derived, not chosen: systems::TextField and systems::Search overwrite the label with the placeholder, and the label-floating flag with the state of the field, every frame. The text the user types is not stored here; it is the components::Text of the input.

See also
systems::TextField, components::TextFieldConfiguration

Definition at line 52 of file text_field.hpp.

Member Function Documentation

◆ getErrorText()

const std::string & guillaume::components::TextField::getErrorText ( void ) const

Get the message shown under the field while it is in error.

Returns
The error text; empty for none.

Definition at line 102 of file text_field.cpp.

Here is the caller graph for this function:

◆ getLabel()

const std::string & guillaume::components::TextField::getLabel ( void ) const

Get the label.

Returns
The label, which the systems keep equal to the placeholder.

Definition at line 42 of file text_field.cpp.

◆ getPlaceholder()

const std::string & guillaume::components::TextField::getPlaceholder ( void ) const

Get the placeholder: the text that names the field.

Returns
The placeholder; it is also the field's accessible name.

Definition at line 27 of file text_field.cpp.

◆ getPrefix()

const std::string & guillaume::components::TextField::getPrefix ( void ) const

Get the fixed text shown before the input.

Returns
The prefix; empty for none.

Definition at line 72 of file text_field.cpp.

◆ getSuffix()

const std::string & guillaume::components::TextField::getSuffix ( void ) const

Get the fixed text shown after the input.

Returns
The suffix; empty for none.

Definition at line 87 of file text_field.cpp.

◆ getSupportingText()

const std::string & guillaume::components::TextField::getSupportingText ( void ) const

Get the helper text shown under the field.

Returns
The supporting text; empty for none.

Definition at line 57 of file text_field.cpp.

◆ isError()

bool guillaume::components::TextField::isError ( void ) const

Tell whether the field is in error.

Returns
True when in error.

Definition at line 117 of file text_field.cpp.

Here is the caller graph for this function:

◆ isLabelFloating()

bool guillaume::components::TextField::isLabelFloating ( void ) const

Tell whether the label is drawn small, above the input.

Returns
True when the label floats; false when it rests in the place of the input.

Definition at line 132 of file text_field.cpp.

◆ setError()

TextField & guillaume::components::TextField::setError ( bool error)

Put the field in error or clear the error.

A field in error is drawn with the error colors, shows its error icon in place of the trailing icon and its error text in place of the supporting text. Marks the component changed only when the flag differs.

Parameters
errorTrue when the content is invalid.
Returns
This component, for chaining.

Definition at line 122 of file text_field.cpp.

Here is the call graph for this function:

◆ setErrorText()

TextField & guillaume::components::TextField::setErrorText ( const std::string & errorText)

Set the message shown under the field while it is in error.

It replaces the supporting text only while isError() is true. Marks the component changed only when the text differs.

Parameters
errorTextThe new error text.
Returns
This component, for chaining.

Definition at line 107 of file text_field.cpp.

Here is the call graph for this function:

◆ setLabel()

TextField & guillaume::components::TextField::setLabel ( const std::string & label)

Store the label.

systems::TextField and systems::Search overwrite it with the placeholder every frame, so set the placeholder instead. Marks the component changed only when the text differs.

Parameters
labelThe new label.
Returns
This component, for chaining.

Definition at line 47 of file text_field.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLabelFloating()

TextField & guillaume::components::TextField::setLabelFloating ( bool floating)

Store whether the label floats above the input.

The systems overwrite it every frame: the label of a text field widget floats while the field is focused or has content; the label of any other entity with this component floats while it has content or is in error. Marks the component changed only when the flag differs.

Parameters
floatingTrue when the label floats.
Returns
This component, for chaining.

Definition at line 137 of file text_field.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPlaceholder()

TextField & guillaume::components::TextField::setPlaceholder ( const std::string & placeholder)

Set the placeholder: the text that names the field, such as "Email".

It is drawn by the label child, inside the field while it is empty and above the input once it floats. Marks the component changed only when the text differs.

Parameters
placeholderThe new placeholder.
Returns
This component, for chaining.

Definition at line 32 of file text_field.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPrefix()

TextField & guillaume::components::TextField::setPrefix ( const std::string & prefix)

Set the fixed text shown before the input, such as "$".

Marks the component changed only when the text differs.

Parameters
prefixThe new prefix.
Returns
This component, for chaining.

Definition at line 77 of file text_field.cpp.

Here is the call graph for this function:

◆ setSuffix()

TextField & guillaume::components::TextField::setSuffix ( const std::string & suffix)

Set the fixed text shown after the input, such as "kg".

Marks the component changed only when the text differs.

Parameters
suffixThe new suffix.
Returns
This component, for chaining.

Definition at line 92 of file text_field.cpp.

Here is the call graph for this function:

◆ setSupportingText()

TextField & guillaume::components::TextField::setSupportingText ( const std::string & supportingText)

Set the helper text shown under the field, such as "At least 8 characters".

While the field is in error and has an error text, the error text is shown in its place. Marks the component changed only when the text differs.

Parameters
supportingTextThe new supporting text.
Returns
This component, for chaining.

Definition at line 62 of file text_field.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: