pub struct TextLayout<'a> { /* private fields */ }egc only.Expand description
Builder for laying out a Line within a bounded Rect.
Call measure to get TextMetrics without
touching any surface, or render_to_surface to write
directly into a Surface.
§Examples
use retroglyph_core::layout::{TextLayout, HAlign, VAlign};
use retroglyph_core::grid::Rect;
use retroglyph_core::text::Line;
let rect = Rect::new(0, 0, 20, 5);
let line = Line::raw("Hello, world!");
let metrics = TextLayout::new(&line)
.rect(rect)
.h_align(HAlign::Center)
.measure();
assert_eq!(metrics.height, 1);Implementations§
Source§impl<'a> TextLayout<'a>
impl<'a> TextLayout<'a>
Sourcepub const fn new(line: &'a Line) -> Self
pub const fn new(line: &'a Line) -> Self
Creates a new layout builder for line.
Defaults: zero-sized rect at origin, left/top alignment. Call
rect before measure or
render_to_surface.
Sourcepub fn measure(&self) -> TextMetrics
pub fn measure(&self) -> TextMetrics
Measures the text without rendering, returning its TextMetrics.
Uses the rect’s width for word-wrapping; ignores height.
Sourcepub fn render_to_surface(&self, surface: &mut Surface<'_>)
pub fn render_to_surface(&self, surface: &mut Surface<'_>)
Renders the text into surface, clipping to both the rect’s bounds and surface’s own
area (the rect is intersected with Surface::area first, so text can never escape the
surface it was given even if rect extends past it).
Sourcepub fn render_to_grid(&self, grid: &mut Grid, layer: u8)
pub fn render_to_grid(&self, grid: &mut Grid, layer: u8)
Renders the text into grid on layer, clipping to the rect’s bounds.
The Grid-level twin of render_to_surface, for callers
with no Surface of their own to hand over.