23#include <utility/graphic/text/text.hpp>
25#include "guillaume/systems/measure_text.hpp"
33 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
34 utility::Engine &engine)
38 , _ressourceProvider(ressourceProvider)
40 , _defaultFontPath(
"fonts/Roboto-Regular.ttf")
59 <<
"Updating MeasureText system for entity " << entityIdentifier;
67 const auto &textComponent =
69 auto &boundComponent =
71 auto &transformComponent =
73 auto &colorComponent =
77 textComponent.getFontSize(),
78 colorComponent.getColor(),
79 textComponent.getFontWeight() };
80 const float lineHeight = textComponent.getLineHeight();
82 getLogger().debug() <<
"Measuring text '" << cacheKey.
content
83 <<
"' for entity " << entityIdentifier;
85 if (contains(cacheKey)) {
86 getLogger().debug() <<
"Text '" << cacheKey.
content
87 <<
"' already measured, skipping.";
88 const auto &cacheValue = get(cacheKey);
89 if (cacheValue.has_value()) {
91 .setWidth(cacheValue->getWidth())
92 .setHeight(std::max(cacheValue->getHeight(), lineHeight));
97 utility::graphic::Text text(
98 _ressourceProvider, transformComponent.getPose(),
101 text.setColor(utility::graphic::Color32Bit());
103 auto textSize = _engine.measureText(text);
106 .setWidth(textSize.getWidth())
107 .setHeight(std::max(textSize.getHeight(), lineHeight));
109 put(cacheKey, textSize);
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)
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
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...
void cleanup(void) override
Does nothing: the cache is kept from one frame to the next.
MeasureText(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Measure phase, with an empty cache.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the size of one text into its components::Bound, measuring it with the engine when it is not in...
~MeasureText(void)
Destroy the system and its cache.
void prepare(void) override
Does nothing: the system needs no per-frame setup.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.
const std::string & fontPath(FontWeight weight)
Get the font file shipped with the library for a weight.
Key of the size cache of MeasureText: everything a measured size is looked up by.
float fontSize
Font size the string was measured at.
theme::FontWeight fontWeight
Font weight, which selects the font file measured with.
std::string content
The string that was measured.