cranpose_ui/widgets/
row.rs1use cranpose_core::NodeId;
4use cranpose_ui_layout::{LinearArrangement, VerticalAlignment};
5
6use super::layout::compose_layout;
7use crate::{composable, layout::policies::FlexMeasurePolicy, modifier::Modifier};
8
9#[derive(Clone, Copy, Debug, PartialEq)]
11pub struct RowSpec {
12 pub horizontal_arrangement: LinearArrangement,
14 pub vertical_alignment: VerticalAlignment,
16}
17
18impl RowSpec {
19 pub fn new() -> Self {
21 Self::default()
22 }
23
24 pub fn horizontal_arrangement(mut self, arrangement: LinearArrangement) -> Self {
26 self.horizontal_arrangement = arrangement;
27 self
28 }
29
30 pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self {
32 self.vertical_alignment = alignment;
33 self
34 }
35}
36
37impl Default for RowSpec {
38 fn default() -> Self {
39 Self {
40 horizontal_arrangement: LinearArrangement::Start,
41 vertical_alignment: VerticalAlignment::Top,
42 }
43 }
44}
45
46#[composable]
67pub fn Row<F>(modifier: Modifier, spec: RowSpec, content: F) -> NodeId
68where
69 F: FnMut() + 'static,
70{
71 let density = crate::density::density();
72 let mut policy = FlexMeasurePolicy::row(
73 spec.horizontal_arrangement,
74 spec.vertical_alignment,
75 density.density(),
76 );
77 policy.layout_direction = crate::layout_direction();
78 compose_layout(modifier, policy, density, content)
79}