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
//! An invisible component for creating empty space in a layout.
//!
//! ## Usage
//!
//! Use to add gaps between components or to create flexible, expanding regions.
use tessera_ui::{
ComputedData, Constraint, LayoutInput, LayoutOutput, LayoutSpec, MeasurementError, Modifier,
tessera,
};
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
struct SpacerLayout;
impl LayoutSpec for SpacerLayout {
fn measure(
&self,
input: &LayoutInput<'_>,
_output: &mut LayoutOutput<'_>,
) -> Result<ComputedData, MeasurementError> {
let constraint = Constraint::new(
input.parent_constraint().width(),
input.parent_constraint().height(),
);
Ok(ComputedData::min_from_constraint(&constraint))
}
}
/// # spacer
///
/// Renders an empty, flexible space to influence layout.
///
/// ## Usage
///
/// Add fixed-size gaps or create flexible space that pushes other components
/// apart.
///
/// ## Parameters
///
/// - `modifier` — configures sizing and layout constraints for this spacer.
///
/// ## Examples
///
/// ```
/// use tessera_components::{
/// row::{RowArgs, row},
/// spacer::spacer,
/// text::{TextArgs, text},
/// };
/// use tessera_ui::Modifier;
///
/// # use tessera_ui::tessera;
/// # #[tessera]
/// # fn component() {
/// row(RowArgs::default(), |scope| {
/// scope.child(|| text(TextArgs::default().text("Left")));
/// // Use weight to let the spacer expand and push the trailing content.
/// scope.child_weighted(|| spacer(Modifier::new()), 1.0);
/// scope.child(|| text(TextArgs::default().text("Right")));
/// });
/// # }
/// # component();
/// ```
#[tessera]
pub fn spacer(modifier: Modifier) {
modifier.run(spacer_inner);
}
#[tessera]
fn spacer_inner() {
layout(SpacerLayout);
}