From 7b02217ad4d50a7779236a2863b6a33384810581 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 23 Jul 2022 18:59:00 +0200 Subject: [PATCH] Map from the Params object in GenericUi Otherwise reactivity doesn't work. --- nih_plug_vizia/src/widgets/generic_ui.rs | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nih_plug_vizia/src/widgets/generic_ui.rs b/nih_plug_vizia/src/widgets/generic_ui.rs index 57d85595..ae8fb043 100644 --- a/nih_plug_vizia/src/widgets/generic_ui.rs +++ b/nih_plug_vizia/src/widgets/generic_ui.rs @@ -2,7 +2,6 @@ use nih_plug::prelude::{ParamFlags, ParamPtr, Params}; use vizia::prelude::*; -use vizia::state::StaticLens; use super::{ParamSlider, ParamSliderExt, ParamSliderStyle}; @@ -26,17 +25,18 @@ impl GenericUi { ///``` pub fn new(cx: &mut Context, params: L) -> Handle<'_, GenericUi> where - L: Lens, + L: Lens + Clone, PsRef: AsRef + 'static, Ps: Params + 'static, { // Basic styling is done in the `theme.css` style sheet - Self::new_custom(cx, params, |cx, param_ptr| { - HStack::new(cx, |cx| { + Self::new_custom(cx, params.clone(), move |cx, param_ptr| { + let params = params.clone(); + HStack::new(cx, move |cx| { // Align this on the right Label::new(cx, unsafe { param_ptr.name() }).class("label"); - Self::draw_widget(cx, param_ptr); + Self::draw_widget(cx, params, param_ptr); }) .class("row"); }) @@ -72,16 +72,18 @@ impl GenericUi { /// The standard widget drawing function. This can be used together with `.new_custom()` to only /// draw the labels differently. - pub fn draw_widget(cx: &mut Context, param_ptr: ParamPtr) { - // 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(&()); + pub fn draw_widget(cx: &mut Context, params: L, param_ptr: ParamPtr) + where + L: Lens, + PsRef: AsRef + 'static, + Ps: Params + 'static, + { unsafe { match param_ptr { - 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), + 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), } } .set_style(match unsafe { param_ptr.step_count() } {