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>>
impl<'a> WidgetMut<'a, Box<dyn Widget>>
sourcepub fn try_downcast<W2: Widget>(&mut self) -> Option<WidgetMut<'_, W2>>
pub fn try_downcast<W2: Widget>(&mut self) -> Option<WidgetMut<'_, W2>>
Attempt to downcast to WidgetMut
of concrete Widget type.
source§impl<'a> WidgetMut<'a, Flex>
impl<'a> WidgetMut<'a, Flex>
sourcepub fn set_direction(&mut self, direction: Axis)
pub fn set_direction(&mut self, direction: Axis)
Set the flex direction (see Axis
).
sourcepub fn set_cross_axis_alignment(&mut self, alignment: CrossAxisAlignment)
pub fn set_cross_axis_alignment(&mut self, alignment: CrossAxisAlignment)
Set the childrens’ CrossAxisAlignment
.
sourcepub fn set_main_axis_alignment(&mut self, alignment: MainAxisAlignment)
pub fn set_main_axis_alignment(&mut self, alignment: MainAxisAlignment)
Set the childrens’ MainAxisAlignment
.
sourcepub fn set_must_fill_main_axis(&mut self, fill: bool)
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.
sourcepub fn add_child(&mut self, child: impl Widget)
pub fn add_child(&mut self, child: impl Widget)
Add a non-flex child widget.
See also with_child
.
pub fn add_child_id(&mut self, child: impl Widget, id: WidgetId)
sourcepub fn add_flex_child(
&mut self,
child: impl Widget,
params: impl Into<FlexParams>
)
pub fn add_flex_child( &mut self, child: impl Widget, params: impl Into<FlexParams> )
Add a flexible child widget.
sourcepub fn add_default_spacer(&mut self)
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.
sourcepub fn add_spacer(&mut self, len: f64)
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
.
sourcepub fn add_flex_spacer(&mut self, flex: f64)
pub fn add_flex_spacer(&mut self, flex: f64)
Add an empty spacer widget with a specific flex
factor.
sourcepub fn insert_child(&mut self, idx: usize, child: impl Widget)
pub fn insert_child(&mut self, idx: usize, child: impl Widget)
Add a non-flex child widget.
See also with_child
.
sourcepub fn insert_child_pod(
&mut self,
idx: usize,
widget: WidgetPod<Box<dyn Widget>>
)
pub fn insert_child_pod( &mut self, idx: usize, widget: WidgetPod<Box<dyn Widget>> )
Add a non-flex child widget.
pub fn insert_flex_child( &mut self, idx: usize, child: impl Widget, params: impl Into<FlexParams> )
sourcepub fn insert_default_spacer(&mut self, idx: usize)
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.
sourcepub fn insert_spacer(&mut self, idx: usize, len: f64)
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
.
sourcepub fn insert_flex_spacer(&mut self, idx: usize, flex: f64)
pub fn insert_flex_spacer(&mut self, idx: usize, flex: f64)
Add an empty spacer widget with a specific flex
factor.
pub fn remove_child(&mut self, idx: usize)
pub fn child_mut( &mut self, idx: usize ) -> Option<WidgetMut<'_, Box<dyn Widget>>>
pub fn clear(&mut self)
source§impl<'a> WidgetMut<'a, Image>
impl<'a> WidgetMut<'a, Image>
sourcepub fn set_fill_mode(&mut self, newfil: FillStrat)
pub fn set_fill_mode(&mut self, newfil: FillStrat)
Modify the widget’s fill strategy.
sourcepub fn set_image_data(&mut self, image_data: ImageBuf)
pub fn set_image_data(&mut self, image_data: ImageBuf)
Set new ImageBuf
.
source§impl WidgetMut<'_, Label>
impl WidgetMut<'_, Label>
pub fn text(&self) -> &ArcStr
pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextLayout<ArcStr>) -> R ) -> R
pub fn set_text(&mut self, new_text: impl Into<ArcStr>)
pub fn set_text_brush(&mut self, brush: impl Into<TextBrush>)
pub fn set_text_size(&mut self, size: f32)
pub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_font(&mut self, font_stack: FontStack<'static>)
pub fn set_font_family(&mut self, family: FontFamily<'static>)
pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)
source§impl<W: Widget> WidgetMut<'_, Portal<W>>
impl<W: Widget> WidgetMut<'_, Portal<W>>
pub fn child_mut(&mut self) -> WidgetMut<'_, W>
pub fn horizontal_scrollbar_mut(&mut self) -> WidgetMut<'_, ScrollBar>
pub fn vertical_scrollbar_mut(&mut self) -> WidgetMut<'_, ScrollBar>
sourcepub fn set_constrain_horizontal(&mut self, constrain: bool)
pub fn set_constrain_horizontal(&mut self, constrain: bool)
Set whether to constrain the child horizontally.
See constrain_vertical
for more details.
sourcepub fn set_constrain_vertical(&mut self, constrain: bool)
pub fn set_constrain_vertical(&mut self, constrain: bool)
Set whether to constrain the child vertically.
See constrain_vertical
for more details.
sourcepub fn set_content_must_fill(&mut self, must_fill: bool)
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.
pub fn set_viewport_pos(&mut self, position: Point) -> bool
pub fn pan_viewport_by(&mut self, translation: Vec2) -> bool
pub fn pan_viewport_to(&mut self, target: Rect) -> bool
source§impl WidgetMut<'_, Prose>
impl WidgetMut<'_, Prose>
pub fn text(&self) -> &ArcStr
pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextWithSelection<ArcStr>) -> R ) -> R
sourcepub fn set_text(&mut self, new_text: ArcStr)
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.
pub fn set_text_brush(&mut self, brush: impl Into<TextBrush>)
pub fn set_text_size(&mut self, size: f32)
pub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_font(&mut self, font_stack: FontStack<'static>)
pub fn set_font_family(&mut self, family: FontFamily<'static>)
pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)
source§impl<W: Widget> WidgetMut<'_, RootWidget<W>>
impl<W: Widget> WidgetMut<'_, RootWidget<W>>
pub fn get_element(&mut self) -> WidgetMut<'_, W>
source§impl WidgetMut<'_, ScrollBar>
impl WidgetMut<'_, ScrollBar>
pub fn set_sizes(&mut self, portal_size: f64, content_size: f64)
pub fn set_content_size(&mut self, content_size: f64)
pub fn set_cursor_progress(&mut self, cursor_progress: f64)
source§impl WidgetMut<'_, SizedBox>
impl WidgetMut<'_, SizedBox>
pub fn set_child(&mut self, child: impl Widget)
pub fn remove_child(&mut self)
sourcepub fn set_height(&mut self, height: f64)
pub fn set_height(&mut self, height: f64)
Set container’s height.
sourcepub fn unset_width(&mut self)
pub fn unset_width(&mut self)
Set container’s width.
sourcepub fn unset_height(&mut self)
pub fn unset_height(&mut self)
Set container’s height.
sourcepub fn set_background(&mut self, brush: impl Into<BackgroundBrush>)
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
.
sourcepub fn clear_background(&mut self)
pub fn clear_background(&mut self)
Clears background.
sourcepub fn set_border(&mut self, color: impl Into<Color>, width: impl Into<f64>)
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.
sourcepub fn clear_border(&mut self)
pub fn clear_border(&mut self)
Clears border.
sourcepub fn set_rounded(&mut self, radius: impl Into<RoundedRectRadii>)
pub fn set_rounded(&mut self, radius: impl Into<RoundedRectRadii>)
Round off corners of this container by setting a corner radius
pub fn child_mut(&mut self) -> Option<WidgetMut<'_, Box<dyn Widget>>>
source§impl WidgetMut<'_, Spinner>
impl WidgetMut<'_, Spinner>
sourcepub fn set_color(&mut self, color: impl Into<Color>)
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>
impl WidgetMut<'_, Split>
sourcepub fn set_split_point(&mut self, split_point: f64)
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
.
sourcepub fn set_min_size(&mut self, first: f64, second: f64)
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.
sourcepub fn set_bar_size(&mut self, bar_size: f64)
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
.
sourcepub fn set_min_bar_area(&mut self, min_bar_area: f64)
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
.
sourcepub fn set_draggable(&mut self, draggable: bool)
pub fn set_draggable(&mut self, draggable: bool)
Set whether the split point can be changed by dragging.
sourcepub fn set_bar_solid(&mut self, solid: bool)
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>
impl WidgetMut<'_, Textbox>
pub fn text(&self) -> &str
pub fn set_text_properties<R>( &mut self, f: impl FnOnce(&mut TextWithSelection<String>) -> R ) -> R
sourcepub fn reset_text(&mut self, new_text: String)
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.
pub fn set_text_brush(&mut self, brush: impl Into<TextBrush>)
pub fn set_text_size(&mut self, size: f32)
pub fn set_alignment(&mut self, alignment: Alignment)
pub fn set_font(&mut self, font_stack: FontStack<'static>)
pub fn set_font_family(&mut self, family: FontFamily<'static>)
pub fn set_line_break_mode(&mut self, line_break_mode: LineBreaking)
Trait Implementations§
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> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
source§fn as_dyn_any(&self) -> &(dyn Any + 'static)
fn as_dyn_any(&self) -> &(dyn Any + 'static)
source§fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.