lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1
11
12#pragma once
13
16#include "lmgl/ui/font.hpp"
18
19#include <glm/glm.hpp>
20#include <memory>
21#include <string>
22
23namespace lmgl {
24
25namespace ui {
26
30enum class TextAlign { Left, Center, Right };
31
38class Text : public UIElement {
39 public:
46 Text(const std::string &text = "", const std::string &name = "Text");
47
51 ~Text() override = default;
52
58 void set_text(const std::string &text);
59
65 inline const std::string &get_text() const { return m_text; }
66
72 void set_font(std::shared_ptr<Font> font);
73
79 inline std::shared_ptr<Font> get_font() const { return m_font; }
80
86 inline void set_color(const glm::vec4 &color) { m_color = color; }
87
93 inline const glm::vec4 &get_color() const { return m_color; }
94
100 inline void set_alignment(TextAlign align) { m_alignment = align; }
101
107 inline TextAlign get_alignment() const { return m_alignment; }
108
116 void render(float canvas_width, float canvas_height, const glm::mat4 &projection) override;
117
118 private:
120 std::string m_text;
121
123 std::shared_ptr<Font> m_font;
124
126 glm::vec4 m_color{1.0f, 1.0f, 1.0f, 1.0f};
127
129 TextAlign m_alignment{TextAlign::Left};
130
132 static std::shared_ptr<renderer::Shader> s_shader;
133
135 static std::shared_ptr<renderer::VertexArray> s_vao;
136
138 static std::shared_ptr<renderer::VertexBuffer> s_vbo;
139
141 static void initialize_resources();
142
144 static bool s_initialized;
145
149 void update_size();
150};
151
152} // namespace ui
153
154} // namespace lmgl
std::shared_ptr< Font > get_font() const
Get the current font.
Definition text.hpp:79
const std::string & get_text() const
Get the text string.
Definition text.hpp:65
~Text() override=default
Destructor for Text.
void set_alignment(TextAlign align)
Set text alignment.
Definition text.hpp:100
void render(float canvas_width, float canvas_height, const glm::mat4 &projection) override
Render the text.
Definition text.cpp:71
void set_font(std::shared_ptr< Font > font)
Set the font.
Definition text.cpp:55
TextAlign get_alignment() const
Get text alignment.
Definition text.hpp:107
const glm::vec4 & get_color() const
Get the text color.
Definition text.hpp:93
Text(const std::string &text="", const std::string &name="Text")
Constructor for Text.
Definition text.cpp:27
void set_color(const glm::vec4 &color)
Set the text color.
Definition text.hpp:86
void set_text(const std::string &text)
Set the text string.
Definition text.cpp:50
UIElement(const std::string &name="UIElement")
Constructor for UIElement.
Definition ui_element.cpp:10
Font loading and glyph atlas generation for text rendering.
Definition button.cpp:15
TextAlign
Text alignment options.
Definition text.hpp:30
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
Declaration of the Shader class for managing shader programs in OpenGL.
Base class for all UI elements.
Declaration of the VertexArray class for managing Vertex Array Objects (VAOs) in OpenGL.