winrt-xaml 1.0.0

A Rust library for creating modern Windows UIs using WinRT and XAML with reactive data binding
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<nav class="navbar">
  <div class="container">
    <div class="nav-brand">
      <h1>🦀 WinRT-XAML</h1>
      <span class="version">v0.1.0</span>
    </div>
    <div class="nav-links">
      <a href="#overview">Overview</a>
      <a href="#quickstart">Quick Start</a>
      <a href="#examples">Examples</a>
      <a href="#api">API</a>
      <a href="https://github.com/pegasusheavy/winrt-xaml" target="_blank">GitHub</a>
    </div>
  </div>
</nav>

<main class="main-content">
  <!-- Hero Section -->
  <section id="overview" class="hero">
    <div class="container">
      <h1 class="hero-title">Build Modern Windows Apps in Rust</h1>
      <p class="hero-subtitle">
        WinRT-XAML brings native Windows Runtime XAML controls to Rust through XAML Islands.
        Create beautiful, production-ready Windows applications with Fluent Design styling,
        event handling, scrolling, and 15 styled examples to get started.
      </p>
      <div class="hero-buttons">
        <a href="#quickstart" class="btn btn-primary">Get Started</a>
        <a href="#examples" class="btn btn-secondary">View 15 Examples</a>
      </div>
      <div class="features-grid">
        <div class="feature">
          <div class="feature-icon">🎨</div>
          <h3>Modern Styling</h3>
          <p>Fluent Design with dark themes, colors, and rounded corners</p>
        </div>
        <div class="feature">
          <div class="feature-icon">🎯</div>
          <h3>Event Handling</h3>
          <p>Click events with Rust closures and callbacks</p>
        </div>
        <div class="feature">
          <div class="feature-icon">📜</div>
          <h3>Scrolling Support</h3>
          <p>ScrollViewer for content that exceeds window bounds</p>
        </div>
        <div class="feature">
          <div class="feature-icon">🔒</div>
          <h3>Memory Safe</h3>
          <p>RAII-based COM lifetime management, zero leaks</p>
        </div>
        <div class="feature">
          <div class="feature-icon"></div>
          <h3>High Performance</h3>
          <p>Minimal FFI overhead (~5-10ns per call)</p>
        </div>
        <div class="feature">
          <div class="feature-icon">📚</div>
          <h3>Well Documented</h3>
          <p>Extensive docs: Architecture, Build System, Status</p>
        </div>
      </div>
    </div>
  </section>

  <!-- Quick Start Section -->
  <section id="quickstart" class="section">
    <div class="container">
      <h2>Quick Start</h2>

      <div class="step">
        <h3>1. Add to Your Cargo.toml</h3>
        <pre class="code-block"><code>[dependencies]
winrt-xaml = "0.1.0"
windows = {{ '{' }}version = "0.58", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging"]{{ '}' }}</code></pre>
      </div>

      <div class="step">
        <h3>2. Build the C++ Helper (One-time)</h3>
        <pre class="code-block"><code>cd xaml_islands_helper
./build.bat</code></pre>
      </div>

      <div class="step">
        <h3>3. Create Your First WinRT App</h3>
        <pre class="code-block"><code>use winrt_xaml::xaml_native::*;
use windows::Win32::System::Com::{{'{'}CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED{'}'}}

;

fn main() -> Result<()> {{'{'}
    // Initialize COM
    unsafe {{'{'} CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok(); {'}'}

    // Initialize XAML
    let _manager = XamlManager::new()?;

    // Create host window
    let host_hwnd = create_host_window()?;

    // Create XAML source and attach to window
    let mut xaml_source = XamlSource::new()?;
    let island_hwnd = xaml_source.attach_to_window(host_hwnd)?;

    // Create a button
    let button = XamlButton::new()?;
    button.set_content("Hello WinRT!")?;
    button.set_size(200.0, 50.0)?;

    // Display it
    xaml_source.set_content_element(&button.as_uielement())?;

    // Show and run
    unsafe {{'{'} ShowWindow(island_hwnd, SW_SHOW); {'}'}
    run_message_loop()?;

    unsafe {{'{'} CoUninitialize(); {'}'}
    Ok(())
{'}'}
</code></pre>
      </div>
    </div>
  </section>

  <!-- Available Controls -->
  <section id="controls" class="section alt-bg">
    <div class="container">
      <h2>Available WinRT Controls</h2>
      <div class="controls-grid">
        <div class="control-card">
          <h3>XamlButton</h3>
          <p>Interactive button with click events and styling</p>
          <code>button.on_click(|| {...})?</code>
        </div>
        <div class="control-card">
          <h3>XamlTextBlock</h3>
          <p>Text display with fonts, colors, and weights</p>
          <code>textblock.set_font_weight(700)?</code>
        </div>
        <div class="control-card">
          <h3>XamlTextBox</h3>
          <p>Text input/output with placeholders</p>
          <code>textbox.get_text()?</code>
        </div>
        <div class="control-card">
          <h3>XamlStackPanel</h3>
          <p>Vertical/horizontal layout with spacing</p>
          <code>panel.set_spacing(20.0)?</code>
        </div>
        <div class="control-card">
          <h3>XamlGrid</h3>
          <p>Grid layout for complex UIs</p>
          <code>grid.add_child(&element)?</code>
        </div>
        <div class="control-card">
          <h3>XamlScrollViewer</h3>
          <p>Scrollable content container</p>
          <code>scroll.set_content(&panel)?</code>
        </div>
      </div>

      <h3 style="margin-top: 2rem;">Styling Features</h3>
      <div class="controls-grid">
        <div class="control-card">
          <h3>Colors</h3>
          <p>ARGB format: background, foreground</p>
          <code>set_background(0xFF0078D4)?</code>
        </div>
        <div class="control-card">
          <h3>Padding & Margin</h3>
          <p>Control spacing and layout</p>
          <code>set_padding(20, 15, 20, 15)?</code>
        </div>
        <div class="control-card">
          <h3>Corner Radius</h3>
          <p>Rounded corners for modern look</p>
          <code>set_corner_radius(10.0)?</code>
        </div>
      </div>
    </div>
  </section>

  <!-- Examples -->
  <section id="examples" class="section">
    <div class="container">
      <h2>15 Production-Ready Examples</h2>
      <p style="text-align: center; margin-bottom: 2rem; opacity: 0.9;">
        All examples feature modern dark themes with Fluent Design styling
      </p>

      <h3>Featured Examples</h3>
      <div class="examples-grid">
        <div class="example-card highlight">
          <h3>📜 Scrollable List</h3>
          <p>30 items with ScrollViewer, color-coded badges</p>
          <code>cargo run --example scrollable_list</code>
        </div>
        <div class="example-card highlight">
          <h3>🧮 Functional Calculator</h3>
          <p>Full calculator with event handling</p>
          <code>cargo run --example winrt_calculator_functional</code>
        </div>
        <div class="example-card highlight">
          <h3>💬 Chat Interface</h3>
          <p>Chat UI with text input/output</p>
          <code>cargo run --example chat_interface</code>
        </div>
      </div>

      <h3>Application Examples</h3>
      <div class="examples-grid">
        <div class="example-card">
          <h3>✅ Todo App</h3>
          <p>Add/clear todo items</p>
          <code>cargo run --example todo_app</code>
        </div>
        <div class="example-card">
          <h3>📝 Form Demo</h3>
          <p>Multi-field registration form</p>
          <code>cargo run --example form_demo</code>
        </div>
        <div class="example-card">
          <h3>⚙️ Settings Panel</h3>
          <p>Settings with theme toggles</p>
          <code>cargo run --example settings_panel</code>
        </div>
        <div class="example-card">
          <h3>🎨 Color Picker</h3>
          <p>Interactive color selection</p>
          <code>cargo run --example color_picker</code>
        </div>
      </div>

      <h3>Basic Examples</h3>
      <div class="examples-grid">
        <div class="example-card">
          <h3>🔢 Counter</h3>
          <p>4 operations: inc/dec/reset/double</p>
          <code>cargo run --example counter</code>
        </div>
        <div class="example-card">
          <h3>⚡ Simple Counter</h3>
          <p>Minimal counter example</p>
          <code>cargo run --example counter_simple</code>
        </div>
        <div class="example-card">
          <h3>🎨 WinRT Controls</h3>
          <p>Showcase all controls</p>
          <code>cargo run --example winrt_controls_demo</code>
        </div>
        <div class="example-card">
          <h3>🔄 WinRT Counter</h3>
          <p>Interactive counter</p>
          <code>cargo run --example winrt_counter</code>
        </div>
        <div class="example-card">
          <h3>🪟 Basic Window</h3>
          <p>Click counter demo</p>
          <code>cargo run --example basic_window</code>
        </div>
        <div class="example-card">
          <h3>👋 Simple Window</h3>
          <p>Hello World with styling</p>
          <code>cargo run --example simple_window</code>
        </div>
      </div>
    </div>
  </section>

  <!-- API Documentation -->
  <section id="api" class="section alt-bg">
    <div class="container">
      <h2>API Reference</h2>

      <div class="api-section">
        <h3>XamlManager</h3>
        <p>Manages the Windows XAML framework. Must be kept alive for the duration of XAML usage.</p>
        <pre class="code-block"><code>let _manager = XamlManager::new()?;</code></pre>
      </div>

      <div class="api-section">
        <h3>XamlSource</h3>
        <p>DesktopWindowXamlSource for hosting XAML content in Win32 windows.</p>
        <pre class="code-block"><code>let mut source = XamlSource::new()?;
let island_hwnd = source.attach_to_window(host_hwnd)?;
source.set_content_element(&element.as_uielement())?;</code></pre>
      </div>

      <div class="api-section">
        <h3>XamlButton</h3>
        <p>Interactive button with click events, styling, and modern design.</p>
        <pre class="code-block"><code>let button = XamlButton::new()?;
button.set_content("Click Me")?;
button.set_size(200.0, 50.0)?;
button.set_background(0xFF0078D4)?;  // Microsoft blue
button.set_corner_radius(10.0)?;
button.on_click(|| {{'{'}
    println!("Button clicked!");
{'}'}})?;</code></pre>
      </div>

      <div class="api-section">
        <h3>XamlTextBox</h3>
        <p>Text input/output control with text retrieval.</p>
        <pre class="code-block"><code>let textbox = XamlTextBox::new()?;
textbox.set_placeholder("Enter text...")?;
textbox.set_size(300.0, 56.0)?;
textbox.set_background(0xFF2D2D2D)?;

// Get text from textbox
let text = textbox.get_text()?;</code></pre>
      </div>

      <div class="api-section">
        <h3>XamlStackPanel</h3>
        <p>Layout container with vertical/horizontal orientation and spacing.</p>
        <pre class="code-block"><code>let panel = XamlStackPanel::new()?;
panel.set_vertical(true)?;
panel.set_spacing(20.0)?;
panel.set_background(0xFF1A1A1A)?;
panel.set_padding(30.0, 30.0, 30.0, 30.0)?;
panel.add_child(&button.as_uielement())?;</code></pre>
      </div>

      <div class="api-section">
        <h3>XamlScrollViewer</h3>
        <p>Scrollable container for content that exceeds window bounds.</p>
        <pre class="code-block"><code>let scroll = XamlScrollViewer::new()?;
scroll.set_vertical_scroll_mode(ScrollMode::Enabled)?;
scroll.set_vertical_scrollbar_visibility(ScrollBarVisibility::Auto)?;
scroll.set_content(&panel.as_uielement())?;</code></pre>
      </div>
    </div>
  </section>

  <!-- Architecture -->
  <section id="architecture" class="section">
    <div class="container">
      <h2>Architecture</h2>
      <div class="architecture-diagram">
        <div class="arch-layer">
          <strong>Rust Application</strong>
          <p>Your Code</p>
        </div>
        <div class="arch-arrow"></div>
        <div class="arch-layer">
          <strong>winrt_xaml::xaml_native</strong>
          <p>Safe Rust API</p>
        </div>
        <div class="arch-arrow">↓ FFI</div>
        <div class="arch-layer">
          <strong>xaml_islands_helper.dll</strong>
          <p>C++ Bridge</p>
        </div>
        <div class="arch-arrow">↓ C++/WinRT</div>
        <div class="arch-layer">
          <strong>Windows.UI.Xaml.*</strong>
          <p>WinRT APIs</p>
        </div>
        <div class="arch-arrow"></div>
        <div class="arch-layer highlight">
          <strong>Fluent Design Rendering</strong>
          <p>Native Windows</p>
        </div>
      </div>
    </div>
  </section>

  <!-- Footer -->
  <footer class="footer">
    <div class="container">
      <div class="footer-content">
        <div class="footer-section">
          <h4>Documentation</h4>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/README.md">README</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/BUILD_SYSTEM.md">Build System</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/ARCHITECTURE.md">Architecture</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/PROJECT_STATUS.md">Project Status</a>
        </div>
        <div class="footer-section">
          <h4>Resources</h4>
          <a href="https://github.com/pegasusheavy/winrt-xaml">GitHub</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/tree/develop/examples">15 Examples</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/TESTING.md">Testing</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/CHANGELOG.md">Changelog</a>
        </div>
        <div class="footer-section">
          <h4>Community</h4>
          <a href="https://github.com/pegasusheavy/winrt-xaml/issues">Issues</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/pulls">Pull Requests</a>
          <a href="https://github.com/pegasusheavy/winrt-xaml/blob/develop/CONTRIBUTING.md">Contributing</a>
          <a href="https://www.patreon.com/c/PegasusHeavyIndustries">Support on Patreon</a>
        </div>
        <div class="footer-section">
          <h4>License</h4>
          <p>Licensed under MIT or Apache-2.0</p>
          <p>© 2025 Pegasus Heavy Industries</p>
          <p style="margin-top: 1rem; opacity: 0.8;">
            ✅ Production-Ready v0.1.0
          </p>
        </div>
      </div>
    </div>
  </footer>
</main>

<router-outlet />