26#include "guillaume/entities/badge.hpp"
28#include "guillaume/entities/builder_base.hpp"
29#include "guillaume/entities/content_helpers.hpp"
31#include "guillaume/systems/badge.hpp"
32#include "guillaume/theme.hpp"
52 _variant = Variant::Large;
55 _config.mainAxisAlignment =
57 _config.crossAxisAlignment =
80 std::shared_ptr<Badge>
82 const std::string &label,
Variant variant)
84 return withLabel(label).withVariant(variant).registerEntity(parent);
88 Variant variant,
const std::string &label)
137 throw std::invalid_argument(
"Badge size must be positive");
194 void Badge::build(
void)
201 buildText(registry, *
this, shared_from_this(), badge.getLabel(),
205 if (label !=
nullptr) {
206 badge.setLabelEntity(label->getIdentifier());
State of a badge: a small dot or pill, usually holding a count, drawn over another widget.
@ Center
Packed in the middle.
@ Horizontal
Row: children placed left to right.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
ComponentRegistry & getComponentRegistry(void)
Configures Badge widgets and registers them in the scene's entity registry.
std::shared_ptr< Badge > buildEntity(void) override
Build a badge and its label from the current configuration, without registering it or giving it a par...
Builder & withLabel(const std::string &label)
Set the text shown in the badge.
Builder & withVariant(Variant variant)
Choose the size class of the badge.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
void reset(void) override
Restore the defaults: default pose, the Large variant, an empty label, and a horizontal layout center...
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the badge is.
std::shared_ptr< Badge > makeBadge(std::shared_ptr< ecs::Entity > parent, const std::string &label, Variant variant)
Build a badge and its label, register it under parent and reset the builder.
Badge & setSize(float size)
Override the height of the variant (Paper size). Resizes at once.
Badge & setLabel(const std::string &label)
Change the text shown in the badge. Restyles at once.
Badge & setContainerColor(const utility::graphic::Color32Bit &color)
Override the fill color of the pill. Restyles at once.
Badge & clearSize(void)
Drop the height override and use the height of the variant again. Resizes at once.
~Badge(void) override
Destructor.
Badge & setContentColor(const utility::graphic::Color32Bit &color)
Override the color of the label. Restyles at once.
float getOpacity(void) const
Get the current opacity of the fade.
Badge & setVariant(Variant variant)
Change the size class of the badge. Resizes at once.
Variant getVariant(void) const
Get the size class of the badge.
components::Badge::Variant Variant
static std::shared_ptr< Badge > create(Arguments &&...arguments)
Build a badge without registering it in an entity registry.
bool isVisible(void) const
Get the visibility the badge is fading to.
float getSize(void) const
Get the height the badge is drawn with.
Badge & setVisible(bool visible)
Show or hide the badge with a 150 ms fade (Paper visible).
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size and color one badge and its label.
static void setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide the badge with a fade.
static float sizeOf(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the height of a badge, in dp.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Prepare the visibility fade of a badge.
static bool needsLabel(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the badge should have a label child.
Makes the color helpers callable from guillaume::entities without qualification.
State. Every class here is plain data attached to an entity.
Widgets: the classes used to create entities with the right components and children.
std::shared_ptr< Text > buildText(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &content, float fontSize, const utility::graphic::Color32Bit &color)
Create a Text of a given font size as a child of a widget, or nothing when there is no content.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ LabelSmall
11 / 16, medium weight.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...