[][src]Struct druid::TextLayout

pub struct TextLayout<T> { /* fields omitted */ }

A component for displaying text on screen.

This is a type intended to be used by other widgets that display text. It allows for the text itself as well as font and other styling information to be set and modified. It wraps an inner layout object, and handles invalidating and rebuilding it as required.

This object is not valid until the rebuild_if_needed method has been called. You should generally do this in your widget's layout method. Additionally, you should call needs_rebuild_after_update as part of your widget's update method; if this returns true, you will need to call rebuild_if_needed again, generally by scheduling another layout pass.

Implementations

impl<T> TextLayout<T>[src]

pub fn new() -> Self[src]

Create a new TextLayout object.

You must set the text (set_text) before using this object.

pub fn from_text(text: impl Into<T>) -> Self[src]

Create a new TextLayout with the provided text.

This is useful when the text is not died to application data.

pub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>)[src]

Set the default text color for this layout.

pub fn set_font(&mut self, font: impl Into<KeyOrValue<FontDescriptor>>)[src]

Set the default font.

The argument is a FontDescriptor or a Key<FontDescriptor> that can be resolved from the Env.

pub fn set_text_size(&mut self, size: impl Into<KeyOrValue<f64>>)[src]

Set the font size.

This overrides the size in the FontDescriptor provided to set_font.

pub fn set_wrap_width(&mut self, width: f64)[src]

Set the width at which to wrap words.

You may pass f64::INFINITY to disable word wrapping (the default behaviour).

pub fn set_text_alignment(&mut self, alignment: TextAlignment)[src]

Set the TextAlignment for this layout.

impl<T: TextStorage> TextLayout<T>[src]

pub fn needs_rebuild(&self) -> bool[src]

Returns true if this layout needs to be rebuilt.

This happens (for instance) after style attributes are modified.

This does not account for things like the text changing, handling that is the responsibility of the user.

pub fn set_text(&mut self, text: T)[src]

Set the text to display.

pub fn text(&self) -> Option<&T>[src]

Returns the TextStorage backing this layout, if it exists.

pub fn layout(&self) -> Option<&PietTextLayout>[src]

Returns the inner Piet TextLayout type.

pub fn size(&self) -> Size[src]

The size of the laid-out text.

This is not meaningful until rebuild_if_needed has been called.

pub fn layout_metrics(&self) -> LayoutMetrics[src]

Return the text's LayoutMetrics.

This is not meaningful until rebuild_if_needed has been called.

pub fn text_position_for_point(&self, point: Point) -> usize[src]

For a given Point (relative to this object's origin), returns index into the underlying text of the nearest grapheme boundary.

pub fn point_for_text_position(&self, text_pos: usize) -> Point[src]

Given the utf-8 position of a character boundary in the underlying text, return the Point (relative to this object's origin) representing the boundary of the containing grapheme.

Panics

Panics if text_pos is not a character boundary.

pub fn rects_for_range(&self, range: Range<usize>) -> Vec<Rect>[src]

Given a utf-8 range in the underlying text, return a Vec of Rects representing the nominal bounding boxes of the text in that range.

Panics

Panics if the range start or end is not a character boundary.

pub fn cursor_line_for_text_position(&self, text_pos: usize) -> Line[src]

Given the utf-8 position of a character boundary in the underlying text, return a Line suitable for drawing a vertical cursor at that boundary.

pub fn needs_rebuild_after_update(
    &mut self,
    ctx: &mut UpdateCtx<'_, '_>
) -> bool
[src]

Called during the containing widgets update method; this text object will check to see if any used environment items have changed, and invalidate itself as needed.

Returns true if the text item needs to be rebuilt.

pub fn rebuild_if_needed(&mut self, factory: &mut PietText, env: &Env)[src]

Rebuild the inner layout as needed.

This TextLayout object manages a lower-level layout object that may need to be rebuilt in response to changes to the text or attributes like the font.

This method should be called whenever any of these things may have changed. A simple way to ensure this is correct is to always call this method as part of your widget's layout method.

pub fn draw(&self, ctx: &mut PaintCtx<'_, '_, '_>, point: impl Into<Point>)[src]

Draw the layout at the provided Point.

The origin of the layout is the top-left corner.

You must call rebuild_if_needed at some point before you first call this method.

Trait Implementations

impl<T: Clone> Clone for TextLayout<T>[src]

impl<T> Debug for TextLayout<T>[src]

impl<T: TextStorage> Default for TextLayout<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for TextLayout<T>[src]

impl<T> !Send for TextLayout<T>[src]

impl<T> !Sync for TextLayout<T>[src]

impl<T> Unpin for TextLayout<T> where
    T: Unpin
[src]

impl<T> !UnwindSafe for TextLayout<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.