Skip to content

Commit

Permalink
Merge pull request #232 from ricardobeat/patch-1
Browse files Browse the repository at this point in the history
Fixes Hello World example in README
  • Loading branch information
fschutt committed Dec 18, 2019
2 parents 5984b80 + 0a9e053 commit 5ea3321
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions README.md
Expand Up @@ -51,28 +51,23 @@ use azul::{
widgets::{button::Button, label::Label},
};

struct DataModel {
struct CounterApp {
counter: usize,
}

impl Layout for DataModel {
// Model renders View
impl Layout for CounterApp {
fn layout(&self, _: LayoutInfo<Self>) -> Dom<Self> {
let label = Label::new(format!("{}", self.counter)).dom();
let button = Button::with_label("Update counter")
.dom()
.with_callback(On::MouseUp, Callback(update_counter));
.with_callback(On::MouseUp, update_counter);

Dom::new(NodeType::Div).with_child(label).with_child(button)
Dom::div().with_child(label).with_child(button)
}
}

// View updates Model
fn update_counter(
app_state: &mut AppState<DataModel>,
_event: &mut CallbackInfo<DataModel>,
) -> UpdateScreen {
app_state.data.modify(|state| state.counter += 1);
fn update_counter(event: CallbackInfo<DataModel>) -> UpdateScreen {
event.state.data.counter += 1;
Redraw
}

Expand Down

0 comments on commit 5ea3321

Please sign in to comment.