From 89c2b1f84e6ac866fdac11e8f8e119c9486362f2 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Nov 2022 13:26:32 +0100 Subject: [PATCH] Replace create_vizia_editor_without_theme w/ enum This involves a small breaking change. You can now also completely disable all of Vizia's theming. --- BREAKING_CHANGES.md | 7 +++ Cargo.lock | 18 +++--- nih_plug_vizia/src/lib.rs | 60 +++++++++---------- plugins/crisp/src/editor.rs | 4 +- plugins/diopser/src/editor.rs | 4 +- plugins/examples/gain_gui_vizia/src/editor.rs | 4 +- plugins/spectral_compressor/src/editor.rs | 4 +- 7 files changed, 53 insertions(+), 48 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 4eba73f2..526bbf0e 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -6,6 +6,13 @@ new and what's changed, this document lists all breaking changes in reverse chronological order. If a new feature did not require any changes to existing code then it will not be listed here. +## [2022-11-06] + +- `nih_plug_vizia::create_vizia_editor_without_theme()` has been removed, and + `nih_plug_vizia::create_vizia_editor()` has gained a new argument to specify + what amount of theming to apply. This can now also be used to completely + disable all theming include Vizia's built-in theme. + ## [2022-10-23] - `nih_plug_vizia` has been updated. Widgets with custom drawing code will need diff --git a/Cargo.lock b/Cargo.lock index 5c9576ae..669fb50a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4464,7 +4464,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vizia" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "vizia_baseview", "vizia_core", @@ -4474,7 +4474,7 @@ dependencies = [ [[package]] name = "vizia_baseview" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)", "femtovg", @@ -4488,7 +4488,7 @@ dependencies = [ [[package]] name = "vizia_core" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "bitflags", "copypasta 0.8.1", @@ -4516,7 +4516,7 @@ dependencies = [ [[package]] name = "vizia_derive" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "proc-macro2", "quote", @@ -4526,12 +4526,12 @@ dependencies = [ [[package]] name = "vizia_id" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" [[package]] name = "vizia_input" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "bitflags", "keyboard-types", @@ -4541,7 +4541,7 @@ dependencies = [ [[package]] name = "vizia_storage" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "morphorm", "vizia_id", @@ -4550,7 +4550,7 @@ dependencies = [ [[package]] name = "vizia_window" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "morphorm", "vizia_input", @@ -4559,7 +4559,7 @@ dependencies = [ [[package]] name = "vizia_winit" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#a75ce4d79eb48535c275c937dc05bdff7c0cf192" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#cbb1aa4243dd4a68605922ae5eba735fb716d032" dependencies = [ "console_error_panic_hook", "copypasta 0.8.1", diff --git a/nih_plug_vizia/src/lib.rs b/nih_plug_vizia/src/lib.rs index a1b48a49..130d45c1 100644 --- a/nih_plug_vizia/src/lib.rs +++ b/nih_plug_vizia/src/lib.rs @@ -30,14 +30,18 @@ pub mod widgets; /// directly to set parameters. Use the `ParamEvent`s instead. /// /// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this. -pub fn create_vizia_editor(vizia_state: Arc, app: F) -> Option> +pub fn create_vizia_editor( + vizia_state: Arc, + theming: ViziaTheming, + app: F, +) -> Option> where F: Fn(&mut Context, Arc) + 'static + Send + Sync, { Some(Box::new(ViziaEditor { vizia_state, app: Arc::new(app), - apply_theming: true, + theming, // TODO: We can't get the size of the window when baseview does its own scaling, so if the // host does not set a scale factor on Windows or Linux we should just use a factor of @@ -49,27 +53,16 @@ where })) } -/// The same as [`create_vizia_editor()`] but without changing VIZIA's default styling and font. -/// This also won't register the styling for any of the widgets that come with `nih_plug_vizia`, or -/// register the custom fonts. Event handlers for the [`ParamEvent`][widgets::ParamEvent]s are still -/// set up when using this function instead of [`create_vizia_editor()`]. -pub fn create_vizia_editor_without_theme( - vizia_state: Arc, - app: F, -) -> Option> -where - F: Fn(&mut Context, Arc) + 'static + Send + Sync, -{ - Some(Box::new(ViziaEditor { - vizia_state, - app: Arc::new(app), - apply_theming: false, - - #[cfg(target_os = "macos")] - scaling_factor: AtomicCell::new(None), - #[cfg(not(target_os = "macos"))] - scaling_factor: AtomicCell::new(Some(1.0)), - })) +/// Controls what level of theming to apply to the editor. +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] +pub enum ViziaTheming { + /// Disable both `nih_plug_vizia`'s and vizia's built-in theming. + None, + /// Disable `nih_plug_vizia`'s custom theming. + Builtin, + /// Apply `nih_plug_vizia`'s custom theming. This is the default. + #[default] + Custom, } /// State for an `nih_plug_vizia` editor. The scale factor can be manipulated at runtime by changing @@ -160,9 +153,8 @@ struct ViziaEditor { vizia_state: Arc, /// The user's app function. app: Arc) + 'static + Send + Sync>, - /// Whether to apply `nih_plug_vizia`'s default theme. If this is disabled, then only the event - /// handler for `ParamEvent`s is set up. - apply_theming: bool, + /// What level of theming to apply. See [`ViziaEditorTheming`]. + theming: ViziaTheming, /// The scaling factor reported by the host, if any. On macOS this will never be set and we /// should use the system scaling factor instead. @@ -177,15 +169,15 @@ impl Editor for ViziaEditor { ) -> Box { let app = self.app.clone(); let vizia_state = self.vizia_state.clone(); - let apply_theming = self.apply_theming; + let theming = self.theming; let (unscaled_width, unscaled_height) = vizia_state.inner_logical_size(); let system_scaling_factor = self.scaling_factor.load(); let user_scale_factor = vizia_state.user_scale_factor(); - let window = Application::new(move |cx| { + let mut application = Application::new(move |cx| { // Set some default styles to match the iced integration - if apply_theming { + if theming >= ViziaTheming::Custom { // NOTE: vizia's font rendering looks way too dark and thick. Going one font weight // lower seems to compensate for this. assets::register_fonts(cx); @@ -220,8 +212,14 @@ impl Editor for ViziaEditor { .unwrap_or(WindowScalePolicy::SystemScaleFactor), ) .inner_size((unscaled_width, unscaled_height)) - .user_scale_factor(user_scale_factor) - .open_parented(&parent); + .user_scale_factor(user_scale_factor); + + // This way the plugin can decide to use none of the built in theming + if theming == ViziaTheming::None { + application = application.ignore_default_theme(); + } + + let window = application.open_parented(&parent); self.vizia_state.open.store(true, Ordering::Release); Box::new(ViziaEditorHandle { diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs index e8bcbe97..1df2ace3 100644 --- a/plugins/crisp/src/editor.rs +++ b/plugins/crisp/src/editor.rs @@ -17,7 +17,7 @@ use nih_plug::prelude::Editor; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; -use nih_plug_vizia::{assets, create_vizia_editor, ViziaState}; +use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; use std::sync::Arc; use crate::CrispParams; @@ -41,7 +41,7 @@ pub(crate) fn create( params: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx, _| { + create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { Data { params: params.clone(), } diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index f1095d8f..c1723fd3 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -17,7 +17,7 @@ use nih_plug::prelude::Editor; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; -use nih_plug_vizia::{assets, create_vizia_editor, ViziaState}; +use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; use std::sync::Arc; use crate::DiopserParams; @@ -41,7 +41,7 @@ pub(crate) fn create( params: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx, _| { + create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { Data { params: params.clone(), } diff --git a/plugins/examples/gain_gui_vizia/src/editor.rs b/plugins/examples/gain_gui_vizia/src/editor.rs index 90677f2a..fbf4b52b 100644 --- a/plugins/examples/gain_gui_vizia/src/editor.rs +++ b/plugins/examples/gain_gui_vizia/src/editor.rs @@ -2,7 +2,7 @@ use atomic_float::AtomicF32; use nih_plug::prelude::{util, Editor}; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; -use nih_plug_vizia::{assets, create_vizia_editor, ViziaState}; +use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; @@ -32,7 +32,7 @@ pub(crate) fn create( peak_meter: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx, _| { + create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { cx.add_theme(STYLE); Data { diff --git a/plugins/spectral_compressor/src/editor.rs b/plugins/spectral_compressor/src/editor.rs index 6b7abdae..d558f7d2 100644 --- a/plugins/spectral_compressor/src/editor.rs +++ b/plugins/spectral_compressor/src/editor.rs @@ -17,7 +17,7 @@ use nih_plug::prelude::Editor; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; -use nih_plug_vizia::{assets, create_vizia_editor, ViziaState}; +use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming}; use std::sync::Arc; use crate::SpectralCompressorParams; @@ -41,7 +41,7 @@ pub(crate) fn create( params: Arc, editor_state: Arc, ) -> Option> { - create_vizia_editor(editor_state, move |cx, _| { + create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { Data { params: params.clone(), }