1
0
Fork 0

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.
This commit is contained in:
Robbert van der Helm 2022-11-06 13:26:32 +01:00
parent 542b3052f2
commit 89c2b1f84e
7 changed files with 53 additions and 48 deletions

View file

@ -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 chronological order. If a new feature did not require any changes to existing
code then it will not be listed here. 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] ## [2022-10-23]
- `nih_plug_vizia` has been updated. Widgets with custom drawing code will need - `nih_plug_vizia` has been updated. Widgets with custom drawing code will need

18
Cargo.lock generated
View file

@ -4464,7 +4464,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "vizia" name = "vizia"
version = "0.1.0" 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 = [ dependencies = [
"vizia_baseview", "vizia_baseview",
"vizia_core", "vizia_core",
@ -4474,7 +4474,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_baseview" name = "vizia_baseview"
version = "0.1.0" 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 = [ dependencies = [
"baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)", "baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)",
"femtovg", "femtovg",
@ -4488,7 +4488,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_core" name = "vizia_core"
version = "0.1.0" 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 = [ dependencies = [
"bitflags", "bitflags",
"copypasta 0.8.1", "copypasta 0.8.1",
@ -4516,7 +4516,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_derive" name = "vizia_derive"
version = "0.1.0" 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 = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4526,12 +4526,12 @@ dependencies = [
[[package]] [[package]]
name = "vizia_id" name = "vizia_id"
version = "0.1.0" 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]] [[package]]
name = "vizia_input" name = "vizia_input"
version = "0.1.0" 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 = [ dependencies = [
"bitflags", "bitflags",
"keyboard-types", "keyboard-types",
@ -4541,7 +4541,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_storage" name = "vizia_storage"
version = "0.1.0" 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 = [ dependencies = [
"morphorm", "morphorm",
"vizia_id", "vizia_id",
@ -4550,7 +4550,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_window" name = "vizia_window"
version = "0.1.0" 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 = [ dependencies = [
"morphorm", "morphorm",
"vizia_input", "vizia_input",
@ -4559,7 +4559,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_winit" name = "vizia_winit"
version = "0.1.0" 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 = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"copypasta 0.8.1", "copypasta 0.8.1",

View file

@ -30,14 +30,18 @@ pub mod widgets;
/// directly to set parameters. Use the `ParamEvent`s instead. /// 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. /// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this.
pub fn create_vizia_editor<F>(vizia_state: Arc<ViziaState>, app: F) -> Option<Box<dyn Editor>> pub fn create_vizia_editor<F>(
vizia_state: Arc<ViziaState>,
theming: ViziaTheming,
app: F,
) -> Option<Box<dyn Editor>>
where where
F: Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync, F: Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync,
{ {
Some(Box::new(ViziaEditor { Some(Box::new(ViziaEditor {
vizia_state, vizia_state,
app: Arc::new(app), 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 // 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 // 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. /// Controls what level of theming to apply to the editor.
/// This also won't register the styling for any of the widgets that come with `nih_plug_vizia`, or #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
/// register the custom fonts. Event handlers for the [`ParamEvent`][widgets::ParamEvent]s are still pub enum ViziaTheming {
/// set up when using this function instead of [`create_vizia_editor()`]. /// Disable both `nih_plug_vizia`'s and vizia's built-in theming.
pub fn create_vizia_editor_without_theme<F>( None,
vizia_state: Arc<ViziaState>, /// Disable `nih_plug_vizia`'s custom theming.
app: F, Builtin,
) -> Option<Box<dyn Editor>> /// Apply `nih_plug_vizia`'s custom theming. This is the default.
where #[default]
F: Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync, Custom,
{
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)),
}))
} }
/// State for an `nih_plug_vizia` editor. The scale factor can be manipulated at runtime by changing /// 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<ViziaState>, vizia_state: Arc<ViziaState>,
/// The user's app function. /// The user's app function.
app: Arc<dyn Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync>, app: Arc<dyn Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync>,
/// Whether to apply `nih_plug_vizia`'s default theme. If this is disabled, then only the event /// What level of theming to apply. See [`ViziaEditorTheming`].
/// handler for `ParamEvent`s is set up. theming: ViziaTheming,
apply_theming: bool,
/// The scaling factor reported by the host, if any. On macOS this will never be set and we /// 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. /// should use the system scaling factor instead.
@ -177,15 +169,15 @@ impl Editor for ViziaEditor {
) -> Box<dyn std::any::Any + Send> { ) -> Box<dyn std::any::Any + Send> {
let app = self.app.clone(); let app = self.app.clone();
let vizia_state = self.vizia_state.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 (unscaled_width, unscaled_height) = vizia_state.inner_logical_size();
let system_scaling_factor = self.scaling_factor.load(); let system_scaling_factor = self.scaling_factor.load();
let user_scale_factor = vizia_state.user_scale_factor(); 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 // 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 // NOTE: vizia's font rendering looks way too dark and thick. Going one font weight
// lower seems to compensate for this. // lower seems to compensate for this.
assets::register_fonts(cx); assets::register_fonts(cx);
@ -220,8 +212,14 @@ impl Editor for ViziaEditor {
.unwrap_or(WindowScalePolicy::SystemScaleFactor), .unwrap_or(WindowScalePolicy::SystemScaleFactor),
) )
.inner_size((unscaled_width, unscaled_height)) .inner_size((unscaled_width, unscaled_height))
.user_scale_factor(user_scale_factor) .user_scale_factor(user_scale_factor);
.open_parented(&parent);
// 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); self.vizia_state.open.store(true, Ordering::Release);
Box::new(ViziaEditorHandle { Box::new(ViziaEditorHandle {

View file

@ -17,7 +17,7 @@
use nih_plug::prelude::Editor; use nih_plug::prelude::Editor;
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*; 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 std::sync::Arc;
use crate::CrispParams; use crate::CrispParams;
@ -41,7 +41,7 @@ pub(crate) fn create(
params: Arc<CrispParams>, params: Arc<CrispParams>,
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
Data { Data {
params: params.clone(), params: params.clone(),
} }

View file

@ -17,7 +17,7 @@
use nih_plug::prelude::Editor; use nih_plug::prelude::Editor;
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*; 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 std::sync::Arc;
use crate::DiopserParams; use crate::DiopserParams;
@ -41,7 +41,7 @@ pub(crate) fn create(
params: Arc<DiopserParams>, params: Arc<DiopserParams>,
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
Data { Data {
params: params.clone(), params: params.clone(),
} }

View file

@ -2,7 +2,7 @@ use atomic_float::AtomicF32;
use nih_plug::prelude::{util, Editor}; use nih_plug::prelude::{util, Editor};
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*; 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::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
@ -32,7 +32,7 @@ pub(crate) fn create(
peak_meter: Arc<AtomicF32>, peak_meter: Arc<AtomicF32>,
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
cx.add_theme(STYLE); cx.add_theme(STYLE);
Data { Data {

View file

@ -17,7 +17,7 @@
use nih_plug::prelude::Editor; use nih_plug::prelude::Editor;
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*; 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 std::sync::Arc;
use crate::SpectralCompressorParams; use crate::SpectralCompressorParams;
@ -41,7 +41,7 @@ pub(crate) fn create(
params: Arc<SpectralCompressorParams>, params: Arc<SpectralCompressorParams>,
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
Data { Data {
params: params.clone(), params: params.clone(),
} }