pub struct SizedBox { /* private fields */ }
Expand description
A widget with predefined size.
If given a child, this widget forces its child to have a specific width and/or height (assuming values are permitted by this widget’s parent). If either the width or height is not set, this widget will size itself to match the child’s size in that dimension.
If not given a child, SizedBox
will try to size itself as close to the specified height
and width as possible given the parent’s constraints. If height or width is not set,
it will be treated as zero.
Implementations§
source§impl SizedBox
impl SizedBox
sourcepub fn new(child: impl Widget) -> Self
pub fn new(child: impl Widget) -> Self
Construct container with child, and both width and height not set.
sourcepub fn new_with_id(child: impl Widget, id: WidgetId) -> Self
pub fn new_with_id(child: impl Widget, id: WidgetId) -> Self
Construct container with child, and both width and height not set.
sourcepub fn empty() -> Self
pub fn empty() -> Self
Construct container without child, and both width and height not set.
If the widget is unchanged, it will render nothing, which can be useful if you want to draw a widget some of the time.
sourcepub fn expand(self) -> Self
pub fn expand(self) -> Self
Expand container to fit the parent.
Only call this method if you want your widget to occupy all available
space. If you only care about expanding in one of width or height, use
expand_width
or expand_height
instead.
sourcepub fn expand_width(self) -> Self
pub fn expand_width(self) -> Self
Expand the container on the x-axis.
This will force the child to have maximum width.
sourcepub fn expand_height(self) -> Self
pub fn expand_height(self) -> Self
Expand the container on the y-axis.
This will force the child to have maximum height.
sourcepub fn background(self, brush: impl Into<BackgroundBrush>) -> Self
pub fn background(self, brush: impl Into<BackgroundBrush>) -> Self
Builder-style method for setting 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 border(self, color: impl Into<Color>, width: impl Into<f64>) -> Self
pub fn border(self, color: impl Into<Color>, width: impl Into<f64>) -> Self
Builder-style method for painting a border around the widget with a color and width.
sourcepub fn rounded(self, radius: impl Into<RoundedRectRadii>) -> Self
pub fn rounded(self, radius: impl Into<RoundedRectRadii>) -> Self
Builder style method for rounding off corners of this container by setting a corner radius