pub trait TextSink {
// Required methods
fn draw(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8));
fn width(&self, text: &str) -> i16;
fn line_height(&self) -> i16;
// Provided method
fn draw_centered(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8)) { ... }
}Expand description
The minimum a widget needs from a text renderer: draw a run at a position in a colour, and measure it.
UI code written against this works with any renderer – FontAtlas, a
scaled bitmap font, or a game’s own atlas – instead of being written twice
because two renderers happen to have different inherent methods. That is the
situation this exists to prevent: a caller with a list, a menu or a dialog to
draw should not care which one is behind it.
Coordinates are screen pixels with the origin top-left, matching the rest of the SDK’s immediate-mode drawing.
Required Methods§
Sourcefn draw(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8))
fn draw(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8))
Draw text with its top-left corner at (x, y).
Sourcefn width(&self, text: &str) -> i16
fn width(&self, text: &str) -> i16
Width of text in screen pixels, using the same metrics draw will.
Sourcefn line_height(&self) -> i16
fn line_height(&self) -> i16
Baseline-to-baseline distance for stacked rows.
Provided Methods§
Sourcefn draw_centered(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8))
fn draw_centered(&self, x: i16, y: i16, text: &str, tint: (u8, u8, u8))
Draw text centred on x. Provided so every caller does not repeat the
half-width arithmetic, and so a renderer with non-integer metrics can
override the rounding.