23#include "guillaume/systems/icon_button.hpp"
33#include "guillaume/components/borders.hpp"
34#include "guillaume/components/bound.hpp"
35#include "guillaume/components/color.hpp"
36#include "guillaume/components/elevation.hpp"
37#include "guillaume/components/transform.hpp"
41#include "guillaume/systems/button.hpp"
42#include "guillaume/systems/layout.hpp"
43#include "guillaume/theme.hpp"
59 constexpr std::array<SizeMetrics, 3> sizeTable { {
68 std::optional<Role> activeContainer;
69 std::optional<Role> idleContainer;
78 constexpr std::array<Palette, 4> paletteTable { {
80 { std::nullopt, std::nullopt, Role::Primary, Role::OnSurfaceVariant,
83 { Role::Primary, Role::SurfaceVariant, Role::OnPrimary,
84 Role::Primary,
true },
86 { Role::SecondaryContainer, Role::SurfaceVariant,
87 Role::OnSecondaryContainer, Role::OnSurfaceVariant,
true },
89 { Role::InverseSurface, std::nullopt, Role::InverseOnSurface,
90 Role::OnSurfaceVariant,
false },
95 const auto index =
static_cast<std::size_t
>(size);
96 if (index >= sizeTable.size()) {
97 throw std::runtime_error(
"Invalid icon button size");
99 return sizeTable[index];
104 const auto index =
static_cast<std::size_t
>(variant);
105 if (index >= paletteTable.size()) {
106 throw std::runtime_error(
"Invalid icon button variant");
108 return paletteTable[index];
111 bool isActive(
const Palette &entry,
bool isToggle,
bool isSelected)
113 return isSelected || (entry.plainIsActive && !isToggle);
118 return metrics(size).containerSize;
123 return metrics(size).iconFontSize;
129 static_cast<void>(metrics(size));
133 static utility::graphic::Color32Bit
135 bool isToggle,
bool isSelected)
137 const Palette &entry = palette(variant);
138 const auto role = isActive(entry, isToggle, isSelected)
139 ? entry.activeContainer
140 : entry.idleContainer;
143 : utility::graphic::Color32Bit(0, 0, 0, 0);
146 static utility::graphic::Color32Bit
148 bool isToggle,
bool isSelected)
150 const Palette &entry = palette(variant);
153 ? entry.activeContent
154 : entry.idleContent);
161 static utility::graphic::Color32Bit
162 stateLayerOver(
const utility::graphic::Color32Bit &base,
163 const utility::graphic::Color32Bit &content,
166 if (base.getAlpha() == 0) {
172 static utility::graphic::Color32Bit
178 if (variant != components::IconButton::Variant::Outlined) {
179 return utility::graphic::Color32Bit(0, 0, 0, 0);
183 return utility::graphic::Color32Bit(0, 0, 0, 0);
186 return scheme.getColor(SchemeColorRole::Outline).getColor();
214 return getIconFontSize(config.getSize());
217 utility::graphic::Color32Bit
227 getContentColor(config.getVariant(), button.
isToggle(),
228 button.isSelected()));
242 const bool toggle = button.isToggle();
243 const bool selected = button.isSelected();
244 const auto variant = config.getVariant();
248 (variant == Variant::Filled || variant == Variant::Tonal)
253 .setColor(variant == Variant::Outlined
266 button, getContainerColorFor(variant, toggle, selected));
268 button, getContentColor(variant, toggle, selected));
270 utility::graphic::Color32Bit containerColor = baseContainerColor;
273 containerColor = stateLayerOver(baseContainerColor,
contentColor,
275 }
else if (hovered) {
276 containerColor = stateLayerOver(baseContainerColor,
contentColor,
281 .setColor(containerColor);
284 .setColor(getBorderColor(variant, selected))
301 const auto size = config.getSize();
302 const float iconSize =
iconFontSize(registry, identifier);
303 const float containerSize = getContainerSize(size);
306 .setWidth(containerSize)
312 .setBorderRadius(getBorderRadius(size));
315 icon.setFontSize(iconSize);
317 const auto &buttonPose =
320 const auto &iconBound =
323 const float iconX = buttonPose.getPosition().x
324 + (containerSize - iconBound.getWidth()) / 2.0f;
325 const float iconY = buttonPose.getPosition().y
326 - (containerSize - iconBound.getHeight()) / 2.0f;
329 utility::graphic::PositionF(iconX, iconY,
330 buttonPose.getPosition().z),
331 buttonPose.getOrientation(), layer);
Corner radii and outline stroke of a rectangular entity.
Borders & setWidth(float width)
Set the width of the stroke painted by systems::RectangleRender.
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Bound & setHeight(float height) noexcept
Set the height.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Soft shadow drawn around an elevated surface.
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.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
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...
Arranges the children of a container in a row or a column and sizes the container around them.
static const utility::graphic::PoseF contentLayerPose(const utility::graphic::PositionF &position, const utility::graphic::OrientationF &orientation, const std::uint32_t &containerLayer)
Compute the pose of content placed by hand on a 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.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
float getContainerSize(SizeType size)
Width and height of the container of a FAB at its default size: 40 dp for Small, 56 dp for Medium,...
utility::graphic::Color32Bit disabledContainerColor(void)
Fill color of the container of a disabled widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit stateLayer(const utility::graphic::Color32Bit &base, const utility::graphic::Color32Bit &overlay, std::uint8_t alpha)
Blend a translucent tint over a base color.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit withAlpha(const utility::graphic::Color32Bit &color, std::uint8_t alpha)
Copy a color with another alpha channel.
Rules. Every class here runs each frame on the entities that have the components it declares.
@ Level0
Flat: no shadow, no tint.
StateLayer
The interaction states that change how a widget is drawn.
@ Hovered
0.08 overlay of the content color.
@ Pressed
0.12 overlay of the content color.
@ Full
Fully rounded (buttons, icon buttons, badges).
std::uint8_t getStateLayerAlpha(theme::StateLayer layer)
Get the opacity the active theme gives to a state layer, as an alpha channel value.
SchemeColorRole
The named colors of a scheme: what a color is used for, not what it looks like.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.
const Scheme & getActiveScheme(void)
Get the color scheme in use: the scheme of the active theme selected by setActiveScheme().
Style tables of the floating action buttons (FAB): container size, font sizes, corner radius and colo...
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.