lxgui
Public Member Functions | List of all members
lxgui::gui::text Class Reference

Used to draw some text on the screen. More...

#include <gui_text.hpp>

Public Member Functions

 text (renderer &rdr, std::shared_ptr< const font > fnt, std::shared_ptr< const font > outline_fnt=nullptr)
 Constructor. More...
 
 text (const text &)=delete
 
 text (text &&)=delete
 
textoperator= (const text &)=delete
 
textoperator= (text &&)=delete
 
float get_line_height () const
 Returns the height of one line (constant). More...
 
void set_scaling_factor (float scaling_factor)
 Set the scaling factor to use when rendering glyphs. More...
 
float get_scaling_factor () const
 Returns the scaling factor used when rendering glyphs. More...
 
void set_text (const utils::ustring &content)
 Sets the text to render (unicode character set). More...
 
const utils::ustring & get_text () const
 Returns the text that will be rendered (unicode character set). More...
 
void set_color (const color &c, bool force_color=false)
 Sets this text's default color. More...
 
const colorget_color () const
 Returns this text's default color. More...
 
void set_alpha (float alpha)
 Sets this text's transparency (alpha). More...
 
float get_alpha () const
 Returns this text's transparency (alpha). More...
 
void set_box_dimensions (float box_width, float box_height)
 Sets the dimensions of the text box. More...
 
void set_box_width (float box_width)
 Sets the width of the text box. More...
 
void set_box_height (float box_height)
 Sets the height of the text box. More...
 
float get_width () const
 Returns the width of the rendered text. More...
 
float get_height () const
 Returns the height of the rendered text. More...
 
float get_box_width () const
 Returns the width of the text box. More...
 
float get_box_height () const
 Returns the height of the text box. More...
 
float get_text_width () const
 Returns the length of the text. More...
 
std::size_t get_line_count () const
 Returns the number of text lines. More...
 
float get_string_width (const std::string &content) const
 Returns the length of a provided string. More...
 
float get_string_width (const utils::ustring &content) const
 Returns the length of a provided string. More...
 
float get_character_width (char32_t c) const
 Returns the length of a single character. More...
 
float get_character_kerning (char32_t c1, char32_t c2) const
 Returns the kerning between two characters. More...
 
float get_text_height () const
 Returns the height of the text. More...
 
void set_alignment_x (alignment_x align_x)
 Sets text horizontal alignment. More...
 
void set_alignment_y (alignment_y align_y)
 Sets text vertical alignment. More...
 
alignment_x get_alignment_x () const
 Returns the text horizontal alignment. More...
 
alignment_y get_alignment_y () const
 Returns the text vertical alignment. More...
 
void set_tracking (float tracking)
 Sets this text's tracking. More...
 
float get_tracking () const
 Returns this text's tracking. More...
 
void set_line_spacing (float line_spacing)
 Sets this text's line spacing. More...
 
float get_line_spacing () const
 Returns this text's line spacing. More...
 
void set_remove_starting_spaces (bool remove_starting_spaces)
 Allows removal of a line's starting spaces. More...
 
bool get_remove_starting_spaces () const
 Checks if starting spaces removing is active. More...
 
void set_word_wrap_enabled (bool wrap)
 Allows/disallows word wrap when the line is too long for the text box. More...
 
void enable_word_wrap ()
 Allows word wrap when the line is too long for the text box. More...
 
void disable_word_wrap ()
 Disallow word wrap when the line is too long for the text box. More...
 
bool is_word_wrap_enabled () const
 Checks if word wrap is enabled. More...
 
void set_word_ellipsis_enabled (bool add_ellipsis)
 Sets whether to show an ellipsis "..." if words don't fit in the text box. More...
 
void enable_word_ellipsis ()
 Show an ellipsis "..." if words don't fit in the text box. More...
 
void disable_word_ellipsis ()
 Do not show an ellipsis "..." if words don't fit in the text box. More...
 
bool is_word_ellipsis_enabled () const
 Checks if word ellipsis is enabled. More...
 
void set_formatting_enabled (bool formatting)
 Enables color formatting. More...
 
void enable_formatting ()
 Enables color formatting. More...
 
void disable_formatting ()
 Disables color formatting. More...
 
void render (const matrix4f &transform=matrix4f::identity) const
 Renders this text at the given position. More...
 
std::size_t get_letter_count () const
 Returns the number of letters currently displayed. More...
 
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). More...
 
quad create_letter_quad (char32_t c) const
 Creates a quad that contains the provided character. More...
 
void set_use_vertex_cache (bool use_vertex_cache)
 Sets whether this text object should use vertex caches or not. More...
 
bool get_use_vertex_cache () const
 Checks if this text object is using vertex cache or not. More...
 
const rendererget_renderer () const
 Returns the renderer used to render this text. More...
 
rendererget_renderer ()
 Returns the renderer used to render this text. More...
 

Detailed Description

Used to draw some text on the screen.

Definition at line 29 of file gui_text.hpp.

Constructor & Destructor Documentation

◆ text() [1/3]

lxgui::gui::text::text ( renderer rdr,
std::shared_ptr< const font fnt,
std::shared_ptr< const font outline_fnt = nullptr 
)
explicit

Constructor.

Parameters
rdrThe renderer instance to use
fntThe font to use for rendering
outline_fntThe font to use for outlines

Definition at line 283 of file gui_text.cpp.

◆ text() [2/3]

lxgui::gui::text::text ( const text )
delete

◆ text() [3/3]

lxgui::gui::text::text ( text &&  )
delete

Member Function Documentation

◆ create_letter_quad()

quad lxgui::gui::text::create_letter_quad ( char32_t  c) const

Creates a quad that contains the provided character.

Parameters
cThe character to draw
Note
Uses this text's font texture.

Definition at line 1045 of file gui_text.cpp.

◆ disable_formatting()

void lxgui::gui::text::disable_formatting ( )
inline

Disables color formatting.

See also
set_formatting_enabled

Definition at line 355 of file gui_text.hpp.

◆ disable_word_ellipsis()

void lxgui::gui::text::disable_word_ellipsis ( )
inline

Do not show an ellipsis "..." if words don't fit in the text box.

Definition at line 326 of file gui_text.hpp.

◆ disable_word_wrap()

void lxgui::gui::text::disable_word_wrap ( )
inline

Disallow word wrap when the line is too long for the text box.

Definition at line 299 of file gui_text.hpp.

◆ enable_formatting()

void lxgui::gui::text::enable_formatting ( )
inline

Enables color formatting.

See also
set_formatting_enabled

Definition at line 347 of file gui_text.hpp.

◆ enable_word_ellipsis()

void lxgui::gui::text::enable_word_ellipsis ( )
inline

Show an ellipsis "..." if words don't fit in the text box.

Definition at line 319 of file gui_text.hpp.

◆ enable_word_wrap()

void lxgui::gui::text::enable_word_wrap ( )
inline

Allows word wrap when the line is too long for the text box.

Definition at line 292 of file gui_text.hpp.

◆ get_alignment_x()

alignment_x lxgui::gui::text::get_alignment_x ( ) const

Returns the text horizontal alignment.

Returns
The text horizontal alignment

Definition at line 454 of file gui_text.cpp.

◆ get_alignment_y()

alignment_y lxgui::gui::text::get_alignment_y ( ) const

Returns the text vertical alignment.

Returns
The text vertical alignment

Definition at line 458 of file gui_text.cpp.

◆ get_alpha()

float lxgui::gui::text::get_alpha ( ) const

Returns this text's transparency (alpha).

Returns
This text's transparency (alpha)

Definition at line 342 of file gui_text.cpp.

◆ get_box_height()

float lxgui::gui::text::get_box_height ( ) const

Returns the height of the text box.

Returns
The height of the text box

Definition at line 388 of file gui_text.cpp.

◆ get_box_width()

float lxgui::gui::text::get_box_width ( ) const

Returns the width of the text box.

Returns
The width of the text box

Definition at line 384 of file gui_text.cpp.

◆ get_character_kerning()

float lxgui::gui::text::get_character_kerning ( char32_t  c1,
char32_t  c2 
) const

Returns the kerning between two characters.

Parameters
c1The first character
c2The second character
Returns
The kerning between two characters
Note
Kerning is a letter spacing adjustment that makes the text look more condensed: is you stick an A near a V, you can reduce the space between the two letters, but not if you put two Vs side to side.

Definition at line 432 of file gui_text.cpp.

◆ get_character_width()

float lxgui::gui::text::get_character_width ( char32_t  c) const

Returns the length of a single character.

Parameters
cThe character to measure
Returns
The length of this character

Definition at line 423 of file gui_text.cpp.

◆ get_color()

const color & lxgui::gui::text::get_color ( ) const

Returns this text's default color.

Returns
This text's default color

Definition at line 329 of file gui_text.cpp.

◆ get_height()

float lxgui::gui::text::get_height ( ) const

Returns the height of the rendered text.

Returns
The height of the rendered text
Note
Takes the text box into account if any.

Definition at line 379 of file gui_text.cpp.

◆ get_letter_count()

std::size_t lxgui::gui::text::get_letter_count ( ) const

Returns the number of letters currently displayed.

Returns
The number of letters currently displayed
Note
This function may update the quad cache as needed.

Definition at line 1053 of file gui_text.cpp.

◆ get_letter_quad()

const std::array< vertex, 4 > & lxgui::gui::text::get_letter_quad ( std::size_t  index) const

Returns the quad for the letter at the provided index (position, texture coords, color).

Parameters
indexThe index of the letter (0: first letter); must be less than get_letter_count().
Returns
The quad of the specified letter
Note
The vertex positions in the quad do not account for the rendering position provided to render(). The first letter always has its top-left corner as the position (0,0) (if left-aligned). This function may update the quad cache as needed.

Definition at line 1058 of file gui_text.cpp.

◆ get_line_count()

std::size_t lxgui::gui::text::get_line_count ( ) const

Returns the number of text lines.

Returns
The number of text lines

Definition at line 406 of file gui_text.cpp.

◆ get_line_height()

float lxgui::gui::text::get_line_height ( ) const

Returns the height of one line (constant).

Returns
The height of one line (constant)

Definition at line 287 of file gui_text.cpp.

◆ get_line_spacing()

float lxgui::gui::text::get_line_spacing ( ) const

Returns this text's line spacing.

Returns
This text's line spacing

Definition at line 484 of file gui_text.cpp.

◆ get_remove_starting_spaces()

bool lxgui::gui::text::get_remove_starting_spaces ( ) const

Checks if starting spaces removing is active.

Returns
'true' if starting spaces removing is active

Definition at line 497 of file gui_text.cpp.

◆ get_renderer() [1/2]

renderer& lxgui::gui::text::get_renderer ( )
inline

Returns the renderer used to render this text.

Returns
The renderer used to render this text

Definition at line 420 of file gui_text.hpp.

◆ get_renderer() [2/2]

const renderer& lxgui::gui::text::get_renderer ( ) const
inline

Returns the renderer used to render this text.

Returns
The renderer used to render this text

Definition at line 412 of file gui_text.hpp.

◆ get_scaling_factor()

float lxgui::gui::text::get_scaling_factor ( ) const

Returns the scaling factor used when rendering glyphs.

Returns
The scaling factor used when rendering glyphs

Definition at line 302 of file gui_text.cpp.

◆ get_string_width() [1/2]

float lxgui::gui::text::get_string_width ( const std::string &  content) const

Returns the length of a provided string.

Parameters
contentThe string to measure
Returns
The length of the provided string

Definition at line 411 of file gui_text.cpp.

◆ get_string_width() [2/2]

float lxgui::gui::text::get_string_width ( const utils::ustring &  content) const

Returns the length of a provided string.

Parameters
contentThe string to measure
Returns
The length of the provided string

Definition at line 415 of file gui_text.cpp.

◆ get_text()

const utils::ustring & lxgui::gui::text::get_text ( ) const

Returns the text that will be rendered (unicode character set).

Returns
The text that will be rendered (unicode character set)
Note
This string contains format tags.

Definition at line 315 of file gui_text.cpp.

◆ get_text_height()

float lxgui::gui::text::get_text_height ( ) const

Returns the height of the text.

Returns
The height of one text
Note
Ignores the text box, but not manual line jumps.

Definition at line 396 of file gui_text.cpp.

◆ get_text_width()

float lxgui::gui::text::get_text_width ( ) const

Returns the length of the text.

Returns
The length of the text
Note
Ignores the text box, but not manual line jumps.

Definition at line 392 of file gui_text.cpp.

◆ get_tracking()

float lxgui::gui::text::get_tracking ( ) const

Returns this text's tracking.

Returns
This text's tracking

Definition at line 471 of file gui_text.cpp.

◆ get_use_vertex_cache()

bool lxgui::gui::text::get_use_vertex_cache ( ) const

Checks if this text object is using vertex cache or not.

See also
set_use_vertex_cache()

Definition at line 540 of file gui_text.cpp.

◆ get_width()

float lxgui::gui::text::get_width ( ) const

Returns the width of the rendered text.

Returns
The width of the rendered text
Note
Takes the text box into account if any.

Definition at line 374 of file gui_text.cpp.

◆ is_word_ellipsis_enabled()

bool lxgui::gui::text::is_word_ellipsis_enabled ( ) const

Checks if word ellipsis is enabled.

Returns
'true' if word ellipsis is enabled

Definition at line 523 of file gui_text.cpp.

◆ is_word_wrap_enabled()

bool lxgui::gui::text::is_word_wrap_enabled ( ) const

Checks if word wrap is enabled.

Returns
'true' if word wrap is enabled

Definition at line 510 of file gui_text.cpp.

◆ operator=() [1/2]

text& lxgui::gui::text::operator= ( const text )
delete

◆ operator=() [2/2]

text& lxgui::gui::text::operator= ( text &&  )
delete

◆ render()

void lxgui::gui::text::render ( const matrix4f transform = matrix4f::identity) const

Renders this text at the given position.

Parameters
transformThe transform to apply to the text
Note
Must be called between renderer::begin() and renderer::end(). If the transform is left to the default (IDENTITY), the text will be rendered at the top-left corner of the screen, with the anchor position (coordinate [0,0]) set by the vertical and horizontal alignment (see get_alignment() and get_vertical_alignment()).

Definition at line 548 of file gui_text.cpp.

◆ set_alignment_x()

void lxgui::gui::text::set_alignment_x ( alignment_x  align_x)

Sets text horizontal alignment.

Parameters
align_xThe new horizontal alignment

Definition at line 436 of file gui_text.cpp.

◆ set_alignment_y()

void lxgui::gui::text::set_alignment_y ( alignment_y  align_y)

Sets text vertical alignment.

Parameters
align_yThe new vertical alignment

Definition at line 445 of file gui_text.cpp.

◆ set_alpha()

void lxgui::gui::text::set_alpha ( float  alpha)

Sets this text's transparency (alpha).

Parameters
alphaThe new alpha value

Definition at line 333 of file gui_text.cpp.

◆ set_box_dimensions()

void lxgui::gui::text::set_box_dimensions ( float  box_width,
float  box_height 
)

Sets the dimensions of the text box.

Parameters
box_widthThe new width
box_heightThe new height
Note
To remove the text box, use 0.0f.

Definition at line 346 of file gui_text.cpp.

◆ set_box_height()

void lxgui::gui::text::set_box_height ( float  box_height)

Sets the height of the text box.

Parameters
box_heightThe new height
Note
To remove it, use 0.0f.

Definition at line 365 of file gui_text.cpp.

◆ set_box_width()

void lxgui::gui::text::set_box_width ( float  box_width)

Sets the width of the text box.

Parameters
box_widthThe new width
Note
To remove it, use 0.0f.

Definition at line 356 of file gui_text.cpp.

◆ set_color()

void lxgui::gui::text::set_color ( const color c,
bool  force_color = false 
)

Sets this text's default color.

Parameters
cThe default color
force_color'true' to ignore color tags

Definition at line 319 of file gui_text.cpp.

◆ set_formatting_enabled()

void lxgui::gui::text::set_formatting_enabled ( bool  formatting)

Enables color formatting.

Parameters
formatting'true' to enable color formatting
Note
Enabled by default. See set_text for more information on formatting.

Definition at line 527 of file gui_text.cpp.

◆ set_line_spacing()

void lxgui::gui::text::set_line_spacing ( float  line_spacing)

Sets this text's line spacing.

Parameters
line_spacingThe new line spacing
Note
Line spacing is a coefficient that, multiplied by the height of a line, gives the space between two lines. Default is 1.5f.

Definition at line 475 of file gui_text.cpp.

◆ set_remove_starting_spaces()

void lxgui::gui::text::set_remove_starting_spaces ( bool  remove_starting_spaces)

Allows removal of a line's starting spaces.

Parameters
remove_starting_spaces'true' to remove them
Note
The text box does word wrapping: it cuts too long lines only between words. But sometimes, the rendered text must be cut between several spaces. By default, the algorithm puts cut spaces at the beginning of the next line. You can change this behavior by setting this function to 'true'.

Definition at line 488 of file gui_text.cpp.

◆ set_scaling_factor()

void lxgui::gui::text::set_scaling_factor ( float  scaling_factor)

Set the scaling factor to use when rendering glyphs.

Parameters
scaling_factorThe scaling factor
Note
This defines the conversion factor between pixels (from the texture of the font object) and interface units. By default this is set to 1, but needs to be changed on high DPI systems.

Definition at line 294 of file gui_text.cpp.

◆ set_text()

void lxgui::gui::text::set_text ( const utils::ustring &  content)

Sets the text to render (unicode character set).

Parameters
contentThe text to render
Note
This text can be formatted :
  • "|cAARRGGBB": sets text color (hexadecimal).
  • "|r": sets text color to default.
  • "||": writes "|".

Definition at line 306 of file gui_text.cpp.

◆ set_tracking()

void lxgui::gui::text::set_tracking ( float  tracking)

Sets this text's tracking.

Parameters
trackingThe new tracking
Note
Tracking is the space between each character. Default is 0.

Definition at line 462 of file gui_text.cpp.

◆ set_use_vertex_cache()

void lxgui::gui::text::set_use_vertex_cache ( bool  use_vertex_cache)

Sets whether this text object should use vertex caches or not.

Note
If vertex caches are not supported on the current rendering back end, this function has no effect.

Definition at line 536 of file gui_text.cpp.

◆ set_word_ellipsis_enabled()

void lxgui::gui::text::set_word_ellipsis_enabled ( bool  add_ellipsis)

Sets whether to show an ellipsis "..." if words don't fit in the text box.

Parameters
add_ellipsis'true' to put "..." at the end of a truncated line
Note
Disabled by default.

Definition at line 514 of file gui_text.cpp.

◆ set_word_wrap_enabled()

void lxgui::gui::text::set_word_wrap_enabled ( bool  wrap)

Allows/disallows word wrap when the line is too long for the text box.

Parameters
wrap'true' to enable word wrap
Note
Enabled by default.

Definition at line 501 of file gui_text.cpp.


The documentation for this class was generated from the following files: