Private
_dirtyTextHelper#dirty but for internal use.
Private
_heightThe current total text height. May be outdated.
Private
_lineThe current TextHelper#lineHeight. May be outdated
Private
_lineSee TextHelper#lineRanges. For internal use only.
Private
_lineThe current TextHelper#lineSpacing. May be outdated
Private
_spaceThe width of a space in pixels. May be outdated
Private
_tabThe actual TextHelper#tabWidth in pixels. May be outdated
Private
_widthThe current largest text width. May be outdated.
The text alignment mode. Can also be a ratio.
Note that this only aligns text in the text's width. If TextHelper#maxWidth is infinite, then you may still need to align the widget that uses this text helper with a BaseContainer because the width will be set to the longest line range's width.
The current font used for rendering text.
The height of each line of text when wrapped. If null, then the helper will try to automatically detect it.
Private
lineDoes the line height or spacing need to be re-measured?
The amount of spacing between lines. If null, then the helper will try to automatically detect it.
The current maximum text width. If not Infinite and
TextHelper#wrapMode is not WrapMode.None
and not
WrapMode.Ellipsis
, then text will be wrapped and width will be set to
maxWidth.
Private
measureDoes the text need to be re-measured?
The amount of spaces that each tab character is equivalent to. By default, it is equivalent to 4 spaces.
Private
tabDo the space and tab widths need to be re-measured?
The current string of text.
The mode for text wrapping
Get the current line height, even if TextHelper#lineHeight is null. Re-measures line height if neccessary.
Get the current line spacing, even if TextHelper#lineSpacing is null. Re-measures line spacing if neccessary.
Get the current tab width in pixels. Re-measures if neccessary
Has the text (or properties associated with it) changed? Resets to false after reading the current value.
Get the height between the start of each line; the full line height.
Equivalent to the sum of TextHelper#actualLineHeight and TextHelper#actualLineSpacing
The current total text height. Re-measures text if neccessary.
Which range of text indices are used for each line.
If there is no text wrapping (maxWidth
is Infinity
, or wrapMode
is
WrapMode.None
or wrapMode
is WrapMode.Ellipsis
), then this will
contain a single tuple containing [0, (text length)]
.
If there is text wrapping, then this will be an array where each member is a tuple containing the starting index of a line of text and the ending index (exclusive) of a line of text.
Get the current space width in pixels. Re-measures if necessary
The current text width. Re-measures text if neccessary.
Resets TextHelper#dirty to false
Get the index and horizontal offset, in pixels, of the beginning of a character at a given offset.
See TextHelper#findOffsetFromIndex for the opposite.
Returns a 2-tuple containing the index of the character at the offset and a 2-tuple containing the offset, in pixels. Note that this is not neccessarily an integer. Note that the returned offset is not the same as the input offset. The returned offset is exactly at the beginning of the character. This is useful for implementing selectable text.
Get the horizontal offset, in pixels, of the beginning of a character at a given index.
See TextHelper#findIndexOffsetFromOffset for the opposite.
If true, the offset at the end of the line will be returned, instead of at the beginning of the line. Only applies to line ranges that were wrapped.
Returns a 2-tuple containing the offset, in pixels. Vertical offset in the tuple is at the top of the character. Note that this is not neccessarily an integer.
Private
getGet width from line range start to index. Handles out of bounds indices, but keeps them in the same line
Private
measureSimilar to measureTextDims, but uses text render groups for optimisation purposes and for the ability of individual characters to override their natively measured size; tabs having a dynamic size that aligns them to multiples of a value and newlines having no length.
The inclusive index to start measuring at. If there are render groups and unmeasured text before this index, then this value will be overridden to include the unmeasured text. Render groups will also be merged if they don't override width.
The exclusive index to stop measuring at.
The maximum width of a line of text. If the line contains a single character, this will be ignored.
The current text render groups for this line of text. This will be updated in place.
Returns true if the line range was modified and it fit into the maximum width
Private
measureMeasure a slice of text taking left offset into account. If left offset is 0, then this will also add the left bounding box overhang. If not, then it will just return the width.
Only for slices of text which have no width-overriding characters, else, you will get wrong measurements.
Returns the new horizontal offset
Paint all line ranges.
Paint a single text render group with a given offset and left value for checking if the group is zero-width. left value must not be shifted.
Used mainly for injecting debug code; you won't get much use out of this method unless you have a very specific need.
Private
updateUpdate TextHelper#_width, TextHelper#_lineHeight and TextHelper#_lineSpacing. Sets TextHelper#measureDirty to false. Does nothing if measurement is not needed.
An aggregate helper class for widgets that contain text.
Contains utilities for measuring text dimensions, converting between offsets in pixels and text indices and painting.