1
0
Fork 0

Attempt to improve left-side tooltip positioning

This commit is contained in:
Robbert van der Helm 2022-11-15 17:09:32 +01:00
parent 8df9575a16
commit 5a9786fd53

View file

@ -18,6 +18,7 @@ use nih_plug::prelude::Param;
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::param_base::ParamWidgetBase; use nih_plug_vizia::widgets::param_base::ParamWidgetBase;
use nih_plug_vizia::widgets::util::{self, ModifiersExt}; use nih_plug_vizia::widgets::util::{self, ModifiersExt};
use nih_plug_vizia::widgets::RawParamEvent;
/// When shift+dragging the X-Y pad, one pixel dragged corresponds to this much change in the /// When shift+dragging the X-Y pad, one pixel dragged corresponds to this much change in the
/// normalized parameter. /// normalized parameter.
@ -269,6 +270,20 @@ impl View for XyPad {
} }
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| {
if let RawParamEvent::ParametersChanged = window_event {
// The tooltip tracks the mouse position, but it also needs to be recomputed when
// the parameter changes while the tooltip is still visible. Without this the
// position maya be off when the parameter is automated, or because of the samll
// delay between interacting with a parameter and the parameter changing.
// FIXME: This _may_ improve the positioning but it most likely doesn't. Relayouting
// happens _after_ this event.
if cx.hovered() == cx.current() {
self.update_tooltip_pos(cx);
}
}
});
event.map(|window_event, meta| match window_event { event.map(|window_event, meta| match window_event {
WindowEvent::MouseDown(MouseButton::Left) WindowEvent::MouseDown(MouseButton::Left)
| WindowEvent::MouseTripleClick(MouseButton::Left) => { | WindowEvent::MouseTripleClick(MouseButton::Left) => {
@ -328,7 +343,8 @@ impl View for XyPad {
} }
} }
WindowEvent::MouseMove(x, y) => { WindowEvent::MouseMove(x, y) => {
// The tooltip should track the mouse position // The tooltip should track the mouse position. This is also recomputed whenever
// parameter values change so it stays in the correct position.
self.update_tooltip_pos(cx); self.update_tooltip_pos(cx);
if self.drag_active { if self.drag_active {