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,
13 pub vertical_alignment: VerticalAlignment,
14}
15
16impl RowSpec {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn horizontal_arrangement(mut self, arrangement: LinearArrangement) -> Self {
22 self.horizontal_arrangement = arrangement;
23 self
24 }
25
26 pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self {
27 self.vertical_alignment = alignment;
28 self
29 }
30}
31
32impl Default for RowSpec {
33 fn default() -> Self {
34 Self {
35 horizontal_arrangement: LinearArrangement::Start,
36 vertical_alignment: VerticalAlignment::Top,
37 }
38 }
39}
40
41#[composable]
62pub fn Row<F>(modifier: Modifier, spec: RowSpec, content: F) -> NodeId
63where
64 F: FnMut() + 'static,
65{
66 let density = crate::density::density();
67 let mut policy = FlexMeasurePolicy::row(
68 spec.horizontal_arrangement,
69 spec.vertical_alignment,
70 density.density(),
71 );
72 policy.layout_direction = crate::layout_direction();
73 compose_layout(modifier, policy, density, content)
74}