Add popup help to elements

This commit is contained in:
2026-03-27 08:29:11 +00:00
parent b8d3dc48ab
commit ea381fe433
11 changed files with 233 additions and 4 deletions

View File

@@ -141,6 +141,13 @@ impl Module {
&& y >= self.y && y <= self.y + MOD_HEADER
}
/// Hit-test the `?` help badge drawn in the top-right of the header.
fn hit_help_badge(&self, x: f32, y: f32) -> bool {
let bx = self.x + MOD_W - 10.0;
let by = self.y + MOD_HEADER / 2.0;
hypot(x - bx, y - by) <= 9.0
}
fn hit_body(&self, x: f32, y: f32) -> bool {
x >= self.x && x <= self.x + MOD_W
&& y >= self.y && y <= self.y + self.height()
@@ -490,6 +497,18 @@ impl PatchBay {
}
}
/// Returns the markdown description for the module whose `?` badge is at
/// (x, y), or an empty string if none is hovered. JS calls this on every
/// `mousemove` over the patch bay canvas to drive the tooltip overlay.
pub fn get_tooltip_at(&self, x: f32, y: f32) -> String {
for m in self.modules.iter().rev() {
if m.hit_help_badge(x, y) {
return m.descriptor().description.to_string();
}
}
String::new()
}
/// Double-click removes the topmost module under the cursor.
pub fn on_double_click(&mut self, x: f32, y: f32) {
if y < PALETTE_H { return; }
@@ -685,7 +704,25 @@ impl PatchBay {
(m.y + MOD_HEADER * 0.70) as f64,
);
// ? help badge — top-right corner of every module header
{
let bx = (m.x + MOD_W - 10.0) as f64;
let by = (m.y + MOD_HEADER / 2.0) as f64;
ctx.begin_path();
let _ = ctx.arc(bx, by, 7.0, 0.0, core::f64::consts::TAU);
ctx.set_fill_style_str("rgba(0,0,0,0.30)");
ctx.fill();
ctx.set_stroke_style_str("rgba(255,255,255,0.25)");
ctx.set_line_width(1.0);
ctx.stroke();
ctx.set_fill_style_str("rgba(255,255,255,0.70)");
ctx.set_font("bold 9px sans-serif");
ctx.set_text_align("center");
let _ = ctx.fill_text("?", bx, by + 3.5);
}
// Output node: LIVE / UNPATCHED badge on the right of the header
// (shifted left to clear the ? badge)
if is_out {
if has_signal {
ctx.set_fill_style_str("#22c55e");
@@ -693,7 +730,7 @@ impl PatchBay {
ctx.set_text_align("right");
let _ = ctx.fill_text(
"● LIVE",
(m.x + MOD_W - 6.0) as f64,
(m.x + MOD_W - 24.0) as f64,
(m.y + MOD_HEADER * 0.70) as f64,
);
} else {
@@ -702,7 +739,7 @@ impl PatchBay {
ctx.set_text_align("right");
let _ = ctx.fill_text(
"unpatched",
(m.x + MOD_W - 6.0) as f64,
(m.x + MOD_W - 24.0) as f64,
(m.y + MOD_HEADER * 0.70) as f64,
);
}