Euphoria
textdata.cc
Go to the documentation of this file.
1 #include "gui/textdata.h"
2 
3 #include "assert/assert.h"
4 #include "log/log.h"
5 
6 #include "render/font.h"
7 
8 
9 namespace eu::gui
10 {
12  : font(nullptr)
13  , size(-1.0f)
14  {
15  }
16 
17 
18  TextData::~TextData() = default;
19 
20 
21  void
22  TextData::set_font(std::shared_ptr<render::DrawableFont> new_font)
23  {
24  font = new_font;
25  text.reset();
26  update_text();
27  }
28 
29 
32  {
33  ASSERT(font);
34  return *font;
35  }
36 
37 
38  void
39  TextData::update_string(const std::string& str)
40  {
41  string = str;
42  update_text();
43  }
44 
45 
46  bool
48  {
49  return text != nullptr;
50  }
51 
52 
55  {
56  ASSERT(text);
57  return *text;
58  }
59 
60 
63  {
64  ASSERT(text);
65  return *text;
66  }
67 
68 
69  void
70  TextData::set_size(float new_size)
71  {
72  this->size = new_size;
73  if(has_text())
74  {
75  get_text().set_size(new_size);
76  }
77  }
78 
79 
80  void
82  {
83  if(text == nullptr && font != nullptr)
84  {
85  text = std::make_shared<render::DrawableText>(font.get());
86  }
87 
88  if(text != nullptr)
89  {
90  // button assumes this is bottom left
91  text->set_alignment(render::Align::bottom_left);
92 
93  core::UiText parsed;
94  if(false == parsed.init_by_parsing_source(string))
95  {
96  LOG_ERROR("Failed to parse {0}", string);
97  }
98 
99  text->set_text(parsed);
100  text->set_size(size);
101  }
102  }
103 }
104 
#define ASSERT(x)
Definition: assert.h:29
#define LOG_ERROR(...)
Definition: log.h:9
Represents displayed text.
Definition: ui_text.h:107
bool init_by_parsing_source(const std::string &str)
Definition: ui_text.cc:225
const render::DrawableFont & get_font() const
Definition: textdata.cc:31
void update_text()
Definition: textdata.cc:81
bool has_text() const
Definition: textdata.cc:47
const render::DrawableText & get_text() const
Definition: textdata.cc:54
void set_font(std::shared_ptr< render::DrawableFont > font)
Definition: textdata.cc:22
std::shared_ptr< render::DrawableText > text
Definition: textdata.h:53
void set_size(float size)
Definition: textdata.cc:70
std::shared_ptr< render::DrawableFont > font
Definition: textdata.h:50
void update_string(const std::string &str)
Definition: textdata.cc:39
void set_size(float new_size)
Definition: font.cc:550