Skip to content

Commit e35f437

Browse files
committed
Added hello_world counter example to check if wiki / README are outdated
1 parent 8d3ce24 commit e35f437

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

azul/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ name = "game_of_life"
8181
path = "../examples/game_of_life/game_of_life.rs"
8282
required-features = []
8383

84+
[[example]]
85+
name = "hello_world"
86+
path = "../examples/hello_world/hello_world.rs"
87+
required-features = []
88+
89+
8490
[[example]]
8591
name = "hot_reload"
8692
path = "../examples/hot_reload/hot_reload.rs"

examples/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- Shows how to use timers in order to update the game board every 200ms.
2424
- Performance demo, performs the layout for 5600 rectangles (TODO: Should be replaced by an image).
2525

26+
## `hello_world`
27+
28+
- Hello World "counter" example, used for checking that the README and the wiki aren't out-of-date.
29+
2630
## `hot_reload`
2731

2832
- Shows a window where the CSS can be hot-reloaded (you can run the demo, then edit the )

examples/hello_world/hello_world.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern crate azul;
2+
3+
use azul::{prelude::*, widgets::{label::Label, button::Button}};
4+
5+
struct DataModel {
6+
counter: usize,
7+
}
8+
9+
impl Layout for DataModel {
10+
fn layout(&self, _info: LayoutInfo<Self>) -> Dom<Self> {
11+
let label = Label::new(format!("{}", self.counter)).dom();
12+
let button = Button::with_label("Update counter").dom()
13+
.with_callback(On::MouseUp, Callback(update_counter));
14+
15+
Dom::div()
16+
.with_child(label)
17+
.with_child(button)
18+
}
19+
}
20+
21+
fn update_counter(app_state: &mut AppState<DataModel>, _: &mut CallbackInfo<DataModel>) -> UpdateScreen {
22+
app_state.data.modify(|state| state.counter += 1)?;
23+
Redraw
24+
}
25+
26+
fn main() {
27+
let mut app = App::new(DataModel { counter: 0 }, AppConfig::default()).unwrap();
28+
let window = app.create_window(WindowCreateOptions::default(), css::native()).unwrap();
29+
app.run(window).unwrap();
30+
}

0 commit comments

Comments
 (0)