1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Row widget implementation
#![allow(non_snake_case)]
use cranpose_core::NodeId;
use cranpose_ui_layout::{LinearArrangement, VerticalAlignment};
use super::layout::Layout;
use crate::{composable, layout::policies::FlexMeasurePolicy, modifier::Modifier};
/// Specification for Row layout behavior.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RowSpec {
pub horizontal_arrangement: LinearArrangement,
pub vertical_alignment: VerticalAlignment,
}
impl RowSpec {
pub fn new() -> Self {
Self::default()
}
pub fn horizontal_arrangement(mut self, arrangement: LinearArrangement) -> Self {
self.horizontal_arrangement = arrangement;
self
}
pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self {
self.vertical_alignment = alignment;
self
}
}
impl Default for RowSpec {
fn default() -> Self {
Self {
horizontal_arrangement: LinearArrangement::Start,
vertical_alignment: VerticalAlignment::CenterVertically,
}
}
}
/// A layout composable that places its children in a horizontal sequence.
///
/// # When to use
/// Use `Row` to arrange items side-by-side. For vertical arrangement, use [`Column`](crate::widgets::Column).
///
/// # Arguments
///
/// * `modifier` - Modifiers to apply to the row layout.
/// * `spec` - Configuration for horizontal arrangement and vertical alignment.
/// * `content` - The children composables to layout.
///
/// # Example
///
/// ```rust,ignore
/// Row(
/// Modifier::fill_max_width(),
/// RowSpec::default().horizontal_arrangement(LinearArrangement::SpaceBetween),
/// || {
/// Text("Left", Modifier::empty());
/// Text("Right", Modifier::empty());
/// }
/// );
/// ```
#[composable]
pub fn Row<F>(modifier: Modifier, spec: RowSpec, content: F) -> NodeId
where
F: FnMut() + 'static,
{
let policy = FlexMeasurePolicy::row(spec.horizontal_arrangement, spec.vertical_alignment);
Layout(modifier, policy, content)
}