HikoGUI
Select Version: ⚠️ This documents the main development branch of HikoGUI. It might differ from release versions.
A low latency retained GUI
|
#include <hikogui/text/text_shaper.hpp>
Public Types | |
using | char_vector = std::vector<text_shaper_char> |
using | char_iterator = char_vector::iterator |
using | char_const_iterator = char_vector::const_iterator |
using | char_reference = char_vector::reference |
using | char_const_reference = char_vector::const_reference |
using | line_vector = std::vector<text_shaper_line> |
using | line_iterator = line_vector::iterator |
using | line_const_iterator = line_vector::const_iterator |
Public Member Functions | |
constexpr | text_shaper (text_shaper const &) noexcept=default |
constexpr | text_shaper (text_shaper &&) noexcept=default |
constexpr text_shaper & | operator= (text_shaper const &) noexcept=default |
constexpr text_shaper & | operator= (text_shaper &&) noexcept=default |
text_shaper (gstring const &text, text_style const &style, hi::pixel_density pixel_density, hi::alignment alignment, bool left_to_right, iso_15924 script=iso_15924{"Zyyy"}) noexcept | |
Construct a text_shaper with a text and alignment. | |
text_shaper (std::string_view text, text_style const &style, hi::pixel_density pixel_density, hi::alignment alignment, bool left_to_right, iso_15924 script=iso_15924{"Zyyy"}) noexcept | |
bool | empty () const noexcept |
size_t | size () const noexcept |
char_iterator | begin () noexcept |
char_const_iterator | begin () const noexcept |
char_const_iterator | cbegin () const noexcept |
char_iterator | end () noexcept |
char_const_iterator | end () const noexcept |
char_const_iterator | cend () const noexcept |
auto const & | lines () const noexcept |
aarectangle | bounding_rectangle (float maximum_line_width, float line_spacing=1.0f, float paragraph_spacing=1.5f) noexcept |
Get bounding rectangle. | |
void | layout (aarectangle rectangle, float baseline, extent2 sub_pixel_size, float line_spacing=1.0f, float paragraph_spacing=1.5f) noexcept |
Layout the lines of the text. | |
aarectangle | rectangle () const noexcept |
The rectangle used when laying out the text. | |
unicode_bidi_class | text_direction () const noexcept |
Get the text-direction as a whole. | |
alignment | resolved_alignment () const noexcept |
Get the resolved alignment of the text. | |
char_const_iterator | get_it (size_t index) const noexcept |
Get the character at index in logical order. | |
char_const_iterator | get_it (text_cursor cursor) const noexcept |
Get the character at the cursor. | |
char_const_iterator | get_it (size_t column_nr, size_t line_nr) const noexcept |
Get the character at column and row in display order. | |
char_const_iterator | get_it (std::pair< size_t, size_t > column_row) const noexcept |
Get the character at column and row in display order. | |
std::pair< size_t, size_t > | get_column_line (text_shaper::char_const_iterator it) const noexcept |
Get the column and line of a character. | |
std::pair< size_t, size_t > | get_column_line (size_t index) const noexcept |
Get the column and line of a character. | |
std::pair< size_t, size_t > | get_column_line (text_cursor cursor) const noexcept |
Get the column and line of a character. | |
size_t | get_index (text_shaper::char_const_iterator it) const noexcept |
Get the index of the character in logical order. | |
text_cursor | get_begin_cursor () const noexcept |
Get the cursor at the beginning of the document. | |
text_cursor | get_end_cursor () const noexcept |
Get the cursor at the end of the document. | |
text_cursor | get_before_cursor (size_t index) const noexcept |
Get the cursor before the character in logical order. | |
text_cursor | get_after_cursor (size_t index) const noexcept |
Get the cursor after the character in logical order. | |
text_cursor | get_before_cursor (text_shaper::char_const_iterator it) const noexcept |
Get the cursor before the character in logical order. | |
text_cursor | get_after_cursor (text_shaper::char_const_iterator it) const noexcept |
Get the cursor after the character in logical order. | |
text_cursor | get_left_cursor (text_shaper::char_const_iterator it) const noexcept |
Get the cursor left of the character in display order. | |
text_cursor | get_right_cursor (text_shaper::char_const_iterator it) const noexcept |
Get the cursor right of the character in display order. | |
bool | is_on_left (text_cursor cursor) const noexcept |
Check if the cursor is on the left side of the character in display order. | |
bool | is_on_right (text_cursor cursor) const noexcept |
Check if the cursor is on the right side of the character in display order. | |
text_cursor | get_nearest_cursor (point2 position) const noexcept |
find the nearest character. | |
std::pair< text_cursor, text_cursor > | select_char (text_cursor cursor) const noexcept |
Get the selection for the character at the cursor. | |
std::pair< text_cursor, text_cursor > | select_word (text_cursor cursor) const noexcept |
Get the selection for the word at the cursor. | |
std::pair< text_cursor, text_cursor > | select_sentence (text_cursor cursor) const noexcept |
Get the selection for the sentence at the cursor. | |
std::pair< text_cursor, text_cursor > | select_paragraph (text_cursor cursor) const noexcept |
Get the selection for a paragraph at the cursor. | |
std::pair< text_cursor, text_cursor > | select_document (text_cursor cursor) const noexcept |
Get the selection for a paragraph at the cursor. | |
char_const_iterator | move_left_char (char_const_iterator it) const noexcept |
Get the character to the left. | |
char_const_iterator | move_right_char (char_const_iterator it) const noexcept |
Get the character to the right. | |
text_cursor | move_left_char (text_cursor cursor, bool overwrite_mode) const noexcept |
text_cursor | move_right_char (text_cursor cursor, bool overwrite_mode) const noexcept |
text_cursor | move_down_char (text_cursor cursor, float &x) const noexcept |
text_cursor | move_up_char (text_cursor cursor, float &x) const noexcept |
text_cursor | move_left_word (text_cursor cursor, bool overwrite_mode) const noexcept |
text_cursor | move_right_word (text_cursor cursor, bool overwrite_mode) const noexcept |
text_cursor | move_begin_line (text_cursor cursor) const noexcept |
text_cursor | move_end_line (text_cursor cursor) const noexcept |
text_cursor | move_begin_sentence (text_cursor cursor) const noexcept |
text_cursor | move_end_sentence (text_cursor cursor) const noexcept |
text_cursor | move_begin_paragraph (text_cursor cursor) const noexcept |
text_cursor | move_end_paragraph (text_cursor cursor) const noexcept |
text_cursor | move_begin_document (text_cursor cursor) const noexcept |
text_cursor | move_end_document (text_cursor cursor) const noexcept |
Text shaper.
This class takes text as a set of graphemes attributed with font, size, style and color.
Steps:
|
inlinenoexcept |
Construct a text_shaper with a text and alignment.
The constructor will load all the default glyphs for the text.
Horizontal alignment is done for each line independent of the writing direction. This allows labels to remain aligned in the same direction on the user-interface even when the labels have translations in different languages.
Label widgets should flip the alignment passed to the text shaper when the user interface is mirrored.
Text edit fields may want to change the alignment of the text depending on the dominant writing direction, for more natural typing.
Vertical alignment of the text determines what y=0 means:
text | The text as a vector of attributed graphemes. Use U+2029 as paragraph separator, and if needed U+2028 as line separator. |
style | The initial text-style to use to display the text. |
pixel_density | The pixel density of the current display. |
alignment | The alignment how to align the text. |
text_direction | The default text direction when it can not be deduced from the text. |
script | The script of the text. |
|
inlinenoexcept |
Get bounding rectangle.
It will estimate the width and height based on the glyphs before glyph-morphing and kerning and fold the lines using the unicode line breaking algorithm to the max_line_width.
The alignment parameter is used to align the lines vertically:
maximum_line_width | The maximum line width allowed, this may be infinite to determine the natural text size without folding. |
line_spacing | The scaling of the spacing between lines. |
paragraph_spacing | The scaling of the spacing between paragraphs. |
|
inlinenoexcept |
Get the cursor after the character in logical order.
index | The index to the character or one beyond. |
|
inlinenoexcept |
Get the cursor after the character in logical order.
it | The iterator to the character or end() . |
|
inlinenoexcept |
Get the cursor before the character in logical order.
index | The index to the character or one beyond. |
|
inlinenoexcept |
Get the cursor before the character in logical order.
it | The iterator to the character or end() . |
|
inlinenoexcept |
Get the cursor at the beginning of the document.
|
inlinenoexcept |
Get the column and line of a character.
index | The index of the character in logical order. |
std::pair
.
|
inlinenoexcept |
Get the column and line of a character.
cursor | The cursor to the character. |
std::pair
.
|
inlinenoexcept |
Get the column and line of a character.
it | The iterator to the character, or end() . |
std::pair
.
|
inlinenoexcept |
Get the cursor at the end of the document.
|
inlinenoexcept |
Get the index of the character in logical order.
it | The iterator to the character or end() . |
|
inlinenoexcept |
Get the character at column and row in display order.
begin()
and end()
inclusive. column_nr | The column |
line_nr | The row |
|
inlinenoexcept |
Get the character at index in logical order.
begin()
and end()
inclusive. index | The index in the text. |
|
inlinenoexcept |
Get the character at column and row in display order.
begin()
and end()
inclusive. column_row | The column, row packed in a std::pair . |
|
inlinenoexcept |
Get the character at the cursor.
begin()
and end()
inclusive. cursor | The cursor in the text. |
|
inlinenoexcept |
Get the cursor left of the character in display order.
it | The iterator to the character or end() . |
|
inlinenoexcept |
find the nearest character.
position | The point near |
|
inlinenoexcept |
Get the cursor right of the character in display order.
it | The iterator to the character or end() . |
|
inlinenoexcept |
Check if the cursor is on the left side of the character in display order.
cursor | The cursor to query. |
|
inlinenoexcept |
Check if the cursor is on the right side of the character in display order.
cursor | The cursor to query. |
|
inlinenoexcept |
Layout the lines of the text.
It will estimate the width and height based on the glyphs before glyph-morphing and kerning and fold the lines using the unicode line breaking algorithm to the width of the rectangle.
rectangle | The rectangle to position the glyphs in. |
baseline | The position of the recommended base-line. |
sub_pixel_size | The size of a sub-pixel in device-independent-pixels. |
line_spacing | The scaling of the spacing between lines (default: 1.0). |
paragraph_spacing | The scaling of the spacing between paragraphs (default: 1.5). |
|
inlinenoexcept |
Get the character to the left.
it | The iterator to the character. |
|
inlinenoexcept |
Get the character to the right.
it | The iterator to the character. |
|
inlinenoexcept |
The rectangle used when laying out the text.
|
inlinenoexcept |
Get the resolved alignment of the text.
This is the alignment when taking into account the direction of the text and the direction of the selected language.
|
inlinenoexcept |
Get the selection for the character at the cursor.
|
inlinenoexcept |
Get the selection for a paragraph at the cursor.
|
inlinenoexcept |
Get the selection for a paragraph at the cursor.
|
inlinenoexcept |
Get the selection for the sentence at the cursor.
|
inlinenoexcept |
Get the selection for the word at the cursor.
|
inlinenoexcept |
Get the text-direction as a whole.