1 #ifndef LXGUI_GUI_TEXT_HPP
2 #define LXGUI_GUI_TEXT_HPP
4 #include "lxgui/gui_color.hpp"
5 #include "lxgui/gui_font.hpp"
6 #include "lxgui/gui_matrix4.hpp"
7 #include "lxgui/gui_quad.hpp"
8 #include "lxgui/lxgui.hpp"
9 #include "lxgui/utils.hpp"
10 #include "lxgui/utils_maths.hpp"
11 #include "lxgui/utils_string.hpp"
39 std::shared_ptr<const font> fnt,
40 std::shared_ptr<const font> outline_fnt =
nullptr);
77 void set_text(
const utils::ustring& content);
84 const utils::ustring&
get_text()
const;
425 void update_()
const;
426 void update_vertex_cache_()
const;
427 bool use_vertex_cache_()
const;
428 void notify_cache_dirty_()
const;
429 void notify_vertex_cache_dirty_()
const;
431 float round_to_pixel_(
434 std::array<vertex, 4> create_letter_quad_(
const gui::font&
font, char32_t c)
const;
435 std::array<vertex, 4> create_letter_quad_(char32_t c)
const;
436 std::array<vertex, 4> create_outline_letter_quad_(char32_t c)
const;
440 float scaling_factor_ = 1.0f;
441 float tracking_ = 0.0f;
442 float line_spacing_ = 1.0f;
443 bool remove_starting_spaces_ =
false;
444 bool word_wrap_enabled_ =
true;
445 bool ellipsis_enabled_ =
false;
447 bool force_color_ =
false;
449 bool formatting_enabled_ =
false;
450 float box_width_ = std::numeric_limits<float>::infinity();
451 float box_height_ = std::numeric_limits<float>::infinity();
455 std::shared_ptr<const font> font_;
456 std::shared_ptr<const font> outline_font_;
457 utils::ustring unicode_text_;
459 mutable bool update_cache_flag_ =
false;
460 mutable float width_ = 0.0f;
461 mutable float height_ = 0.0f;
462 mutable std::size_t num_lines_ = 0u;
464 bool use_vertex_cache_flag_ =
false;
465 mutable bool update_vertex_cache_flag_ =
false;
466 mutable std::vector<std::array<vertex, 4>> quad_list_;
467 mutable std::shared_ptr<vertex_cache> vertex_cache_;
468 mutable std::vector<std::array<vertex, 4>> outline_quad_list_;
469 mutable std::shared_ptr<vertex_cache> outline_vertex_cache_;
470 mutable std::vector<quad> icons_list_;
Holds a single color (float RGBA, 128 bits)
A texture containing characters.
Abstract type for implementation specific management.
Used to draw some text on the screen.
renderer & get_renderer()
Returns the renderer used to render this text.
float get_alpha() const
Returns this text's transparency (alpha).
bool is_word_ellipsis_enabled() const
Checks if word ellipsis is enabled.
quad create_letter_quad(char32_t c) const
Creates a quad that contains the provided character.
float get_line_spacing() const
Returns this text's line spacing.
void render(const matrix4f &transform=matrix4f::identity) const
Renders this text at the given position.
alignment_y get_alignment_y() const
Returns the text vertical alignment.
float get_box_width() const
Returns the width of the text box.
void set_remove_starting_spaces(bool remove_starting_spaces)
Allows removal of a line's starting spaces.
float get_character_kerning(char32_t c1, char32_t c2) const
Returns the kerning between two characters.
void set_word_ellipsis_enabled(bool add_ellipsis)
Sets whether to show an ellipsis "..." if words don't fit in the text box.
void set_use_vertex_cache(bool use_vertex_cache)
Sets whether this text object should use vertex caches or not.
bool get_remove_starting_spaces() const
Checks if starting spaces removing is active.
bool get_use_vertex_cache() const
Checks if this text object is using vertex cache or not.
void enable_word_wrap()
Allows word wrap when the line is too long for the text box.
float get_string_width(const std::string &content) const
Returns the length of a provided string.
void set_tracking(float tracking)
Sets this text's tracking.
float get_width() const
Returns the width of the rendered text.
void set_box_height(float box_height)
Sets the height of the text box.
const renderer & get_renderer() const
Returns the renderer used to render this text.
void set_scaling_factor(float scaling_factor)
Set the scaling factor to use when rendering glyphs.
alignment_x get_alignment_x() const
Returns the text horizontal alignment.
void enable_formatting()
Enables color formatting.
void enable_word_ellipsis()
Show an ellipsis "..." if words don't fit in the text box.
float get_text_height() const
Returns the height of the text.
const std::array< vertex, 4 > & get_letter_quad(std::size_t index) const
Returns the quad for the letter at the provided index (position, texture coords, color).
float get_text_width() const
Returns the length of the text.
void set_color(const color &c, bool force_color=false)
Sets this text's default color.
text & operator=(const text &)=delete
void set_alpha(float alpha)
Sets this text's transparency (alpha).
void set_alignment_y(alignment_y align_y)
Sets text vertical alignment.
float get_height() const
Returns the height of the rendered text.
void disable_word_ellipsis()
Do not show an ellipsis "..." if words don't fit in the text box.
void set_alignment_x(alignment_x align_x)
Sets text horizontal alignment.
void set_box_dimensions(float box_width, float box_height)
Sets the dimensions of the text box.
std::size_t get_line_count() const
Returns the number of text lines.
void set_word_wrap_enabled(bool wrap)
Allows/disallows word wrap when the line is too long for the text box.
void disable_word_wrap()
Disallow word wrap when the line is too long for the text box.
float get_box_height() const
Returns the height of the text box.
void set_formatting_enabled(bool formatting)
Enables color formatting.
text & operator=(text &&)=delete
text(const text &)=delete
const color & get_color() const
Returns this text's default color.
float get_tracking() const
Returns this text's tracking.
float get_line_height() const
Returns the height of one line (constant).
void set_text(const utils::ustring &content)
Sets the text to render (unicode character set).
void set_line_spacing(float line_spacing)
Sets this text's line spacing.
float get_scaling_factor() const
Returns the scaling factor used when rendering glyphs.
const utils::ustring & get_text() const
Returns the text that will be rendered (unicode character set).
text(renderer &rdr, std::shared_ptr< const font > fnt, std::shared_ptr< const font > outline_fnt=nullptr)
Constructor.
float get_character_width(char32_t c) const
Returns the length of a single character.
std::size_t get_letter_count() const
Returns the number of letters currently displayed.
void disable_formatting()
Disables color formatting.
void set_box_width(float box_width)
Sets the width of the text box.
bool is_word_wrap_enabled() const
Checks if word wrap is enabled.
rounding_method
Rounding method for points to pixels conversions.
@ nearest
Equivalent to round()
A 4x4 matrix, used for coordinate transformations.
static const matrix4f identity
Simple structure holding four vertices and a material.