-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
f911cc5
commit 90fba29
Showing
17 changed files
with
590 additions
and
500 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use futures::StreamExt; | ||
use glam::Vec2; | ||
use violet::{ | ||
core::{ | ||
state::{State, StateStream}, | ||
style::{danger_background, Background, SizeExt}, | ||
unit::Unit, | ||
widget::{ | ||
card, col, label, pill, row, Rectangle, SliderWithLabel, StreamWidget, Text, TextInput, | ||
}, | ||
Widget, | ||
}, | ||
futures_signals::signal::Mutable, | ||
palette::Srgba, | ||
}; | ||
|
||
pub fn app() -> impl Widget { | ||
let name = Mutable::new("".to_string()); | ||
let quest = Mutable::new("".to_string()); | ||
let color = Mutable::new(Srgba::new(0.0, 0.61, 0.388, 1.0)); | ||
|
||
// Map a `Mutable<Srgba>` into a `StateDuplex<f32>` for each field | ||
let r = color.clone().map_ref(|v| &v.red, |v| &mut v.red); | ||
let g = color.clone().map_ref(|v| &v.green, |v| &mut v.green); | ||
let b = color.clone().map_ref(|v| &v.blue, |v| &mut v.blue); | ||
|
||
let speed = Mutable::new(None as Option<f32>); | ||
|
||
col(( | ||
card(row((label("What is your name?"), TextInput::new(name)))), | ||
card(row((label("What is your quest?"), TextInput::new(quest)))), | ||
card(col(( | ||
label("What is your favorite colour?"), | ||
SliderWithLabel::new(r, 0.0, 1.0).round(0.01), | ||
SliderWithLabel::new(g, 0.0, 1.0).round(0.01), | ||
SliderWithLabel::new(b, 0.0, 1.0).round(0.01), | ||
StreamWidget(color.stream().map(|v| { | ||
Rectangle::new(v) | ||
.with_maximize(Vec2::X) | ||
.with_min_size(Unit::px2(100.0, 100.0)) | ||
})), | ||
))), | ||
card(row(( | ||
label("What is the airspeed velocity of an unladen swallow?"), | ||
// Fallibly parse and fill in the None at the same time using the `State` trait | ||
// combinators | ||
TextInput::new(speed.clone().prevent_feedback().filter_map( | ||
|v| v.map(|v| v.to_string()), | ||
|v| Some(v.parse::<f32>().ok()), | ||
)), | ||
StreamWidget(speed.stream().map(|v| { | ||
match v { | ||
Some(v) => pill(Text::new(format!("{v} m/s"))), | ||
None => pill(Text::new("×".to_string())) | ||
.with_background(Background::new(danger_background())), | ||
} | ||
})), | ||
))), | ||
)) | ||
} |
Oops, something went wrong.