Skip to main content

Paragraph

Struct Paragraph 

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

A paragraph of text.

A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted.

To create a Paragraph object, use a ParagraphBuilder.

Paragraphs can be displayed on a Canvas using CanvasText::draw_paragraph.

Implementations§

Source§

impl Paragraph

Source

pub fn width(&self) -> f64

The amount of horizontal space this paragraph occupies.

Valid only after layout has been called. As in Skia, this is the width the paragraph was laid out at (possibly infinite), not the widest line: the lines are aligned within it.

Source

pub fn height(&self) -> f64

The amount of vertical space this paragraph occupies.

Valid only after layout has been called.

Source

pub fn longest_line(&self) -> f64

The distance from the left edge of the leftmost glyph to the right edge of the rightmost glyph in the paragraph.

Source

pub fn min_intrinsic_width(&self) -> f64

The minimum width that this paragraph could be without failing to paint its contents within itself.

Source

pub fn max_intrinsic_width(&self) -> f64

Returns the smallest width beyond which increasing the width never decreases the height.

Source

pub fn alphabetic_baseline(&self) -> f64

The distance from the top of the paragraph to the alphabetic baseline of the first line, in logical pixels.

Source

pub fn ideographic_baseline(&self) -> f64

The distance from the top of the paragraph to the ideographic baseline of the first line, in logical pixels.

The host has no ideographic metrics; this is the bottom of the first line.

Source

pub fn did_exceed_max_lines(&self) -> bool

True if there is more vertical content, but the text was truncated, either because we reached max_lines lines of text or because the max_lines was None, ellipsis was not None, and one of the lines exceeded the width constraint.

Source

pub fn layout(&mut self, constraints: ParagraphConstraints)

Computes the size and position of each glyph in the paragraph.

The ParagraphConstraints control how wide the text is allowed to be.

Source

pub fn get_boxes_for_range( &self, start: i32, end: i32, box_height_style: BoxHeightStyle, box_width_style: BoxWidthStyle, ) -> Vec<TextBox>

Returns a list of text boxes that enclose the given text range.

The host returns tight boxes only: box_height_style and box_width_style do not change the result.

Source

pub fn get_boxes_for_placeholders(&self) -> Vec<TextBox>

Returns a list of text boxes that enclose all placeholders in the paragraph.

The host has no placeholders; this is always empty.

Source

pub fn get_position_for_offset(&self, offset: Offset) -> TextPosition

Returns the text position closest to the given offset.

Source

pub fn get_closest_glyph_info_for_offset( &self, offset: Offset, ) -> Option<GlyphInfo>

Returns the GlyphInfo of the glyph closest to the given offset in the paragraph coordinate system, or None if if the text is empty, or is entirely clipped or ellipsized away.

Source

pub fn get_glyph_info_at(&self, code_unit_offset: i32) -> Option<GlyphInfo>

Returns the GlyphInfo located at the given UTF-16 code_unit_offset in the paragraph, or None if the given code_unit_offset is out of the visible lines’ range.

Source

pub fn get_word_boundary(&self, position: TextPosition) -> TextRange

Returns the TextRange of the word at the given TextPosition.

Source

pub fn get_line_boundary(&self, position: TextPosition) -> TextRange

Returns the TextRange of the line at the given TextPosition.

The newline (if any) is not returned as part of the range.

Source

pub fn compute_line_metrics(&self) -> Vec<LineMetrics>

Returns the full list of LineMetrics that describe in detail the various metrics of each laid out line.

Source

pub fn get_line_metrics_at(&self, line_number: i32) -> Option<LineMetrics>

Returns the LineMetrics for the line at line_number, or None if the given line_number is greater than or equal to number_of_lines.

Source

pub fn number_of_lines(&self) -> i32

The total number of visible lines in the paragraph.

Returns a non-negative number. If max_lines is set, the value of this getter never exceeds max_lines.

Source

pub fn get_line_number_at(&self, code_unit_offset: i32) -> Option<i32>

Returns the line number of the line that contains the code unit that code_unit_offset points to, or None if the code_unit_offset is out of range.

Source

pub fn dispose(&mut self)

Release the resources used by this object. The object is no longer usable after this method is called.

Source

pub fn debug_disposed(&self) -> bool

Whether this reference to the underlying paragraph is disposed.

Trait Implementations§

Source§

impl Debug for Paragraph

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,