Struct masonry::widget::WidgetMut

source ·
pub struct WidgetMut<'a, W: Widget> {
    pub ctx: WidgetCtx<'a>,
    pub widget: &'a mut W,
}
Expand description

A mutable reference to a Widget.

In Masonry, widgets can’t be mutated directly. All mutations go through a WidgetMut wrapper. So, to change a label’s text, you might call WidgetMut<Label>::set_text(). This helps Masonry make sure that internal metadata is propagated after every widget change.

You can create a WidgetMut from TestHarness, EventCtx, LifeCycleCtx or from a parent WidgetMut with WidgetCtx.

WidgetMut implements Deref with W::Mut as target.

§WidgetMut as a Receiver

Once the Receiver trait is stabilized, WidgetMut will implement it so that custom widgets in downstream crates can use WidgetMut as the receiver for inherent methods.

Fields§

§ctx: WidgetCtx<'a>§widget: &'a mut W

Implementations§

source§

impl<'a> WidgetMut<'a, Box<dyn Widget>>

source

pub fn try_downcast<W2: Widget>(&mut self) -> Option<WidgetMut<'_, W2>>

Attempt to downcast to WidgetMut of concrete Widget type.

source

pub fn downcast<W2: Widget>(&mut self) -> WidgetMut<'_, W2>

Downcasts to WidgetMut of concrete Widget type.

§Panics

Panics if the downcast fails, with an error message that shows the discrepancy between the expected and actual types.

source§

impl WidgetMut<'_, Button>

source

pub fn set_text(&mut self, new_text: impl Into<ArcStr>)

Set the text.

source

pub fn label_mut(&mut self) -> WidgetMut<'_, Label>

source§

impl WidgetMut<'_, Checkbox>

source

pub fn set_checked(&mut self, checked: bool)

source

pub fn set_text(&mut self, new_text: ArcStr)

Set the text.

We enforce this to be an ArcStr to make the allocation explicit.

source

pub fn label_mut(&mut self) -> WidgetMut<'_, Label>

source§

impl<'a> WidgetMut<'a, Flex>

source

pub fn set_direction(&mut self, direction: Axis)

Set the flex direction (see Axis).

source

pub fn set_cross_axis_alignment(&mut self, alignment: CrossAxisAlignment)

Set the childrens’ CrossAxisAlignment.

source

pub fn set_main_axis_alignment(&mut self, alignment: MainAxisAlignment)

Set the childrens’ MainAxisAlignment.

source

pub fn set_must_fill_main_axis(&mut self, fill: bool)

Set whether the container must expand to fill the available space on its main axis.

source

pub fn add_child(&mut self, child: impl Widget)

Add a non-flex child widget.

See also with_child.

source

pub fn add_child_id(&mut self, child: impl Widget, id: WidgetId)

source

pub fn add_flex_child( &mut self, child: impl Widget, params: impl Into<FlexParams> )

Add a flexible child widget.

source

pub fn add_default_spacer(&mut self)

Add a spacer widget with a standard size.

The actual value of this spacer depends on whether this container is a row or column, as well as theme settings.

source

pub fn add_spacer(&mut self, len: f64)

Add an empty spacer widget with the given size.

If you are laying out standard controls in this container, you should generally prefer to use add_default_spacer.

source

pub fn add_flex_spacer(&mut self, flex: f64)

Add an empty spacer widget with a specific flex factor.

source

pub fn insert_child(&mut self, idx: usize, child: impl Widget)

Add a non-flex child widget.

See also with_child.

source

pub fn insert_child_pod( &mut self, idx: usize, widget: WidgetPod<Box<dyn Widget>> )

Add a non-flex child widget.

source

pub fn insert_flex_child( &mut self, idx: usize, child: impl Widget, params: impl Into<FlexParams> )

source

pub fn insert_default_spacer(&mut self, idx: usize)

Add a spacer widget with a standard size.

The actual value of this spacer depends on whether this container is a row or column, as well as theme settings.

source

pub fn insert_spacer(&mut self, idx: usize, len: f64)

Add an empty spacer widget with the given size.

If you are laying out standard controls in this container, you should generally prefer to use add_default_spacer.

source

pub fn insert_flex_spacer(&mut self, idx: usize, flex: f64)

Add an empty spacer widget with a specific flex factor.

source

pub fn remove_child(&mut self, idx: usize)

source

pub fn child_mut( &mut self, idx: usize ) -> Option<WidgetMut<'_, Box<dyn Widget>>>

source

pub fn clear(&mut self)

source§

impl<'a> WidgetMut<'a, Image>

source

pub fn set_fill_mode(&mut self, newfil: FillStrat)

Modify the widget’s fill strategy.

source

pub fn set_image_data(&mut self, image_data: ImageBuf)

Set new ImageBuf.

source§

impl WidgetMut<'_, Label>

source

pub fn text(&self) -> &ArcStr

source

pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextLayout<ArcStr>) -> R ) -> R

source

pub fn set_text(&mut self, new_text: impl Into<ArcStr>)

source

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

source

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

source

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

source

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

source

pub fn set_font_family(&mut self, family: FontFamily<'static>)

source

pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)

source§

impl<W: Widget> WidgetMut<'_, Portal<W>>

source

pub fn child_mut(&mut self) -> WidgetMut<'_, W>

source

pub fn horizontal_scrollbar_mut(&mut self) -> WidgetMut<'_, ScrollBar>

source

pub fn vertical_scrollbar_mut(&mut self) -> WidgetMut<'_, ScrollBar>

source

pub fn set_constrain_horizontal(&mut self, constrain: bool)

Set whether to constrain the child horizontally.

See constrain_vertical for more details.

source

pub fn set_constrain_vertical(&mut self, constrain: bool)

Set whether to constrain the child vertically.

See constrain_vertical for more details.

source

pub fn set_content_must_fill(&mut self, must_fill: bool)

Set whether the child’s size must be greater than or equal the size of the ClipBox.

See content_must_fill for more details.

source

pub fn set_viewport_pos(&mut self, position: Point) -> bool

source

pub fn pan_viewport_by(&mut self, translation: Vec2) -> bool

source

pub fn pan_viewport_to(&mut self, target: Rect) -> bool

source§

impl WidgetMut<'_, Prose>

source

pub fn text(&self) -> &ArcStr

source

pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextWithSelection<ArcStr>) -> R ) -> R

source

pub fn set_text(&mut self, new_text: ArcStr)

Change the text. If the user currently has a selection in the box, this will delete that selection.

We enforce this to be an ArcStr to make the allocation explicit.

source

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

source

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

source

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

source

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

source

pub fn set_font_family(&mut self, family: FontFamily<'static>)

source

pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)

source§

impl<W: Widget> WidgetMut<'_, RootWidget<W>>

source

pub fn get_element(&mut self) -> WidgetMut<'_, W>

source§

impl WidgetMut<'_, ScrollBar>

source

pub fn set_sizes(&mut self, portal_size: f64, content_size: f64)

source

pub fn set_content_size(&mut self, content_size: f64)

source

pub fn set_cursor_progress(&mut self, cursor_progress: f64)

source§

impl WidgetMut<'_, SizedBox>

source

pub fn set_child(&mut self, child: impl Widget)

source

pub fn remove_child(&mut self)

source

pub fn set_width(&mut self, width: f64)

Set container’s width.

source

pub fn set_height(&mut self, height: f64)

Set container’s height.

source

pub fn unset_width(&mut self)

Set container’s width.

source

pub fn unset_height(&mut self)

Set container’s height.

source

pub fn set_background(&mut self, brush: impl Into<BackgroundBrush>)

Set the background for this widget.

This can be passed anything which can be represented by a BackgroundBrush; notably, it can be any Color, any gradient, or a fully custom painter FnMut.

source

pub fn clear_background(&mut self)

Clears background.

source

pub fn set_border(&mut self, color: impl Into<Color>, width: impl Into<f64>)

Paint a border around the widget with a color and width.

source

pub fn clear_border(&mut self)

Clears border.

source

pub fn set_rounded(&mut self, radius: impl Into<RoundedRectRadii>)

Round off corners of this container by setting a corner radius

source

pub fn child_mut(&mut self) -> Option<WidgetMut<'_, Box<dyn Widget>>>

source§

impl WidgetMut<'_, Spinner>

source

pub fn set_color(&mut self, color: impl Into<Color>)

Set the spinner’s color.

The argument can be either a Color or a Key<Color>.

source§

impl WidgetMut<'_, Split>

source

pub fn set_split_point(&mut self, split_point: f64)

Set the split point as a fraction of the split axis.

The value must be between 0.0 and 1.0, inclusive. The default split point is 0.5.

source

pub fn set_min_size(&mut self, first: f64, second: f64)

Set the minimum size for both sides of the split axis.

The value must be greater than or equal to 0.0. The value will be rounded up to the nearest integer.

source

pub fn set_bar_size(&mut self, bar_size: f64)

Set the size of the splitter bar.

The value must be positive or zero. The value will be rounded up to the nearest integer. The default splitter bar size is 6.0.

source

pub fn set_min_bar_area(&mut self, min_bar_area: f64)

Set the minimum size of the splitter bar area.

The minimum splitter bar area defines the minimum size of the area where mouse hit detection is done for the splitter bar. The final area is either this or the splitter bar size, whichever is greater.

This can be useful when you want to use a very narrow visual splitter bar, but don’t want to sacrifice user experience by making it hard to click on.

The value must be positive or zero. The value will be rounded up to the nearest integer. The default minimum splitter bar area is 6.0.

source

pub fn set_draggable(&mut self, draggable: bool)

Set whether the split point can be changed by dragging.

source

pub fn set_bar_solid(&mut self, solid: bool)

Set whether the splitter bar is drawn as a solid rectangle.

If this is false (the default), the bar will be drawn as two parallel lines.

source§

impl WidgetMut<'_, Textbox>

source

pub fn text(&self) -> &str

source

pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextWithSelection<String>) -> R ) -> R

source

pub fn reset_text(&mut self, new_text: String)

Reset the contents of the text box.

This is likely to be disruptive if the user is focused on this widget, and so should be avoided if possible.

source

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

source

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

source

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

source

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

source

pub fn set_font_family(&mut self, family: FontFamily<'static>)

source

pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)

Trait Implementations§

source§

impl<W: Widget> Drop for WidgetMut<'_, W>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, W> Freeze for WidgetMut<'a, W>

§

impl<'a, W> !RefUnwindSafe for WidgetMut<'a, W>

§

impl<'a, W> !Send for WidgetMut<'a, W>

§

impl<'a, W> !Sync for WidgetMut<'a, W>

§

impl<'a, W> Unpin for WidgetMut<'a, W>

§

impl<'a, W> !UnwindSafe for WidgetMut<'a, W>

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

source§

fn downcast(&self) -> &T

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Same for T

§

type Output = T

Should always be Self
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> Upcast<T> for T

source§

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

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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