sandbox
Loading...
Searching...
No Matches
label.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_UI_LABEL_HPP_
3#define LIBSBX_UI_LABEL_HPP_
4
5#include <string>
6#include <vector>
7
8#include <libsbx/math/vector2.hpp>
9
10#include <libsbx/ui/element.hpp>
11#include <libsbx/ui/font.hpp>
12
13namespace sbx::ui {
14
15class label : public element {
16
17public:
18
19 label() = default;
20
21 ~label() override = default;
22
23 auto set_text(const std::string& value) -> void;
24
25 [[nodiscard]] auto get_text() const -> const std::string&;
26
27 auto set_font(const font& value) -> void;
28
29 auto set_font_size(std::float_t value) -> void;
30
31protected:
32
33 auto submit(const math::vector2& screen_size) -> void override;
34
35private:
36
37 struct text_quad {
38 math::vector2 position;
39 math::vector2 size;
40 math::vector2 uv_min;
41 math::vector2 uv_max;
42 }; // struct text_quad
43
44 auto _ensure_layout() -> void;
45
46 const font* _font{nullptr};
47 std::string _text{};
48 std::float_t _font_size{16.0f};
49 std::vector<text_quad> _cached_quads;
50 bool _is_dirty{true};
51
52}; // class label
53
54} // namespace sbx::ui
55
56#endif // LIBSBX_UI_LABEL_HPP_
A vector in two-dimensional space.
Definition: vector2.hpp:28
Definition: element.hpp:22
Definition: label.hpp:15
Definition: font.hpp:34