blob: 859490ef2e48bcd3077b7db255af49a67ebfd742 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#pragma once
#include <optional>
#include <string>
#include "../types.h"
#include "Asset.h"
#include "Color.h"
#include "UIObject.h"
namespace crepe {
/**
* \brief Text UIObject component for displaying text
*
* This class can be used to display text on screen. By setting the font_family to a font already stored on the current device it will automatically be loaded in.
*/
class Text : public UIObject {
public:
//! Text data that does not have to be set in the constructor
struct Data {
//! variable indicating if transform is relative to camera(false) or world(true)
bool world_space = false;
//! Label text color.
Color text_color = Color::BLACK;
};
public:
/**
*
* \param dimensions Width and height of the UIObject.
* \param offset Offset of the UIObject relative to its transform
* \param text The text to be displayed.
* \param font_family The font style name to be displayed.
* \param data Data struct containing extra text parameters.
* \param font Optional font asset that can be passed or left empty.
*/
Text(
game_object_id_t id, const vec2 & dimensions, const std::string & font_family,
const Data & data, const vec2 & offset = {0, 0}, const std::string & text = ""
);
//! Label text.
std::string text = "";
//! font family name
std::string font_family = "";
//! Font asset variable if this is not set, it will use the font_family to create an asset.
std::optional<Asset> font;
//! Data instance
Data data;
protected:
virtual std::unique_ptr<Component> save() const;
Text(const Text &) = default;
virtual void restore(const Component & snapshot);
virtual Text & operator=(const Text &);
};
} // namespace crepe
|