ltk::container

Struct Container

Source
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: Corners

Per-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: Length

Padding 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: Length

Padding on the right edge.

§pad_bottom: Length

Padding on the bottom edge.

§pad_left: Length

Padding 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: bool

When 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>

Source

pub fn new(child: impl Into<Element<Msg>>) -> Self

Source

pub fn live_region(self, live: bool) -> Self

Source

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.

Source

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.

Source

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.

Source

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 ) );
Source

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”.

Source

pub fn padding_h(self, p: impl Into<Length>) -> Self

Set horizontal padding (left + right each).

Source

pub fn padding_v(self, p: impl Into<Length>) -> Self

Set vertical padding (top + bottom each).

Source

pub fn padding_top(self, p: impl Into<Length>) -> Self

Set the top edge padding only. Pairs with padding_bottom for asymmetric vertical insets.

Source

pub fn padding_right(self, p: impl Into<Length>) -> Self

Set the right edge padding only.

Source

pub fn padding_bottom(self, p: impl Into<Length>) -> Self

Set the bottom edge padding only.

Source

pub fn padding_left(self, p: impl Into<Length>) -> Self

Set the left edge padding only.

Source

pub fn opacity(self, alpha: f32) -> Self

Set opacity for the entire container and its contents (0.0 = transparent, 1.0 = opaque).

Source

pub fn max_width(self, w: f32) -> Self

Cap the container’s outer width in logical px. When the parent offers a wider rect, the container reports its preferred width as min( offered, w ) so it does not stretch to fill.

Source

pub fn preferred_size(&self, max_width: f32, canvas: &Canvas) -> (f32, f32)

Return the preferred (width, height) accounting for padding.

Trait Implementations§

Source§

impl<Msg: Clone> From<Container<Msg>> for Element<Msg>

Source§

fn from(c: Container<Msg>) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more