https://codewiki.google/github.com/samoylenkodmitry/cranpose
v0.0.40.webm
Cranpose is a declarative UI framework for Rust, inspired by Jetpack Compose. It enables developers to build user interfaces for Desktop (Linux, macOS, Windows), Android, iOS, and Web (WASM) from a single Rust codebase.
To get started, we recommend using the Isolated Demo template found in apps/isolated-demo. This project is pre-configured with the necessary dependencies and build scripts for all supported platforms.
# Clone the repository
git clone https://github.com/samoylenkodmitry/cranpose.git
cd cranpose/apps/isolated-demo
# Run on Desktop (Linux/macOS/Windows)
cargo run --features desktop,renderer-wgpuThe following example demonstrates managing state, handling user input, and rendering a dynamic list.
use cranpose::prelude::*;
#[derive(Clone)]
struct TodoItem {
id: usize,
text: String,
done: bool,
}
#[composable]
fn TodoApp() {
// State management using useState
let items = useState(|| vec![
TodoItem { id: 0, text: "Buy milk".into(), done: false },
TodoItem { id: 1, text: "Walk the dog".into(), done: true },
]);
let input_text = useState(|| String::new());
let next_id = useState(|| 2);
Column(Modifier.fill_max_size().padding(20.0), || {
Text("My Todo List", Modifier.padding(10.0).font_size(24.0));
// Input Row
Row(Modifier.fill_max_width().padding(5.0), || {
BasicTextField(
value = input_text.value(),
on_value_change = move |new_text| input_text.set(new_text),
Modifier.weight(1.0).padding(5.0)
);
Button(
onClick = move || {
if !input_text.value().is_empty() {
let mut list = items.value();
list.push(TodoItem {
id: next_id.value(),
text: input_text.value(),
done: false,
});
items.set(list);
next_id.set(next_id.value() + 1);
input_text.set(String::new());
}
},
|| Text("Add")
);
});
// Dynamic List Rendering
LazyColumn(Modifier.weight(1.0), || {
items(items.value().len(), |i| {
let item = items.value()[i].clone();
Row(
Modifier
.fill_max_width()
.padding(5.0)
.clickable(move || {
// Toggle done status
let mut list = items.value();
if let Some(todo) = list.iter_mut().find(|t| t.id == item.id) {
todo.done = !todo.done;
}
items.set(list);
}),
|| {
Text(if item.done { "[x]" } else { "[ ]" });
Spacer(Modifier.width(10.0));
Text(
item.text,
Modifier.alpha(if item.done { 0.5 } else { 1.0 })
);
}
);
});
});
});
}| Platform | Backend | Status |
|---|---|---|
| Linux x86_64 | Vulkan via wgpu | Supported |
| macOS aarch64 | Metal via wgpu | Supported |
| Windows x86_64 | DX12/Vulkan via wgpu | Supported |
| Android | Vulkan/GLES via wgpu | Supported |
| iOS | Metal via wgpu | Supported |
| Web (WASM) | WebGPU/WebGL2 via wgpu | Supported |
Pre-built binaries for all platforms are available on the Releases page.
The apps/isolated-demo starter project shows the complete cross-platform setup. It depends only on published crates from crates.io.
cd apps/isolated-demo
cargo run --features desktop,renderer-wgpu# Prerequisites: cargo install cargo-ndk
cd apps/isolated-demo/android
./gradlew :app:assembleReleaseOpen apps/isolated-demo/ios/CranposeIsolatedDemo.xcodeproj in Xcode, then build and run on a simulator or device. The Xcode project invokes cargo build via a build phase script.
# Prerequisites: cargo install wasm-pack
cd apps/isolated-demo
./build-web.sh
python3 -m http.server 8080See apps/isolated-demo/README.md for full details.
This project is available under the terms of the Apache License (Version 2.0). See LICENSE-APACHE for the full license text.