23#include "guillaume/systems/tooltip.hpp"
29#include "guillaume/components/accessibility.hpp"
30#include "guillaume/components/animation.hpp"
31#include "guillaume/components/borders.hpp"
32#include "guillaume/components/bound.hpp"
33#include "guillaume/components/color.hpp"
34#include "guillaume/components/elevation.hpp"
35#include "guillaume/components/layout.hpp"
36#include "guillaume/components/overlay.hpp"
37#include "guillaume/components/text.hpp"
38#include "guillaume/components/transform.hpp"
41#include "guillaume/motion/easing.hpp"
42#include "guillaume/systems/layout.hpp"
43#include "guillaume/theme.hpp"
54 constexpr float PlainHeight = 32.0f;
57 constexpr float RichHeight = 64.0f;
65 void colorChild(ecs::ComponentRegistry ®istry,
67 const utility::graphic::Color32Bit &color)
69 if (registry.hasComponent<components::Color>(child)) {
70 registry.getComponent<components::Color>(child).setColor(color);
79 void arrange(ecs::ComponentRegistry ®istry,
83 registry.getComponent<components::Layout>(identifier)
117 tooltip.setLastProgress(progress);
118 advance(*registry, identifier, delta);
122 .setOnDismissHandler([registry, identifier]() {
123 hide(*registry, identifier);
160 float width,
float height)
165 tooltip.
setViewport(std::make_pair(width, height));
166 if (tooltip.isVisible()) {
167 place(componentRegistry, entityIdentifier);
176 place(componentRegistry, entityIdentifier);
177 apply(componentRegistry, entityIdentifier);
185 apply(componentRegistry, entityIdentifier);
192 if (!
hasAnchor(componentRegistry, entityIdentifier)) {
200 tooltip.setLeaveTime(0.0f);
201 tooltip.setHoverTime(tooltip.getHoverTime() + deltaTime);
202 if (!tooltip.isVisible()
203 && tooltip.getHoverTime() >= tooltip.getEnterDelay()) {
204 show(componentRegistry, entityIdentifier);
210 if (tooltip.isVisible()) {
211 tooltip.setLeaveTime(tooltip.getLeaveTime() + deltaTime);
212 if (tooltip.getLeaveTime() >= tooltip.getLeaveDelay()) {
213 tooltip.setLeaveTime(0.0f);
214 hide(componentRegistry, entityIdentifier);
222 if (!
hasAnchor(componentRegistry, entityIdentifier)) {
226 const auto &tooltip =
234 const auto anchorPose =
237 const auto &anchorBound =
242 const float width = bound.getWidth();
243 const float height = bound.getHeight();
244 float x = anchorPose.getPosition().getX()
245 + (anchorBound.getWidth() - width) / 2.0f;
248 float y = anchorPose.getPosition().getY() - anchorBound.getHeight();
250 if (tooltip.getViewport().has_value()) {
252 const float viewportWidth = tooltip.getViewport()->first;
253 const float viewportHeight = tooltip.getViewport()->second;
255 if (down + height > viewportHeight) {
256 down = -anchorPose.getPosition().getY() - height;
258 x = std::clamp(x, 0.0f, std::max(0.0f, viewportWidth - width));
260 std::clamp(down, 0.0f, std::max(0.0f, viewportHeight - height));
265 .setPose(utility::graphic::PoseF(
266 utility::graphic::PositionF(x, y,
267 anchorPose.getPosition().getZ()),
268 anchorPose.getOrientation()));
269 arrange(componentRegistry, entityIdentifier);
275 const auto &tooltip =
278 const bool rich = (tooltip.getVariant() == Variant::Rich);
279 const bool visible = tooltip.
isVisible();
280 const auto title = tooltip.getTitleEntity();
281 const auto text = tooltip.getTextEntity();
284 std::vector<ecs::Entity::Identifier> children;
286 children.push_back(title);
289 children.push_back(text);
311 ?
schemeColor(rich ? SchemeColorRole::SurfaceContainer
312 : SchemeColorRole::InverseSurface)
323 .setLabel(tooltip.getText());
329 colorChild(componentRegistry, title,
332 colorChild(componentRegistry, text,
334 ?
schemeColor(rich ? SchemeColorRole::OnSurfaceVariant
335 : SchemeColorRole::InverseOnSurface)
338 arrange(componentRegistry, entityIdentifier);
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setLiveRegion(LiveRegion liveRegion)
Set how urgently a change of the entity is announced.
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.
Animation & setLooping(bool looping)
Set whether the animation starts again when it completes.
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.
Soft shadow drawn around an elevated surface.
How a container arranges its children: in a row or a column, with which alignment,...
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
Layout & setPadding(float padding)
Set the inset between the container's edges and its children.
Layout & setMainAxisAlignment(MainAxisAlignment alignment)
Set where the children go along the main axis.
@ Start
At the top (row) or left (column).
Layout & setFixedHeight(float height)
Force the container height instead of wrapping the children.
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
@ Center
Packed in the middle.
@ Vertical
Column: children placed top to bottom.
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
Marks an entity as something shown temporarily above the rest of the interface (a dialog,...
Overlay & setDismissOnOutsideClick(bool dismiss)
Choose whether a click outside the overlay dismisses it.
Overlay & setDismissOnEscape(bool dismiss)
Choose whether the Escape key dismisses the overlay.
Overlay & setVisible(bool visible)
Show or hide the overlay.
A run of text: its content, its font metrics and the position of the editing cursor.
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...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
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 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.
State. Every class here is plain data attached to an entity.
@ Polite
Announced once the current speech is over.
The entity-component-system core, independent of any widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
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 transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Level2
Second raised level.
@ Level0
Flat: no shadow, no tint.
@ ExtraSmall
4 dp (text fields, menus, snackbars).
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Helpers of the namespace systems::interaction: what "pressable" means for a widget,...
bool isHovered(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier)
Whether the mouse pointer or a hand is over an entity.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.