winrt_xaml/lib.rs
1//! # WinRT-XAML
2//!
3//! A Rust library for creating UIs using WinRT and XAML.
4//!
5//! This library provides a safe, idiomatic Rust interface to Windows Runtime (WinRT)
6//! XAML APIs, enabling the creation of modern Windows applications with XAML-based UIs.
7//!
8//! ## Features
9//!
10//! - **Application Management**: Easy application lifecycle management
11//! - **Window Management**: Create and manage windows with XAML content
12//! - **XAML Controls**: Rich set of UI controls (Button, TextBlock, TextBox, etc.)
13//! - **Layout Panels**: Flexible layout system (StackPanel, Grid, Canvas)
14//! - **Event Handling**: Type-safe event subscription and handling
15//! - **Data Binding**: Reactive data binding support
16//! - **XAML Parsing**: Runtime and compile-time XAML parsing
17//! - **Compile-Time XAML**: `xaml!` macro for zero-cost abstractions
18//! - **Styling**: Resource dictionaries and style management
19//!
20//! ## Example
21//!
22//! ```rust,no_run
23//! use winrt_xaml::prelude::*;
24//!
25//! fn main() -> Result<()> {
26//! let app = Application::new()?;
27//!
28//! let window = Window::new()?
29//! .title("My XAML App")
30//! .size(800, 600);
31//!
32//! let button = Button::new()
33//! .content("Click Me!")
34//! .on_click(|_| {
35//! println!("Button clicked!");
36//! });
37//!
38//! window.set_content(button)?;
39//! app.run()
40//! }
41//! ```
42//!
43//! ## XAML Islands
44//!
45//! For desktop (Win32) applications, this library uses XAML Islands to host
46//! XAML content within traditional windows. Enable the `xaml-islands` feature
47//! (enabled by default) to use this functionality.
48
49#![cfg(windows)]
50#![warn(missing_docs)]
51#![warn(rust_2018_idioms)]
52
53#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
54pub mod winrt;
55pub mod xaml_native;
56
57#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
58pub mod xaml_islands;
59#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
60pub mod app;
61#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
62pub mod controls;
63#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
64pub mod error;
65#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
66pub mod events;
67#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
68pub mod layout;
69#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
70pub mod media;
71#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
72pub mod resources;
73#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
74pub mod window;
75
76/// Reactive state management and data binding.
77#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
78pub mod reactive;
79
80// Re-export windows crate for advanced usage
81#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
82pub use windows;
83
84/// Prelude module for convenient imports
85#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
86pub mod prelude {
87 pub use crate::app::Application;
88 pub use crate::controls::*;
89 pub use crate::error::{Error, Result};
90 pub use crate::events::*;
91 pub use crate::layout::{self, *};
92 pub use crate::media::*;
93 pub use crate::resources::*;
94 pub use crate::window::Window;
95
96 // Re-export WinRT XAML types
97 #[cfg(feature = "xaml-islands")]
98 pub use crate::xaml_native::{
99 ImageStretch, ListViewSelectionMode, ScrollBarVisibility, ScrollMode, XamlButton,
100 XamlCheckBox, XamlComboBox, XamlGrid, XamlImage, XamlListView, XamlManager,
101 XamlProgressBar, XamlRadioButton, XamlScrollViewer, XamlSlider, XamlSource,
102 XamlStackPanel, XamlTextBlock, XamlTextBox, XamlUIElement,
103 };
104
105 // Re-export reactive types
106 #[cfg(any(feature = "xaml-islands", feature = "uwp"))]
107 pub use crate::reactive::{Property, ObservableCollection, Computed, CollectionChange};
108}
109
110/// Re-export of the Result type with our Error
111#[cfg(any(feature = "xaml-islands", feature = "uwp"))]
112pub type Result<T> = std::result::Result<T, error::Error>;
113
114// Re-export the compile-time XAML macro
115/// Compile-time XAML parsing macro.
116///
117/// Parses XAML at compile time and generates Rust code to create WinRT controls.
118///
119/// # Example
120///
121/// ```rust,ignore
122/// use winrt_xaml::xaml;
123///
124/// let button = xaml! {
125/// r#"<Button Content="Click Me"
126/// Width="200"
127/// Height="50"
128/// Background="#FF0078D4"
129/// Foreground="#FFFFFFFF"
130/// CornerRadius="8" />"#
131/// };
132/// ```
133pub use winrt_xaml_macros::xaml;