30#include <utility/graphic/color.hpp>
31#include <utility/graphic/pose.hpp>
33#include "guillaume/ecs/component_registry.hpp"
34#include "guillaume/ecs/entity_builder.hpp"
36#include "guillaume/components/line.hpp"
37#include "guillaume/components/text_field.hpp"
38#include "guillaume/components/text_field_configuration.hpp"
40#include "guillaume/entities/builder_base.hpp"
41#include "guillaume/entities/icon.hpp"
42#include "guillaume/entities/surface.hpp"
43#include "guillaume/entities/text.hpp"
44#include "guillaume/entities/view.hpp"
117 public SurfaceBase<components::TextField, components::Line,
118 components::TextFieldConfiguration>
138 Variant _variant { Variant::Filled };
139 std::string _placeholder {};
140 std::string _leadingIcon {};
141 std::string _trailingIcon {};
142 std::string _supportingText {};
143 bool _error {
false };
144 std::string _text {};
162 std::shared_ptr<TextField>
buildEntity(
void)
override;
169 void reset(
void)
override;
251 std::shared_ptr<TextField>
253 Variant variant,
const std::string &placeholder,
254 const std::string &leadingIcon,
255 const std::string &trailingIcon,
256 const std::string &supportingText,
bool error,
257 const std::string &text =
"");
273 template<
typename... Arguments>
274 static std::shared_ptr<TextField>
create(Arguments &&...arguments)
276 std::shared_ptr<TextField> entity(
277 new TextField(std::forward<Arguments>(arguments)...));
324 std::string
getText(
void)
const;
483 setOnChange(std::function<
void(
const std::string &)> onChange);
553 void buildContent(
void);
593 Variant variant,
const std::string &placeholder,
594 const std::string &leadingIcon,
595 const std::string &trailingIcon,
596 const std::string &supportingText,
bool error,
597 const std::string &text);
State of a text field widget that is not text around the input: its variant, icons,...
static constexpr float MinWidth
Smallest width of a text field, in dp.
Variant
Look of the field: Filled has a tinted background and a line under it; Outlined has a border the labe...
The texts around the input of a text field, and its error state: placeholder, label,...
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
Builder & withText(const std::string &text)
Set the text the field holds when created.
Builder & withLeadingIcon(const std::string &iconGlyph)
Set the icon shown at the start of the box.
Builder & withError(bool error)
Choose whether the field starts in the error state.
void reset(void) override
Restore the defaults: Filled variant, no label, no icon, no supporting text, no error,...
Builder & withTrailingIcon(const std::string &iconGlyph)
Set the icon shown at the end of the box.
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the field is created with.
std::shared_ptr< TextField > makeTextField(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &placeholder, const std::string &leadingIcon, const std::string &trailingIcon, const std::string &supportingText, bool error, const std::string &text="")
Build a text field, register it under parent and reset the builder.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withPlaceholder(const std::string &placeholder)
Set the label.
Builder & withVariant(Variant variant)
Set the field variant.
std::shared_ptr< TextField > buildEntity(void) override
Build a text field and its children from the current configuration, without registering it or setting...
Builder & withSupportingText(const std::string &supportingText)
Set the helper text shown under the box.
A box the user types text into, with a label, optional icons, prefix and suffix, and a helper or erro...
static std::shared_ptr< TextField > create(Arguments &&...arguments)
Create a text field and its children, without registering it in an entity registry.
ecs::Entity::Identifier getSupportingIdentifier(void) const
Get the identifier of the child that shows the supporting or error text under the box.
TextField & setSupportingText(const std::string &supportingText)
Set the helper text shown under the box.
TextField & setSuffix(const std::string &suffix)
Set the text shown just after the typed text, such as a unit.
TextField & setErrorText(const std::string &errorText)
Set the text shown under the box in the error state.
~TextField(void) override
Default destructor.
bool isError(void) const
Check whether the field is in the error state.
TextField & setText(const std::string &text)
Replace the typed text. Restyles at once.
TextField & setDisabled(bool disabled)
Enable or disable the field.
bool isMultiline(void) const
Check whether the height follows the content.
TextField & setOnFocus(std::function< void(void)> onFocus)
Set the handler called when the field gains the focus.
bool isFocused(void) const
Check whether the field has the keyboard focus.
bool isEditable(void) const
Check whether the user may edit the text.
TextField & setOnChange(std::function< void(const std::string &)> onChange)
Set the handler called when the user edits the text (Paper onChangeText).
ecs::Entity::Identifier getPrefixIdentifier(void) const
Get the identifier of the prefix child.
ecs::Entity::Identifier getInputIdentifier(void) const
Get the identifier of the child that holds the typed text.
TextField & setError(bool error)
Put the field in or out of the error state.
std::string getText(void) const
Get the typed text.
TextField & setOnBlur(std::function< void(void)> onBlur)
Set the handler called when the field loses the focus.
bool isDisabled(void) const
Check whether the field is disabled.
Variant getVariant(void) const
Get the field variant.
static constexpr float MinWidth
Smallest width of the box, in dp (100).
TextField & setDense(bool dense)
Use the smaller, dense height (Paper dense).
TextField & setVariant(Variant variant)
Change the field variant. Restyles at once.
components::TextFieldConfiguration::Variant Variant
Look of the field: Filled or Outlined.
TextField & setPlaceholder(const std::string &placeholder)
Change the label text.
TextField & setWidth(float width)
Fix the width of the box instead of letting it follow the content. Restyles at once.
ecs::Entity::Identifier getErrorIconIdentifier(void) const
Get the identifier of the "error" icon shown in the error state.
TextField & setPrefix(const std::string &prefix)
Set the text shown just before the typed text, such as a currency sign.
bool isLabelFloating(void) const
Check whether the label floats above the typed text.
ecs::Entity::Identifier getLabelIdentifier(void) const
Get the identifier of the label child.
ecs::Entity::Identifier getSuffixIdentifier(void) const
Get the identifier of the suffix child.
TextField & setEditable(bool editable)
Allow or forbid typing in the field (Paper editable).
TextField & setMultiline(bool multiline)
Let the height of the box follow its content instead of being fixed (Paper multiline)....
bool isDense(void) const
Check whether the field uses the dense height.
Widgets: the classes used to create entities with the right components and children.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...