diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 526bbf0e..28102fdb 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -12,6 +12,14 @@ code then it will not be listed here. `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. +- `nih_plug_vizia::create_vizia_editor()` no longer registers any fonts by + default. Even when those fonts are not used, they will still be embedded in + the binary, increasing its size by several megabytes. Instead, you can now + register individual fonts by calling the + `nih_plug_vizia::assets::register_*()` functions. This means that you _must_ + call `nih_plug_vizia::assets::register_noto_sans_light()` for the default + theming to work. All of the plugins in this repo also use + `nih_plug_vizia::assets::register_noto_sans_thin()` as a title font. ## [2022-10-23] diff --git a/nih_plug_vizia/src/assets.rs b/nih_plug_vizia/src/assets.rs index 038d5322..2f4ff775 100644 --- a/nih_plug_vizia/src/assets.rs +++ b/nih_plug_vizia/src/assets.rs @@ -1,29 +1,57 @@ -//! Binary assets for use with `nih_plug_vizia`. These fonts first need to be registered by calling -//! [`nih_plug_vizia::assets::register_fonts()`][register_fonts()]. +//! Binary assets for use with `nih_plug_vizia`. These fonts first need to be registered using their +//! associated registration function. use vizia::prelude::*; // This module provides a re-export and simple font wrappers around the re-exported fonts. pub use nih_plug_assets::*; -/// Register the fonts from this module so they can be used with VIZIA. This is automatically called -/// for you when using [`create_vizia_editor()`][super::create_vizia_editor()]. -pub fn register_fonts(cx: &mut Context) { +/// The font name for Noto Sans Regular, needs to be registered using +/// [`register_noto_sans_regular()`] first. +pub const NOTO_SANS_REGULAR: &str = "Noto Sans Regular"; +/// The font name for Noto Sans Regular Italic, needs to be registered using +/// [`register_noto_sans_regular_italic()`] first. +pub const NOTO_SANS_REGULAR_ITALIC: &str = "Noto Sans Regular Italic"; +/// The font name for Noto Sans Thin, needs to be registered using [`register_noto_sans_thin()`] +/// first. +pub const NOTO_SANS_THIN: &str = "Noto Sans Thin"; +/// The font name for Noto Sans Thin Italic, needs to be registered using +/// [`register_noto_sans_thin_italic()`] first. +pub const NOTO_SANS_THIN_ITALIC: &str = "Noto Sans Thin Italic"; +/// The font name for Noto Sans Light, needs to be registered using [`register_noto_sans_light()`] +/// first. +pub const NOTO_SANS_LIGHT: &str = "Noto Sans Light"; +/// The font name for Noto Sans Light Italic, needs to be registered using +/// [`register_noto_sans_light_italic()`] first. +pub const NOTO_SANS_LIGHT_ITALIC: &str = "Noto Sans Light Italic"; +/// The font name for Noto Sans Bold, needs to be registered using [`register_noto_sans_bold()`] +/// first. +pub const NOTO_SANS_BOLD: &str = "Noto Sans Bold"; +/// The font name for Noto Sans Bold Italic, needs to be registered using +/// [`register_noto_sans_bold_italic()`] first. +pub const NOTO_SANS_BOLD_ITALIC: &str = "Noto Sans Bold Italic"; + +pub fn register_noto_sans_regular(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_REGULAR, fonts::NOTO_SANS_REGULAR); +} +pub fn register_noto_sans_regular_italic(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_REGULAR_ITALIC, fonts::NOTO_SANS_REGULAR_ITALIC); +} +pub fn register_noto_sans_thin(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_THIN, fonts::NOTO_SANS_THIN); +} +pub fn register_noto_sans_thin_italic(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_THIN_ITALIC, fonts::NOTO_SANS_THIN_ITALIC); +} +pub fn register_noto_sans_light(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_LIGHT, fonts::NOTO_SANS_LIGHT); +} +pub fn register_noto_sans_light_italic(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_LIGHT_ITALIC, fonts::NOTO_SANS_LIGHT_ITALIC); +} +pub fn register_noto_sans_bold(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_BOLD, fonts::NOTO_SANS_BOLD); +} +pub fn register_noto_sans_bold_italic(cx: &mut Context) { cx.add_font_mem(NOTO_SANS_BOLD_ITALIC, fonts::NOTO_SANS_BOLD_ITALIC); } - -pub const NOTO_SANS_REGULAR: &str = "Noto Sans Regular"; -pub const NOTO_SANS_REGULAR_ITALIC: &str = "Noto Sans Regular Italic"; -pub const NOTO_SANS_THIN: &str = "Noto Sans Thin"; -pub const NOTO_SANS_THIN_ITALIC: &str = "Noto Sans Thin Italic"; -pub const NOTO_SANS_LIGHT: &str = "Noto Sans Light"; -pub const NOTO_SANS_LIGHT_ITALIC: &str = "Noto Sans Light Italic"; -pub const NOTO_SANS_BOLD: &str = "Noto Sans Bold"; -pub const NOTO_SANS_BOLD_ITALIC: &str = "Noto Sans Bold Italic"; diff --git a/nih_plug_vizia/src/lib.rs b/nih_plug_vizia/src/lib.rs index 130d45c1..f0633dfa 100644 --- a/nih_plug_vizia/src/lib.rs +++ b/nih_plug_vizia/src/lib.rs @@ -29,6 +29,11 @@ pub mod widgets; /// restoring state as part of your plugin's preset handling. You should not interact with this /// directly to set parameters. Use the `ParamEvent`s instead. /// +/// The `theming` argument controls what level of theming to apply. If you use +/// [`ViziaTheming::Custom`], then you **need** to call +/// [`nih_plug_vizia::assets::register_noto_sans_light()`][assets::register_noto_sans_light()] at +/// the start of your app function. +/// /// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this. pub fn create_vizia_editor( vizia_state: Arc, @@ -60,7 +65,9 @@ pub enum ViziaTheming { None, /// Disable `nih_plug_vizia`'s custom theming. Builtin, - /// Apply `nih_plug_vizia`'s custom theming. This is the default. + /// Apply `nih_plug_vizia`'s custom theming. This is the default. You **need** to call + /// [`nih_plug_vizia::assets::register_noto_sans_light()`][assets::register_noto_sans_light()] + /// at the start of your app function for the font to work correctly. #[default] Custom, } @@ -180,7 +187,6 @@ impl Editor for ViziaEditor { 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); cx.set_default_font(assets::NOTO_SANS_LIGHT); cx.add_theme(include_str!("../assets/theme.css")); diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs index 1df2ace3..85b488b5 100644 --- a/plugins/crisp/src/editor.rs +++ b/plugins/crisp/src/editor.rs @@ -42,6 +42,9 @@ pub(crate) fn create( editor_state: Arc, ) -> Option> { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { + assets::register_noto_sans_light(cx); + assets::register_noto_sans_thin(cx); + Data { params: params.clone(), } diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index c1723fd3..3cab9b42 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -42,6 +42,9 @@ pub(crate) fn create( editor_state: Arc, ) -> Option> { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { + assets::register_noto_sans_light(cx); + assets::register_noto_sans_thin(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 fbf4b52b..9280c75a 100644 --- a/plugins/examples/gain_gui_vizia/src/editor.rs +++ b/plugins/examples/gain_gui_vizia/src/editor.rs @@ -33,6 +33,9 @@ pub(crate) fn create( editor_state: Arc, ) -> Option> { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { + assets::register_noto_sans_light(cx); + assets::register_noto_sans_thin(cx); + cx.add_theme(STYLE); Data { diff --git a/plugins/spectral_compressor/src/editor.rs b/plugins/spectral_compressor/src/editor.rs index d558f7d2..64c55dab 100644 --- a/plugins/spectral_compressor/src/editor.rs +++ b/plugins/spectral_compressor/src/editor.rs @@ -42,6 +42,9 @@ pub(crate) fn create( editor_state: Arc, ) -> Option> { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { + assets::register_noto_sans_light(cx); + assets::register_noto_sans_thin(cx); + Data { params: params.clone(), }