From eed5a62abbe2148c716306fb1c7a2415ed463fc1 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 20 Oct 2022 14:03:55 +0200 Subject: [PATCH] Add build closure parameter to create_egui_editor --- BREAKING_CHANGES.md | 2 ++ nih_plug_egui/src/lib.rs | 11 +++++++++-- plugins/examples/gain_gui_egui/src/lib.rs | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 6c8f499b..38b3319f 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -8,6 +8,8 @@ code then it will not be listed here. ## [2022-10-20] +- The `create_egui_editor()` function from `nih_plug_egui` now also takes a + build closure to apply initialization logic to the egui context. - The `nih_plug::param` module has been renamed to `nih_plug::params`. Code that only uses the prelude module doesn't need to be changed. - Some items have been moved out of `nih_plug::param::internals`. The main diff --git a/nih_plug_egui/src/lib.rs b/nih_plug_egui/src/lib.rs index d089cd66..300ca1aa 100644 --- a/nih_plug_egui/src/lib.rs +++ b/nih_plug_egui/src/lib.rs @@ -35,18 +35,21 @@ pub mod widgets; /// field on your parameters struct. /// /// See [`EguiState::from_size()`]. -pub fn create_egui_editor( +pub fn create_egui_editor( egui_state: Arc, user_state: T, + build: B, update: U, ) -> Option> where T: 'static + Send + Sync, + B: Fn(&Context, &mut T) + 'static + Send + Sync, U: Fn(&Context, &ParamSetter, &mut T) + 'static + Send + Sync, { Some(Box::new(EguiEditor { egui_state, user_state: Arc::new(RwLock::new(user_state)), + build: Arc::new(build), update: Arc::new(update), // TODO: We can't get the size of the window when baseview does its own scaling, so if the @@ -110,6 +113,9 @@ struct EguiEditor { egui_state: Arc, /// The plugin's state. This is kept in between editor openenings. user_state: Arc>, + + /// The user's build function. Applied once at the start of the application. + build: Arc, /// The user's update function. update: Arc, @@ -127,6 +133,7 @@ where parent: ParentWindowHandle, context: Arc, ) -> Box { + let build = self.build.clone(); let update = self.update.clone(); let state = self.user_state.clone(); @@ -161,7 +168,7 @@ where }), }, state, - |_, _, _| {}, + move |egui_ctx, _queue, state| build(egui_ctx, &mut state.write()), move |egui_ctx, _queue, state| { let setter = ParamSetter::new(context.as_ref()); diff --git a/plugins/examples/gain_gui_egui/src/lib.rs b/plugins/examples/gain_gui_egui/src/lib.rs index 5197b0b2..e97926c4 100644 --- a/plugins/examples/gain_gui_egui/src/lib.rs +++ b/plugins/examples/gain_gui_egui/src/lib.rs @@ -93,6 +93,7 @@ impl Plugin for Gain { create_egui_editor( self.params.editor_state.clone(), (), + |_, _| {}, move |egui_ctx, setter, _state| { egui::CentralPanel::default().show(egui_ctx, |ui| { // NOTE: See `plugins/diopser/src/editor.rs` for an example using the generic UI widget