1
0
Fork 0

Don't register any fonts by default for vizia

These now need to be registered individually by the plugin. This saves
on binary size.
This commit is contained in:
Robbert van der Helm 2022-11-06 13:48:12 +01:00
parent 89c2b1f84e
commit 6f7780bdeb
7 changed files with 70 additions and 16 deletions

View file

@ -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 `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 what amount of theming to apply. This can now also be used to completely
disable all theming include Vizia's built-in theme. 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] ## [2022-10-23]

View file

@ -1,29 +1,57 @@
//! Binary assets for use with `nih_plug_vizia`. These fonts first need to be registered by calling //! Binary assets for use with `nih_plug_vizia`. These fonts first need to be registered using their
//! [`nih_plug_vizia::assets::register_fonts()`][register_fonts()]. //! associated registration function.
use vizia::prelude::*; use vizia::prelude::*;
// This module provides a re-export and simple font wrappers around the re-exported fonts. // This module provides a re-export and simple font wrappers around the re-exported fonts.
pub use nih_plug_assets::*; pub use nih_plug_assets::*;
/// Register the fonts from this module so they can be used with VIZIA. This is automatically called /// The font name for Noto Sans Regular, needs to be registered using
/// for you when using [`create_vizia_editor()`][super::create_vizia_editor()]. /// [`register_noto_sans_regular()`] first.
pub fn register_fonts(cx: &mut Context) { 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); 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); 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); 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); 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); 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); 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); 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); 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";

View file

@ -29,6 +29,11 @@ pub mod widgets;
/// restoring state as part of your plugin's preset handling. You should not interact with this /// 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. /// 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. /// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this.
pub fn create_vizia_editor<F>( pub fn create_vizia_editor<F>(
vizia_state: Arc<ViziaState>, vizia_state: Arc<ViziaState>,
@ -60,7 +65,9 @@ pub enum ViziaTheming {
None, None,
/// Disable `nih_plug_vizia`'s custom theming. /// Disable `nih_plug_vizia`'s custom theming.
Builtin, 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] #[default]
Custom, Custom,
} }
@ -180,7 +187,6 @@ impl Editor for ViziaEditor {
if theming >= ViziaTheming::Custom { 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);
cx.set_default_font(assets::NOTO_SANS_LIGHT); cx.set_default_font(assets::NOTO_SANS_LIGHT);
cx.add_theme(include_str!("../assets/theme.css")); cx.add_theme(include_str!("../assets/theme.css"));

View file

@ -42,6 +42,9 @@ pub(crate) fn create(
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(cx);
Data { Data {
params: params.clone(), params: params.clone(),
} }

View file

@ -42,6 +42,9 @@ pub(crate) fn create(
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(cx);
Data { Data {
params: params.clone(), params: params.clone(),
} }

View file

@ -33,6 +33,9 @@ pub(crate) fn create(
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { 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); cx.add_theme(STYLE);
Data { Data {

View file

@ -42,6 +42,9 @@ pub(crate) fn create(
editor_state: Arc<ViziaState>, editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> { ) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| { create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(cx);
Data { Data {
params: params.clone(), params: params.clone(),
} }