From 101075795d399dbc63315004463448a5a1832933 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 22 Mar 2022 18:32:02 +0100 Subject: [PATCH] Use a vizia generic UI for Diopser --- Cargo.lock | 2 +- plugins/diopser/Cargo.toml | 2 +- plugins/diopser/src/editor.rs | 107 +++++++++++++--------------------- plugins/diopser/src/lib.rs | 4 +- 4 files changed, 44 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0481e988..8932a045 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -801,7 +801,7 @@ version = "0.1.0" dependencies = [ "fftw", "nih_plug", - "nih_plug_iced", + "nih_plug_vizia", "triple_buffer", ] diff --git a/plugins/diopser/Cargo.toml b/plugins/diopser/Cargo.toml index 76d64bf6..e0b01922 100644 --- a/plugins/diopser/Cargo.toml +++ b/plugins/diopser/Cargo.toml @@ -16,7 +16,7 @@ simd = ["nih_plug/simd"] [dependencies] nih_plug = { path = "../../", features = ["assert_process_allocs"] } -nih_plug_iced = { path = "../../nih_plug_iced" } +nih_plug_vizia = { path = "../../nih_plug_vizia" } # For the GUI fftw = "0.7" diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index dcabd7ef..35d4b908 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -14,85 +14,58 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use nih_plug::prelude::{Editor, GuiContext}; -use nih_plug_iced::widgets as nih_widgets; -use nih_plug_iced::widgets::generic_ui::GenericUi; -use nih_plug_iced::*; +use nih_plug::prelude::Editor; +use nih_plug_vizia::vizia::*; +use nih_plug_vizia::widgets::*; +use nih_plug_vizia::{assets, create_vizia_editor, ViziaState}; use std::pin::Pin; use std::sync::Arc; use crate::DiopserParams; +/// VIZIA uses points instead of pixels for text +const POINT_SCALE: f32 = 0.75; + +#[derive(Lens)] +// TODO: Lens requires everything to be marked as `pub` +pub struct Data { + params: Pin>, +} + +impl Model for Data {} + // Makes sense to also define this here, makes it a bit easier to keep track of -pub(crate) fn default_state() -> Arc { - IcedState::from_size(360, 300) +pub(crate) fn default_state() -> Arc { + ViziaState::from_size(360, 300) } pub(crate) fn create( params: Pin>, - editor_state: Arc, + editor_state: Arc, ) -> Option> { - create_iced_editor::(editor_state, params) -} - -struct DiopserEditor { - params: Pin>, - context: Arc, - - generic_ui_state: nih_widgets::generic_ui::State, -} - -#[derive(Debug, Clone, Copy)] -enum Message { - /// Update a parameter's value. - ParamUpdate(nih_widgets::ParamMessage), -} - -impl IcedEditor for DiopserEditor { - type Executor = executor::Default; - type Message = Message; - type InitializationFlags = Pin>; - - fn new( - params: Self::InitializationFlags, - context: Arc, - ) -> (Self, Command) { - let editor = DiopserEditor { - params, - context, - - generic_ui_state: Default::default(), - }; - - (editor, Command::none()) - } - - fn context(&self) -> &dyn GuiContext { - self.context.as_ref() - } - - fn update( - &mut self, - _window: &mut WindowQueue, - message: Self::Message, - ) -> Command { - match message { - Message::ParamUpdate(message) => self.handle_param_message(message), + create_vizia_editor(editor_state, move |cx| { + Data { + params: params.clone(), } + .build(cx); - Command::none() - } + VStack::new(cx, |cx| { + Label::new(cx, "Diopser") + .font(assets::NOTO_SANS_THIN) + .font_size(40.0 * POINT_SCALE) + .height(Pixels(50.0)) + .child_top(Stretch(1.0)) + .child_bottom(Pixels(0.0)) + // Make this more or less align with the parameters column + .right(Percentage(14.0)); - fn view(&mut self) -> Element<'_, Self::Message> { - GenericUi::new(&mut self.generic_ui_state, self.params.as_ref()).map(Message::ParamUpdate) - } - - fn background_color(&self) -> nih_plug_iced::Color { - nih_plug_iced::Color { - r: 0.98, - g: 0.98, - b: 0.98, - a: 1.0, - } - } + ScrollView::new(cx, 0.0, 0.0, false, true, |cx| { + GenericUI::new(cx, Data::params); + }) + .width(Percentage(100.0)); + }) + .row_between(Pixels(0.0)) + .child_left(Stretch(1.0)) + .child_right(Stretch(1.0)); + }) } diff --git a/plugins/diopser/src/lib.rs b/plugins/diopser/src/lib.rs index e18ca0e9..cfb6d8f9 100644 --- a/plugins/diopser/src/lib.rs +++ b/plugins/diopser/src/lib.rs @@ -23,7 +23,7 @@ compile_error!("Compiling without SIMD support is currently not supported"); extern crate nih_plug; use nih_plug::prelude::*; -use nih_plug_iced::IcedState; +use nih_plug_vizia::ViziaState; use std::pin::Pin; use std::simd::f32x2; use std::sync::atomic::{AtomicBool, Ordering}; @@ -50,7 +50,7 @@ const MAX_AUTOMATION_STEP_SIZE: u32 = 512; // - A proper GUI struct Diopser { params: Pin>, - editor_state: Arc, + editor_state: Arc, /// Needed for computing the filter coefficients. sample_rate: f32,