29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
69 using Handler = std::function<void(
void)>;
75 Variant _variant { Variant::Filled };
76 std::string _leadingIcon {};
77 std::string _trailingIcon {};
79 bool _editable {
true };
80 bool _dense {
false };
81 bool _multiline {
false };
82 std::optional<float> _width {};
190 const std::string &
getText(
void)
const noexcept;
224 bool isDense(
void)
const noexcept;
258 const std::optional<float> &
getWidth(
void)
const noexcept;
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.
~TextFieldConfiguration(void)=default
Default destructor.
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.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
State. Every class here is plain data attached to an entity.