diff --git a/src/editor.rs b/src/editor.rs index 72b7db9..75d85a8 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1279,6 +1279,35 @@ impl ActionTrigger { own_index, } .build(cx, move |cx| { + let class_nr = ( + params, + is_learning, + learned_notes, + last_played_notes, + enabled_actions, + ) + .map( + move |( + params, + is_learning, + learned_notes, + last_played_notes, + enabled_actions, + )| { + Self::get_action_class( + // ¶ms.get(cx), + // is_learning.get(cx), + learned_notes.get(cx), + // last_played_notes.get(cx), + // enabled_actions.get(cx), + own_index, + ) + }, + ); + Element::new(cx) + .class("trigger-element") + .class("default") + .hoverable(true); Label::new( cx, learned_notes.map(move |notes| { @@ -1292,6 +1321,7 @@ impl ActionTrigger { })) .class("action-label"); }) + .hoverable(true) } pub fn start_learning(&self) { @@ -1418,7 +1448,7 @@ impl ActionTrigger { paint.set_color(paint_color); paint.set_anti_alias(true); - canvas.draw_path(&path, &paint); + // canvas.draw_path(&path, &paint); // Drawing the border around the rectangle let mut path = vg::Path::new(); @@ -1430,7 +1460,62 @@ impl ActionTrigger { paint.set_stroke_width(border_width); paint.set_style(vg::PaintStyle::Stroke); - canvas.draw_path(&path, &paint); + // canvas.draw_path(&path, &paint); + } + + // clippy's suggestion doesn't work, cause we need the early exit + // #[allow(clippy::match_same_arms)] + // fn OLD_get_action_class() -> String { + // let class = match ( + // self.is_learning(), + // self.params.global.mute_is_toggle.value(), + // self.is_enabled(), + // self.is_playing(), + // self.own_index == CLEAR_TAPS, + // ) { + // (true, _, _, _, _) => "learning", + // (_, _, _, true, true) => "muted", + // (_, true, true, _, _) => "muted", + // (_, true, false, _, _) => "default", + // (_, _, true, _, _) => "muted", + // (_, _, _, true, _) => "live", + // _ => "default", // Default: paint with background color + // }; + // class + // } + #[allow(clippy::match_same_arms)] + fn get_action_class( + // params: &Arc, + // is_learning: Arc, + learned_notes: Arc, + // last_played_notes: Arc, + // enabled_actions: Arc, + own_index: usize, + ) -> u8 { + // let is_learning = + // is_learning.load(Ordering::SeqCst) && learned_notes.load(own_index) == LEARNING; + // let is_playing = last_played_notes.is_playing(learned_notes.load(own_index)); + // let is_enabled = enabled_actions.load(own_index); + + // Determine the paint color based on the state + let class = match ( + true, true, true, true, + true, + // is_learning, + // params.global.mute_is_toggle.value(), + // is_enabled, + // is_playing, + // own_index == CLEAR_TAPS, + ) { + (true, _, _, _, _) => "learning", + (_, _, _, true, true) => "muted", + (_, true, true, _, _) => "muted", + (_, true, false, _, _) => "default", + (_, _, true, _, _) => "muted", + (_, _, _, true, _) => "live", + _ => "default", // Default: paint with background color + }; + 1 } } @@ -1440,7 +1525,7 @@ impl View for ActionTrigger { Some("action-trigger") } - 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) @@ -1451,7 +1536,6 @@ impl View for ActionTrigger { } else { self.start_learning(); } - cx.needs_redraw(); meta.consume(); } _ => {} @@ -1460,22 +1544,21 @@ impl View for ActionTrigger { fn draw(&self, draw_context: &mut DrawContext, canvas: &Canvas) { draw_context.needs_redraw(); - let bounds = draw_context.bounds(); - let background_color: vg::Color = draw_context.background_color().into(); - let border_color: vg::Color = draw_context.border_color().into(); - let outline_color: vg::Color = draw_context.outline_color().into(); - let selection_color: vg::Color = draw_context.selection_color().into(); - let border_width = draw_context.border_width(); - // let outline_width = draw_context.outline_width(); - - self.draw_background( - canvas, - bounds, - background_color, - border_color, - outline_color, - selection_color, - border_width, - ); + // let bounds = draw_context.bounds(); + // let background_color: vg::Color = draw_context.background_color().into(); + // let border_color: vg::Color = draw_context.border_color().into(); + // let outline_color: vg::Color = draw_context.outline_color().into(); + // let selection_color: vg::Color = draw_context.selection_color().into(); + // let border_width = draw_context.border_width(); + + // self.draw_background( + // canvas, + // bounds, + // background_color, + // border_color, + // outline_color, + // selection_color, + // border_width, + // ); } } diff --git a/src/style.css b/src/style.css index e698300..2d898b7 100644 --- a/src/style.css +++ b/src/style.css @@ -167,19 +167,35 @@ action-trigger { height: 30px; top: 0px; bottom: 0px; - background-color: #4e4e4e; - border-color: #5879af; - outline-color: #e0ce91; - selection-color: #fabdf0; +} + +.trigger-element { + /* width: 210px; */ + height: 30px; + top: 0px; + bottom: 0px; + border-width: 1px; - shadow: 0px 0px 5px #fabdf0; + background-color: #4e4e4e; + border-color: #fabdf0; + shadow: 0px 0px 13px #fabdf03f; transition: background-color 240ms; + learning-color: #fabdf0; + mute-color: #5879af; + live-color: #e0ce91; } -action-trigger:hover { - /* background-color: #292929; */ +.trigger-element:active, +.trigger-element:hover { + background-color: #292929; transition: background-color 120ms; } + +.action-label { + right: 1s; + top: 1s; + bottom: 3px; +} .action-name { right: 9px; top: 1s;