Skip to content

Commit

Permalink
wip use element for actiontrigger
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Dec 12, 2024
1 parent 57be9b1 commit 108a1bf
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 28 deletions.
125 changes: 104 additions & 21 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
// &params.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| {
Expand All @@ -1292,6 +1321,7 @@ impl ActionTrigger {
}))
.class("action-label");
})
.hoverable(true)
}

pub fn start_learning(&self) {
Expand Down Expand Up @@ -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();
Expand All @@ -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<Del2Params>,
// is_learning: Arc<AtomicBool>,
learned_notes: Arc<AtomicByteArray>,
// last_played_notes: Arc<LastPlayedNotes>,
// enabled_actions: Arc<AtomicBoolArray>,
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
}
}

Expand All @@ -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)
Expand All @@ -1451,7 +1536,6 @@ impl View for ActionTrigger {
} else {
self.start_learning();
}
cx.needs_redraw();
meta.consume();
}
_ => {}
Expand All @@ -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,
// );
}
}
30 changes: 23 additions & 7 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 108a1bf

Please sign in to comment.