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
//! Fuchsia Hello World Example
//!
//! A simple Blinc application for Fuchsia OS demonstrating
//! basic UI rendering with touch interactions.
//!
//! # Building
//!
//! ```bash
//! # Add Fuchsia target
//! rustup target add x86_64-unknown-fuchsia
//!
//! # Build for Fuchsia
//! cargo build --example fuchsia_hello --target x86_64-unknown-fuchsia --features fuchsia
//! ```
//!
//! # Running in Fuchsia Emulator
//!
//! See docs/fuchsia/SETUP.md for emulator setup instructions.
#[cfg(target_os = "fuchsia")]
use blinc_app::fuchsia::FuchsiaApp;
#[cfg(target_os = "fuchsia")]
use blinc_app::prelude::*;
#[cfg(target_os = "fuchsia")]
fn main() {
FuchsiaApp::run(|ctx| {
// Counter state
let count = ctx.state("count", 0i32);
// Button press handler
let on_increment = ctx.callback({
let count = count.clone();
move |_| {
count.update(|n| *n + 1);
}
});
let on_decrement = ctx.callback({
let count = count.clone();
move |_| {
count.update(|n| *n - 1);
}
});
// Main UI
div()
.w(ctx.width)
.h(ctx.height)
.bg([0.1, 0.1, 0.15, 1.0])
.flex_col()
.items_center()
.justify_center()
.gap(24.0)
.child(
// Title
text("Hello Fuchsia!")
.size(48.0)
.color([0.9, 0.9, 0.95, 1.0]),
)
.child(
// Counter display
div()
.bg([0.2, 0.2, 0.25, 1.0])
.rounded(16.0)
.px(32.0)
.py(16.0)
.child(
text(format!("Count: {}", count.get()))
.size(32.0)
.color([0.95, 0.95, 1.0, 1.0]),
),
)
.child(
// Button row
div()
.flex_row()
.gap(16.0)
.child(
// Decrement button
div()
.bg([0.8, 0.3, 0.3, 1.0])
.rounded(12.0)
.px(24.0)
.py(12.0)
.on_click(on_decrement)
.child(text("-").size(28.0).color([1.0, 1.0, 1.0, 1.0])),
)
.child(
// Increment button
div()
.bg([0.3, 0.7, 0.4, 1.0])
.rounded(12.0)
.px(24.0)
.py(12.0)
.on_click(on_increment)
.child(text("+").size(28.0).color([1.0, 1.0, 1.0, 1.0])),
),
)
.child(
// Platform info
text("Running on Fuchsia OS")
.size(14.0)
.color([0.5, 0.5, 0.6, 1.0]),
)
})
.expect("Failed to run Fuchsia app");
}
#[cfg(not(target_os = "fuchsia"))]
fn main() {
eprintln!("This example can only run on Fuchsia OS.");
eprintln!("Build with: cargo build --example fuchsia_hello --target x86_64-unknown-fuchsia --features fuchsia");
std::process::exit(1);
}