23#include "guillaume/systems/badge.hpp"
28#include "guillaume/components/animation.hpp"
29#include "guillaume/components/borders.hpp"
30#include "guillaume/components/bound.hpp"
31#include "guillaume/components/color.hpp"
32#include "guillaume/components/layout.hpp"
33#include "guillaume/components/text.hpp"
34#include "guillaume/components/typography.hpp"
36#include "guillaume/systems/layout.hpp"
37#include "guillaume/systems/typography.hpp"
38#include "guillaume/theme.hpp"
53 utility::graphic::Color32Bit
54 faded(
const utility::graphic::Color32Bit &color,
float opacity)
58 static_cast<std::uint8_t
>(
59 static_cast<float>(color.getAlpha()) * opacity + 0.5f));
70 void styleLabel(ecs::ComponentRegistry ®istry,
72 const std::string &content,
float fontSize,
73 const utility::graphic::Color32Bit &color)
78 if (registry.hasComponent<components::Typography>(label)) {
79 registry.getComponent<components::Typography>(label)
80 .setFontSize(fontSize);
84 if (registry.hasComponent<components::Color>(label)) {
85 registry.getComponent<components::Color>(label).setColor(color);
105 fade(*registry, identifier, progress);
115 if (badge.getSize().has_value()) {
116 return *badge.getSize();
118 switch (badge.getVariant()) {
135 return badge.
getVariant() != Variant::Dot && !badge.getLabel().empty();
145 if (badge.isVisible() == visible) {
159 const float target = badge.
isVisible() ? 1.0f : 0.0f;
160 const float from = badge.getFadeFrom();
162 badge.setOpacity(from + (target - from) * progress);
163 apply(componentRegistry, entityIdentifier);
171 const float size =
sizeOf(componentRegistry, entityIdentifier);
172 const float opacity = badge.getOpacity();
173 const auto label = badge.getLabelEntity();
182 if (badge.getVariant() != Variant::Dot
190 layout.setPadding(0.0f)
192 .setFixedWidth(width)
193 .setFixedHeight(size);
196 .setColor(faded(badge.getContainerColor().value_or(
200 styleLabel(componentRegistry, label, badge.getLabel(),
202 faded(badge.getContentColor().value_or(
206 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
A timer that runs from 0 to a duration and reports its eased progress, from 0 to 1,...
Animation & setEasing(motion::Easing easing)
Set the curve that turns the linear progress into the value passed to the sample handler.
Animation & setOnSampleHandler(const SampleHandler &handler)
Store the callback that applies the animation.
State of a badge: a small dot or pill, usually holding a count, drawn over another widget.
static constexpr float SmallSize
Height of the Small variant, in dp.
Badge & setVisible(bool visible)
Store the visibility the fade heads to.
Variant
Kind of badge; it sets the height and whether a label is shown.
Badge & setFadeFrom(float opacity)
Record the opacity a fade starts from.
bool isVisible(void) const noexcept
Check whether the badge is shown or fading in.
static constexpr float LargeSize
Height of the Large variant, in dp.
static constexpr float LabelScale
Label font size as a fraction of the badge height.
static constexpr float DotSize
Height of the Dot variant, in dp.
Variant getVariant(void) const noexcept
Get the kind of badge.
static constexpr float HorizontalPadding
Space on each side of the label, in dp.
Corner radii and outline stroke of a rectangular entity.
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
How a container arranges its children: in a row or a column, with which alignment,...
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.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Size and color one badge and its label.
static void fade(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, float progress)
Move the visibility fade to a given progress and restyle.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one badge; called by the frame loop.
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.
Badge(void)
Create the system in the Layout phase.
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.
Arranges the children of a container in a row or a column and sizes the container around them.
static void apply(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
static std::uint32_t layerOf(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Resolve the metrics of one text and write them into its components::Text.
static constexpr motion::Easing standard(void)
Get the easing for elements that move or change while staying on screen.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
utility::graphic::Color32Bit withAlpha(const utility::graphic::Color32Bit &color, std::uint8_t alpha)
Copy a color with another alpha channel.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
Rules. Every class here runs each frame on the entities that have the components it declares.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Full
Fully rounded (buttons, icon buttons, badges).
float getMotionDuration(theme::MotionDuration duration)
Get the length the active theme gives to a duration token.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.