Skip to main content

swiftui_native/views/
sets.rs

1//! Modifiers taking option sets and further plain arguments.
2
3use super::*;
4use crate::abi;
5use crate::resolve;
6//
7// An option set is a wrapper around an integer, so unlike the resilient enums
8// above it travels in a register: its static members are read through their
9// getters and the value passed straight through. `SafeAreaRegions` is the same
10// shape without the name.
11
12swift_statics! {
13    /// `SwiftUI.Axis.Set`, an option set.
14    ///
15    /// The cases are its static members; each is read through its own getter and
16    /// travels in a register, since an option set is a wrapper around an integer.
17    pub enum AxisSet {
18        Horizontal = c"$s7SwiftUI4AxisO3SetV10horizontalAEvgZ",
19        Vertical = c"$s7SwiftUI4AxisO3SetV8verticalAEvgZ",
20    }
21}
22
23swift_statics! {
24    /// `SwiftUI.Edge.Set`, an option set.
25    ///
26    /// The cases are its static members; each is read through its own getter and
27    /// travels in a register, since an option set is a wrapper around an integer.
28    pub enum EdgeSet {
29        All = c"$s7SwiftUI4EdgeO3SetV3allAEvgZ",
30        Bottom = c"$s7SwiftUI4EdgeO3SetV6bottomAEvgZ",
31        Horizontal = c"$s7SwiftUI4EdgeO3SetV10horizontalAEvgZ",
32        Leading = c"$s7SwiftUI4EdgeO3SetV7leadingAEvgZ",
33        Top = c"$s7SwiftUI4EdgeO3SetV3topAEvgZ",
34        Trailing = c"$s7SwiftUI4EdgeO3SetV8trailingAEvgZ",
35        Vertical = c"$s7SwiftUI4EdgeO3SetV8verticalAEvgZ",
36    }
37}
38
39swift_statics! {
40    /// `SwiftUI.VerticalEdge.Set`, an option set.
41    ///
42    /// The cases are its static members; each is read through its own getter and
43    /// travels in a register, since an option set is a wrapper around an integer.
44    pub enum VerticalEdgeSet {
45        All = c"$s7SwiftUI12VerticalEdgeO3SetV3allAEvgZ",
46        Bottom = c"$s7SwiftUI12VerticalEdgeO3SetV6bottomAEvgZ",
47        Top = c"$s7SwiftUI12VerticalEdgeO3SetV3topAEvgZ",
48    }
49}
50
51swift_statics! {
52    /// `SwiftUI.SafeAreaRegions`.
53    ///
54    /// The cases are the type's documented static properties.
55    pub enum SafeAreaRegions {
56        All = c"$s7SwiftUI15SafeAreaRegionsV3allACvgZ",
57        Container = c"$s7SwiftUI15SafeAreaRegionsV9containerACvgZ",
58        Keyboard = c"$s7SwiftUI15SafeAreaRegionsV8keyboardACvgZ",
59    }
60}
61
62swift_statics! {
63    /// `SwiftUI.ScenePadding`.
64    ///
65    /// The cases are the type's documented static properties.
66    pub enum ScenePadding {
67        Minimum = c"$s7SwiftUI12ScenePaddingV7minimumACvgZ",
68    }
69}
70
71swift_statics! {
72    /// `SwiftUI.ScrollBounceBehavior`.
73    ///
74    /// The cases are the type's documented static properties.
75    pub enum ScrollBounceBehavior {
76        Always = c"$s7SwiftUI20ScrollBounceBehaviorV6alwaysACvgZ",
77        Automatic = c"$s7SwiftUI20ScrollBounceBehaviorV9automaticACvgZ",
78        BasedOnSize = c"$s7SwiftUI20ScrollBounceBehaviorV11basedOnSizeACvgZ",
79    }
80}
81
82swift_statics! {
83    /// `SwiftUI.ScrollIndicatorVisibility`.
84    ///
85    /// The cases are the type's documented static properties.
86    pub enum ScrollIndicatorVisibility {
87        Automatic = c"$s7SwiftUI25ScrollIndicatorVisibilityV9automaticACvgZ",
88        Hidden = c"$s7SwiftUI25ScrollIndicatorVisibilityV6hiddenACvgZ",
89        Never = c"$s7SwiftUI25ScrollIndicatorVisibilityV5neverACvgZ",
90        Visible = c"$s7SwiftUI25ScrollIndicatorVisibilityV7visibleACvgZ",
91    }
92}
93
94/// Apply `.containerCornerOffset(_:)`.
95pub fn container_corner_offset(view: &ViewHandle, v0: EdgeSet, v1: bool) -> ViewHandle {
96    unsafe {
97        let m0 = abi::metadata0(resolve::edge_set_ma());
98        let (r0, _) = static_getter(v0.resolved(), m0);
99        opaque_modifier(
100            resolve::container_corner_offset_fn(),
101            resolve::container_corner_offset_oret(),
102            view,
103            &[r0, u64::from(v1)],
104            [0.0, 0.0, 0.0, 0.0],
105        )
106    }
107}
108
109/// Apply `.edgesIgnoringSafeArea(_:)`.
110pub fn edges_ignoring_safe_area(view: &ViewHandle, v0: EdgeSet) -> ViewHandle {
111    unsafe {
112        let m0 = abi::metadata0(resolve::edge_set_ma());
113        let (r0, _) = static_getter(v0.resolved(), m0);
114        opaque_modifier(
115            resolve::edges_ignoring_safe_area_fn(),
116            resolve::edges_ignoring_safe_area_oret(),
117            view,
118            &[r0],
119            [0.0, 0.0, 0.0, 0.0],
120        )
121    }
122}
123
124/// Apply `.gridCellUnsizedAxes(_:)`.
125pub fn grid_cell_unsized_axes(view: &ViewHandle, v0: AxisSet) -> ViewHandle {
126    unsafe {
127        let m0 = abi::metadata0(resolve::axis_set_ma());
128        let (r0, _) = static_getter(v0.resolved(), m0);
129        opaque_modifier(
130            resolve::grid_cell_unsized_axes_fn(),
131            resolve::grid_cell_unsized_axes_oret(),
132            view,
133            &[r0],
134            [0.0, 0.0, 0.0, 0.0],
135        )
136    }
137}
138
139/// Apply `.ignoresSafeArea(_:)`.
140pub fn ignores_safe_area(view: &ViewHandle, v0: SafeAreaRegions, v1: EdgeSet) -> ViewHandle {
141    unsafe {
142        let m0 = abi::metadata0(resolve::safe_area_regions_ma());
143        let (r0, _) = static_getter(v0.resolved(), m0);
144        let m1 = abi::metadata0(resolve::edge_set_ma());
145        let (r1, _) = static_getter(v1.resolved(), m1);
146        opaque_modifier(
147            resolve::ignores_safe_area_fn(),
148            resolve::ignores_safe_area_oret(),
149            view,
150            &[r0, r1],
151            [0.0, 0.0, 0.0, 0.0],
152        )
153    }
154}
155
156/// Apply `.listRowSeparator(_:)`.
157pub fn list_row_separator(view: &ViewHandle, v0: Visibility, v1: VerticalEdgeSet) -> ViewHandle {
158    unsafe {
159        // `Visibility` in a register, not by address. Both of these store the
160        // value inside a closure, so a dump of the result shows `(Function)`
161        // and nothing else — which is why passing the address here went
162        // unnoticed while the same mistake in `toolbarVisibility`, whose
163        // modifier stores the case, showed up at once as `Visibility.()`.
164        let m0 = abi::metadata0(resolve::visibility_ma());
165        let a0 = abi::enum_argument(m0, v0 as u32);
166        let m1 = abi::metadata0(resolve::vertical_edge_set_ma());
167        let (r1, _) = static_getter(v1.resolved(), m1);
168        opaque_modifier(
169            resolve::list_row_separator_fn(),
170            resolve::list_row_separator_oret(),
171            view,
172            &[a0, r1],
173            [0.0, 0.0, 0.0, 0.0],
174        )
175    }
176}
177
178/// Apply `.listSectionSeparator(_:)`.
179pub fn list_section_separator(view: &ViewHandle, v0: Visibility, v1: VerticalEdgeSet) -> ViewHandle {
180    unsafe {
181        // `Visibility` in a register, not by address. Both of these store the
182        // value inside a closure, so a dump of the result shows `(Function)`
183        // and nothing else — which is why passing the address here went
184        // unnoticed while the same mistake in `toolbarVisibility`, whose
185        // modifier stores the case, showed up at once as `Visibility.()`.
186        let m0 = abi::metadata0(resolve::visibility_ma());
187        let a0 = abi::enum_argument(m0, v0 as u32);
188        let m1 = abi::metadata0(resolve::vertical_edge_set_ma());
189        let (r1, _) = static_getter(v1.resolved(), m1);
190        opaque_modifier(
191            resolve::list_section_separator_fn(),
192            resolve::list_section_separator_oret(),
193            view,
194            &[a0, r1],
195            [0.0, 0.0, 0.0, 0.0],
196        )
197    }
198}
199
200/// Apply `.scenePadding(_:)`.
201pub fn scene_padding(view: &ViewHandle, v0: ScenePadding, v1: EdgeSet) -> ViewHandle {
202    unsafe {
203        let m0 = abi::metadata0(resolve::scene_padding_ma());
204        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
205        let m1 = abi::metadata0(resolve::edge_set_ma());
206        let (r1, _) = static_getter(v1.resolved(), m1);
207        opaque_modifier(
208            resolve::scene_padding_fn(),
209            resolve::scene_padding_oret(),
210            view,
211            &[a0.as_mut_ptr() as u64, r1],
212            [0.0, 0.0, 0.0, 0.0],
213        )
214    }
215}
216
217/// Apply `.scrollBounceBehavior(_:)`.
218pub fn scroll_bounce_behavior(view: &ViewHandle, v0: ScrollBounceBehavior, v1: AxisSet) -> ViewHandle {
219    unsafe {
220        let m0 = abi::metadata0(resolve::scroll_bounce_behavior_ma());
221        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
222        let m1 = abi::metadata0(resolve::axis_set_ma());
223        let (r1, _) = static_getter(v1.resolved(), m1);
224        opaque_modifier(
225            resolve::scroll_bounce_behavior_fn(),
226            resolve::scroll_bounce_behavior_oret(),
227            view,
228            &[a0.as_mut_ptr() as u64, r1],
229            [0.0, 0.0, 0.0, 0.0],
230        )
231    }
232}
233
234/// Apply `.scrollEdgeEffectHidden(_:)`.
235pub fn scroll_edge_effect_hidden(view: &ViewHandle, v0: bool, v1: EdgeSet) -> ViewHandle {
236    unsafe {
237        let m1 = abi::metadata0(resolve::edge_set_ma());
238        let (r1, _) = static_getter(v1.resolved(), m1);
239        opaque_modifier(
240            resolve::scroll_edge_effect_hidden_fn(),
241            resolve::scroll_edge_effect_hidden_oret(),
242            view,
243            &[u64::from(v0), r1],
244            [0.0, 0.0, 0.0, 0.0],
245        )
246    }
247}
248
249/// Apply `.scrollIndicators(_:)`.
250pub fn scroll_indicators(view: &ViewHandle, v0: ScrollIndicatorVisibility, v1: AxisSet) -> ViewHandle {
251    unsafe {
252        let m0 = abi::metadata0(resolve::scroll_indicator_visibility_ma());
253        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
254        let m1 = abi::metadata0(resolve::axis_set_ma());
255        let (r1, _) = static_getter(v1.resolved(), m1);
256        opaque_modifier(
257            resolve::scroll_indicators_fn(),
258            resolve::scroll_indicators_oret(),
259            view,
260            &[a0.as_mut_ptr() as u64, r1],
261            [0.0, 0.0, 0.0, 0.0],
262        )
263    }
264}