From 193ec70b8a5c56eaf728f778a8704a68e912f9ac Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 14 Nov 2023 22:46:10 +0100 Subject: [PATCH] Update resize handle for upstream vizia changes --- CHANGELOG.md | 13 +++++-- nih_plug_vizia/src/widgets/resize_handle.rs | 39 ++++++++----------- plugins/crisp/src/editor.rs | 4 +- plugins/diopser/src/editor.rs | 4 +- plugins/examples/gain_gui_vizia/src/editor.rs | 4 +- plugins/spectral_compressor/src/editor.rs | 4 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7cc71b1..96cf4070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,15 @@ state is to list breaking changes. system has changed a lot since the last update, so plugin GUIs and stylesheets may require small changes before they behave the same again. A summary of the most important changes can be found in Vizia PR - [#291](https://github.com/vizia/vizia/pull/291). Notably, font handling and - choosing between different variations of the same font (e.g. `Noto Sans` - versus `Noto Sans Light` versus `Noto Sans Light Italic`) works very - differently now. + [#291](https://github.com/vizia/vizia/pull/291). Some notable breaking changes + include: + + - Font handling and choosing between different variations of the same font + (e.g. `Noto Sans` versus `Noto Sans Light` versus `Noto Sans Light Italic`) + works very differently now. + - `ResizeHandle` now needs to be the last element in a GUI because of changes + to Vizia's event targetting mechanism. + - The `raw_window_handle` version used by NIH-plug has been updated to version 0.5.x. diff --git a/nih_plug_vizia/src/widgets/resize_handle.rs b/nih_plug_vizia/src/widgets/resize_handle.rs index 937f8c17..da28c1c4 100644 --- a/nih_plug_vizia/src/widgets/resize_handle.rs +++ b/nih_plug_vizia/src/widgets/resize_handle.rs @@ -1,10 +1,12 @@ //! A resize handle for uniformly scaling a plugin GUI. -use vizia::cache::BoundingBox; use vizia::prelude::*; use vizia::vg; /// A resize handle placed at the bottom right of the window that lets you resize the window. +/// +/// Needs to be the last element in the GUI because of how event targetting in Vizia works right +/// now. pub struct ResizeHandle { /// Will be set to `true` if we're dragging the parameter. Resetting the parameter or entering a /// text value should not initiate a drag. @@ -15,7 +17,7 @@ pub struct ResizeHandle { start_scale_factor: f64, /// The DPI factor when we started dragging, includes both the HiDPI scaling and the user /// scaling factor. This is kept track of separately to avoid accumulating rounding errors. - start_dpi_factor: f64, + start_dpi_factor: f32, /// The cursor position in physical screen pixels when the drag started. start_physical_coordinates: (f32, f32), } @@ -47,17 +49,17 @@ impl View for ResizeHandle { // triangle if intersects_triangle( cx.cache.get_bounds(cx.current()), - (cx.mouse.cursorx, cx.mouse.cursory), + (cx.mouse().cursorx, cx.mouse().cursory), ) { cx.capture(); cx.set_active(true); self.drag_active = true; self.start_scale_factor = cx.user_scale_factor(); - self.start_dpi_factor = cx.style.dpi_factor; + self.start_dpi_factor = cx.scale_factor(); self.start_physical_coordinates = ( - cx.mouse.cursorx * cx.style.dpi_factor as f32, - cx.mouse.cursory * cx.style.dpi_factor as f32, + cx.mouse().cursorx * self.start_dpi_factor, + cx.mouse().cursory * self.start_dpi_factor, ); meta.consume(); @@ -86,10 +88,8 @@ impl View for ResizeHandle { // to the same absoltue screen spotion. // TODO: This may start doing fun things when the window grows so large that it // gets pushed upwards or leftwards - let (compensated_physical_x, compensated_physical_y) = ( - x * self.start_dpi_factor as f32, - y * self.start_dpi_factor as f32, - ); + let (compensated_physical_x, compensated_physical_y) = + (x * self.start_dpi_factor, y * self.start_dpi_factor); let (start_physical_x, start_physical_y) = self.start_physical_coordinates; let new_scale_factor = (self.start_scale_factor * (compensated_physical_x / start_physical_x) @@ -116,19 +116,14 @@ impl View for ResizeHandle { return; } - let background_color = cx.background_color().copied().unwrap_or_default(); - let border_color = cx.border_color().copied().unwrap_or_default(); + let background_color = cx.background_color(); + let border_color = cx.border_color(); let opacity = cx.opacity(); let mut background_color: vg::Color = background_color.into(); background_color.set_alphaf(background_color.a * opacity); let mut border_color: vg::Color = border_color.into(); border_color.set_alphaf(border_color.a * opacity); - - let border_width = match cx.border_width().unwrap_or_default() { - Units::Pixels(val) => val, - Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0), - _ => 0.0, - }; + let border_width = cx.border_width(); let mut path = vg::Path::new(); let x = bounds.x + border_width / 2.0; @@ -144,12 +139,12 @@ impl View for ResizeHandle { // Fill with background color let paint = vg::Paint::color(background_color); - canvas.fill_path(&mut path, &paint); + canvas.fill_path(&path, &paint); // Borders are only supported to make debugging easier let mut paint = vg::Paint::color(border_color); paint.set_line_width(border_width); - canvas.stroke_path(&mut path, &paint); + canvas.stroke_path(&path, &paint); // We'll draw a simple triangle, since we're going flat everywhere anyways and that style // tends to not look too tacky @@ -179,10 +174,10 @@ impl View for ResizeHandle { // path.move_to(x + (w / 3.0 * 1.5), y + h); // path.close(); - let mut color: vg::Color = cx.font_color().copied().unwrap_or(Color::white()).into(); + let mut color: vg::Color = cx.font_color().into(); color.set_alphaf(color.a * opacity); let paint = vg::Paint::color(color); - canvas.fill_path(&mut path, &paint); + canvas.fill_path(&path, &paint); } } diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs index 827d7ac0..873513e6 100644 --- a/plugins/crisp/src/editor.rs +++ b/plugins/crisp/src/editor.rs @@ -47,8 +47,6 @@ pub(crate) fn create( } .build(cx); - ResizeHandle::new(cx); - VStack::new(cx, |cx| { Label::new(cx, "Crisp") .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))]) @@ -71,5 +69,7 @@ pub(crate) fn create( .row_between(Pixels(0.0)) .child_left(Stretch(1.0)) .child_right(Stretch(1.0)); + + ResizeHandle::new(cx); }) } diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index e8cebb8e..7b44606b 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -74,13 +74,13 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc) -> Option editor_data.clone().build(cx); - ResizeHandle::new(cx); - VStack::new(cx, |cx| { top_bar(cx); spectrum_analyzer(cx); other_params(cx); }); + + ResizeHandle::new(cx); }) } diff --git a/plugins/examples/gain_gui_vizia/src/editor.rs b/plugins/examples/gain_gui_vizia/src/editor.rs index 9ca20905..43b9bc7a 100644 --- a/plugins/examples/gain_gui_vizia/src/editor.rs +++ b/plugins/examples/gain_gui_vizia/src/editor.rs @@ -37,8 +37,6 @@ pub(crate) fn create( } .build(cx); - ResizeHandle::new(cx); - VStack::new(cx, |cx| { Label::new(cx, "Gain GUI") .font_family(vec![FamilyOwned::Name(String::from( @@ -64,5 +62,7 @@ pub(crate) fn create( .row_between(Pixels(0.0)) .child_left(Stretch(1.0)) .child_right(Stretch(1.0)); + + ResizeHandle::new(cx); }) } diff --git a/plugins/spectral_compressor/src/editor.rs b/plugins/spectral_compressor/src/editor.rs index 3b8a92d7..b1ce79c6 100644 --- a/plugins/spectral_compressor/src/editor.rs +++ b/plugins/spectral_compressor/src/editor.rs @@ -89,8 +89,6 @@ pub(crate) fn create(editor_state: Arc, editor_data: Data) -> Option editor_data.clone().build(cx); - ResizeHandle::new(cx); - HStack::new(cx, |cx| { main_column(cx); @@ -102,6 +100,8 @@ pub(crate) fn create(editor_state: Arc, editor_data: Data) -> Option } }); }); + + ResizeHandle::new(cx); }) }