23#include "guillaume/systems/extended_floating_action_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"
106 const bool visible = button.isVisible();
107 const auto mode = config.getMode();
108 const bool lowered = config.isLowered();
113 if (disabled || !visible || mode == Mode::Flat) {
115 }
else if (hovered && !pressed) {
117 static_cast<std::size_t
>(level) + 1);
120 .setElevationLevel(level);
137 const bool labelShown = config.isExtended() && label
144 const bool visible = button.isVisible();
145 const auto variant = config.getVariant();
146 const bool lowered = config.isLowered();
182 utility::graphic::Color32Bit containerColor = baseContainerColor;
187 }
else if (hovered) {
193 .setColor(containerColor);
217 const bool visible = button.isVisible();
219 const auto variant = config.getVariant();
220 const auto size = config.getSize();
221 const auto &customSize = config.getCustomSize();
222 const bool extended = config.isExtended();
223 const float baseHeight =
228 .setBorderRadius(customSize.has_value()
232 if (!icon && !label) {
237 icon.setFontSize(fontHeight);
247 constexpr float leading = 16.0f;
248 constexpr float gap = 12.0f;
249 constexpr float trailing = 20.0f;
251 const auto &buttonPose =
254 const auto sizeOf = [®istry](
const Button::Child &child) {
257 return std::make_pair(bound.getWidth(), bound.getHeight());
264 utility::graphic::PositionF(buttonPose.getPosition().x + x,
265 buttonPose.getPosition().y
266 - (baseHeight - height)
268 buttonPose.getPosition().z),
269 buttonPose.getOrientation(), layer));
272 const auto [iconWidth, iconHeight] =
273 icon ? sizeOf(icon) : std::make_pair(0.0f, 0.0f);
274 const auto [labelWidth, labelHeight] =
275 label ? sizeOf(label) : std::make_pair(0.0f, 0.0f);
277 const bool showLabel = extended && labelWidth > 0.0f;
278 float width = baseHeight;
281 width = leading + labelWidth + trailing;
282 float cursor = leading;
283 if (iconWidth > 0.0f) {
284 place(icon, cursor, iconHeight);
285 cursor += iconWidth + gap;
286 width += iconWidth + gap;
288 place(label, cursor, labelHeight);
291 place(icon, (baseHeight - iconWidth) / 2.0f, iconHeight);
294 place(label, (baseHeight - labelWidth) / 2.0f, labelHeight);
304 }
else if (!disabled && visible) {
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...
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.
utility::graphic::Color32Bit getContentColor(VariantType variant)
Color of the icon and of the label of a FAB: Primary for the Surface variant, the "on container" role...
float getLabelFontSize(SizeType size)
Font size shared by the label and the icon of an extended FAB: 18 dp for Small, 24 dp for Medium,...
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 getContainerColor(VariantType variant, bool lowered)
Fill color of the container of a FAB.
float getBorderRadius(SizeType size)
Corner radius of the container: the Medium, Large and ExtraLarge shape of the active theme for a Smal...
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.
Rules. Every class here runs each frame on the entities that have the components it declares.
ElevationLevel
How far a surface is raised above the background, in six steps.
@ Level1
Lowest raised level.
@ Level3
Third raised level.
@ Level0
Flat: no shadow, no tint.
@ LabelLarge
14 / 20, medium weight.
@ Hovered
0.08 overlay of the content color.
@ Pressed
0.12 overlay of the content color.
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.