pub struct TextLayout(/* private fields */);Expand description
The laid-out state of a text element, for mapping between byte indices and pixels.
Get one from StyledText::layout, or from the text state that other text
elements keep. Clones share the same state. The query methods read the most
recent layout, so a query made after a relayout returns the new result.
The text elements fill this in during layout and prepaint. The query methods panic if the element hasn’t been laid out yet, and the ones that need pixel positions panic if it hasn’t been prepainted.
Implementations§
Source§impl TextLayout
impl TextLayout
Sourcepub fn evaluate_wrap_width(
white_space: &WhiteSpace,
known_dimensions: Size<Option<Pixels>>,
available_space: Size<AvailableSpace>,
) -> Option<Pixels>
pub fn evaluate_wrap_width( white_space: &WhiteSpace, known_dimensions: Size<Option<Pixels>>, available_space: Size<AvailableSpace>, ) -> Option<Pixels>
Returns the width that text wraps at, or None when it doesn’t wrap.
Text does not wrap when white_space is WhiteSpace::Nowrap. Otherwise
the width comes from TextLayout::evaluate_alignment_width.
Sourcepub fn evaluate_alignment_width(
known_dimensions: Size<Option<Pixels>>,
available_space: Size<AvailableSpace>,
) -> Option<Pixels>
pub fn evaluate_alignment_width( known_dimensions: Size<Option<Pixels>>, available_space: Size<AvailableSpace>, ) -> Option<Pixels>
Returns the width that text aligns within, from the known or available width.
The known width wins. Otherwise a definite available width is used. Under
min-content or max-content sizing, this returns None.
Sourcepub fn evaluate_overflow(
text_style: &TextStyle,
known_dimensions: Size<Option<Pixels>>,
available_space: Size<AvailableSpace>,
) -> TextLayoutTruncation
pub fn evaluate_overflow( text_style: &TextStyle, known_dimensions: Size<Option<Pixels>>, available_space: Size<AvailableSpace>, ) -> TextLayoutTruncation
Returns how the text should be truncated, from the style’s text_overflow.
When the style has no text_overflow, the result has no width and an empty affix,
so the text is never truncated.
Sourcepub fn apply_truncation<'runs>(
text: SharedString,
text_style: &TextStyle,
font_size: Pixels,
line_height: Pixels,
wrap_width: Option<Pixels>,
truncation: &TextLayoutTruncation,
runs: &'runs [TextRun],
paragraph_direction: ParagraphDirection,
unicode_bidi: UnicodeBidi,
window: &mut Window,
cx: &mut App,
) -> (SharedString, Cow<'runs, [TextRun]>)
pub fn apply_truncation<'runs>( text: SharedString, text_style: &TextStyle, font_size: Pixels, line_height: Pixels, wrap_width: Option<Pixels>, truncation: &TextLayoutTruncation, runs: &'runs [TextRun], paragraph_direction: ParagraphDirection, unicode_bidi: UnicodeBidi, window: &mut Window, cx: &mut App, ) -> (SharedString, Cow<'runs, [TextRun]>)
Shortens text so that it fits truncation.width, and returns the text to display.
When truncation.width is None, the text and runs come back unchanged. Otherwise
the removed part is replaced by truncation.affix, on the side given by
truncation.source. Wrapping and line_clamp from text_style still apply.
The returned runs match the returned text. They borrow runs when nothing changes.
Sourcepub fn paint_background(&self, window: &mut Window, cx: &mut App) -> Result<()>
pub fn paint_background(&self, window: &mut Window, cx: &mut App) -> Result<()>
Paints the backgrounds of the text runs without the glyphs, so callers can paint content such as highlights between the backgrounds and text.
Sourcepub fn paint_foreground(&self, window: &mut Window, cx: &mut App) -> Result<()>
pub fn paint_foreground(&self, window: &mut Window, cx: &mut App) -> Result<()>
Paints the glyphs and decorations without the run backgrounds.
Sourcepub fn index_for_position(
&self,
pixel_point: Point<Pixels>,
) -> Result<usize, usize>
pub fn index_for_position( &self, pixel_point: Point<Pixels>, ) -> Result<usize, usize>
Returns the UTF-8 byte index of the character at pixel_point, in window coordinates.
Returns Ok with the index of the character under the point. Returns Err
with 0 when the point is above the text. Points to the side of or below the
text return Err with the closest index. Use this for hit testing, such as
placing a caret on click.
§Panics
Panics if the element hasn’t been laid out or prepainted.
Sourcepub fn position_for_index(&self, byte_index: usize) -> Option<Point<Pixels>>
pub fn position_for_index(&self, byte_index: usize) -> Option<Point<Pixels>>
Returns the top-left corner of the caret for byte_index, in window coordinates.
Returns None if the text has no shaped layout, or if byte_index is past the end
of the text. Use this to place a caret or an overlay at a position in the text.
§Panics
Panics if the element hasn’t been laid out or prepainted.
Sourcepub fn line_layout_for_index(
&self,
index: usize,
) -> Option<Arc<ShapedTextLayout>>
pub fn line_layout_for_index( &self, index: usize, ) -> Option<Arc<ShapedTextLayout>>
Returns the shaped layout of the text, or None if index is past the end or the
text has not been shaped.
The layout covers the whole text, not one visual line or paragraph.
Use TextLayout::line_layouts to get every layout in source order.
§Panics
Panics if the element hasn’t been laid out.
Sourcepub fn line_layouts(&self) -> SmallVec<[Arc<ShapedTextLayout>; 1]>
pub fn line_layouts(&self) -> SmallVec<[Arc<ShapedTextLayout>; 1]>
Returns the shaped layout of the text as a collection with one entry.
This returns an empty collection if the text has not been shaped.
§Panics
Panics if the element hasn’t been laid out.
Sourcepub fn bounds(&self) -> Bounds<Pixels>
pub fn bounds(&self) -> Bounds<Pixels>
Returns the window bounds of the element, as set during prepaint.
§Panics
Panics if the element hasn’t been prepainted.
Sourcepub fn line_height(&self) -> Pixels
pub fn line_height(&self) -> Pixels
Returns the line height that the text is laid out with, in logical pixels.
§Panics
Panics if the element hasn’t been laid out.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the shaped text in UTF-8 bytes.
This is the length after any text transform or truncation. It is 0
when the text has not been shaped.
§Panics
Panics if the element hasn’t been laid out.
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Returns the text that was shaped, as a String.
This is the text after any TextTransform and truncation. A truncated
text includes the affix, such as an ellipsis. It returns an empty string if
the text has not been shaped.
§Panics
Panics if the element hasn’t been laid out.
Sourcepub fn wrapped_text(&self) -> String
pub fn wrapped_text(&self) -> String
Returns the shaped text with each visual line followed by a \n, except the last.
Soft wraps therefore become \n. A hard line break keeps its own \n as part of
its line, so it is followed by one more \n. Use this to copy wrapped text as it
appears on screen.
§Panics
Panics if the element hasn’t been laid out.
Trait Implementations§
Source§impl Clone for TextLayout
impl Clone for TextLayout
Auto Trait Implementations§
impl !RefUnwindSafe for TextLayout
impl !Send for TextLayout
impl !Sync for TextLayout
impl !UnwindSafe for TextLayout
impl Freeze for TextLayout
impl Unpin for TextLayout
impl UnsafeUnpin for TextLayout
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more