pub struct Container {Show 21 fields
pub id: Option<WidgetId>,
pub child: Option<Widget>,
pub width: Option<f32>,
pub height: Option<f32>,
pub min_width: Option<f32>,
pub max_width: Option<f32>,
pub min_height: Option<f32>,
pub max_height: Option<f32>,
pub padding: [f32; 4],
pub flex_grow: f32,
pub flex_shrink: f32,
pub box_style: BoxStyle,
pub margin: [f32; 4],
pub background_fill: Option<Fill>,
pub background_color: Option<Color>,
pub border_color: Option<Color>,
pub border_width: f32,
pub border_radius: f32,
pub shadow: Option<BoxShadow>,
pub shadows: Vec<BoxShadow>,
pub backdrop_filter: Option<BackdropFilter>,
}Expand description
The universal wrapper widget: background fill, border, padding, size constraints, and box shadow on a single child.
Container is the workhorse of layout composition. Use it whenever you
need to add visual decoration or spacing around a child widget.
§Example
Container::new(Text::new("Card body"))
.bg(theme.tokens.colors.surface)
.border(theme.tokens.colors.border, 1.0)
.border_radius(8.0)
.padding_all(16.0)
.width(320.0)
.flex_grow(1.0)Fields§
§id: Option<WidgetId>Explicit node identity.
child: Option<Widget>The single child widget.
width: Option<f32>Fixed width in layout points.
height: Option<f32>Fixed height in layout points.
min_width: Option<f32>Minimum width constraint.
max_width: Option<f32>Maximum width constraint.
min_height: Option<f32>Minimum height constraint.
max_height: Option<f32>Maximum height constraint.
padding: [f32; 4]Padding [left, right, top, bottom].
flex_grow: f32Flex grow factor (how much extra space this container absorbs).
flex_shrink: f32Flex shrink factor (how much this container shrinks when space is tight).
box_style: BoxStyleDeclarative sizing, padding, aspect ratio, and overflow.
margin: [f32; 4]Outer spacing [left, right, top, bottom].
background_fill: Option<Fill>Background fill.
background_color: Option<Color>Legacy background fill colour.
border_color: Option<Color>Border stroke colour.
border_width: f32Border stroke width in layout points.
border_radius: f32Corner radius for rounded corners.
shadow: Option<BoxShadow>Optional drop shadow.
shadows: Vec<BoxShadow>Additional shadows drawn behind the container in order.
backdrop_filter: Option<BackdropFilter>Filter applied to content painted behind this container.
Implementations§
Source§impl Container
impl Container
pub fn new(child: impl Into<Widget>) -> Self
pub fn size(self, w: f32, h: f32) -> Self
pub fn width(self, w: f32) -> Self
Sourcepub fn width_length(self, width: Length) -> Self
pub fn width_length(self, width: Length) -> Self
Sets a typed preferred width.
Sourcepub fn height_length(self, height: Length) -> Self
pub fn height_length(self, height: Length) -> Self
Sets a typed preferred height.
Sourcepub fn min_width_length(self, width: Length) -> Self
pub fn min_width_length(self, width: Length) -> Self
Sets a typed minimum width.
Sourcepub fn max_width_length(self, width: Length) -> Self
pub fn max_width_length(self, width: Length) -> Self
Sets a typed maximum width.
Sourcepub fn min_height_length(self, height: Length) -> Self
pub fn min_height_length(self, height: Length) -> Self
Sets a typed minimum height.
Sourcepub fn max_height_length(self, height: Length) -> Self
pub fn max_height_length(self, height: Length) -> Self
Sets a typed maximum height.
pub fn height(self, h: f32) -> Self
pub fn min_width(self, w: f32) -> Self
pub fn max_width(self, w: f32) -> Self
pub fn min_height(self, h: f32) -> Self
pub fn max_height(self, h: f32) -> Self
pub fn padding_all(self, p: f32) -> Self
pub fn padding(self, padding: [f32; 4]) -> Self
Sourcepub fn padding_lengths(self, padding: [Length; 4]) -> Self
pub fn padding_lengths(self, padding: [Length; 4]) -> Self
Sets typed [left, right, top, bottom] padding.
Sourcepub fn margin_all(self, margin: f32) -> Self
pub fn margin_all(self, margin: f32) -> Self
Sets equal point-based margin on every edge.
Sourcepub fn margin(self, margin: [f32; 4]) -> Self
pub fn margin(self, margin: [f32; 4]) -> Self
Sets point-based [left, right, top, bottom] margin.
Sourcepub fn margin_lengths(self, margin: [Length; 4]) -> Self
pub fn margin_lengths(self, margin: [Length; 4]) -> Self
Sets typed [left, right, top, bottom] margin.
Sourcepub fn align_child(self, alignment: BoxAlignment) -> Self
pub fn align_child(self, alignment: BoxAlignment) -> Self
Aligns the child inside this container.
Sourcepub fn aspect_ratio(self, ratio: f32) -> Self
pub fn aspect_ratio(self, ratio: f32) -> Self
Sets a non-negative width-to-height ratio.
Sourcepub fn positioned(
self,
left: Option<f32>,
top: Option<f32>,
right: Option<f32>,
bottom: Option<f32>,
) -> Self
pub fn positioned( self, left: Option<f32>, top: Option<f32>, right: Option<f32>, bottom: Option<f32>, ) -> Self
Absolutely positions this container with point-based offsets.
Sourcepub fn positioned_lengths(
self,
left: Option<Length>,
top: Option<Length>,
right: Option<Length>,
bottom: Option<Length>,
) -> Self
pub fn positioned_lengths( self, left: Option<Length>, top: Option<Length>, right: Option<Length>, bottom: Option<Length>, ) -> Self
Positions this box with typed offsets relative to its positioned ancestor.
Sourcepub fn grid_cell(self, row: i16, column: i16) -> Self
pub fn grid_cell(self, row: i16, column: i16) -> Self
Places this container at a one-based grid row and column.
Sourcepub fn grid_span(self, rows: u16, columns: u16) -> Self
pub fn grid_span(self, rows: u16, columns: u16) -> Self
Spans this container across parent grid rows and columns.
Sourcepub fn clip_overflow(self, clip: bool) -> Self
pub fn clip_overflow(self, clip: bool) -> Self
Clips painting and descendants to this container’s bounds.
pub fn flex_grow(self, grow: f32) -> Self
pub fn flex_shrink(self, shrink: f32) -> Self
pub fn bg(self, color: Color) -> Self
pub fn bg_fill(self, fill: Fill) -> Self
pub fn border(self, color: Color, width: f32) -> Self
pub fn border_radius(self, radius: f32) -> Self
pub fn shadow(self, shadow: BoxShadow) -> Self
pub fn shadows(self, shadows: Vec<BoxShadow>) -> Self
Sourcepub fn backdrop_blur(self, sigma: f32) -> Self
pub fn backdrop_blur(self, sigma: f32) -> Self
Blurs content behind this container, clipped to its rounded bounds.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Container
impl<'de> Deserialize<'de> for Container
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !RefUnwindSafe for Container
impl !UnwindSafe for Container
impl Freeze for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl UnsafeUnpin for Container
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.