From 5a9786fd5319333d28a9aa53e916f52a004ae868 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 15 Nov 2022 17:09:32 +0100 Subject: [PATCH] Attempt to improve left-side tooltip positioning --- plugins/diopser/src/editor/xy_pad.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/diopser/src/editor/xy_pad.rs b/plugins/diopser/src/editor/xy_pad.rs index 64f0eac3..c3d78cc3 100644 --- a/plugins/diopser/src/editor/xy_pad.rs +++ b/plugins/diopser/src/editor/xy_pad.rs @@ -18,6 +18,7 @@ use nih_plug::prelude::Param; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::param_base::ParamWidgetBase; 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 /// normalized parameter. @@ -269,6 +270,20 @@ impl View for XyPad { } 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 { WindowEvent::MouseDown(MouseButton::Left) | WindowEvent::MouseTripleClick(MouseButton::Left) => { @@ -328,7 +343,8 @@ impl View for XyPad { } } 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); if self.drag_active {