From 56e9cd54c12caf6980be77faa14f6918e66576c9 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 7 Apr 2022 16:14:34 +0200 Subject: [PATCH] Pass the GuiContext to vizia editors There's no clean way to expose the state save/restore functionality through events. --- nih_plug_vizia/src/lib.rs | 12 ++++++++---- plugins/crisp/src/editor.rs | 2 +- plugins/diopser/src/editor.rs | 2 +- plugins/examples/gain-gui-vizia/src/editor.rs | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nih_plug_vizia/src/lib.rs b/nih_plug_vizia/src/lib.rs index 04c0defc..af4afd23 100644 --- a/nih_plug_vizia/src/lib.rs +++ b/nih_plug_vizia/src/lib.rs @@ -21,10 +21,14 @@ pub mod widgets; /// persisted when restoring a plugin instance, then you can store it in a `#[persist = "key"]` /// field on your parameters struct. /// +/// The [`GuiContext`] is also passed to the app function. This is only meant for saving and +/// restoring state as part of your plugin's preset handling. You should not interact with this +/// directly to set parameters. Use the `ParamEvent`s instead. +/// /// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this. pub fn create_vizia_editor(vizia_state: Arc, app: F) -> Option> where - F: Fn(&mut Context) + 'static + Send + Sync, + F: Fn(&mut Context, Arc) + 'static + Send + Sync, { Some(Box::new(ViziaEditor { vizia_state, @@ -44,7 +48,7 @@ pub fn create_vizia_editor_without_theme( app: F, ) -> Option> where - F: Fn(&mut Context) + 'static + Send + Sync, + F: Fn(&mut Context, Arc) + 'static + Send + Sync, { Some(Box::new(ViziaEditor { vizia_state, @@ -127,7 +131,7 @@ impl ViziaState { struct ViziaEditor { vizia_state: Arc, /// The user's app function. - app: Arc, + app: Arc) + 'static + Send + Sync>, /// Whether to apply `nih_plug_vizia`'s default theme. If this is disabled, then only the event /// handler for `ParamEvent`s is set up. apply_theming: bool, @@ -186,7 +190,7 @@ impl Editor for ViziaEditor { } .build(cx); - app(cx) + app(cx, context.clone()) }) .with_scale_policy( system_scaling_factor diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs index 1cfdad3f..52794f44 100644 --- a/plugins/crisp/src/editor.rs +++ b/plugins/crisp/src/editor.rs @@ -41,7 +41,7 @@ pub(crate) fn create( params: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx| { + create_vizia_editor(editor_state, move |cx, _| { Data { params: params.clone(), } diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index 7ec2430d..cb0b1e3a 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -41,7 +41,7 @@ pub(crate) fn create( params: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx| { + create_vizia_editor(editor_state, move |cx, _| { Data { params: params.clone(), } diff --git a/plugins/examples/gain-gui-vizia/src/editor.rs b/plugins/examples/gain-gui-vizia/src/editor.rs index eace12ff..84675398 100644 --- a/plugins/examples/gain-gui-vizia/src/editor.rs +++ b/plugins/examples/gain-gui-vizia/src/editor.rs @@ -32,7 +32,7 @@ pub(crate) fn create( peak_meter: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx| { + create_vizia_editor(editor_state, move |cx, _| { cx.add_theme(STYLE); Data {