diff --git a/examples/dial_test3.rs b/examples/dial_test3.rs index a96a6b34080df617a51ccb3534c7ea4b240390b5..84844fb1e3f1c7fe842cdd2d16c0fc1c4cd6c291 100644 --- a/examples/dial_test3.rs +++ b/examples/dial_test3.rs @@ -34,11 +34,11 @@ struct DialLabel { } impl DialLabel { - fn new(text: String) -> impl Widget<DialLabel> { - let solid = Color::rgb8(0x3a, 0x3a, 0x3a); - + fn new(text: &str) -> impl Widget<DialLabel> { + let text = text.to_string(); let label = Label::new(move |data: &DialLabel, _env: &_| format!("{} {:.3}", text, data.value)); + let solid = Color::rgb8(0x3a, 0x3a, 0x3a); let mut col = Flex::column(); col.add_child( Dial::new(Size::new(100.0, 100.0)) @@ -51,9 +51,38 @@ impl DialLabel { col } } +#[derive(Clone, Data, Lens)] +struct Envelope { + attack: DialLabel, + decay: DialLabel, + sustain: DialLabel, + release: DialLabel, +} + +impl Envelope { + fn new() -> impl Widget<Envelope> { + let solid = Color::rgb8(0x3a, 0x3a, 0x3a); + let mut col = Flex::column(); + col.add_child( + DialLabel::new("Attack") + .lens(Envelope::attack) + .background(solid.clone()) + .padding(5.0), + 0.0, + ); + col.add_child( + DialLabel::new("Decay") + .lens(Envelope::decay) + .background(solid.clone()) + .padding(5.0), + 0.0, + ); + col + } +} fn main() -> Result<(), PlatformError> { - AppLauncher::with_window(WindowDesc::new(|| DialLabel::new("Value".to_string()))) + AppLauncher::with_window(WindowDesc::new(|| DialLabel::new("Value"))) .use_simple_logger() .launch(DialLabel { value: 0.0 })?;