-
Notifications
You must be signed in to change notification settings - Fork 27
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
12 changed files
with
364 additions
and
87 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use gooey::value::Dynamic; | ||
use gooey::widget::{MakeWidget, WidgetInstance}; | ||
use gooey::widgets::{Button, Label, Switcher}; | ||
use gooey::Run; | ||
|
||
#[derive(Debug)] | ||
enum ActiveContent { | ||
Intro, | ||
Success, | ||
} | ||
|
||
fn main() -> gooey::Result { | ||
let active = Dynamic::new(ActiveContent::Intro); | ||
|
||
Switcher::new(active.clone(), move |content| match content { | ||
ActiveContent::Intro => intro(active.clone()), | ||
ActiveContent::Success => success(active.clone()), | ||
}) | ||
.contain() | ||
.centered() | ||
.expand() | ||
.run() | ||
} | ||
|
||
fn intro(active: Dynamic<ActiveContent>) -> WidgetInstance { | ||
const INTRO: &str = "This example demonstrates the Switcher<T> widget, which uses a mapping function to convert from a generic type to the widget it uses for its contents."; | ||
Label::new(INTRO) | ||
.and( | ||
Button::new("Switch!") | ||
.on_click(move |_| active.set(ActiveContent::Success)) | ||
.centered(), | ||
) | ||
.into_rows() | ||
.make_widget() | ||
} | ||
|
||
fn success(active: Dynamic<ActiveContent>) -> WidgetInstance { | ||
Label::new("The value changed to `ActiveContent::Success`!") | ||
.and( | ||
Button::new("Start Over") | ||
.on_click(move |_| active.set(ActiveContent::Intro)) | ||
// .centered(), | ||
) | ||
.into_rows() | ||
.make_widget() | ||
} |
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
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
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
Oops, something went wrong.