25 releases (9 breaking)
0.10.0-alpha.5 | Jan 8, 2024 |
---|---|
0.9.4 | Dec 16, 2023 |
0.8.0 | Dec 15, 2023 |
0.6.0-alpha.3 | Nov 16, 2023 |
#24 in #control-flow
56 downloads per month
26KB
687 lines
A cross-platform user interface framework for Rust.
Viewbuilder is a modular GUI library that can be used as an entire framework, or with individual parts.
use viewbuilder::{
view,
web::{self, html, Web},
ControlFlow, Model, View,
};
enum Message {
Increment,
Decrement,
}
#[derive(Default)]
struct App {
count: i32,
}
impl Model<Message> for App {
fn handle(&mut self, msg: Message) -> ControlFlow {
match msg {
Message::Decrement => self.count -= 1,
Message::Increment => self.count += 1,
}
ControlFlow::Rebuild
}
}
fn view(model: &App) -> impl View<Web, Message> {
(
format!("High five count: {}", model.count),
view::once(html::button(
html::on_click(|| Message::Increment),
"Up high!",
)),
view::once(html::button(
html::on_click(|| Message::Decrement),
"Down low!",
)),
)
}
fn main() {
web::run(App::default(), view)
}
Getting started
Instatllation is simple with:
cargo add viewbuilder --features full
Dependencies
~0–2.3MB
~42K SLoC