pub struct SizedBox<T> { /* 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<T> SizedBox<T>
impl<T> SizedBox<T>
sourcepub fn new(child: impl Widget<T> + 'static) -> Self
pub fn new(child: impl Widget<T> + 'static) -> 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 do nothing, which can be useful if you want to draw a
widget some of the time (for example, it is used to implement
Maybe
).
sourcepub fn width(self, width: impl Into<KeyOrValue<f64>>) -> Self
pub fn width(self, width: impl Into<KeyOrValue<f64>>) -> Self
Set container’s width.
sourcepub fn height(self, height: impl Into<KeyOrValue<f64>>) -> Self
pub fn height(self, height: impl Into<KeyOrValue<f64>>) -> Self
Set container’s height.
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.