PanelText

Text drawn from the outlines of its glyphs with the boundary drawer of the program, Windfoil by default, instead of from textures of glyphs. Text is crisp at any scale and in any transform. The work is cached at every step:

  • faces are loaded once per font, weight and size, by FontFaces, shared with compositions; text is shaped in one face per font and weight and its glyphs are scaled to the size of the text

  • text is shaped once per face and string, kept for the most recently used maxShapedTexts strings; the shaped text gives both the measures that layout uses and the glyphs that are drawn, so they agree

  • the outline of every glyph is uploaded to the GPU once, for all sizes, in the glyph map of the boundary drawer that all elements, compositions and other text drawers share, see GlyphMaps

  • the draw commands of every text an element draws are prepared once in a buffer of their own, in the coordinates of the element; drawing them again, also when the element moved because it scrolled, only draws the buffer. Buffers that were not drawn in a redraw are released after it, see releaseUnused

Types

Link copied to clipboard
data class Placed(val shaped: ShapedText, val position: Vector2, val color: ColorRGBa)

a text of drawBatch: shaped at position, the origin of its first baseline, in color

Link copied to clipboard
class RichShaped(val shaped: ShapedText, val runOfGlyph: IntArray)

rich text shaped in lines: shaped, and the run of every glyph

Link copied to clipboard
class Run(val text: String, val style: StyleSheet)

a run of rich text: text in the face and color of style

Properties

Link copied to clipboard

the most strings whose shaping is kept

Functions

Link copied to clipboard
fun carets(style: StyleSheet, text: String): DoubleArray

The x of the caret before every character of text in a single line in the face of style, and after the last: text.length + 1 positions, kept like the shaping. From the glyphs of the line, which white space has none of: a glyph for every other character, or else for every character of a word, by the glyphs of each word alone; in the words whose glyphs are not one per character, as with ligatures, from the widths of the beginnings of the word

Link copied to clipboard
fun draw(drawer: Drawer, owner: Any, slot: String, shaped: ShapedText, position: Vector2, color: ColorRGBa, decoration: TextDecoration = TextDecoration.NONE, glyphColors: List<ColorRGBa>? = null)

Draws shaped at position, the origin of its first baseline, in color. The draw commands are kept for owner under slot and drawn again as long as the text, its position and its color stay the same.

Link copied to clipboard
fun drawBatch(drawer: Drawer, owner: Any, slot: String, texts: List<PanelText.Placed>)

Draws texts with a single draw call, without decorations, for many small texts like the labels of a graph. The draw commands are kept for owner under slot and drawn again as long as the texts, their positions and their colors stay the same, so texts that change often are best batched apart from those that do not.

Link copied to clipboard
fun drawInBox(drawer: Drawer, owner: Any, slot: String, style: StyleSheet, text: String, box: Rectangle, horizontalAlign: Double, verticalAlign: Double, color: ColorRGBa, wrap: Boolean = false)

Draws text in the face of style in box, at horizontalAlign and verticalAlign in it, from 0 at the left and the top to 1 at the right and the bottom; broken into lines at the width of the box when wrap is set and the white space of the style wraps, cut with an ellipsis when it is a single line that does not fit and the text overflow of the style is ellipsis, with the decoration of the style

Link copied to clipboard
fun drawLine(drawer: Drawer, owner: Any, slot: String, style: StyleSheet, text: String, x: Double, y: Double, color: ColorRGBa)

draws a single line of text in the face of style, with its decoration, see draw

Link copied to clipboard
fun ellipsized(style: StyleSheet, text: String, width: Double): String

text cut at its end, with an ellipsis, so that it fits in width, as a single line in the face of style

Link copied to clipboard
fun face(style: StyleSheet): Face

the face of style: its font family, weight, style and size

Link copied to clipboard
fun line(style: StyleSheet, text: String): ShapedText

text shaped as a single line in the face of style, with its letter spacing

fun line(face: Face, text: String, spacing: Double = 0.0): ShapedText

text shaped as a single line in face, with spacing after every character

Link copied to clipboard
fun paragraph(style: StyleSheet, text: String, width: Double, horizontalAlign: Double = 0.0): ShapedText

text in the face of style, broken into lines at most width wide; the first baseline is at y = 0

Link copied to clipboard
fun placeInBox(style: StyleSheet, text: String, box: Rectangle, horizontalAlign: Double, verticalAlign: Double, color: ColorRGBa): PanelText.Placed

text as a single line in the face of style, at horizontalAlign and verticalAlign in box, see drawInBox

Link copied to clipboard

releases the buffers of the texts that were not drawn since the last call, after a redraw

Link copied to clipboard
fun richParagraph(runs: List<PanelText.Run>, width: Double, horizontalAlign: Double = 0.0): PanelText.RichShaped

runs of text in their own faces broken into lines at most width wide, as one paragraph; the first baseline is at y = 0. The lines are as far apart as the line height of the largest face.

Link copied to clipboard
fun width(style: StyleSheet, text: String): Double

the width of text in a single line in the face of style