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