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:
parent
542b3052f2
commit
89c2b1f84e
|
@ -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
|
||||
|
|
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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<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
|
||||
F: Fn(&mut Context, Arc<dyn GuiContext>) + '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<F>(
|
||||
vizia_state: Arc<ViziaState>,
|
||||
app: F,
|
||||
) -> Option<Box<dyn Editor>>
|
||||
where
|
||||
F: Fn(&mut Context, Arc<dyn GuiContext>) + '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<ViziaState>,
|
||||
/// The user's app function.
|
||||
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
|
||||
/// 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<dyn std::any::Any + Send> {
|
||||
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 {
|
||||
|
|
|
@ -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<CrispParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
) -> Option<Box<dyn Editor>> {
|
||||
create_vizia_editor(editor_state, move |cx, _| {
|
||||
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
||||
Data {
|
||||
params: params.clone(),
|
||||
}
|
||||
|
|
|
@ -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<DiopserParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
) -> Option<Box<dyn Editor>> {
|
||||
create_vizia_editor(editor_state, move |cx, _| {
|
||||
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
||||
Data {
|
||||
params: params.clone(),
|
||||
}
|
||||
|
|
|
@ -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<AtomicF32>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
) -> Option<Box<dyn Editor>> {
|
||||
create_vizia_editor(editor_state, move |cx, _| {
|
||||
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
||||
cx.add_theme(STYLE);
|
||||
|
||||
Data {
|
||||
|
|
|
@ -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<SpectralCompressorParams>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
) -> Option<Box<dyn Editor>> {
|
||||
create_vizia_editor(editor_state, move |cx, _| {
|
||||
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
||||
Data {
|
||||
params: params.clone(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue