Struct masonry::text2::TextWithSelection
source · pub struct TextWithSelection<T: Selectable> {
pub layout: TextLayout<T>,
pub selection: Option<Selection>,
/* private fields */
}
Fields§
§layout: TextLayout<T>
§selection: Option<Selection>
The current selection within this widget
Implementations§
source§impl<T: Selectable> TextWithSelection<T>
impl<T: Selectable> TextWithSelection<T>
pub fn new(text: T, text_size: f32) -> Self
pub fn set_text(&mut self, text: T)
pub fn needs_rebuild(&self) -> bool
pub fn pointer_down( &mut self, origin: Point, state: &PointerState, button: MouseButton ) -> bool
pub fn pointer_up( &mut self, _origin: Point, _state: &PointerState, button: MouseButton )
pub fn pointer_move(&mut self, origin: Point, state: &PointerState) -> bool
pub fn text_event(&mut self, event: &TextEvent) -> Handled
sourcepub fn focus_lost(&mut self)
pub fn focus_lost(&mut self)
Call when another widget becomes focused
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> )
pub fn rebuild(&mut self, fcx: &mut FontContext)
pub fn draw(&mut self, scene: &mut Scene, point: impl Into<Point>)
Methods from Deref<Target = TextLayout<T>>§
sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Mark that the inner layout needs to be updated.
This should be used if your T
has interior mutability
sourcepub fn set_brush(&mut self, brush: impl Into<TextBrush>)
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
sourcepub fn set_text_size(&mut self, size: f32)
pub fn set_text_size(&mut self, size: f32)
Set the font size.
sourcepub fn set_weight(&mut self, weight: Weight)
pub fn set_weight(&mut self, weight: Weight)
Set the font weight.
sourcepub fn set_text_alignment(&mut self, alignment: Alignment)
pub fn set_text_alignment(&mut self, alignment: Alignment)
Set the Alignment
for this layout.
sourcepub fn set_max_advance(&mut self, max_advance: Option<f32>)
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).
sourcepub fn needs_rebuild(&self) -> bool
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.
sourcepub fn text(&self) -> &T
pub fn text(&self) -> &T
Returns the TextStorage
backing this layout, if it exists.
sourcepub fn text_mut(&mut self) -> &mut T
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
sourcepub fn size(&self) -> Size
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.
sourcepub fn full_size(&self) -> Size
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.
sourcepub fn layout_metrics(&self) -> LayoutMetrics
pub fn layout_metrics(&self) -> LayoutMetrics
Return the text’s LayoutMetrics
.
This is not meaningful until Self::rebuild
has been called.
sourcepub fn cursor_for_point(&self, point: Point) -> Cursor
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.
sourcepub fn cursor_for_text_position(&self, text_pos: usize) -> Cursor
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.
sourcepub fn point_for_text_position(&self, text_pos: usize) -> Point
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.
sourcepub fn cursor_line_for_text_position(&self, text_pos: usize) -> Line
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.
sourcepub fn link_for_pos(&self, pos: Point) -> Option<&Link>
pub fn link_for_pos(&self, pos: Point) -> Option<&Link>
sourcepub fn rebuild(&mut self, fcx: &mut FontContext)
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.
sourcepub fn rebuild_with_attributes(
&mut self,
fcx: &mut FontContext,
attributes: impl for<'b> FnOnce(RangedBuilder<'b, TextBrush, &'b str>) -> RangedBuilder<'b, TextBrush, &'b str>
)
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