Boxed
pub fn boxed<F>(args: BoxedArgs, scope_config: F)
where
F: FnOnce(&mut BoxedScope),The boxed component is a container that overlays its children, aligning them relative to each other.
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.
Arguments
args: BoxedArgsThis argument configures the
boxedcomponent's style, including width, height, and default alignment. 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 itschildandchild_with_alignmentmethods to add children.
Examples
use tessera_ui_basic_components::boxed::{boxed, BoxedArgs};
use tessera_ui_basic_components::text::{text, TextArgsBuilder};
use tessera_ui_basic_components::alignment::Alignment;
boxed(BoxedArgs::default(), |scope| {
// Add a child that will be in the background (rendered first).
scope.child(|| {
text(TextArgsBuilder::default().text("Background".to_string()).build().unwrap());
});
// Add another child aligned to the center, which will appear on top.
scope.child_with_alignment(Alignment::Center, || {
text(TextArgsBuilder::default().text("Foreground".to_string()).build().unwrap());
});
});Preview
