-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
use floem::{ | ||
reactive::create_signal, | ||
views::{button, label, Decorators}, | ||
IntoView, | ||
}; | ||
use floem::prelude::*; | ||
|
||
fn app_view() -> impl IntoView { | ||
// Create a reactive signal with a counter value, defaulting to 0 | ||
let (counter, mut set_counter) = create_signal(0); | ||
|
||
// Create a vertical layout | ||
( | ||
// The counter value updates automatically, thanks to reactivity | ||
label(move || format!("Value: {counter}")), | ||
// Create a horizontal layout | ||
( | ||
button("Increment").action(move || set_counter += 1), | ||
button("Decrement").action(move || set_counter -= 1), | ||
), | ||
) | ||
.style(|s| s.flex_col()) | ||
fn main() { | ||
floem::launch(counter_view); | ||
} | ||
|
||
fn main() { | ||
floem::launch(app_view); | ||
fn counter_view() -> impl IntoView { | ||
let mut counter = RwSignal::new(0); | ||
|
||
h_stack(( | ||
button("Increment").action(move || counter += 1), | ||
label(move || format!("Value: {counter}")), | ||
button("Decrement").action(move || counter -= 1), | ||
)) | ||
.style(|s| s.size_full().items_center().justify_center().gap(10)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters