Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Nov 20, 2023
1 parent 0790d23 commit beb45f3
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,28 @@ Cross-platform user interface framework for Rust.

This crate provides a moduler GUI library that can be used as an entire framework, or with individual parts.

## Dioxus support
```rust
fn app(cx: Scope) -> Element {
cx.render(rsx! { text { font_size: 100., "Hello World!" } })
enum Message {
Increment,
Decrement,
}
```

## HTML-like API
```rust
viewbuilder::transaction(|ui| {
ui.insert(
Text::builder()
.font_size(100.)
.color(Color4f::new(1., 0., 0., 1.))
.on_click(|text| {
viewbuilder::transaction(move |ui| ui[text].set_content(0, "Clicked!"))
})
.content("Hello World!")
.build(),
);
});
fn app<'a>(bump: &'a Bump, count: &mut i32) -> impl View<'a, Message> {
LinearLayout::new((
format_in!(bump, "High five count: {}", *count),
LinearLayout::new((
Text::new("Up high!").on_click(Message::Increment),
Text::new("Down low!").on_click(Message::Decrement),
)),
))
}

viewbuilder::run();
fn main() {
viewbuilder::run(0, app, |count: &mut i32, msg| match msg {
Message::Increment => *count += 1,
Message::Decrement => *count -= 1,
})
}
```

## Features
Expand Down

0 comments on commit beb45f3

Please sign in to comment.