Crates.io | rui |
lib.rs | rui |
version | 0.6.1 |
source | src |
created_at | 2015-05-03 13:35:07.32745 |
updated_at | 2023-05-31 23:09:10.304613 |
description | Experimental Declarative UI library |
homepage | |
repository | https://github.com/audulus/rui |
max_upload_size | |
id | 2012 |
size | 399,060 |
Experimental Rust UI library, inspired by SwiftUI. Early days, but some stuff already works. rui will be used for a future version of Audulus
rui is immediate mode (there is no retained tree of views), GPU rendered, updates reactively (when your state changes), and has richer layout options than other immediate mode UIs.
obligatory Counter (cargo run --example counter
):
use rui::*;
fn main() {
rui(state(
|| 1,
|count, cx| {
vstack((
cx[count].padding(Auto),
button("increment", move |cx| {
cx[count] += 1;
})
.padding(Auto),
))
},
));
}
some shapes (cargo run --example shapes
):
use rui::*;
fn main() {
rui(vstack((
circle()
.color(RED_HIGHLIGHT)
.padding(Auto),
rectangle()
.corner_radius(5.0)
.color(AZURE_HIGHLIGHT)
.padding(Auto)
)));
}
canvas for gpu drawing (cargo run --example canvas
):
use rui::*;
fn main() {
rui(canvas(|_, rect, vger| {
vger.translate(rect.center() - LocalPoint::zero());
let paint = vger.linear_gradient(
[-100.0, -100.0],
[100.0, 100.0],
AZURE_HIGHLIGHT,
RED_HIGHLIGHT,
0.0,
);
let radius = 100.0;
vger.fill_circle(LocalPoint::zero(), radius, paint);
}));
}
slider
with map
(cargo run --example slider
):
use rui::*;
#[derive(Default)]
struct MyState {
value: f32,
}
/// A slider with a value.
fn my_slider(s: impl Binding<f32>) -> impl View {
with_ref(s, move |v| {
vstack((
v.to_string().font_size(10).padding(Auto),
hslider(s).thumb_color(RED_HIGHLIGHT).padding(Auto),
))
})
}
fn main() {
rui(state(MyState::default, |state, cx|
map(
cx[state].value,
move |v, cx| cx[state].value = v,
|s, _| my_slider(s),
),
));
}
widget gallery (cargo run --example gallery
):
unsafe
.winit
- (enabled by default) use winit for windowing.default-features = false
if you are embedding rui (see https://github.com/audulus/rui-ios).In the long term, I'd like to move Audulus over to Rust. After looking at other available UI options, it seemed best to implement something resembling the existing immediate mode UI system I already have working in Audulus, but better.
Towards principled reactive UI