VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
elementComponent.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3#pragma once
4
5#include <algorithm>
6#include <string>
7#include <vector>
8
9#include "core/math/color.h"
10#include "core/math/vector2.h"
11#include "core/math/vector4.h"
14
15namespace visutwin::canvas
16{
17 enum class ElementType
18 {
21 };
22
29
31 {
32 public:
34 ~ElementComponent() override;
35
36 void initializeComponentData() override {}
37
38 static const std::vector<ElementComponent*>& instances() { return _instances; }
39
40 ElementType type() const { return _type; }
41 void setType(const ElementType value) { _type = value; }
42
43 const Vector2& pivot() const { return _pivot; }
44 void setPivot(const Vector2& value) { _pivot = value; _textDirty = true; }
45
46 const Vector4& anchor() const { return _anchor; }
47 void setAnchor(const Vector4& value) { _anchor = value; _textDirty = true; }
48
49 const Vector4& margin() const { return _margin; }
50 void setMargin(const Vector4& value) { _margin = value; _textDirty = true; }
51
52 float width() const { return _width; }
53 void setWidth(const float value) { _width = std::max(value, 0.0f); _textDirty = true; }
54
55 float height() const { return _height; }
56 void setHeight(const float value) { _height = std::max(value, 0.0f); _textDirty = true; }
57
58 float opacity() const { return _opacity; }
59 void setOpacity(const float value) { _opacity = std::clamp(value, 0.0f, 1.0f); }
60
61 const Color& color() const { return _color; }
62 void setColor(const Color& value) { _color = value; }
63
64 int fontSize() const { return _fontSize; }
65 void setFontSize(const int value) { _fontSize = std::max(value, 1); _textDirty = true; }
66
67 const std::string& text() const { return _text; }
68 void setText(const std::string& value) { _text = value; _textDirty = true; }
69
70 FontResource* fontResource() const { return _fontResource; }
71 void setFontResource(FontResource* value) { _fontResource = value; _textDirty = true; }
72
73 ElementHorizontalAlign horizontalAlign() const { return _horizontalAlign; }
74 void setHorizontalAlign(const ElementHorizontalAlign value) { _horizontalAlign = value; _textDirty = true; }
75
76 bool wrapLines() const { return _wrapLines; }
77 void setWrapLines(const bool value) { _wrapLines = value; _textDirty = true; }
78
79 bool useInput() const { return _useInput; }
80 void setUseInput(const bool value) { _useInput = value; }
81
82 bool textDirty() const { return _textDirty; }
83 void clearTextDirty() { _textDirty = false; }
84
85 private:
86 inline static std::vector<ElementComponent*> _instances;
87
89 Vector2 _pivot = Vector2(0.5f, 0.5f);
90 Vector4 _anchor = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
91 Vector4 _margin = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
92 float _width = 100.0f;
93 float _height = 50.0f;
94 float _opacity = 1.0f;
95 Color _color = Color(1.0f, 1.0f, 1.0f, 1.0f);
96 int _fontSize = 16;
97 std::string _text;
98 FontResource* _fontResource = nullptr;
100 bool _wrapLines = false;
101 bool _textDirty = true;
102 bool _useInput = false;
103 };
104}
Entity * entity() const
Definition component.cpp:16
Component(IComponentSystem *system, Entity *entity)
Definition component.cpp:12
IComponentSystem * system() const
Definition component.h:47
ElementComponent(IComponentSystem *system, Entity *entity)
FontResource * fontResource() const
void setFontResource(FontResource *value)
void setColor(const Color &value)
void setHeight(const float value)
void setPivot(const Vector2 &value)
void setOpacity(const float value)
static const std::vector< ElementComponent * > & instances()
void setType(const ElementType value)
ElementHorizontalAlign horizontalAlign() const
void setWrapLines(const bool value)
const std::string & text() const
void setHorizontalAlign(const ElementHorizontalAlign value)
void setMargin(const Vector4 &value)
void setAnchor(const Vector4 &value)
void setText(const std::string &value)
ECS entity — a GraphNode that hosts components defining its behavior.
Definition entity.h:32
RGBA color with floating-point components in [0, 1].
Definition color.h:18
2D vector for UV coordinates, screen positions, and 2D math.
Definition vector2.h:18
4D vector for homogeneous coordinates, color values, and SIMD operations.
Definition vector4.h:20