pub struct Container { /* private fields */ }Expand description
Flex box with optional rounded, bordered, shadowed background.
§Example
use dfui::widgets::{Styled, column, container, row, spacer, text};
use dfui::{Color, Element, Shadow};
fn chip(label: String, color: u32) -> Element {
container(text(label).color(Color::WHITE))
.bg(Color::hex(color))
.radius(10.0)
.padding_xy(12.0, 8.0)
.into()
}
fn view() -> Element {
column([
row([
chip("left".into(), 0x3b6fe0),
spacer().grow(1.0).into(),
chip("right".into(), 0x8a5ce2),
])
.into(),
row((1..=9).map(|i| chip(format!("wrap {i}"), 0x4cae6e)))
.wrap()
.gap(8.0)
.into(),
container(text("Border and shadow"))
.bg(Color::WHITE)
.radius(14.0)
.border(1.0, Color::hex(0xdfe1e8))
.shadow(Shadow {
color: Color::BLACK.alpha(0.15),
offset: (0.0, 4.0),
blur: 12.0,
})
.padding(20.0)
.into(),
])
.gap(16.0)
.padding(16.0)
.into()
}
fn main() {
dfui::run(view);
}Implementations§
Trait Implementations§
Source§impl Styled for Container
impl Styled for Container
Source§fn style_mut(&mut self) -> &mut Style
fn style_mut(&mut self) -> &mut Style
The taffy style the modifiers write; also an escape hatch for the rest.
Source§fn padding(self, p: f32) -> Self
fn padding(self, p: f32) -> Self
Space between the box’s edges and its children on all sides, logical px.
Source§fn padding_xy(self, x: f32, y: f32) -> Self
fn padding_xy(self, x: f32, y: f32) -> Self
Padding of
x left and right and y top and bottom, logical px.Source§fn grow(self, g: f32) -> Self
fn grow(self, g: f32) -> Self
Share of the parent’s spare main-axis space to take; 0 by default.
The content still sets the minimum, so see
fill around a scroll().Source§fn shrink(self, s: f32) -> Self
fn shrink(self, s: f32) -> Self
How much to give up when the parent is too small; 1 by default, 0 keeps the size.
Source§fn min_width(self, w: f32) -> Self
fn min_width(self, w: f32) -> Self
Lower bound on the width, logical px;
min_width(0.0) lets a flex child shrink below its content.Source§fn min_height(self, h: f32) -> Self
fn min_height(self, h: f32) -> Self
Lower bound on the height, logical px;
min_height(0.0) lets a flex child shrink below its content.Source§fn max_height(self, h: f32) -> Self
fn max_height(self, h: f32) -> Self
Upper bound on the height, logical px, e.g. a
scroll() that grows with its content up to a point.Source§fn fill(self) -> Self
fn fill(self) -> Self
Takes the space left along the parent’s main axis, and no more: unlike
grow(1.0), the content’s size doesn’t push the parent. Use it on
every flex box between the window and a scroll(). In a row, siblings
that all fill get equal widths, whatever their content.Source§fn fill_width(self) -> Self
fn fill_width(self) -> Self
As wide as the parent’s content box, whatever the flex direction.
Source§fn align(self, a: AlignItems) -> Self
fn align(self, a: AlignItems) -> Self
Places children on the cross axis: across a row, along a column.
Source§fn justify(self, j: JustifyContent) -> Self
fn justify(self, j: JustifyContent) -> Self
Distributes children and spare space along the main axis.
Source§impl Widget for Container
impl Widget for Container
fn style(&self) -> Style
fn children(&self) -> &[Element]
fn paint(&self, cx: &mut PaintCx<'_>)
Source§fn expand(&self, _cx: &mut BuildCx<'_>)
fn expand(&self, _cx: &mut BuildCx<'_>)
Runs before
children with this node’s id, state slot and providers;
lets a widget build its subtree from framework-owned state.Source§fn layer(&self) -> Option<Layer>
fn layer(&self) -> Option<Layer>
Takes this subtree out of the layout flow: it covers
Layer’s box,
isn’t clipped by ancestors, paints above and gets input before the
rest of the tree.Source§fn focus(&self) -> Option<Focus>
fn focus(&self) -> Option<Focus>
Lets Tab move keyboard focus here. The focused widget gets keys first
and handles Enter, Space or arrows when
EventCx::focused.Source§fn measure(
&self,
_known: Size<Option<f32>>,
_available: Size<AvailableSpace>,
_text: &Text,
) -> Size<f32>
fn measure( &self, _known: Size<Option<f32>>, _available: Size<AvailableSpace>, _text: &Text, ) -> Size<f32>
Intrinsic size of a leaf (children-less) widget.
Source§fn measure_key(&self) -> u64
fn measure_key(&self) -> u64
Hash of everything
measure reads besides its arguments. Layout is
kept across rebuilds and a leaf is only re-measured when this changes,
so widgets whose size depends on their data must override it.Auto Trait Implementations§
impl !RefUnwindSafe for Container
impl !Send for Container
impl !Sync for Container
impl !UnwindSafe for Container
impl Forget for Container
impl Freeze for Container
impl Move 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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.Source§fn as_any(&self) -> &(dyn Any + 'static)
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.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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.