Skip to main content

TextLayout

Struct TextLayout 

Source
pub struct TextLayout { /* private fields */ }
Expand description

A paragraph laid out in lines: glyph runs placed for drawing, and the queries of Compose’s TextLayoutResult. Distances are in pixels from the layout’s top left corner; offsets are byte offsets in the text. The default is empty, ready for TextLayouter::layout_into.

Implementations§

Source§

impl TextLayout

Source

pub fn id(&self) -> u32

A number this layout’s glyphs and positions go by: a layout laid out or aligned again takes a new one, so a renderer keys what it drew of a layout by it; a clone keeps it.

Source

pub fn holds(&self, min_width: f32, max_width: f32) -> bool

Whether the text laid out again between min_width and max_width, with the rest of its input the same, breaks into the same lines: TextLayout::align then gives that layout without laying the text out again.

Source

pub fn width_between(&self, min_width: f32, max_width: f32) -> f32

The width the paragraph takes laid out between min_width and max_width: its max intrinsic width rounded up to whole device pixels within them, the max when they are equal, and its widest line rounded up to whole device pixels within them when its lines wrap.

Source

pub fn max_widths_kept(&self, min_width: f32) -> (f32, f32)

The max widths, from .0 up to and with .1, at which the paragraph laid out from min_width keeps its width and its lines: every width when its width follows no max, every width from its own when its text fits, else the widths its lines wrap the same at below the width it fits at, or only the one it wraps at when those are not known or its widest line is wider than that one: its width is then the one it wraps at, and moves with it.

Source

pub fn align(&mut self, min_width: f32, max_width: f32, align: TextAlign)

Places the lines across the width the paragraph takes between min_width and max_width as align says, for widths the layout holds.

Source

pub fn try_align( &mut self, min_width: f32, max_width: f32, align: TextAlign, ) -> bool

Aligns the lines between min_width and max_width when the layout holds there; false, leaving the layout as it was, when it does not.

Source

pub fn width(&self) -> f32

The paragraph’s width: its max intrinsic width rounded up to whole device pixels, within the widths it was laid out between.

Source

pub fn height(&self) -> f32

The height of all lines.

Source

pub fn line_advance(&self) -> f32

The distance from the first line’s baseline down to the next line’s: the first line’s height before the paragraph’s edges trim it.

Source

pub fn line_count(&self) -> usize

The number of lines, at least one.

Source

pub fn lines_reach(&self) -> (f32, f32)

How far the visible text of the lines reaches across: the left edge of the leftmost line’s and the right edge of the rightmost line’s, both zero for the empty default.

Source

pub fn typefaces(&self) -> &[Typeface]

The typefaces the glyphs come from.

Source

pub fn synthesized_style(&self) -> SynthesizedStyle

The bold and the italic the glyphs ask of faces that lack them, which a renderer synthesizes and which spread their ink.

Source

pub fn glyph_reach(&self) -> Rect

How far the glyphs reach, in pixels from the layout’s top left corner: across, the visible text of the lines and the ink a glyph puts past it, as the overhang of an f that ends a line does; down, from the top, or the ink above it, to the lowest ink, at the top when the glyphs ink no lower than the box. A renderer joins it with the box it draws the text in.

Source

pub fn did_overflow_height(&self) -> bool

Whether the text had more lines than the line limit: Compose’s didOverflowHeight of a layout the line limit cut.

Source

pub fn did_overflow_width(&self) -> bool

Whether the paragraph is wider than the widest it was laid out at, or a line wider than the paragraph: Compose’s didOverflowWidth.

Source

pub fn is_line_ellipsized(&self, line: usize) -> bool

Whether line shows an ellipsis in place of text.

Source

pub fn line_start(&self, line: usize) -> usize

The offset where line starts. Panics when line is out of range, as Compose throws.

Source

pub fn line_end(&self, line: usize) -> usize

The offset where line ends, after its line break and trailing whitespace.

Source

pub fn line_visible_end(&self, line: usize) -> usize

The offset where the visible text of line ends, before its line break and trailing whitespace: Compose’s getLineEnd(line, true).

Source

pub fn line_top(&self, line: usize) -> f32

The top of line.

Source

pub fn line_bottom(&self, line: usize) -> f32

The bottom of line.

Source

pub fn line_baseline(&self, line: usize) -> f32

The baseline of line.

Source

pub fn line_left(&self, line: usize) -> f32

The left edge of the visible text of line.

Source

pub fn line_right(&self, line: usize) -> f32

The right edge of the visible text of line.

Source

pub fn line_for_offset(&self, offset: usize) -> usize

The line that holds offset; the last line for the end of the text.

Source

pub fn line_for_vertical_position(&self, y: f32) -> usize

The line at height y, the first above the text and the last below it.

Source

pub fn horizontal_position( &self, offset: usize, direction: CaretDirection, ) -> f32

The x of a caret at offset. Where the text before and after offset runs in different directions the caret has two places, and direction picks one.

Source

pub fn offset_for_position(&self, x: f32, y: f32) -> usize

The offset of the caret nearest to the point x, y.

Source

pub fn glyph_runs(&self, line: usize) -> impl Iterator<Item = GlyphRun<'_>> + '_

The glyph runs of line, left to right.

Source

pub fn bounding_box(&self, offset: usize) -> Rect

The box of the character at offset, across its line: Compose’s getBoundingBox. A zero-width box at the caret for an offset with no character, such as the end of the text.

Source

pub fn cursor_rect(&self, offset: usize) -> Rect

The caret at offset as a zero-width rectangle across its line: Compose’s getCursorRect.

Source

pub fn selection_rects(&self, start: usize, end: usize, rects: &mut Vec<Rect>)

Pushes onto rects the rectangles that cover the text from start to end line by line, one for each stretch of it that runs in one direction, within the paragraph’s width or its visible text: Compose’s getPathForRange as rectangles. The spaces a wrapped line ends with hang past the widest line, which they do not widen, and cover nothing there.

Trait Implementations§

Source§

impl Clone for TextLayout

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextLayout

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TextLayout

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.