Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make example an iota more expressive #18

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use xilem::{button, App, AppLauncher, View};

fn app_logic(_data: &mut ()) -> impl View<()> {
button("click me", |_| println!("clicked"))
fn app_logic(data: &mut i32) -> impl View<i32> {
// here's some logic, deriving state for the view from our state
let label = if *data == 1 {
"clicked 1 time".to_string()
} else {
format!("clicked {data} times")
};

// The actual UI Code starts here
button(label, |data| {
println!("clicked");
*data += 1;
})
}

fn main() {
Expand All @@ -15,6 +26,7 @@ fn main() {
window_handle.show();
app.run(None);
*/
let app = App::new((), app_logic);
let app = App::new(0, app_logic);
AppLauncher::new(app).run()
}