Struct masonry::text2::TextEditor

source ·
pub struct TextEditor<T: EditableText> { /* private fields */ }
Expand description

A region of text which can support editing operations

Implementations§

source§

impl<T: EditableText> TextEditor<T>

source

pub fn new(text: T, text_size: f32) -> Self

source

pub fn reset_preedit(&mut self)

source

pub fn rebuild(&mut self, fcx: &mut FontContext)

source

pub fn draw(&mut self, scene: &mut Scene, point: impl Into<Point>)

source

pub fn pointer_down( &mut self, origin: Point, state: &PointerState, button: MouseButton ) -> bool

source

pub fn text_event( &mut self, ctx: &mut EventCtx<'_>, event: &TextEvent ) -> Handled

Methods from Deref<Target = TextWithSelection<T>>§

source

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

source

pub fn needs_rebuild(&self) -> bool

source

pub fn pointer_down( &mut self, origin: Point, state: &PointerState, button: MouseButton ) -> bool

source

pub fn pointer_up( &mut self, _origin: Point, _state: &PointerState, button: MouseButton )

source

pub fn pointer_move(&mut self, origin: Point, state: &PointerState) -> bool

source

pub fn text_event(&mut self, event: &TextEvent) -> Handled

source

pub fn focus_lost(&mut self)

Call when another widget becomes focused

source

pub fn rebuild_with_attributes( &mut self, fcx: &mut FontContext, attributes: impl for<'b> FnOnce(RangedBuilder<'b, TextBrush, &'b str>) -> RangedBuilder<'b, TextBrush, &'b str> )

source

pub fn rebuild(&mut self, fcx: &mut FontContext)

source

pub fn draw(&mut self, scene: &mut Scene, point: impl Into<Point>)

Methods from Deref<Target = TextLayout<T>>§

source

pub fn invalidate(&mut self)

Mark that the inner layout needs to be updated.

This should be used if your T has interior mutability

source

pub fn set_scale(&mut self, scale: f32)

Set the scaling factor

source

pub fn set_brush(&mut self, brush: impl Into<TextBrush>)

Set the default brush used for the layout.

This is the non-layout impacting styling (primarily colour) used when displaying the text

source

pub fn set_font(&mut self, font: FontStack<'static>)

Set the default font stack.

source

pub fn set_text_size(&mut self, size: f32)

Set the font size.

source

pub fn set_weight(&mut self, weight: Weight)

Set the font weight.

source

pub fn set_style(&mut self, style: Style)

Set the font style.

source

pub fn set_text_alignment(&mut self, alignment: Alignment)

Set the Alignment for this layout.

source

pub fn set_max_advance(&mut self, max_advance: Option<f32>)

Set the width at which to wrap words.

You may pass None to disable word wrapping (the default behaviour).

source

pub fn needs_rebuild(&self) -> bool

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.

source

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

Set the text to display.

source

pub fn text(&self) -> &T

Returns the TextStorage backing this layout, if it exists.

source

pub fn text_mut(&mut self) -> &mut T

Returns the TextStorage backing this layout, if it exists.

Invalidates the layout and so should only be used when definitely applying an edit

source

pub fn layout(&self) -> &Layout<TextBrush>

Returns the inner Parley Layout value.

source

pub fn size(&self) -> Size

The size of the laid-out text, excluding any trailing whitespace.

This is not meaningful until Self::rebuild has been called.

source

pub fn full_size(&self) -> Size

The size of the laid-out text, including any trailing whitespace.

This is not meaningful until Self::rebuild has been called.

source

pub fn layout_metrics(&self) -> LayoutMetrics

Return the text’s LayoutMetrics.

This is not meaningful until Self::rebuild has been called.

source

pub fn cursor_for_point(&self, point: Point) -> Cursor

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

This is not meaningful until Self::rebuild has been called.

source

pub fn cursor_for_text_position(&self, text_pos: usize) -> Cursor

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.

This is not meaningful until Self::rebuild has been called.

source

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

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.

This is not meaningful until Self::rebuild has been called.

source

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

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.

This is not meaningful until Self::rebuild has been called.

Returns the Link at the provided point (relative to the layout’s origin) if one exists.

This can be used both for hit-testing (deciding whether to change the mouse cursor, or performing some other action when hovering) as well as for retrieving a Link on click.

source

pub fn rebuild(&mut self, fcx: &mut FontContext)

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.

source

pub fn rebuild_with_attributes( &mut self, fcx: &mut FontContext, attributes: impl for<'b> FnOnce(RangedBuilder<'b, TextBrush, &'b str>) -> RangedBuilder<'b, TextBrush, &'b str> )

Rebuild the inner layout as needed, adding attributes to the underlying layout.

See Self::rebuild for more information

source

pub fn draw(&mut self, scene: &mut Scene, point: impl Into<Point>)

Draw the layout at the provided Point.

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

You must call Self::rebuild at some point before you first call this method.

Trait Implementations§

source§

impl<T: EditableText> Deref for TextEditor<T>

§

type Target = TextWithSelection<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: EditableText> DerefMut for TextEditor<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for TextEditor<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for TextEditor<T>

§

impl<T> !Send for TextEditor<T>

§

impl<T> !Sync for TextEditor<T>

§

impl<T> Unpin for TextEditor<T>
where T: Unpin,

§

impl<T> !UnwindSafe for TextEditor<T>

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> AsAny for T
where T: Any,

source§

fn as_dyn_any(&self) -> &(dyn Any + 'static)

Return self.
source§

fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)

Return self.
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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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

source§

impl<T> MaybeSendSync for T