25 #include "eng3d/ui/text.hpp"
26 #include "eng3d/ui/label.hpp"
57 this->kill_children();
58 if(text.empty())
return;
63 size_t max_width = 0, max_height = 0;
64 size_t line_width = glm::max(this->width / 12,
static_cast<size_t>(1));
65 while(pos < text.length()) {
66 size_t remaining_chars = text.length() - pos;
67 size_t end_pos = text.length();
68 if(remaining_chars > line_width)
69 end_pos = pos + line_width;
71 bool break_line =
false;
72 for(
size_t i = pos; i <= end_pos; i++) {
80 if(!break_line && remaining_chars > line_width) {
81 for(
size_t i = end_pos; i > pos; i--) {
89 std::string buf = text.substr(pos, end_pos - pos);
92 auto& lab = this->make_widget<UI::Label>(4, 4, buf);
93 max_width = glm::max(max_width, lab.width);
94 max_height += lab.height;
97 if(this->auto_adjust) {
98 this->width = max_width + 4;
99 this->height = max_height + 4;
The UI context that handles all the ui widgets.
virtual void on_render(Context &ctx, Eng3D::Rect viewport)
virtual void set_text(const std::string &text)
Generates text for the widget and overrides the current text texture.
Text(int x, int y, unsigned w, unsigned h, UI::Widget *parent)
bool auto_adjust
Whetever to auto adjust the widget depending on the text.
WidgetType
The type of the widget, some widgets share types between them to keep simplicity.