swiftui-native 0.0.1

SwiftUI from pure Rust — no Swift bridge, no shim, only swift-runtime calls
Documentation
//! Modifiers taking option sets and further plain arguments.

use super::*;
use crate::abi;
use crate::resolve;
//
// An option set is a wrapper around an integer, so unlike the resilient enums
// above it travels in a register: its static members are read through their
// getters and the value passed straight through. `SafeAreaRegions` is the same
// shape without the name.

swift_statics! {
    /// `SwiftUI.Axis.Set`, an option set.
    ///
    /// The cases are its static members; each is read through its own getter and
    /// travels in a register, since an option set is a wrapper around an integer.
    pub enum AxisSet {
        Horizontal = c"$s7SwiftUI4AxisO3SetV10horizontalAEvgZ",
        Vertical = c"$s7SwiftUI4AxisO3SetV8verticalAEvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.Edge.Set`, an option set.
    ///
    /// The cases are its static members; each is read through its own getter and
    /// travels in a register, since an option set is a wrapper around an integer.
    pub enum EdgeSet {
        All = c"$s7SwiftUI4EdgeO3SetV3allAEvgZ",
        Bottom = c"$s7SwiftUI4EdgeO3SetV6bottomAEvgZ",
        Horizontal = c"$s7SwiftUI4EdgeO3SetV10horizontalAEvgZ",
        Leading = c"$s7SwiftUI4EdgeO3SetV7leadingAEvgZ",
        Top = c"$s7SwiftUI4EdgeO3SetV3topAEvgZ",
        Trailing = c"$s7SwiftUI4EdgeO3SetV8trailingAEvgZ",
        Vertical = c"$s7SwiftUI4EdgeO3SetV8verticalAEvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.VerticalEdge.Set`, an option set.
    ///
    /// The cases are its static members; each is read through its own getter and
    /// travels in a register, since an option set is a wrapper around an integer.
    pub enum VerticalEdgeSet {
        All = c"$s7SwiftUI12VerticalEdgeO3SetV3allAEvgZ",
        Bottom = c"$s7SwiftUI12VerticalEdgeO3SetV6bottomAEvgZ",
        Top = c"$s7SwiftUI12VerticalEdgeO3SetV3topAEvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.SafeAreaRegions`.
    ///
    /// The cases are the type's documented static properties.
    pub enum SafeAreaRegions {
        All = c"$s7SwiftUI15SafeAreaRegionsV3allACvgZ",
        Container = c"$s7SwiftUI15SafeAreaRegionsV9containerACvgZ",
        Keyboard = c"$s7SwiftUI15SafeAreaRegionsV8keyboardACvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.ScenePadding`.
    ///
    /// The cases are the type's documented static properties.
    pub enum ScenePadding {
        Minimum = c"$s7SwiftUI12ScenePaddingV7minimumACvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.ScrollBounceBehavior`.
    ///
    /// The cases are the type's documented static properties.
    pub enum ScrollBounceBehavior {
        Always = c"$s7SwiftUI20ScrollBounceBehaviorV6alwaysACvgZ",
        Automatic = c"$s7SwiftUI20ScrollBounceBehaviorV9automaticACvgZ",
        BasedOnSize = c"$s7SwiftUI20ScrollBounceBehaviorV11basedOnSizeACvgZ",
    }
}

swift_statics! {
    /// `SwiftUI.ScrollIndicatorVisibility`.
    ///
    /// The cases are the type's documented static properties.
    pub enum ScrollIndicatorVisibility {
        Automatic = c"$s7SwiftUI25ScrollIndicatorVisibilityV9automaticACvgZ",
        Hidden = c"$s7SwiftUI25ScrollIndicatorVisibilityV6hiddenACvgZ",
        Never = c"$s7SwiftUI25ScrollIndicatorVisibilityV5neverACvgZ",
        Visible = c"$s7SwiftUI25ScrollIndicatorVisibilityV7visibleACvgZ",
    }
}

/// Apply `.containerCornerOffset(_:)`.
pub fn container_corner_offset(view: &ViewHandle, v0: EdgeSet, v1: bool) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::edge_set_ma());
        let (r0, _) = static_getter(v0.resolved(), m0);
        opaque_modifier(
            resolve::container_corner_offset_fn(),
            resolve::container_corner_offset_oret(),
            view,
            &[r0, u64::from(v1)],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.edgesIgnoringSafeArea(_:)`.
pub fn edges_ignoring_safe_area(view: &ViewHandle, v0: EdgeSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::edge_set_ma());
        let (r0, _) = static_getter(v0.resolved(), m0);
        opaque_modifier(
            resolve::edges_ignoring_safe_area_fn(),
            resolve::edges_ignoring_safe_area_oret(),
            view,
            &[r0],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.gridCellUnsizedAxes(_:)`.
pub fn grid_cell_unsized_axes(view: &ViewHandle, v0: AxisSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::axis_set_ma());
        let (r0, _) = static_getter(v0.resolved(), m0);
        opaque_modifier(
            resolve::grid_cell_unsized_axes_fn(),
            resolve::grid_cell_unsized_axes_oret(),
            view,
            &[r0],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.ignoresSafeArea(_:)`.
pub fn ignores_safe_area(view: &ViewHandle, v0: SafeAreaRegions, v1: EdgeSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::safe_area_regions_ma());
        let (r0, _) = static_getter(v0.resolved(), m0);
        let m1 = abi::metadata0(resolve::edge_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::ignores_safe_area_fn(),
            resolve::ignores_safe_area_oret(),
            view,
            &[r0, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.listRowSeparator(_:)`.
pub fn list_row_separator(view: &ViewHandle, v0: Visibility, v1: VerticalEdgeSet) -> ViewHandle {
    unsafe {
        // `Visibility` in a register, not by address. Both of these store the
        // value inside a closure, so a dump of the result shows `(Function)`
        // and nothing else — which is why passing the address here went
        // unnoticed while the same mistake in `toolbarVisibility`, whose
        // modifier stores the case, showed up at once as `Visibility.()`.
        let m0 = abi::metadata0(resolve::visibility_ma());
        let a0 = abi::enum_argument(m0, v0 as u32);
        let m1 = abi::metadata0(resolve::vertical_edge_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::list_row_separator_fn(),
            resolve::list_row_separator_oret(),
            view,
            &[a0, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.listSectionSeparator(_:)`.
pub fn list_section_separator(view: &ViewHandle, v0: Visibility, v1: VerticalEdgeSet) -> ViewHandle {
    unsafe {
        // `Visibility` in a register, not by address. Both of these store the
        // value inside a closure, so a dump of the result shows `(Function)`
        // and nothing else — which is why passing the address here went
        // unnoticed while the same mistake in `toolbarVisibility`, whose
        // modifier stores the case, showed up at once as `Visibility.()`.
        let m0 = abi::metadata0(resolve::visibility_ma());
        let a0 = abi::enum_argument(m0, v0 as u32);
        let m1 = abi::metadata0(resolve::vertical_edge_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::list_section_separator_fn(),
            resolve::list_section_separator_oret(),
            view,
            &[a0, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.scenePadding(_:)`.
pub fn scene_padding(view: &ViewHandle, v0: ScenePadding, v1: EdgeSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::scene_padding_ma());
        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
        let m1 = abi::metadata0(resolve::edge_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::scene_padding_fn(),
            resolve::scene_padding_oret(),
            view,
            &[a0.as_mut_ptr() as u64, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.scrollBounceBehavior(_:)`.
pub fn scroll_bounce_behavior(view: &ViewHandle, v0: ScrollBounceBehavior, v1: AxisSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::scroll_bounce_behavior_ma());
        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
        let m1 = abi::metadata0(resolve::axis_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::scroll_bounce_behavior_fn(),
            resolve::scroll_bounce_behavior_oret(),
            view,
            &[a0.as_mut_ptr() as u64, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.scrollEdgeEffectHidden(_:)`.
pub fn scroll_edge_effect_hidden(view: &ViewHandle, v0: bool, v1: EdgeSet) -> ViewHandle {
    unsafe {
        let m1 = abi::metadata0(resolve::edge_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::scroll_edge_effect_hidden_fn(),
            resolve::scroll_edge_effect_hidden_oret(),
            view,
            &[u64::from(v0), r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}

/// Apply `.scrollIndicators(_:)`.
pub fn scroll_indicators(view: &ViewHandle, v0: ScrollIndicatorVisibility, v1: AxisSet) -> ViewHandle {
    unsafe {
        let m0 = abi::metadata0(resolve::scroll_indicator_visibility_ma());
        let mut a0 = static_getter_indirect(v0.resolved(), m0, 0);
        let m1 = abi::metadata0(resolve::axis_set_ma());
        let (r1, _) = static_getter(v1.resolved(), m1);
        opaque_modifier(
            resolve::scroll_indicators_fn(),
            resolve::scroll_indicators_oret(),
            view,
            &[a0.as_mut_ptr() as u64, r1],
            [0.0, 0.0, 0.0, 0.0],
        )
    }
}