fix: 1-to-1 official equalizer, settings, animations, and click-outside dismissal

This commit is contained in:
marwy 2026-11-27 19:54:12 +03:00
parent b7cfde1f6b
commit b315b212a4
9 changed files with 928 additions and 557 deletions

View file

@ -554,6 +554,36 @@ impl InputState {
}
}
/// Consume the current pointer press (`active_id = None`, `left_pressed = false`,
/// `right_pressed = false`) so releasing over an underlying widget cannot trigger a click/drag.
pub fn consume_pointer_press(&mut self) {
self.active_id = None;
self.left_pressed = false;
self.right_pressed = false;
}
/// Like `clicked_outside`, but also consumes the dismissing press (`active_id = None`,
/// `left_pressed = false`, `right_pressed = false`) so releasing over an underlying
/// toggle trigger button (e.g. PlayerBar EQ button) can NEVER re-open the overlay.
pub fn consume_clicked_outside(&mut self, rect: Rect) -> bool {
if self.clicked_outside(rect) {
self.consume_pointer_press();
true
} else {
false
}
}
/// Multi-rect variant of `consume_clicked_outside`.
pub fn consume_clicked_outside_any(&mut self, rects: &[Rect]) -> bool {
if self.clicked_outside_any(rects) {
self.consume_pointer_press();
true
} else {
false
}
}
pub fn key_pressed(&self, key: Key) -> bool {
self.key_events.iter().any(|e| e.key == key)
}
@ -694,3 +724,47 @@ impl Animator {
self.values.clear();
}
}
#[cfg(test)]
mod tests {
use super::*;
use winit::dpi::PhysicalPosition;
#[test]
fn test_consume_clicked_outside_prevents_trigger_reopen_on_release() {
let mut input = InputState::new();
let screen = Vec2::new(1280.0, 800.0);
let trigger_id = WidgetId::new("pb_r_eq");
let trigger_r = Rect::from_xywh(1000.0, 740.0, 36.0, 36.0);
let pop_r = Rect::from_xywh(800.0, 400.0, 430.0, 300.0);
// Frame 1: Mouse down on the underlying trigger button while popover is open.
input.begin_frame(screen, 1.0, 1.0);
input.handle_winit_event(&WindowEvent::CursorMoved {
device_id: unsafe { std::mem::zeroed() },
position: PhysicalPosition::new(1018.0, 758.0),
});
input.handle_winit_event(&WindowEvent::MouseInput {
device_id: unsafe { std::mem::zeroed() },
state: ElementState::Pressed,
button: MouseButton::Left,
});
let press_resp = input.interact(trigger_id, ZLayer::Base, trigger_r, None);
assert!(!press_resp.clicked);
assert!(input.consume_clicked_outside(pop_r));
assert!(input.active_id.is_none());
input.end_frame();
// Frame 2: Mouse up over the same trigger button — MUST NOT fire clicked!
input.begin_frame(screen, 1.0, 1.05);
input.handle_winit_event(&WindowEvent::MouseInput {
device_id: unsafe { std::mem::zeroed() },
state: ElementState::Released,
button: MouseButton::Left,
});
let rel_resp = input.interact(trigger_id, ZLayer::Base, trigger_r, None);
assert!(!rel_resp.clicked);
input.end_frame();
}
}