From 158ab548d03b0e3828c178eda9662c5a56a1aac0 Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Mon, 9 Dec 2024 12:19:57 +0100 Subject: [PATCH] working Arc -> bool --- src/editor.rs | 49 +++++++++++++++++++++---------------------------- src/lib.rs | 4 +--- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index aa44658..3b48b1f 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -52,7 +52,17 @@ pub struct Data { pub show_full_parameters: bool, } -impl Model for Data {} +enum AppEvent { + ToggleShowView, +} + +impl Model for Data { + fn event(&mut self, _cx: &mut EventContext, event: &mut Event) { + event.map(|app_event, _| match app_event { + AppEvent::ToggleShowView => self.show_full_parameters ^= true, + }); + } +} // Makes sense to also define this here, makes it a bit easier to keep track of pub fn default_state() -> Arc { @@ -78,10 +88,8 @@ pub fn create(editor_data: Data, editor_state: Arc) -> Option( - cx: &mut Context, - show_full_parameters: ShowFullParametersL, - ) -> Handle - where - ShowFullParametersL: Lens, - { - Self { - show_full_parameters: show_full_parameters.get(cx), - } - .build(cx, move |cx| { + pub fn new(cx: &mut Context) -> Handle { + Self {}.build(cx, move |cx| { Label::new( cx, - show_full_parameters.map(|show_full_parameters| { + Data::show_full_parameters.map(|show_full_parameters| { // ▲ ▼ ◀ ▶ if *show_full_parameters { String::from("▴") @@ -1728,17 +1725,13 @@ impl CollapseButton { } impl View for CollapseButton { - fn event(&mut self, _cx: &mut EventContext, event: &mut Event) { + fn event(&mut self, cx: &mut EventContext, event: &mut Event) { event.map(|window_event, meta| match window_event { // We don't need special double and triple click handling WindowEvent::MouseDown(MouseButton::Left) | WindowEvent::MouseDoubleClick(MouseButton::Left) | WindowEvent::MouseTripleClick(MouseButton::Left) => { - if self.show_full_parameters { - self.show_full_parameters = false; - } else { - self.show_full_parameters = true; - } + cx.emit(AppEvent::ToggleShowView); meta.consume(); } _ => {} diff --git a/src/lib.rs b/src/lib.rs index 7a12842..d32331b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,6 @@ pub struct Del2 { counting_state: CountingState, should_update_filter: Arc, enabled_actions: Arc, - show_full_parameters: bool, running_delay_tempo: f32, first_process_after_reset: bool, } @@ -532,7 +531,6 @@ impl Default for Del2 { counting_state: CountingState::TimeOut, should_update_filter, enabled_actions, - show_full_parameters: true, running_delay_tempo: DEFAULT_TEMPO, first_process_after_reset: true, } @@ -634,7 +632,7 @@ impl Plugin for Del2 { last_learned_notes: self.last_learned_notes.clone(), last_played_notes: self.last_played_notes.clone(), enabled_actions: self.enabled_actions.clone(), - show_full_parameters: self.show_full_parameters.clone(), + show_full_parameters: true, }, self.params.editor_state.clone(), )