Skip to main content

swiftui_native/views/
plain.rs

1//! Modifiers with several plain arguments.
2
3use super::*;
4use crate::abi;
5use crate::resolve;
6//
7// Generated from each function's demangled signature: integer-shaped arguments
8// fill x0 upward and floats fill d0 upward, in declaration order, with strings
9// taking two words and a `LocalizedStringKey` or a `Text` taking four.
10
11swift_statics! {
12    /// `SwiftUI.AccessibilityChildBehavior`.
13    ///
14    /// The cases are the type's documented static properties.
15    pub enum AccessibilityChildBehavior {
16        Combine = c"$s7SwiftUI26AccessibilityChildBehaviorV7combineACvgZ",
17        Contain = c"$s7SwiftUI26AccessibilityChildBehaviorV7containACvgZ",
18        Ignore = c"$s7SwiftUI26AccessibilityChildBehaviorV6ignoreACvgZ",
19    }
20}
21
22swift_statics! {
23    /// `SwiftUI.ContentMarginPlacement`.
24    ///
25    /// The cases are the type's documented static properties.
26    pub enum ContentMarginPlacement {
27        Automatic = c"$s7SwiftUI22ContentMarginPlacementV9automaticACvgZ",
28        ScrollIndicators = c"$s7SwiftUI22ContentMarginPlacementV16scrollIndicatorsACvgZ",
29    }
30}
31
32swift_statics! {
33    /// `SwiftUI.HandGestureShortcut`.
34    ///
35    /// The cases are the type's documented static properties.
36    pub enum HandGestureShortcut {
37        PrimaryAction = c"$s7SwiftUI19HandGestureShortcutV13primaryActionACvgZ",
38    }
39}
40
41swift_statics! {
42    /// `SwiftUI.RedactionReasons`.
43    ///
44    /// The cases are the type's documented static properties.
45    pub enum RedactionReasons {
46        Invalidated = c"$s7SwiftUI16RedactionReasonsV11invalidatedACvgZ",
47        Placeholder = c"$s7SwiftUI16RedactionReasonsV11placeholderACvgZ",
48        Privacy = c"$s7SwiftUI16RedactionReasonsV7privacyACvgZ",
49    }
50}
51
52swift_statics! {
53    /// `SwiftUI.TabBarMinimizeBehavior`.
54    ///
55    /// The cases are the type's documented static properties.
56    pub enum TabBarMinimizeBehavior {
57        Automatic = c"$s7SwiftUI22TabBarMinimizeBehaviorV9automaticACvgZ",
58    }
59}
60
61swift_statics! {
62    /// `SwiftUI.ToolbarRole`.
63    ///
64    /// The cases are the type's documented static properties.
65    pub enum ToolbarRole {
66        Automatic = c"$s7SwiftUI11ToolbarRoleV9automaticACvgZ",
67        Editor = c"$s7SwiftUI11ToolbarRoleV6editorACvgZ",
68    }
69}
70
71swift_statics! {
72    /// `SwiftUI.TypesettingLanguage`.
73    ///
74    /// The cases are the type's documented static properties.
75    pub enum TypesettingLanguage {
76        Automatic = c"$s7SwiftUI19TypesettingLanguageV9automaticACvgZ",
77    }
78}
79
80/// Apply `.accessibilityElement(_:)`.
81pub fn accessibility_element(view: &ViewHandle, v0: AccessibilityChildBehavior) -> ViewHandle {
82    unsafe {
83        let m0 = abi::metadata0(resolve::accessibility_child_behavior_ma());
84        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
85        opaque_modifier(
86            resolve::accessibility_element_fn(),
87            resolve::accessibility_element_oret(),
88            view,
89            &[a0.as_mut_ptr() as u64],
90            [0.0, 0.0, 0.0, 0.0],
91        )
92    }
93}
94
95/// Apply `.accessibilityShowsLargeContentViewer(_:)`.
96pub fn accessibility_shows_large_content_viewer(view: &ViewHandle, ) -> ViewHandle {
97    unsafe {
98        // no argument needs building
99        opaque_modifier(
100            resolve::accessibility_shows_large_content_viewer_fn(),
101            resolve::accessibility_shows_large_content_viewer_oret(),
102            view,
103            &[],
104            [0.0, 0.0, 0.0, 0.0],
105        )
106    }
107}
108
109/// Apply `.assistiveAccessNavigationIcon(_:)`.
110pub fn assistive_access_navigation_icon(view: &ViewHandle, v0: &str) -> ViewHandle {
111    unsafe {
112        let s0 = abi::swift_string(v0);
113        opaque_modifier(
114            resolve::assistive_access_navigation_icon_fn(),
115            resolve::assistive_access_navigation_icon_oret(),
116            view,
117            &[u64::from_le_bytes(s0[..8].try_into().expect("lo")), u64::from_le_bytes(s0[8..].try_into().expect("hi"))],
118            [0.0, 0.0, 0.0, 0.0],
119        )
120    }
121}
122
123/// Apply `.contentMargins(_:)`.
124pub fn content_margins(view: &ViewHandle, v0: f64, v1: ContentMarginPlacement) -> ViewHandle {
125    unsafe {
126        let m1 = abi::metadata0(resolve::content_margin_placement_ma());
127        let mut a1 = static_getter_indirect(v1.resolved(), m1, 0);
128        opaque_modifier(
129            resolve::content_margins_fn(),
130            resolve::content_margins_oret(),
131            view,
132            &[a1.as_mut_ptr() as u64],
133            [v0, 0.0, 0.0, 0.0],
134        )
135    }
136}
137
138/// Apply `.handGestureShortcut(_:)`.
139pub fn hand_gesture_shortcut(view: &ViewHandle, v0: HandGestureShortcut, v1: bool) -> ViewHandle {
140    unsafe {
141        let m0 = abi::metadata0(resolve::hand_gesture_shortcut_ma());
142        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
143        opaque_modifier(
144            resolve::hand_gesture_shortcut_fn(),
145            resolve::hand_gesture_shortcut_oret(),
146            view,
147            &[a0.as_mut_ptr() as u64, u64::from(v1)],
148            [0.0, 0.0, 0.0, 0.0],
149        )
150    }
151}
152
153/// Apply `.position(_:)`.
154pub fn position(view: &ViewHandle, v0: f64, v1: f64) -> ViewHandle {
155    unsafe {
156        // no argument needs building
157        opaque_modifier(
158            resolve::position_fn(),
159            resolve::position_oret(),
160            view,
161            &[],
162            [v0, v1, 0.0, 0.0],
163        )
164    }
165}
166
167
168/// Apply `.redacted(_:)`.
169pub fn redacted(view: &ViewHandle, v0: RedactionReasons) -> ViewHandle {
170    unsafe {
171        let m0 = abi::metadata0(resolve::redaction_reasons_ma());
172        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
173        opaque_modifier(
174            resolve::redacted_fn(),
175            resolve::redacted_oret(),
176            view,
177            &[a0.as_mut_ptr() as u64],
178            [0.0, 0.0, 0.0, 0.0],
179        )
180    }
181}
182
183/// Apply `.scrollIndicatorsFlash(_:)`.
184pub fn scroll_indicators_flash(view: &ViewHandle, v0: bool) -> ViewHandle {
185    unsafe {
186        // no argument needs building
187        opaque_modifier(
188            resolve::scroll_indicators_flash_fn(),
189            resolve::scroll_indicators_flash_oret(),
190            view,
191            &[u64::from(v0)],
192            [0.0, 0.0, 0.0, 0.0],
193        )
194    }
195}
196
197/// Apply `.scrollTargetLayout(_:)`.
198pub fn scroll_target_layout(view: &ViewHandle, v0: bool) -> ViewHandle {
199    unsafe {
200        // no argument needs building
201        opaque_modifier(
202            resolve::scroll_target_layout_fn(),
203            resolve::scroll_target_layout_oret(),
204            view,
205            &[u64::from(v0)],
206            [0.0, 0.0, 0.0, 0.0],
207        )
208    }
209}
210
211/// Apply `.tabBarMinimizeBehavior(_:)`.
212pub fn tab_bar_minimize_behavior(view: &ViewHandle, v0: TabBarMinimizeBehavior) -> ViewHandle {
213    unsafe {
214        let m0 = abi::metadata0(resolve::tab_bar_minimize_behavior_ma());
215        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
216        opaque_modifier(
217            resolve::tab_bar_minimize_behavior_fn(),
218            resolve::tab_bar_minimize_behavior_oret(),
219            view,
220            &[a0.as_mut_ptr() as u64],
221            [0.0, 0.0, 0.0, 0.0],
222        )
223    }
224}
225
226/// Apply `.toolbarRole(_:)`.
227pub fn toolbar_role(view: &ViewHandle, v0: ToolbarRole) -> ViewHandle {
228    unsafe {
229        let m0 = abi::metadata0(resolve::toolbar_role_ma());
230        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
231        opaque_modifier(
232            resolve::toolbar_role_fn(),
233            resolve::toolbar_role_oret(),
234            view,
235            &[a0.as_mut_ptr() as u64],
236            [0.0, 0.0, 0.0, 0.0],
237        )
238    }
239}
240
241/// Apply `.typesettingLanguage(_:)`.
242pub fn typesetting_language(view: &ViewHandle, v0: TypesettingLanguage, v1: bool) -> ViewHandle {
243    unsafe {
244        let m0 = abi::metadata0(resolve::typesetting_language_ma());
245        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
246        opaque_modifier(
247            resolve::typesetting_language_fn(),
248            resolve::typesetting_language_oret(),
249            view,
250            &[a0.as_mut_ptr() as u64, u64::from(v1)],
251            [0.0, 0.0, 0.0, 0.0],
252        )
253    }
254}
255
256/// Apply `.inspectorColumnWidth(min:ideal:max:)` — a width the user can drag
257/// within.
258///
259/// `min` and `max` are `Optional<CGFloat>` and `ideal` is not, which is exactly
260/// how they travel: an `Optional<CGFloat>` is lowered as payload-then-tag in
261/// *integer* registers — the same shape [`frame_optional`](super::frame_optional)
262/// passes — while the bare `ideal` goes in `d0` with the floats. Leaving a bound
263/// out is not the same as pinning it to zero: `None` means the column is
264/// unconstrained in that direction.
265pub fn inspector_column_width_range(
266    view: &ViewHandle,
267    min: Option<f64>,
268    ideal: f64,
269    max: Option<f64>,
270) -> ViewHandle {
271    unsafe {
272        opaque_modifier(
273            resolve::inspector_column_width_range_fn(),
274            resolve::inspector_column_width_range_oret(),
275            view,
276            &[
277                min.map_or(0, f64::to_bits),
278                u64::from(min.is_none()),
279                max.map_or(0, f64::to_bits),
280                u64::from(max.is_none()),
281            ],
282            [ideal, 0.0, 0.0, 0.0],
283        )
284    }
285}
286
287// `.scrollInputBehavior(_:for:)` is deliberately not bound.
288//
289// The modifier itself is available from macOS 15, and its two arguments are
290// reachable — but every `ScrollInputKind` is `@available(macOS, unavailable)`
291// *and* `@available(iOS, unavailable)`: `handGestureShortcut` is watchOS-only
292// and `look` visionOS-only. So on both platforms this crate targets there is no
293// value to pass, and calling it reaches the trap stub with "Unavailable code
294// reached".
295//
296// It was bound, and the binding worked — which is the point of the note. A
297// modifier that compiles and traps on every platform anyone here can run is
298// worse than an absent one, because it looks available.
299//
300// Worth recording separately: the two argument types measure one byte and
301// three, and neither is `@frozen`. Size says nothing about how a value
302// travels; resilient types go by address, and reading these into registers on
303// the strength of their size was a SIGBUS.