swiftui-native 0.0.1

SwiftUI from pure Rust — no Swift bridge, no shim, only swift-runtime calls
Documentation
//! Everything you need for a native SwiftUI app.
//!
//! ```ignore
//! use swiftui_native::prelude::*;
//!
//! fn main() {
//!     run(|| {
//!         vstack(&[
//!             text("Hello").padding(20.0),
//!             color(Color::BLUE).frame(100.0, 50.0),
//!             spacer(),
//!         ]).bg(Color::DARK)
//!     });
//! }
//! ```

// View type + chainable modifiers
pub use crate::view::{Image, IntoView, Shape, Transition, View};

// Free functions (DSL)
pub use crate::view::{
    button, capsule, capsule_shape, circle, circle_shape, color, disclosure_group, divider, ellipse, empty, for_each, form,
    conditional, for_each_items, geometry_reader, grid, grid_row, group_box, hstack, navigation_link, navigation_link_labelled, image, label, lazy_hstack, lazy_vstack, list, list_identified, list_identified_str, navigation_split_view3, navigation_stack,
    ellipse_shape, progress, rectangle, rectangle_shape, rounded_rectangle,
    rounded_rectangle_shape, rounded_rectangle_shape_styled, securefield, slider, spacer, stepper, tab_view, text,
    textfield, timeline, toggle, vstack, zstack,
};

// The constructors for what this crate synthesises: a `Shape` written in Rust,
// an AppKit view, a scroll reader. Free functions because they *start* a view;
// the synthesised things that modify one — a custom `ViewModifier`, a
// `Transition`, an environment key — are chainable methods like any other.
pub use crate::view::{content_unavailable, environment_reader, scroll_reader, shape};

// What `environment_reader` hands its closure.
pub use crate::views::EnvironmentValues;
#[cfg(target_os = "macos")]
pub use crate::view::ns_view;

// The same controls, bound to Rust state instead of a constant. These are the
// ones that can be *used*: the plain forms above build `Binding.constant`,
// which SwiftUI treats as read-only, so a `slider` cannot be dragged and a
// `picker` cannot be chosen from.
pub use crate::view::{
    color_picker, color_picker_bound, date_picker, date_picker_bound, date_picker_range, picker, picker_bound,
    async_image, canvas, equatable_text, named_image, progress_indeterminate,
    // The configured stack forms and the bare `TupleView`, which had been
    // reachable only as `view::vstack_spacing(…)` — not where anyone looks.
    hstack_spacing, tuple_view, vstack_spacing, zstack_aligned,
    securefield_bound, slider_bound, slider_step_bound, stepper_actions, stepper_bound, system_image,
    tab, tab_view_tabs, table, text_verbatim, textfield_axis, textfield_bound, toggle_bound, toggle_labelled, toggle_sources,
};

// Containers and controls that had no chainable constructor.
pub use crate::view::{
    button_labelled, control_group, gauge, group, laid_out, layout, link, menu,
    navigation_split_view,
    outline_group, section, section_expanded, section_footer, section_titled,
    section_titled_footer,
    share_link, text_editor, view_that_fits,
    vstack_aligned, vstack_aligned_spacing,
    hstack_aligned, hstack_aligned_spacing, grid_row_aligned,
    lazy_hstack_aligned, lazy_vstack_aligned,
};
#[cfg(not(target_os = "macos"))]
pub use crate::view::edit_button;

// Enums used by the chainable modifiers
pub use crate::views::{
    Alignment, AxisSet, BoundState, VerticalAlignment,
    GestureData, GestureMask, GestureValue, ButtonStyle, ColorScheme, ControlSize, Design, EdgeSet,
    Font as SwiftFont, HashableValue, HorizontalAlignment, ImageScale, InsettableShape,
    AccessibilityChildBehavior, AccessibilityTrait, ActionCategory, ActionKind,
    BadgeProminence, CustomContentImportance, DirectTouchOption, DragDropPreviewsFormation,
    AlternatingRowBackgroundBehavior, ContainerBackgroundPlacement, DragOperations,
    ButtonRepeatBehavior, ButtonSizing, DropOperation, Edge, EventModifier, FileOutcome,
    LabeledPairRole, LayoutDirectionBehavior, MaterialActiveAppearance,
    MenuActionDismissBehavior, MenuButtonStyle, PaletteSelectionEffect, PointerStyle,
    PresentationAdaptation,
    PresentationBackgroundInteraction, PresentationContentInteraction,
    SearchPresentationToolbarBehavior, SearchSuggestionsPlacementSet, SearchToolbarBehavior,
    HandGestureShortcut, ShapeStyle, SpringLoadingBehavior, TabBarMinimizeBehavior,
    TextInputFormattingControlPlacementSet, TextSelectionAffinity,
    TransactionRef, ButtonBorderShape, CharacterSetKind, ContentMarginPlacement,
    ContentTransition, ContentType, ControlGroupStyle, DynamicTypeSize, MenuOrder, Prominence,
    TextScale,
    DatePickerStyle, DisclosureGroupStyle, FontWidth, FormStyle, GaugeStyle, GeometryProperties,
    GroupBoxStyle, HeadingLevel, LabeledContentStyle, PickerStyle,
    TableStyle, TextEditorStyle, TextSelectability, ToggleStyle,
    HorizontalEdge, KeyPressPhases, KeyPressResult, KeyboardShortcut, LabelStyle, LineHeightKind,
    LinePattern, ListStyle, MaterialKind, MenuStyle, PresentationDetent, RedactionReasons,
    Axis, DefaultFocusPriority, EdgeSetMember, SafeAreaRegions, ScrollAnchorRole,
    ScrollBounceBehavior, ScrollDismissesKeyboardMode, ScrollEdgeEffectStyle,
    ScrollIndicatorVisibility, ScrollTargetBehavior, ScrollTransitionConfiguration,
    SearchFieldPlacement, SensoryFeedback, SubmitLabel, SubmitTrigger, SymbolRenderingMode,
    SymbolVariants, SystemColor, TextAlign, TextCase, TextContentKind, TextFieldStyle, TextStyle,
    // `TextContentType` is accessibility's (how VoiceOver should read this);
    // `TextContentKind` above is text input's (what a field holds, so the
    // system can offer a saved password). Different modifiers, near-identical
    // names — both spelled out rather than one of them left unexported.
    TextContentType,
    ToolbarItemPlacement, ToolbarPlacement, ToolbarRole, ToolbarTitleDisplayMode, TruncationMode,
    VerticalEdge,
    VerticalEdgeSet, Visibility, Weight,
};

// Gestures as values: build one, give it handlers, attach it. `drag` and the
// rest are constructors, not modifiers, which is why they come from `views`
// rather than from the chainable set — `.gesture(…)` is the chainable.
pub use crate::views::{drag, long_press, magnify, rotate, tap};

// Color type + constants
pub use crate::color::Color;

// Swift's generic modifiers dispatch on the argument's type. The trait is only
// needed in scope to add a style of one's own — `.foreground_style(…)` itself
// is an inherent method and always available.
pub use crate::view::style::{
    Accessibility, AppStorageStore, BackgroundStyleArg, ClipShape, ClipShapeArg, Draggable, EnvironmentArg,
    NavigationViewStyle, ScrollTarget, ShapeStyleArg,
};

// App lifecycle
pub use crate::app::run;

// Window (for manual hosting without App lifecycle)
// Only where it exists: on iOS the UIKit entry point is behind `uikit-entry`.
#[cfg(any(target_os = "macos", feature = "uikit-entry"))]
pub use crate::views::show_window;

// Runtime-synthesised `@State`. See [`crate::state`] for the one-at-a-time caveat.
pub use crate::state::StatefulView;

// The other way state reaches a view. `BoundState` above is `@State` — one
// value, written from Rust and read by the view. This is `@Observable`: one
// object with as many named, typed properties as it needs, each tracked
// separately, so a body that read one of them is not rebuilt when another
// changes.
//
// The module rather than its contents: a bare `model` or `Model` in scope from a
// glob import says nothing about what it is. One import, both namespaces — this
// brings in the `observable!` macro too, which declares a model's properties.
pub use crate::observable;

// Keys defined *here* rather than in SwiftUI — an environment key, a container
// value key, a focused value key — each generic over what it holds. `KeyValue`
// is the set of types a synthesised key can carry; it is needed in scope only to
// name one in a signature.
pub use crate::views::{
    container_key, env_key, focus_key, CustomContainerKey, CustomEnvKey, FocusKey, KeyValue,
};

// Offscreen capture and the run-loop pump, for animated output.
pub use crate::render::{pump, Animation, Rendered};

// The declarative forms. `#[macro_export]` puts these at the crate root, so
// without this they are the one part of the DSL that `use prelude::*` does not
// bring in.
pub use crate::{
    control_group, foreach, form, grid, grid_row, group, hstack, image, lazy_hstack, lazy_vstack,
    ltext,
    laid_out, list, menu, picker, picker_bound, section, tab_view, text, view_if, vstack,
    zstack,
};

// The declaration macros: keys and observable models. These declare items rather
// than build views, so they are used at module scope and not inside a body.
pub use crate::{container_keys, environment_keys, focused_keys};