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
use super::Drawable;
use crate::primitives::FlexWrap;
/// Capability for configuring flex container behavior on a node.
pub trait FlexContainer: Drawable {
/// Reverses or restores the current flex direction based on the provided
/// flag.
///
/// # Arguments
/// - `reverse`: Whether the flex direction should be reversed.
///
/// # Returns
/// - [`Self`]
fn reversed(mut self, reverse: bool) -> Self {
self.layout_mut().flex_direction = if reverse {
match self.layout().flex_direction {
taffy::FlexDirection::Row => taffy::FlexDirection::RowReverse,
taffy::FlexDirection::Column => taffy::FlexDirection::ColumnReverse,
other => other,
}
} else {
match self.layout().flex_direction {
taffy::FlexDirection::RowReverse => taffy::FlexDirection::Row,
taffy::FlexDirection::ColumnReverse => taffy::FlexDirection::Column,
other => other,
}
};
self
}
/// Sets how flex items wrap within the container.
///
/// # Arguments
/// - `value`: The [`FlexWrap`] behavior applied to the container.
///
/// # Returns
/// - [`Self`]
fn flex_wrap(mut self, value: FlexWrap) -> Self {
self.layout_mut().flex_wrap = value.into();
self
}
/// Toggles the current flex direction between normal and reversed.
///
/// This is a convenience method that flips the direction without requiring
/// an explicit flag.
///
/// # Returns
/// - [`Self`]
fn reverse(mut self) -> Self {
self.layout_mut().flex_direction = match self.layout().flex_direction {
taffy::FlexDirection::Row => taffy::FlexDirection::RowReverse,
taffy::FlexDirection::RowReverse => taffy::FlexDirection::Row,
taffy::FlexDirection::Column => taffy::FlexDirection::ColumnReverse,
taffy::FlexDirection::ColumnReverse => taffy::FlexDirection::Column,
};
self
}
}