Boxed
pub fn boxed<F>(args: BoxedArgs, scope_config: F)
where
F: FnOnce(&mut BoxedScope<'_>),The boxed component is used to stack a set of child components.
Unlike other container components, boxed requires you to use methods like BoxedScope::child to add children, instead of calling child component functions directly inside the closure.
WARNING
If you attempt to call child component functions directly inside the closure, the boxed component will panic at runtime.
Below is a correct example of using boxed:
use tessera_ui_basic_components::{
boxed::{boxed, BoxedArgs},
surface::{surface, SurfaceArgs},
text::text,
};
boxed(
BoxedArgs {
alignment: Alignment::Center,
..Default::default()
},
|scope| {
scope.child(|| {
surface(
SurfaceArgs {
width: DimensionValue::from(Dp(300.0)),
height: DimensionValue::from(Dp(300.0)),
..Default::default()
},
None,
|| {},
)
});
scope.child(|| text("test"));
},
);Arguments
args: BoxedArgsThis argument configures the
boxedcomponent's style, including width, height, alignment, etc. You can useBoxedArgsBuilderto construct it.scope_config: FA closure used to add child components into the
boxedcomponent. The closure receives a&mut BoxedScopeand you should use itschild,child_weighted, etc. methods to add children.
Preview
