Add `Toggler` to tour example
This commit is contained in:
parent
1ef38cc207
commit
be3ee9adf1
|
@ -1,7 +1,7 @@
|
||||||
use iced::{
|
use iced::{
|
||||||
button, scrollable, slider, text_input, Button, Checkbox, Color, Column,
|
button, scrollable, slider, text_input, Button, Checkbox, Color, Column,
|
||||||
Container, Element, HorizontalAlignment, Image, Length, Radio, Row,
|
Container, Element, HorizontalAlignment, Image, Length, Radio, Row,
|
||||||
Sandbox, Scrollable, Settings, Slider, Space, Text, TextInput,
|
Sandbox, Scrollable, Settings, Slider, Space, Text, TextInput, Toggler,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
@ -135,6 +135,9 @@ impl Steps {
|
||||||
color: Color::BLACK,
|
color: Color::BLACK,
|
||||||
},
|
},
|
||||||
Step::Radio { selection: None },
|
Step::Radio { selection: None },
|
||||||
|
Step::Toggler {
|
||||||
|
can_continue: false,
|
||||||
|
},
|
||||||
Step::Image {
|
Step::Image {
|
||||||
width: 300,
|
width: 300,
|
||||||
slider: slider::State::new(),
|
slider: slider::State::new(),
|
||||||
|
@ -206,6 +209,9 @@ enum Step {
|
||||||
Radio {
|
Radio {
|
||||||
selection: Option<Language>,
|
selection: Option<Language>,
|
||||||
},
|
},
|
||||||
|
Toggler {
|
||||||
|
can_continue: bool,
|
||||||
|
},
|
||||||
Image {
|
Image {
|
||||||
width: u16,
|
width: u16,
|
||||||
slider: slider::State,
|
slider: slider::State,
|
||||||
|
@ -232,6 +238,7 @@ pub enum StepMessage {
|
||||||
InputChanged(String),
|
InputChanged(String),
|
||||||
ToggleSecureInput(bool),
|
ToggleSecureInput(bool),
|
||||||
DebugToggled(bool),
|
DebugToggled(bool),
|
||||||
|
TogglerChanged(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Step {
|
impl<'a> Step {
|
||||||
|
@ -287,6 +294,11 @@ impl<'a> Step {
|
||||||
*is_secure = toggle;
|
*is_secure = toggle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StepMessage::TogglerChanged(value) => {
|
||||||
|
if let Step::Toggler { can_continue, .. } = self {
|
||||||
|
*can_continue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +306,7 @@ impl<'a> Step {
|
||||||
match self {
|
match self {
|
||||||
Step::Welcome => "Welcome",
|
Step::Welcome => "Welcome",
|
||||||
Step::Radio { .. } => "Radio button",
|
Step::Radio { .. } => "Radio button",
|
||||||
|
Step::Toggler { .. } => "Toggler",
|
||||||
Step::Slider { .. } => "Slider",
|
Step::Slider { .. } => "Slider",
|
||||||
Step::Text { .. } => "Text",
|
Step::Text { .. } => "Text",
|
||||||
Step::Image { .. } => "Image",
|
Step::Image { .. } => "Image",
|
||||||
|
@ -309,6 +322,7 @@ impl<'a> Step {
|
||||||
match self {
|
match self {
|
||||||
Step::Welcome => true,
|
Step::Welcome => true,
|
||||||
Step::Radio { selection } => *selection == Some(Language::Rust),
|
Step::Radio { selection } => *selection == Some(Language::Rust),
|
||||||
|
Step::Toggler { can_continue } => *can_continue,
|
||||||
Step::Slider { .. } => true,
|
Step::Slider { .. } => true,
|
||||||
Step::Text { .. } => true,
|
Step::Text { .. } => true,
|
||||||
Step::Image { .. } => true,
|
Step::Image { .. } => true,
|
||||||
|
@ -324,6 +338,7 @@ impl<'a> Step {
|
||||||
match self {
|
match self {
|
||||||
Step::Welcome => Self::welcome(),
|
Step::Welcome => Self::welcome(),
|
||||||
Step::Radio { selection } => Self::radio(*selection),
|
Step::Radio { selection } => Self::radio(*selection),
|
||||||
|
Step::Toggler { can_continue } => Self::toggler(*can_continue),
|
||||||
Step::Slider { state, value } => Self::slider(state, *value),
|
Step::Slider { state, value } => Self::slider(state, *value),
|
||||||
Step::Text {
|
Step::Text {
|
||||||
size_slider,
|
size_slider,
|
||||||
|
@ -545,6 +560,18 @@ impl<'a> Step {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn toggler(can_continue: bool) -> Column<'a, StepMessage> {
|
||||||
|
Self::container("Toggler")
|
||||||
|
.push(Text::new(
|
||||||
|
"A toggler is mostly used to enable or disable something.",
|
||||||
|
))
|
||||||
|
.push(Toggler::new(
|
||||||
|
can_continue,
|
||||||
|
String::from("Toggle me to continue..."),
|
||||||
|
StepMessage::TogglerChanged,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
fn image(
|
fn image(
|
||||||
width: u16,
|
width: u16,
|
||||||
slider: &'a mut slider::State,
|
slider: &'a mut slider::State,
|
||||||
|
|
Loading…
Reference in New Issue