Skip to content

Cross-platform user interface framework for Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

matthunz/viewbuilder

Repository files navigation

Viewbuilder

Crates.io version docs.rs docs CI status

A cross-platform user interface framework for Rust.

Viewbuilder is a moduler 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

About

Cross-platform user interface framework for Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages