pub struct Container<Msg: Clone> {
pub child: Box<Element<Msg>>,
pub background: Option<Paint>,
pub surface: Option<String>,
pub corners: Corners,
pub pad_top: Length,
pub pad_right: Length,
pub pad_bottom: Length,
pub pad_left: Length,
pub opacity: f32,
pub border: Option<(Color, f32)>,
pub max_width: Option<f32>,
pub a11y_live: bool,
}Expand description
A transparent wrapper that adds a background color or a themed
surface and padding around any child Element.
Does not consume a flat index — it is invisible to focus/hit-testing.
Two background styles. Container::background paints a flat
colour rounded rect. Container::surface names a theme slot (a
"type": "surface" entry in the active ThemeDocument) which
resolves at paint time to a full Glass stack: gradient / solid
fill, outer drop shadow, inset shadows, backdrop blur. surface
takes precedence when both are set, and degrades to background
(or to no background at all, when neither is set) if the slot is
absent from the active theme — third-party themes that do not
ship the named surface still render the content, just without
the Glass chrome.
// Flat colour
let flat = container( text( "Hello" ) )
.background( Color::rgb( 0.2, 0.2, 0.25 ) )
.padding( 12.0 );
// Glass card backed by a named theme surface
let card = container(
row()
.push( icon )
.push( column().push( title ).push( subtitle ) )
)
.surface( "surface-card" )
.radius( 32.0 )
.padding_h( 16.5 )
.padding_v( 24.0 );Fields§
§child: Box<Element<Msg>>§background: Option<Paint>Optional background paint — flat colour, linear or radial
gradient. Constructed via Container::background, which
accepts anything Into<Paint> (a plain Color gets
promoted to Paint::Solid via the trait impl).
surface: Option<String>Slot id of a themed surface (resolved via
crate::theme::resolve_surface). When set, takes precedence
over background and paints the full Glass stack instead of a
flat colour fill.
corners: CornersPer-corner radii applied to every painted layer of the
container chrome — flat fill, themed surface (gradient + outer
shadows + insets + backdrop blur). Stored as Corners so
callers can pin the rounded shape to one or two corners (a
panel pinned to the screen bottom, a side panel pinned to the
left edge, …) without hitting the renderer with an offset
trick.
pad_top: LengthPadding on the top edge — gap between the container’s top boundary
and its child. Stored as a Length so it can scale with the
viewport via Length::dp / Length::vmin.
pad_right: LengthPadding on the right edge.
pad_bottom: LengthPadding on the bottom edge.
pad_left: LengthPadding on the left edge.
opacity: f32§border: Option<(Color, f32)>Optional ( color, width_px ) border stroke painted around the
container’s rounded rectangle, after the fill / surface and
before the child draws. None leaves the chrome flat.
max_width: Option<f32>Optional hard cap on the container’s outer width. When the parent
offers more, the container reports its preferred width as
min( offered, max_width ) so it does not stretch to fill.
Mirrors the same flag on Column
and Row.
a11y_live: boolWhen true, the contents of this container are announced by
assistive technologies as a Live::Polite region — useful for
toasts, status banners and OSDs that need to be read on
appearance even when the user has not navigated to them.
Implementations§
Source§impl<Msg: Clone> Container<Msg>
impl<Msg: Clone> Container<Msg>
pub fn new(child: impl Into<Element<Msg>>) -> Self
pub fn live_region(self, live: bool) -> Self
Sourcepub fn border(self, color: Color, width: f32) -> Self
pub fn border(self, color: Color, width: f32) -> Self
Paint a rounded-rect stroke around the container with the given colour and pixel width. Useful for input fields, popovers and any chrome the design system specifies as outlined rather than filled.
Sourcepub fn background(self, paint: impl Into<Paint>) -> Self
pub fn background(self, paint: impl Into<Paint>) -> Self
Set the background fill. Accepts anything convertible to
Paint — a plain Color (auto-wrapped in
Paint::Solid) or an explicit crate::theme::LinearGradient
/ crate::theme::RadialGradient. Ignored at paint time if a
themed surface is set and resolves against
the active theme.
Sourcepub fn surface(self, slot: impl Into<String>) -> Self
pub fn surface(self, slot: impl Into<String>) -> Self
Back the container with a themed surface slot. The slot id is
resolved against the active ThemeDocument at paint time via
crate::theme::resolve_surface; missing slots fall through
to background or to no background at all.
Slot ids are documented by the theme. The default theme ships
surface-card (generic Glass container) and the slider-specific
slots; downstream themes are free to add their own.
Sourcepub fn radius(self, corners: impl Into<Corners>) -> Self
pub fn radius(self, corners: impl Into<Corners>) -> Self
Set the corner radii for every painted layer of the container
chrome. Accepts a single f32 (uniform radius — the common
case, equivalent to Corners::all( r )), a tuple ( tl, tr, br, bl ) (CSS shorthand order), or any explicit
Corners value.
// Uniform 16 px on all corners (single-value form).
let a = container( text( "child" ) ).radius( 16.0 );
// Rounded top corners only — for a panel pinned flush against
// the bottom edge of the screen.
let b = container( text( "child" ) ).radius( Corners::top( 16.0 ) );
// Custom four-corner radii.
let c = container( text( "child" ) ).radius( ( 16.0, 16.0, 0.0, 0.0 ) );Sourcepub fn padding(self, p: impl Into<Length>) -> Self
pub fn padding(self, p: impl Into<Length>) -> Self
Set uniform padding on all four sides — equivalent to setting
padding_top, padding_right, padding_bottom, and
padding_left to p. Asymmetric variants
(padding_top, …) override individual
edges, so calling this first and then a per-edge setter is the
idiomatic way to express “uniform padding except for one
edge”.
Sourcepub fn padding_h(self, p: impl Into<Length>) -> Self
pub fn padding_h(self, p: impl Into<Length>) -> Self
Set horizontal padding (left + right each).
Sourcepub fn padding_top(self, p: impl Into<Length>) -> Self
pub fn padding_top(self, p: impl Into<Length>) -> Self
Set the top edge padding only. Pairs with
padding_bottom for asymmetric
vertical insets.
Sourcepub fn padding_right(self, p: impl Into<Length>) -> Self
pub fn padding_right(self, p: impl Into<Length>) -> Self
Set the right edge padding only.
Sourcepub fn padding_bottom(self, p: impl Into<Length>) -> Self
pub fn padding_bottom(self, p: impl Into<Length>) -> Self
Set the bottom edge padding only.
Sourcepub fn padding_left(self, p: impl Into<Length>) -> Self
pub fn padding_left(self, p: impl Into<Length>) -> Self
Set the left edge padding only.
Sourcepub fn opacity(self, alpha: f32) -> Self
pub fn opacity(self, alpha: f32) -> Self
Set opacity for the entire container and its contents (0.0 = transparent, 1.0 = opaque).
Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Container<Msg>
impl<Msg> !RefUnwindSafe for Container<Msg>
impl<Msg> !Send for Container<Msg>
impl<Msg> !Sync for Container<Msg>
impl<Msg> Unpin for Container<Msg>
impl<Msg> !UnwindSafe for Container<Msg>
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more