guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
image.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <utility>
26#include <memory>
27#include "guillaume/ecs/component_registry.hpp"
28#include "guillaume/entities/builder_base.hpp"
29#include "guillaume/ecs/entity_builder.hpp"
30#include "guillaume/ecs/entity_filler.hpp"
31
32#include "guillaume/components/accessibility.hpp"
33#include "guillaume/components/image.hpp"
34#include "guillaume/components/bound.hpp"
35#include "guillaume/components/transform.hpp"
36
37namespace guillaume::entities
38{
39
74 class Image:
75 public ecs::EntityFiller<components::Transform, components::Bound,
76 components::Image, components::Accessibility>
77 {
78 public:
83 class Builder: public EntityBuilderBase<Image>
84 {
85 private:
86 std::string _texturePath;
87 std::string _fallbackPath;
89 float _width { 0.0f };
91 float _height { 0.0f };
93
94 public:
102 Builder(ecs::ComponentRegistry &componentRegistry,
103 ecs::EntityRegistry &entityRegistry);
104
113 std::shared_ptr<Image> buildEntity(void) override;
114
119 void reset(void) override;
120
128 Builder &withTexturePath(const std::string &texturePath);
129
136 Builder &withFallbackPath(const std::string &fallbackPath);
137
148 Builder &withSize(float width, float height);
149
161 std::shared_ptr<Image> makeImage(std::shared_ptr<Entity> parent,
162 const std::string &texturePath);
163 };
164
165 public:
176 template<typename... Arguments>
177 static std::shared_ptr<Image> create(Arguments &&...arguments)
178 {
179 std::shared_ptr<Image> entity(
180 new Image(std::forward<Arguments>(arguments)...));
181 return entity;
182 }
183
187 ~Image(void);
188
197 Image &setTexturePath(const std::string &texturePath);
198
204 const std::string &getTexturePath(void) const;
205
212 Image &setFallbackPath(const std::string &fallbackPath);
213
221 Image &setSize(float width, float height);
222
235 Image &setAspectRatio(float width, float aspectRatio);
236
244
251 Image &setAccessibilityLabel(const std::string &label);
252
253 private:
260 Image(ecs::ComponentRegistry &registry, const std::string &texturePath);
261 };
262
263} // namespace guillaume::entities
LoadState
Whether the texture could be loaded, as recorded by systems::ImageRender.
Definition image.hpp:62
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
The base class of a widget without children: an Entity that creates its components when it is constru...
Owns entities and gives the systems the list of entities to visit.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder & withFallbackPath(const std::string &fallbackPath)
Set the texture drawn when the main one fails to load.
Definition image.cpp:59
std::shared_ptr< Image > makeImage(std::shared_ptr< Entity > parent, const std::string &texturePath)
Build an image, register it under parent and reset the builder.
Definition image.cpp:80
std::shared_ptr< Image > buildEntity(void) override
Build an image from the current configuration, without registering it or giving it a parent.
Definition image.cpp:39
Builder & withTexturePath(const std::string &texturePath)
Choose the texture to draw.
Definition image.cpp:73
Builder & withSize(float width, float height)
Set the displayed size.
Definition image.cpp:65
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
void reset(void) override
Restore the defaults: empty texture path, no fallback texture, and no size (width and height 0).
Definition image.cpp:50
A picture loaded from a texture file and stretched over a rectangle.
Definition image.hpp:77
Image & setAccessibilityLabel(const std::string &label)
Describe the picture for assistive technologies.
Definition image.cpp:141
Image & setSize(float width, float height)
Set the displayed size, written to components::Bound.
Definition image.cpp:113
~Image(void)
Destructor.
Definition image.cpp:149
Image & setAspectRatio(float width, float aspectRatio)
Set the displayed size from a width and an aspect ratio.
Definition image.cpp:125
Image & setTexturePath(const std::string &texturePath)
Change the texture to draw.
Definition image.cpp:153
Image & setFallbackPath(const std::string &fallbackPath)
Set the texture drawn when the main one fails to load.
Definition image.cpp:105
components::Image::LoadState getLoadState(void) const
Tell whether the texture could be loaded.
Definition image.cpp:134
const std::string & getTexturePath(void) const
Get the path of the texture the image was asked to draw.
Definition image.cpp:98
static std::shared_ptr< Image > create(Arguments &&...arguments)
Build an image without registering it in an entity registry.
Definition image.hpp:177
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46