ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
ui_text.hpp
Go to the documentation of this file.
1
11
12#ifndef TOYMAKERBUILTINS_UITEXT_H
13#define TOYMAKERBUILTINS_UITEXT_H
14
17
18#include "ui_container.hpp"
19
20namespace ToyMaker {
21
27 class UIText: public ToyMaker::SimObjectAspect<UIText>, public IUIElement {
28 public:
33 UIText(): SimObjectAspect<UIText>{0} {}
34
40 inline static std::string getSimObjectAspectTypeName() { return "UIText"; }
41
48 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
49
55 std::shared_ptr<BaseSimObjectAspect> clone() const override;
56
61 void onActivated() override;
62
68 inline std::string getText() const { return mText; }
69
75 void updateText(const std::string& newText);
76
82 void updateColor(glm::u8vec4 newColour);
83
89 void updateScale(float scale);
90
96 void updateFont(const std::string& textResourceName);
97
103 void updateAnchor(glm::vec2 anchor);
104
105 inline glm::vec2 getReferenceCoordinate() const override {
107 }
108
109 inline glm::vec3 getOffsets() const override {
110 return mOffsets;
111 }
112
113 inline bool allowsDescendantControl() const override {
114 return false;
115 }
116
117 private:
122 void recomputeTexture();
123
128 glm::u8vec4 mColor {0x00, 0x00, 0x00, 0xFF};
129
134 std::shared_ptr<ToyMaker::TextFont> mFont {};
135
140 std::string mText {};
141
146 float mScale { 1e-2 };
147
152 uint32_t mMaxWidthPixels { 0 };
153
158 glm::vec2 mAnchor {0.f, 0.f};
159
164 glm::vec2 mReferenceCoordinate { 0.f, 0.f };
165
170 glm::vec3 mOffsets { 0.f, 0.f, 0.f };
171 };
172}
173
174#endif
Interface for a single UI element.
Definition ui_container.hpp:18
An object containing closely related methods and data, and exposing object lifecycle and application ...
Definition sim_system.hpp:956
glm::vec2 mReferenceCoordinate
The coordinate on the owning container relative to which this elements position is computed.
Definition ui_text.hpp:164
std::shared_ptr< BaseSimObjectAspect > clone() const override
Constructs a new UIText instance using this one as its blueprint.
Definition ui_text.cpp:73
void updateText(const std::string &newText)
Updates the text rendered by this object.
Definition ui_text.cpp:96
void updateFont(const std::string &textResourceName)
Updates the font using which this object's text texture is rendered.
Definition ui_text.cpp:102
void onActivated() override
Renders the initial text associated with this object once it becomes a part of the active scene.
Definition ui_text.cpp:86
std::string mText
The text displayed by this object on its associated StaticModel surface.
Definition ui_text.hpp:140
static std::shared_ptr< BaseSimObjectAspect > create(const nlohmann::json &jsonAspectProperties)
Creates a new UIText aspect based on its JSON description.
Definition ui_text.cpp:11
float mScale
The scale, relative to the texture's dimensions, with which the object is made.
Definition ui_text.hpp:146
uint32_t mMaxWidthPixels
The width, in pixels, a single line of text is rendered on before it is wrapped around to the next li...
Definition ui_text.hpp:152
void updateScale(float scale)
Updates the scale of this object.
Definition ui_text.cpp:90
glm::vec2 getReferenceCoordinate() const override
Returns the reference coordinate on the container relative to which this element's offsets are define...
Definition ui_text.hpp:105
std::shared_ptr< ToyMaker::TextFont > mFont
The font used to render the text texture used by this object.
Definition ui_text.hpp:134
glm::vec3 getOffsets() const override
Returns the offsets relative to the container reference coordinates used to position this element's a...
Definition ui_text.hpp:109
static std::string getSimObjectAspectTypeName()
Gets the aspect type string for this class.
Definition ui_text.hpp:40
UIText()
Constructs a new UIText aspect.
Definition ui_text.hpp:33
glm::vec3 mOffsets
The offsets of this element relative to the parent container's reference coordinate.
Definition ui_text.hpp:170
void updateColor(glm::u8vec4 newColour)
Updates the color of the text rendered by this object.
Definition ui_text.cpp:117
void recomputeTexture()
Recomputes the text texture and vertex offsets associated with this object based on its configuration...
Definition ui_text.cpp:123
void updateAnchor(glm::vec2 anchor)
Updates the point considered this object's origin, where (0,0) represents the top left corner of the ...
Definition ui_text.cpp:111
std::string getText() const
Gets the actual text associated with this UIText object.
Definition ui_text.hpp:68
bool allowsDescendantControl() const override
Whether the container is permitted to reposition this element's children.
Definition ui_text.hpp:113
glm::u8vec4 mColor
The color associated with the text rendered by this object.
Definition ui_text.hpp:128
glm::vec2 mAnchor
The point considered the origin of this object, where (0,0) represents the top left hand corner,...
Definition ui_text.hpp:158
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:26
Classes and structs relating to the SimSystem, the system responsible for providing some level of gen...
Classes relating to the creation and use of fonts to render text.