From 5c9ac31408ae13520572ccdab02b4ba8f1bfddab Mon Sep 17 00:00:00 2001 From: Robbert van der Helm <mail@robbertvanderhelm.nl> Date: Sun, 6 Feb 2022 00:50:44 +0100 Subject: [PATCH] Initialize the egui GUI using the update function --- nih_plug_egui/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nih_plug_egui/src/lib.rs b/nih_plug_egui/src/lib.rs index 3c19d550..17013d24 100644 --- a/nih_plug_egui/src/lib.rs +++ b/nih_plug_egui/src/lib.rs @@ -20,7 +20,7 @@ use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy}; use egui::CtxRef; -use egui_baseview::{EguiWindow, Queue, RenderSettings, Settings}; +use egui_baseview::{EguiWindow, RenderSettings, Settings}; use nih_plug::{Editor, EditorWindowHandle, GuiContext}; use std::sync::Arc; @@ -44,8 +44,12 @@ pub fn create_egui_editor<'context, T, U>( ) -> Option<Box<dyn Editor + 'context>> where T: 'static + Send, - U: FnMut(&CtxRef, &dyn GuiContext, &mut T) + 'static + Send, + U: FnMut(&CtxRef, &dyn GuiContext, &mut T) + 'static + Send + Clone, { + // For convenience we'll make the same closure for the update and the build functions. + let mut build = update.clone(); + let context_build = context.clone(); + // TODO: Also pass the context reference to the update callback let (width, height) = size.load(); let window = EguiWindow::open_parented( @@ -76,7 +80,7 @@ where }, }, initial_state, - |_, _, _| {}, + move |ctx, _, state| build(ctx, context_build.as_ref(), state), move |ctx, _, state| update(ctx, context.as_ref(), state), );