lxgui
Loading...
Searching...
No Matches
gui_font_string.hpp
1#ifndef LXGUI_GUI_FONT_STRING_HPP
2#define LXGUI_GUI_FONT_STRING_HPP
3
4#include "lxgui/gui_layered_region.hpp"
5#include "lxgui/gui_text.hpp"
6#include "lxgui/lxgui.hpp"
7#include "lxgui/utils.hpp"
8
9namespace lxgui::gui {
10
24
49public:
51
53 explicit font_string(
54 utils::control_block& block, manager& mgr, const region_core_attributes& attr);
55
61 std::string serialize(const std::string& tab) const override;
62
64 void render() const override;
65
70 void copy_from(const region& obj) override;
71
76 const std::string& get_font_name() const;
77
82 float get_font_height() const;
83
90 void set_outlined(bool outlined);
91
96 bool is_outlined() const;
97
103
109
114 const color& get_shadow_color() const;
115
121 const vector2f& get_shadow_offset() const;
122
128 const vector2f& get_offset() const;
129
134 float get_spacing() const;
135
140 float get_line_spacing() const;
141
146 const color& get_text_color() const;
147
153 void set_font(const std::string& font_name, float height);
154
159 void set_alignment_x(alignment_x align_x);
160
165 void set_alignment_y(alignment_y align_y);
166
171 void set_shadow_color(const color& shadow_color);
172
178 void set_shadow_offset(const vector2f& shadow_offset);
179
185 void set_offset(const vector2f& offset);
186
191 void set_spacing(float spacing);
192
200 void set_line_spacing(float line_spacing);
201
206 void set_text_color(const color& text_color);
207
213 bool is_non_space_wrap_enabled() const;
214
219 float get_string_height() const;
220
225 float get_string_width() const;
226
232 float get_string_width(const utils::ustring& content) const;
233
238 const utils::ustring& get_text() const;
239
246 void set_non_space_wrap_enabled(bool enabled);
247
255
263
268 bool is_shadow_enabled() const;
269
274 void set_shadow_enabled(bool enabled);
275
281 set_shadow_enabled(true);
282 }
283
289 set_shadow_enabled(false);
290 }
291
297 void set_word_wrap_enabled(bool enabled);
298
304 }
305
311 }
312
317 bool is_word_wrap_enabled() const;
318
324 void set_word_ellipsis_enabled(bool enabled);
325
332
339
344 bool is_word_ellipsis_enabled() const;
345
351 void set_formatting_enabled(bool enabled);
352
359 }
360
367 }
368
373 bool is_formatting_enabled() const;
374
388
394
400 void set_text(const utils::ustring& content);
401
403 void notify_scaling_factor_updated() override;
404
409 void parse_layout(const layout_node& node) override;
410
416
421 const text* get_text_object() const;
422
424 static void register_on_lua(sol::state& lua);
425
426 static constexpr const char* class_name = "FontString";
427
428private:
429 void parse_attributes_(const layout_node& node) override;
430 void parse_shadow_node_(const layout_node& node);
431
432 const std::vector<std::string>& get_type_list_() const override;
433
434 void create_text_object_();
435 bool is_vertex_cache_used_() const;
436
437 void update_borders_() override;
438
439 std::unique_ptr<text> text_;
440
441 utils::ustring content_;
442 std::string font_name_;
443 float height_ = 0.0f;
444
445 float spacing_ = 0.0f;
446 float line_spacing_ = 1.0f;
449 vector2f offset_ = vector2f::zero;
450
451 bool is_outlined_ = false;
452 bool non_space_wrap_enabled_ = false;
453 bool word_wrap_enabled_ = true;
454 bool ellipsis_enabled_ = true;
455 bool formatting_enabled_ = true;
456 color text_color_ = color::white;
457
459
460 bool is_shadow_enabled_ = false;
461 color shadow_color_ = color::black;
462 vector2f shadow_offset_ = vector2f::zero;
463};
464
465} // namespace lxgui::gui
466
467#endif
Holds a single color (float RGBA, 128 bits)
Definition gui_color.hpp:13
static const color white
Definition gui_color.hpp:44
static const color black
Definition gui_color.hpp:45
A layered_region that can draw text on the screen.
void enable_formatting()
Enables color formatting.
const color & get_text_color() const
Returns the text color.
void set_word_wrap_enabled(bool enabled)
Enables/disables word wrap.
void enable_word_ellipsis()
Show an ellipsis "..." if words don't fit in the text box.
void set_non_space_wrap_enabled(bool enabled)
Sets whether large text without whitespace is truncated or wrapped.
const std::string & get_font_name() const
Returns the name of the font file.
const vector2f & get_offset() const
Returns this font_string's offset.
void set_formatting_enabled(bool enabled)
Enables color formatting.
const color & get_shadow_color() const
Returns this font_string's shadow color.
float get_string_width() const
Returns the width of the string if no format or wrapping is applied.
bool is_word_ellipsis_enabled() const
Checks if word ellipsis is enabled.
void set_shadow_color(const color &shadow_color)
Sets this font_string's shadow color.
void copy_from(const region &obj) override
Copies a region's parameters into this font_string (inheritance).
bool is_non_space_wrap_enabled() const
Checks if large text is truncated or wrapped.
void enable_non_space_wrap()
Allows large text without whitespace to wrap.
float get_string_height() const
Returns the height of the string if no format or wrapping is applied.
const vector2f & get_shadow_offset() const
Returns this font_string's shadow offset.
void set_line_spacing(float line_spacing)
Sets the space between each line as a fraction of the font height.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
void set_alignment_x(alignment_x align_x)
Sets this font_string's horizontal alignment behavior.
bool is_formatting_enabled() const
Checks if color formatting is enabled.
float get_font_height() const
Returns the height of the font.
void render() const override
Renders this region on the current render target.
void enable_shadow()
Makes this font_string draw a shadow under its text.
void set_vertex_cache_strategy(vertex_cache_strategy strategy)
Selects the strategy for using vertex caches.
void set_alignment_y(alignment_y align_y)
Sets this font_string's vertical alignment behavior.
void notify_scaling_factor_updated() override
Tells this region that the global interface scaling factor has changed.
void disable_word_wrap()
Disables word wrap.
text * get_text_object()
Returns the text used to render this font_string.
void set_offset(const vector2f &offset)
Sets this font_string's offset.
void set_outlined(bool outlined)
Adds or remove the outline around the text.
void set_shadow_offset(const vector2f &shadow_offset)
Sets this font_string's shadow offset.
static constexpr const char * class_name
bool is_outlined() const
Check if this font_string is outlined.
void set_text(const utils::ustring &content)
Sets the rendered text.
static void register_on_lua(sol::state &lua)
Registers this region class to the provided Lua state.
void disable_word_ellipsis()
Do not show an ellipsis "..." if words don't fit in the text box.
void parse_layout(const layout_node &node) override
Parses data from a layout_node.
float get_line_spacing() const
Returns the space between each line as a fraction of the font height.
bool is_word_wrap_enabled() const
Checks if word wrap is enabled.
void disable_formatting()
Disables color formatting.
void set_text_color(const color &text_color)
Sets the text color.
alignment_y get_alignment_y() const
Returns the vertical alignment behavior.
void set_shadow_enabled(bool enabled)
Sets whether this font_string should draw a shadow under its text.
vertex_cache_strategy get_vertex_cache_strategy() const
Gets the strategy for using vertex caches.
bool is_shadow_enabled() const
Checks if this font_string draws a shadow under its text.
void set_word_ellipsis_enabled(bool enabled)
Sets whether to show an ellipsis "..." if words don't fit in the text box.
float get_spacing() const
Returns the space between each letter.
void set_font(const std::string &font_name, float height)
Sets this font_string's font (file and size).
const utils::ustring & get_text() const
Returns the rendered text (with format tags).
void set_spacing(float spacing)
Sets the space between each letter.
void enable_word_wrap()
Enables word wrap.
alignment_x get_alignment_x() const
Returns the horizontal alignment behavior.
void disable_non_space_wrap()
Does not allow large text without whitespace to wrap.
void disable_shadow()
Makes this font_string draw a shadow under its text.
A region that can be rendered in a layer.
An node in a layout file.
Manages the user interface.
The base class of all elements in the GUI.
Used to draw some text on the screen.
Definition gui_text.hpp:29
vertex_cache_strategy
Strategy for using a vertex cache.
@ prefer_enabled
Use vertex cache if renderer supports and allows.
@ automatic
Choose automatically to maximize performance on common case.
@ always_disabled
Never use vertex cache.
@ always_enabled
Use vertex cache if renderer supports, even if not allowed.
Struct holding all the core information about a region necessary for its creation.
static const vector2 zero