From 40d7799df9f62a0d3229146960c840465187347a Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Feb 2022 14:02:55 +0100 Subject: [PATCH] Don't handle context in create_egui_editor There's no need for special handling here, just let the plugin do its own thing. --- nih_plug_egui/src/lib.rs | 12 +++++------- plugins/examples/gain-gui/src/lib.rs | 5 ++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/nih_plug_egui/src/lib.rs b/nih_plug_egui/src/lib.rs index 2444d1dd..a75cba3a 100644 --- a/nih_plug_egui/src/lib.rs +++ b/nih_plug_egui/src/lib.rs @@ -21,7 +21,7 @@ use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy}; use egui::CtxRef; use egui_baseview::{EguiWindow, RenderSettings, Settings}; -use nih_plug::{Editor, EditorWindowHandle, GuiContext}; +use nih_plug::{Editor, EditorWindowHandle}; use std::sync::Arc; /// Re-export for convenience. @@ -36,18 +36,16 @@ pub use egui; // to the user // TODO: Provide 'advanced' versions that expose more of the low level settings and details here // TODO: DPI scaling, this needs to be implemented on the framework level -pub fn create_egui_editor<'context, T, U>( +pub fn create_egui_editor( parent: EditorWindowHandle, - context: Arc, size: Arc>, initial_state: T, mut update: U, -) -> Option> +) -> Option> where T: 'static + Send, - U: FnMut(&CtxRef, &dyn GuiContext, &mut T) + 'static + Send, + U: FnMut(&CtxRef, &mut T) + 'static + Send, { - // TODO: Also pass the context reference to the update callback let (width, height) = size.load(); let window = EguiWindow::open_parented( &parent, @@ -78,7 +76,7 @@ where }, initial_state, |_, _, _| {}, - move |ctx, _, state| update(ctx, context.as_ref(), state), + move |ctx, _, state| update(ctx, state), ); // There's no error handling here, so let's just pray it worked diff --git a/plugins/examples/gain-gui/src/lib.rs b/plugins/examples/gain-gui/src/lib.rs index 5caac48c..3271df9c 100644 --- a/plugins/examples/gain-gui/src/lib.rs +++ b/plugins/examples/gain-gui/src/lib.rs @@ -106,11 +106,10 @@ impl Plugin for Gain { let peak_meter = self.peak_meter.clone(); create_egui_editor( parent, - context, self.editor_size.clone(), (), - move |egui_ctx, nih_ctx, _state| { - let setter = ParamSetter::new(nih_ctx); + move |egui_ctx, _state| { + let setter = ParamSetter::new(context.as_ref()); egui::CentralPanel::default().show(egui_ctx, |ui| { ui.allocate_space(egui::Vec2::splat(3.0));