23#include "guillaume/components/text_field_configuration.hpp"
38 if (_variant == variant) {
55 if (_leadingIcon == glyph) {
72 if (_trailingIcon == glyph) {
75 _trailingIcon = glyph;
103 if (_editable == editable) {
106 _editable = editable;
118 if (_dense == dense) {
133 if (_multiline == multiline) {
136 _multiline = multiline;
141 const std::optional<float> &
150 if (width.has_value()) {
153 if (_width == width) {
170 _onChange = std::move(handler);
182 _onFocus = std::move(handler);
194 _onBlur = std::move(handler);
201 return _leadingIconEntity;
207 if (_leadingIconEntity == identifier) {
210 _leadingIconEntity = identifier;
218 return _trailingIconEntity;
224 if (_trailingIconEntity == identifier) {
227 _trailingIconEntity = identifier;
235 return _errorIconEntity;
241 if (_errorIconEntity == identifier) {
244 _errorIconEntity = identifier;
258 if (_inputColumn == identifier) {
261 _inputColumn = identifier;
275 if (_labelEntity == identifier) {
278 _labelEntity = identifier;
292 if (_inputEntity == identifier) {
295 _inputEntity = identifier;
303 return _prefixEntity;
309 if (_prefixEntity == identifier) {
312 _prefixEntity = identifier;
320 return _suffixEntity;
326 if (_suffixEntity == identifier) {
329 _suffixEntity = identifier;
337 return _supportingEntity;
343 if (_supportingEntity == identifier) {
346 _supportingEntity = identifier;
State of a text field widget that is not text around the input: its variant, icons,...
ecs::Entity::Identifier getLabelEntity(void) const noexcept
Get the child that draws the label (the placeholder text).
ecs::Entity::Identifier getInputColumn(void) const noexcept
Get the column that stacks the label above the input.
bool isMultiline(void) const noexcept
Tell whether the field grows with its content.
TextFieldConfiguration(void)=default
Create the configuration of an editable, single-line filled field with no icon and no forced width.
TextFieldConfiguration & setTrailingIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the trailing icon.
ecs::Entity::Identifier getSupportingEntity(void) const noexcept
Get the child that draws the supporting or error text under the field.
std::function< void(void)> Handler
TextFieldConfiguration & setTrailingIcon(const std::string &glyph)
Set the icon shown after the input.
ecs::Entity::Identifier getInputEntity(void) const noexcept
Get the child the user types in.
TextFieldConfiguration & setVariant(Variant variant)
Choose between the filled and the outlined look.
TextFieldConfiguration & setErrorIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the icon shown while the field is in error.
TextFieldConfiguration & setSupportingEntity(ecs::Entity::Identifier identifier)
Record the child that draws the supporting or error text under the field.
bool isEditable(void) const noexcept
Tell whether the user can edit the text.
const std::string & getLeadingIcon(void) const noexcept
Get the icon shown before the input.
TextFieldConfiguration & setPrefixEntity(ecs::Entity::Identifier identifier)
Record the child that draws the prefix.
TextFieldConfiguration & setDense(bool dense)
Choose between the regular and the compact height.
static constexpr float MinWidth
Smallest width of a text field, in dp.
const ChangeHandler & getOnChange(void) const noexcept
Get the callback run when the user edits the text.
const std::string & getText(void) const noexcept
Get the last known input text.
ecs::Entity::Identifier getErrorIconEntity(void) const noexcept
Get the child that draws the icon shown while the field is in error.
TextFieldConfiguration & setInputColumn(ecs::Entity::Identifier identifier)
Record the column that stacks the label above the input.
TextFieldConfiguration & setLeadingIcon(const std::string &glyph)
Set the icon shown before the input.
TextFieldConfiguration & setMultiline(bool multiline)
Choose between a fixed height and a height that follows the content.
Variant getVariant(void) const noexcept
Get the look of the field.
TextFieldConfiguration & setOnChange(ChangeHandler handler)
Set the callback run when the user edits the text.
TextFieldConfiguration & setLeadingIconEntity(ecs::Entity::Identifier identifier)
Record the child that draws the leading icon.
TextFieldConfiguration & setText(const std::string &text)
Store the last known input text.
const Handler & getOnFocus(void) const noexcept
Get the callback run when the field gains the focus.
TextFieldConfiguration & setInputEntity(ecs::Entity::Identifier identifier)
Record the child the user types in.
TextFieldConfiguration & setOnBlur(Handler handler)
Set the callback run when the field loses the focus.
TextFieldConfiguration & setOnFocus(Handler handler)
Set the callback run when the field gains the focus.
std::function< void(const std::string &)> ChangeHandler
ecs::Entity::Identifier getSuffixEntity(void) const noexcept
Get the child that draws the suffix.
const Handler & getOnBlur(void) const noexcept
Get the callback run when the field loses the focus.
const std::optional< float > & getWidth(void) const noexcept
Get the forced width of the field.
bool isDense(void) const noexcept
Tell whether the field uses the compact height.
const std::string & getTrailingIcon(void) const noexcept
Get the icon shown after the input.
ecs::Entity::Identifier getPrefixEntity(void) const noexcept
Get the child that draws the prefix.
TextFieldConfiguration & setWidth(std::optional< float > width)
Force the width of the field, or let it follow its content.
TextFieldConfiguration & setEditable(bool editable)
Allow or forbid editing by the user.
Variant
Look of the field: Filled has a tinted background and a line under it; Outlined has a border the labe...
TextFieldConfiguration & setSuffixEntity(ecs::Entity::Identifier identifier)
Record the child that draws the suffix.
ecs::Entity::Identifier getTrailingIconEntity(void) const noexcept
Get the child that draws the trailing icon.
ecs::Entity::Identifier getLeadingIconEntity(void) const noexcept
Get the child that draws the leading icon.
TextFieldConfiguration & setLabelEntity(ecs::Entity::Identifier identifier)
Record the child that draws the label.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
State. Every class here is plain data attached to an entity.