ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
ui_panel.hpp
Go to the documentation of this file.
1
11
12#ifndef TOYMAKERBUILTINS_UIPANEL_H
13#define TOYMAKERBUILTINS_UIPANEL_H
14
16
17#include "nine_slice_panel.hpp"
18#include "ui_container.hpp"
19
20namespace ToyMaker {
21
42 class UIPanel: public ToyMaker::SimObjectAspect<UIPanel>, public IUIElement {
43 public:
48 UIPanel(): SimObjectAspect<UIPanel>{0} {}
49
56 inline static std::string getSimObjectAspectTypeName() { return "UIPanel"; }
57
64 static std::shared_ptr<BaseSimObjectAspect> create(const nlohmann::json& jsonAspectProperties);
65
72 std::shared_ptr<BaseSimObjectAspect> clone() const override;
73
78 void onActivated() override;
79
85 virtual void updateContentSize(glm::vec2 contentSize);
86
93 void updateAnchor(glm::vec2 anchor);
94
100 void updateBasePanel(std::shared_ptr<NineSlicePanel> newPanel);
101
106 inline glm::vec2 getContentSize() const { return mContentSize; }
107
113 inline glm::vec2 getReferenceCoordinate() const override { return mReferenceCoordinate; }
114
119 inline glm::vec3 getOffsets() const override { return mOffsets; }
120
125 inline bool allowsDescendantControl() const override { return mAllowsDescendantControl; }
126
127 private:
132 void recomputeTexture();
133
138 std::shared_ptr<NineSlicePanel> mBasePanel {};
139
144 glm::vec2 mContentSize {0.f, 0.f};
145
150 glm::vec2 mAnchor {0.f, 0.f};
151
158 glm::vec2 mReferenceCoordinate { 0.f, 0.f };
159
165 glm::vec3 mOffsets { 0.f, 0.f, 0.f };
166
173 };
174}
175
176#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
bool allowsDescendantControl() const override
Returns whether the owning container can modify this object's children's positions.
Definition ui_panel.hpp:125
glm::vec2 getReferenceCoordinate() const override
Returns the reference coordinate relative to which the position of this element is computed.
Definition ui_panel.hpp:113
void updateAnchor(glm::vec2 anchor)
Updates the point considered the new origin for this object, where (0,0) represents the top left corn...
Definition ui_panel.cpp:49
virtual void updateContentSize(glm::vec2 contentSize)
Updates the size of the central region of the NineSlicePanel.
Definition ui_panel.cpp:44
static std::shared_ptr< BaseSimObjectAspect > create(const nlohmann::json &jsonAspectProperties)
Constructs a new UIPanel instance based on its JSON description.
Definition ui_panel.cpp:6
std::shared_ptr< NineSlicePanel > mBasePanel
The panel resource used to create this texture.
Definition ui_panel.hpp:138
UIPanel()
Constructs a new UIPanel aspect.
Definition ui_panel.hpp:48
glm::vec3 mOffsets
The offsets of the anchor of this element relative to the owning container's reference coordinate.
Definition ui_panel.hpp:165
static std::string getSimObjectAspectTypeName()
Gets the aspect type string associated with this class.
Definition ui_panel.hpp:56
void recomputeTexture()
The method responsible for actually creating the new texture through the loaded panel resource.
Definition ui_panel.cpp:76
glm::vec3 getOffsets() const override
Returns this element's offsets relative to the owning container's reference coordinate.
Definition ui_panel.hpp:119
void updateBasePanel(std::shared_ptr< NineSlicePanel > newPanel)
Changes the panel resource used to create this object's panel texture.
Definition ui_panel.cpp:54
std::shared_ptr< BaseSimObjectAspect > clone() const override
Constructs a new UIPanel instance using this one as a blueprint.
Definition ui_panel.cpp:60
glm::vec2 getContentSize() const
Returns the current content size for this panel.
Definition ui_panel.hpp:106
glm::vec2 mContentSize
The size of the central area of the nine slice panel in which content can be displayed.
Definition ui_panel.hpp:144
glm::vec2 mReferenceCoordinate
The point on the owning container relative to which this elements offsets are computed.
Definition ui_panel.hpp:158
glm::vec2 mAnchor
The point considered the origin of this object, where (0,0) represents the top left corner and (1,...
Definition ui_panel.hpp:150
void onActivated() override
Loads and renders the texture of a panel per its configuration.
Definition ui_panel.cpp:72
bool mAllowsDescendantControl
Whether elements falling under this panel can have their positions controlled by the owning container...
Definition ui_panel.hpp:172
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:26
Contains class defining this project's implementation of nine-slice (or nine-region) resizable panels...
Classes and structs relating to the SimSystem, the system responsible for providing some level of gen...