1
0
Fork 0

Don't handle context in create_egui_editor

There's no need for special handling here, just let the plugin do its
own thing.
This commit is contained in:
Robbert van der Helm 2022-02-06 14:02:55 +01:00
parent a10e1e1152
commit 40d7799df9
2 changed files with 7 additions and 10 deletions

View file

@ -21,7 +21,7 @@
use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy}; use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy};
use egui::CtxRef; use egui::CtxRef;
use egui_baseview::{EguiWindow, RenderSettings, Settings}; use egui_baseview::{EguiWindow, RenderSettings, Settings};
use nih_plug::{Editor, EditorWindowHandle, GuiContext}; use nih_plug::{Editor, EditorWindowHandle};
use std::sync::Arc; use std::sync::Arc;
/// Re-export for convenience. /// Re-export for convenience.
@ -36,18 +36,16 @@ pub use egui;
// to the user // to the user
// TODO: Provide 'advanced' versions that expose more of the low level settings and details here // 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 // 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<T, U>(
parent: EditorWindowHandle, parent: EditorWindowHandle,
context: Arc<dyn GuiContext + 'context>,
size: Arc<AtomicCell<(u32, u32)>>, size: Arc<AtomicCell<(u32, u32)>>,
initial_state: T, initial_state: T,
mut update: U, mut update: U,
) -> Option<Box<dyn Editor + 'context>> ) -> Option<Box<dyn Editor>>
where where
T: 'static + Send, 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 (width, height) = size.load();
let window = EguiWindow::open_parented( let window = EguiWindow::open_parented(
&parent, &parent,
@ -78,7 +76,7 @@ where
}, },
initial_state, 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 // There's no error handling here, so let's just pray it worked

View file

@ -106,11 +106,10 @@ impl Plugin for Gain {
let peak_meter = self.peak_meter.clone(); let peak_meter = self.peak_meter.clone();
create_egui_editor( create_egui_editor(
parent, parent,
context,
self.editor_size.clone(), self.editor_size.clone(),
(), (),
move |egui_ctx, nih_ctx, _state| { move |egui_ctx, _state| {
let setter = ParamSetter::new(nih_ctx); let setter = ParamSetter::new(context.as_ref());
egui::CentralPanel::default().show(egui_ctx, |ui| { egui::CentralPanel::default().show(egui_ctx, |ui| {
ui.allocate_space(egui::Vec2::splat(3.0)); ui.allocate_space(egui::Vec2::splat(3.0));