cranpose_ui/widgets/
box_widget.rs1use cranpose_core::NodeId;
4use cranpose_ui_layout::Alignment;
5
6use super::layout::Layout;
7use crate::{composable, layout::policies::BoxMeasurePolicy, modifier::Modifier};
8
9#[derive(Clone, Copy, Debug, PartialEq)]
11pub struct BoxSpec {
12 pub content_alignment: Alignment,
13 pub propagate_min_constraints: bool,
14}
15
16impl BoxSpec {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn content_alignment(mut self, alignment: Alignment) -> Self {
22 self.content_alignment = alignment;
23 self
24 }
25
26 pub fn propagate_min_constraints(mut self, propagate: bool) -> Self {
27 self.propagate_min_constraints = propagate;
28 self
29 }
30}
31
32impl Default for BoxSpec {
33 fn default() -> Self {
34 Self {
35 content_alignment: Alignment::TOP_START,
36 propagate_min_constraints: false,
37 }
38 }
39}
40
41#[composable]
66pub fn Box<F>(modifier: Modifier, spec: BoxSpec, content: F) -> NodeId
67where
68 F: FnMut() + 'static,
69{
70 let policy = BoxMeasurePolicy::new(spec.content_alignment, spec.propagate_min_constraints);
71 Layout(modifier, policy, content)
72}