slint-ui-system 0.5.0

Neon Design System — Slint UI components for Rust desktop apps. 35+ components, dark/light theme, neon accents.
//! Generic bridge helpers for consumer apps.
//!
//! ## Why this is mostly documentation
//!
//! Slint generates one `Theme` (and `AnimationPresets`) global per
//! crate that calls [`slint::include_modules!`]. We can't ship a
//! pre-baked `Theme` type from this crate to a consumer because
//! their generated type is local to *their* crate. The bridge is
//! therefore a thin layer that documents the integration pattern
//! plus the canonical macro for one-shot setup.
//!
//! ## The integration pattern
//!
//! Inside your binary that consumes Neon UI:
//!
//! ```ignore
//! use slint::ComponentHandle;
//! slint::include_modules!();   // generates `MainWindow`, `Theme`, …
//!
//! fn main() -> Result<(), slint::PlatformError> {
//!     let win = MainWindow::new()?;
//!     win.global::<Theme>().set_dark_mode(true);
//!     win.run()
//! }
//! ```
//!
//! ## The convenience macro
//!
//! For zero-boilerplate setup, [`neon_ui_setup!`](crate::neon_ui_setup)
//! constructs the window + applies the initial dark-mode flag:
//!
//! ```ignore
//! use slint_ui_system::neon_ui_setup;
//! slint::include_modules!();
//!
//! fn main() -> Result<(), slint::PlatformError> {
//!     let win = neon_ui_setup!(MainWindow, Theme, dark = true);
//!     win.run()
//! }
//! ```
//!
//! ## Where the actual helpers live
//!
//! * Theme switching helper: [`crate::theme::set_dark_mode`].
//! * Hex color parsing / formatting: [`crate::color`].
//! * Slint-include path constant: [`crate::SLINT_LIBRARY_PATH`].

/// One-shot setup: instantiate a window + apply the dark/light flag.
///
/// `$window` is the generated window type, `$theme` the generated
/// `Theme` global type — both come from `slint::include_modules!()`
/// in the caller's scope. The `dark = true|false` arg drives the
/// initial theme.
///
/// Panics if window construction fails. For graceful error
/// handling, call the underlying methods by hand — this macro is
/// sugar, not a load-bearing API.
#[macro_export]
macro_rules! neon_ui_setup {
    ($window:ty, $theme:ty, dark = $dark:expr) => {{
        let __win = <$window>::new().expect("Failed to construct Slint window");
        ::slint::ComponentHandle::global::<$theme>(&__win).set_dark_mode($dark);
        __win
    }};
}