pub struct TextLayout { /* private fields */ }Expand description
A block of text shaped with a single style.
TextLayout is retained by text elements: shaping results are cached per
paragraph by cosmic-text, and measurements are cached per wrap width, so
re-layout after a parent resize only re-wraps lines.
Implementations§
Source§impl TextLayout
impl TextLayout
pub fn new() -> Self
pub fn text(&self) -> &str
pub fn style(&self) -> Option<&TextStyle>
Sourcepub fn set(
&mut self,
ts: &mut TextSystem,
text: &str,
style: &TextStyle,
) -> bool
pub fn set( &mut self, ts: &mut TextSystem, text: &str, style: &TextStyle, ) -> bool
Updates text and style. Returns true if the layout (size) may have
changed; paint-only style changes return false.
Sourcepub fn measure(&mut self, ts: &mut TextSystem, max_width: Option<f32>) -> Size
pub fn measure(&mut self, ts: &mut TextSystem, max_width: Option<f32>) -> Size
Measures the text wrapped to max_width (None = no wrapping).
Sourcepub fn layout(&mut self, ts: &mut TextSystem, width: Option<f32>) -> Size
pub fn layout(&mut self, ts: &mut TextSystem, width: Option<f32>) -> Size
Lays the text out for painting at the final width.
Sourcepub fn lines(&self) -> Vec<LineMetrics>
pub fn lines(&self) -> Vec<LineMetrics>
Visual lines at the current layout width.
Sourcepub fn for_each_glyph(
&self,
origin: Point,
scale: f32,
f: impl FnMut(GlyphInstance),
)
pub fn for_each_glyph( &self, origin: Point, scale: f32, f: impl FnMut(GlyphInstance), )
Visits every glyph positioned for an origin given in logical pixels,
rendered at scale device pixels per logical pixel.
Sourcepub fn hit_test(&self, point: Point) -> usize
pub fn hit_test(&self, point: Point) -> usize
Byte offset of the character boundary closest to point (logical px,
relative to the text origin).
Sourcepub fn caret_bounds(&self, offset: usize) -> Bounds
pub fn caret_bounds(&self, offset: usize) -> Bounds
Caret rectangle for byte offset (logical px, relative to the origin).