1use super::*;
2
3#[widget($crate::Row { ($height:expr) => { height = $height; }; })]
15pub struct Row(WidgetBase);
16impl Row {
17 widget_impl! {
18 pub max_height(max: impl IntoVar<Length>);
20
21 pub min_height(max: impl IntoVar<Length>);
23
24 pub height(max: impl IntoVar<Length>);
26 }
27
28 fn widget_intrinsic(&mut self) {
29 widget_set! {
30 self;
31 access_role = AccessRole::Row;
32 }
33 }
34}
35
36static_id! {
37 pub(super) static ref INDEX_ID: StateId<(usize, usize)>;
39}
40
41#[property(CONTEXT, widget_impl(Row))]
47pub fn is_even(child: impl IntoUiNode, state: impl IntoVar<bool>) -> UiNode {
48 widget_state_is_state(child, |w| w.get(*INDEX_ID).copied().unwrap_or((0, 0)).0 % 2 == 0, |_| false, state)
49}
50
51#[property(CONTEXT, widget_impl(Row))]
57pub fn is_odd(child: impl IntoUiNode, state: impl IntoVar<bool>) -> UiNode {
58 widget_state_is_state(child, |w| w.get(*INDEX_ID).copied().unwrap_or((0, 0)).0 % 2 != 0, |_| false, state)
59}
60
61#[property(CONTEXT, widget_impl(Row))]
63pub fn is_first(child: impl IntoUiNode, state: impl IntoVar<bool>) -> UiNode {
64 widget_state_is_state(
65 child,
66 |w| {
67 let (i, l) = w.get(*INDEX_ID).copied().unwrap_or((0, 0));
68 i == 0 && l > 0
69 },
70 |_| false,
71 state,
72 )
73}
74
75#[property(CONTEXT, widget_impl(Row))]
77pub fn is_last(child: impl IntoUiNode, state: impl IntoVar<bool>) -> UiNode {
78 widget_state_is_state(
79 child,
80 |w| {
81 let (i, l) = w.get(*INDEX_ID).copied().unwrap_or((0, 0));
82 i < l && i == l - 1
83 },
84 |_| false,
85 state,
86 )
87}
88
89#[property(CONTEXT, widget_impl(Row))]
93pub fn get_index(child: impl IntoUiNode, state: impl IntoVar<usize>) -> UiNode {
94 widget_state_get_state(
95 child,
96 |w, &i| {
97 let a = w.get(*INDEX_ID).copied().unwrap_or((0, 0)).0;
98 if a != i { Some(a) } else { None }
99 },
100 |_, &i| if i != 0 { Some(0) } else { None },
101 state,
102 )
103}
104
105#[property(CONTEXT, widget_impl(Row))]
107pub fn get_index_len(child: impl IntoUiNode, state: impl IntoVar<(usize, usize)>) -> UiNode {
108 widget_state_get_state(
109 child,
110 |w, &i| {
111 let a = w.get(*INDEX_ID).copied().unwrap_or((0, 0));
112 if a != i { Some(a) } else { None }
113 },
114 |_, &i| if i != (0, 0) { Some((0, 0)) } else { None },
115 state,
116 )
117}
118
119#[property(CONTEXT, widget_impl(Row))]
121pub fn get_rev_index(child: impl IntoUiNode, state: impl IntoVar<usize>) -> UiNode {
122 widget_state_get_state(
123 child,
124 |w, &i| {
125 let a = w.get(*INDEX_ID).copied().unwrap_or((0, 0));
126 let a = a.1 - a.0;
127 if a != i { Some(a) } else { None }
128 },
129 |_, &i| if i != 0 { Some(0) } else { None },
130 state,
131 )
132}