From 2fbf4ca00dd9f16c644c6ae96d2343657e4d8e91 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 23 Jul 2022 18:23:22 +0200 Subject: [PATCH] Remove Copy requirement from Vizia generic UI This now uses a dummy lens to map to the parameter. --- nih_plug_vizia/src/widgets/generic_ui.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nih_plug_vizia/src/widgets/generic_ui.rs b/nih_plug_vizia/src/widgets/generic_ui.rs index 48da2257..fa2667c3 100644 --- a/nih_plug_vizia/src/widgets/generic_ui.rs +++ b/nih_plug_vizia/src/widgets/generic_ui.rs @@ -1,9 +1,8 @@ //! Generic UIs for NIH-plug using VIZIA. -use std::sync::Arc; - use nih_plug::prelude::{ParamFlags, ParamPtr, Params}; use vizia::prelude::*; +use vizia::state::StaticLens; use super::{ParamSlider, ParamSliderExt, ParamSliderStyle}; @@ -25,9 +24,10 @@ impl GenericUi { /// }) /// .width(Percentage(100.0)); ///``` - pub fn new(cx: &mut Context, params: L) -> Handle<'_, GenericUi> + pub fn new(cx: &mut Context, params: L) -> Handle<'_, GenericUi> where - L: Lens> + Copy, + L: Lens, + PsRef: AsRef + 'static, Ps: Params + 'static, { // Basic styling is done in the `theme.css` style sheet @@ -38,12 +38,13 @@ impl GenericUi { // TODO: Come up with a less hacky way to iterate over the mapping like this while // keeping the clean interface on the `ParamSlider` widget + let dummy = StaticLens::new(&()); unsafe { match param_ptr { - ParamPtr::FloatParam(p) => ParamSlider::new(cx, params, move |_| &*p), - ParamPtr::IntParam(p) => ParamSlider::new(cx, params, move |_| &*p), - ParamPtr::BoolParam(p) => ParamSlider::new(cx, params, move |_| &*p), - ParamPtr::EnumParam(p) => ParamSlider::new(cx, params, move |_| &*p), + ParamPtr::FloatParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), + ParamPtr::IntParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), + ParamPtr::BoolParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), + ParamPtr::EnumParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), } } .set_style(match unsafe { param_ptr.step_count() } { @@ -68,13 +69,14 @@ impl GenericUi { /// Creates a new [`GenericUi`] for all provided parameters using a custom closure that receives /// a function that should draw some widget for each parameter. - pub fn new_custom( + pub fn new_custom( cx: &mut Context, params: L, mut make_widget: impl FnMut(&mut Context, ParamPtr), ) -> Handle where - L: Lens> + Copy, + L: Lens, + PsRef: AsRef + 'static, Ps: Params + 'static, { // Basic styling is done in the `theme.css` style sheet