pub struct Container<Msg: Clone> { /* private fields */ }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 );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