1
0
Fork 0

Map from the Params object in GenericUi

Otherwise reactivity doesn't work.
This commit is contained in:
Robbert van der Helm 2022-07-23 18:59:00 +02:00
parent 8ae93cc6ab
commit 7b02217ad4

View file

@ -2,7 +2,6 @@
use nih_plug::prelude::{ParamFlags, ParamPtr, Params}; use nih_plug::prelude::{ParamFlags, ParamPtr, Params};
use vizia::prelude::*; use vizia::prelude::*;
use vizia::state::StaticLens;
use super::{ParamSlider, ParamSliderExt, ParamSliderStyle}; use super::{ParamSlider, ParamSliderExt, ParamSliderStyle};
@ -26,17 +25,18 @@ impl GenericUi {
///``` ///```
pub fn new<L, PsRef, Ps>(cx: &mut Context, params: L) -> Handle<'_, GenericUi> pub fn new<L, PsRef, Ps>(cx: &mut Context, params: L) -> Handle<'_, GenericUi>
where where
L: Lens<Target = PsRef>, L: Lens<Target = PsRef> + Clone,
PsRef: AsRef<Ps> + 'static, PsRef: AsRef<Ps> + 'static,
Ps: Params + 'static, Ps: Params + 'static,
{ {
// Basic styling is done in the `theme.css` style sheet // Basic styling is done in the `theme.css` style sheet
Self::new_custom(cx, params, |cx, param_ptr| { Self::new_custom(cx, params.clone(), move |cx, param_ptr| {
HStack::new(cx, |cx| { let params = params.clone();
HStack::new(cx, move |cx| {
// Align this on the right // Align this on the right
Label::new(cx, unsafe { param_ptr.name() }).class("label"); Label::new(cx, unsafe { param_ptr.name() }).class("label");
Self::draw_widget(cx, param_ptr); Self::draw_widget(cx, params, param_ptr);
}) })
.class("row"); .class("row");
}) })
@ -72,16 +72,18 @@ impl GenericUi {
/// The standard widget drawing function. This can be used together with `.new_custom()` to only /// The standard widget drawing function. This can be used together with `.new_custom()` to only
/// draw the labels differently. /// draw the labels differently.
pub fn draw_widget(cx: &mut Context, param_ptr: ParamPtr) { pub fn draw_widget<L, PsRef, Ps>(cx: &mut Context, params: L, param_ptr: ParamPtr)
// TODO: Come up with a less hacky way to iterate over the mapping like this while where
// keeping the clean interface on the `ParamSlider` widget L: Lens<Target = PsRef>,
let dummy = StaticLens::new(&()); PsRef: AsRef<Ps> + 'static,
Ps: Params + 'static,
{
unsafe { unsafe {
match param_ptr { match param_ptr {
ParamPtr::FloatParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), ParamPtr::FloatParam(p) => ParamSlider::new(cx, params, move |_| &*p),
ParamPtr::IntParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), ParamPtr::IntParam(p) => ParamSlider::new(cx, params, move |_| &*p),
ParamPtr::BoolParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), ParamPtr::BoolParam(p) => ParamSlider::new(cx, params, move |_| &*p),
ParamPtr::EnumParam(p) => ParamSlider::new(cx, dummy, move |_| &*p), ParamPtr::EnumParam(p) => ParamSlider::new(cx, params, move |_| &*p),
} }
} }
.set_style(match unsafe { param_ptr.step_count() } { .set_style(match unsafe { param_ptr.step_count() } {