From 5a2ef860b16c4d75126af677a79dcba6d7635334 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 5 Nov 2023 22:05:28 +0100 Subject: [PATCH] Update Vizia assets for font selection changes --- CHANGELOG.md | 5 ++- nih_plug_vizia/assets/theme.css | 5 +++ nih_plug_vizia/src/assets.rs | 50 ++++++++--------------- nih_plug_vizia/src/editor.rs | 9 ++-- nih_plug_vizia/src/vizia_assets.rs | 42 ++++++------------- nih_plug_vizia/src/widgets.rs | 6 ++- plugins/crisp/src/editor.rs | 5 +-- plugins/diopser/src/editor.rs | 11 ++--- plugins/spectral_compressor/src/editor.rs | 14 +++---- 9 files changed, 62 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4c1daa..f7cc71b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,10 @@ state is to list breaking changes. system has changed a lot since the last update, so plugin GUIs and stylesheets may require small changes before they behave the same again. A summary of the most important changes can be found in Vizia PR - [#291](https://github.com/vizia/vizia/pull/291). + [#291](https://github.com/vizia/vizia/pull/291). Notably, font handling and + choosing between different variations of the same font (e.g. `Noto Sans` + versus `Noto Sans Light` versus `Noto Sans Light Italic`) works very + differently now. - The `raw_window_handle` version used by NIH-plug has been updated to version 0.5.x. diff --git a/nih_plug_vizia/assets/theme.css b/nih_plug_vizia/assets/theme.css index 8cfffc11..73a8a954 100644 --- a/nih_plug_vizia/assets/theme.css +++ b/nih_plug_vizia/assets/theme.css @@ -4,6 +4,11 @@ background-color: #fafafa; color: #0a0a0a; font-size: 15; + /* + * NOTE: vizia's font rendering looks way too dark and thick. Going one font + * weight lower seems to compensate for this. + */ + font-weight: light; } scrollview > vstack { diff --git a/nih_plug_vizia/src/assets.rs b/nih_plug_vizia/src/assets.rs index 7f0c40e3..36baed92 100644 --- a/nih_plug_vizia/src/assets.rs +++ b/nih_plug_vizia/src/assets.rs @@ -6,54 +6,36 @@ use vizia::prelude::*; // This module provides a re-export and simple font wrappers around the re-exported fonts. pub use nih_plug_assets::*; -/// 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. -// NOTE: I'd expect this to be an alias for Noto Sans Regular but this is what cosmic-text thinks -// the font is called -pub const NOTO_SANS_BOLD: &str = "Noto Sans"; -/// 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 Italic"; +/// The font name for the Noto Sans font family. Comes in regular, thin, light and bold versions, +/// with italic variations for each. Register the variations you want to use with +/// [`register_noto_sans_regular()`], [`register_noto_sans_regular_italic()`], +/// [`register_noto_sans_thin()`], [`register_noto_sans_thin_italic()`], +/// [`register_noto_sans_light()`], [`register_noto_sans_light_italic()`], +/// [`register_noto_sans_bold()`], and [`register_noto_sans_bold_italic()`], Use the font weight and +/// font style properties to select a specific variation. +pub const NOTO_SANS: &str = "Noto Sans"; pub fn register_noto_sans_regular(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_REGULAR]); + cx.add_font_mem(fonts::NOTO_SANS_REGULAR); } pub fn register_noto_sans_regular_italic(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_REGULAR_ITALIC]); + cx.add_font_mem(fonts::NOTO_SANS_REGULAR_ITALIC); } pub fn register_noto_sans_thin(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_THIN]); + cx.add_font_mem(fonts::NOTO_SANS_THIN); } pub fn register_noto_sans_thin_italic(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_THIN_ITALIC]); + cx.add_font_mem(fonts::NOTO_SANS_THIN_ITALIC); } pub fn register_noto_sans_light(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_LIGHT]); + cx.add_font_mem(fonts::NOTO_SANS_LIGHT); } pub fn register_noto_sans_light_italic(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_LIGHT_ITALIC]); + cx.add_font_mem(fonts::NOTO_SANS_LIGHT_ITALIC); } pub fn register_noto_sans_bold(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_BOLD]); + cx.add_font_mem(fonts::NOTO_SANS_BOLD); } pub fn register_noto_sans_bold_italic(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::NOTO_SANS_BOLD_ITALIC]); + cx.add_font_mem(fonts::NOTO_SANS_BOLD_ITALIC); } diff --git a/nih_plug_vizia/src/editor.rs b/nih_plug_vizia/src/editor.rs index b326ea9f..a285d868 100644 --- a/nih_plug_vizia/src/editor.rs +++ b/nih_plug_vizia/src/editor.rs @@ -2,6 +2,7 @@ use baseview::{WindowHandle, WindowScalePolicy}; use crossbeam::atomic::AtomicCell; +use nih_plug::debug::*; use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -48,10 +49,10 @@ impl Editor for ViziaEditor { let mut application = Application::new(move |cx| { // Set some default styles to match the iced integration 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. - cx.set_default_font(&[assets::NOTO_SANS_LIGHT]); - cx.add_theme(include_str!("../assets/theme.css")); + cx.set_default_font(&[assets::NOTO_SANS]); + if let Err(err) = cx.add_stylesheet(include_style!("assets/theme.css")) { + nih_error!("Failed to load stylesheet: {err:?}") + } // There doesn't seem to be any way to bundle styles with a widget, so we'll always // include the style sheet for our custom widgets at context creation diff --git a/nih_plug_vizia/src/vizia_assets.rs b/nih_plug_vizia/src/vizia_assets.rs index c3ef049a..5237e0ab 100644 --- a/nih_plug_vizia/src/vizia_assets.rs +++ b/nih_plug_vizia/src/vizia_assets.rs @@ -6,40 +6,24 @@ use vizia::prelude::*; // This module provides a re-export and simple font wrappers around the re-exported fonts. pub use vizia::fonts; -/// The font name for the Roboto (Regular) font, needs to be registered using [`register_roboto()`] -/// first. +/// The font name for the Roboto font family. Comes in regular, bold, and italic variations. +/// Register the variations you want to use with [`register_roboto()`], [`register_roboto_bold()`], +/// and [`register_roboto_italic()`] first. Use the font weight and font style properties to select +/// a specific variation. pub const ROBOTO: &str = "Roboto"; -/// The font name for the Roboto Bold font, needs to be registered using [`register_roboto_bold()`] -/// first. -pub const ROBOTO_BOLD: &str = "Roboto Bold"; -/// The font name for the icon font (Entypo), needs to be registered using [`register_icons()`] -/// first. -pub const ICONS: &str = "Entypo"; -/// The font name for the emoji font (Open Sans Eomji), needs to be registered using -/// [`register_emoji()`] first. -pub const EMOJI: &str = "OpenSansEmoji"; -/// The font name for the arabic font (Amiri Regular), needs to be registered using -/// [`register_arabic()`] first. -pub const ARABIC: &str = "Amiri"; -/// The font name for the material font (Material Icons), needs to be registered using -/// [`register_material()`] first. -pub const MATERIAL: &str = "Material Icons"; +/// The font name for the icon font (tabler-icons), needs to be registered using +/// [`register_tabler_icons()`] first. +pub const TABLER_ICONS: &str = "tabler-icons"; pub fn register_roboto(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::ROBOTO_REGULAR]); + cx.add_font_mem(fonts::ROBOTO_REGULAR); } pub fn register_roboto_bold(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::ROBOTO_BOLD]); + cx.add_font_mem(fonts::ROBOTO_BOLD); } -pub fn register_icons(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::ENTYPO]); +pub fn register_roboto_italic(cx: &mut Context) { + cx.add_font_mem(fonts::ROBOTO_ITALIC); } -pub fn register_emoji(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::OPEN_SANS_EMOJI]); -} -pub fn register_arabic(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::AMIRI_REGULAR]); -} -pub fn register_material(cx: &mut Context) { - cx.add_fonts_mem(&[fonts::MATERIAL_ICONS_REGULAR]); +pub fn register_tabler_icons(cx: &mut Context) { + cx.add_font_mem(fonts::TABLER_ICONS); } diff --git a/nih_plug_vizia/src/widgets.rs b/nih_plug_vizia/src/widgets.rs index ea7a5652..01da5009 100644 --- a/nih_plug_vizia/src/widgets.rs +++ b/nih_plug_vizia/src/widgets.rs @@ -6,7 +6,7 @@ //! to copy the widgets and modify them to your personal taste. use crossbeam::atomic::AtomicCell; -use nih_plug::nih_debug_assert_eq; +use nih_plug::debug::*; use nih_plug::prelude::{GuiContext, Param, ParamPtr}; use std::sync::Arc; use vizia::prelude::*; @@ -30,7 +30,9 @@ pub use resize_handle::ResizeHandle; /// Register the default theme for the widgets exported by this module. This is automatically called /// for you when using [`create_vizia_editor()`][super::create_vizia_editor()]. pub fn register_theme(cx: &mut Context) { - cx.add_theme(include_str!("../assets/widgets.css")); + if let Err(err) = cx.add_stylesheet(include_style!("assets/widgets.css")) { + nih_error!("Failed to load stylesheet: {err:?}") + } } /// An event that updates a parameter's value. Since NIH-plug manages the parameters, interacting diff --git a/plugins/crisp/src/editor.rs b/plugins/crisp/src/editor.rs index 28db42ed..827d7ac0 100644 --- a/plugins/crisp/src/editor.rs +++ b/plugins/crisp/src/editor.rs @@ -51,9 +51,8 @@ pub(crate) fn create( VStack::new(cx, |cx| { Label::new(cx, "Crisp") - .font_family(vec![FamilyOwned::Name(String::from( - assets::NOTO_SANS_THIN, - ))]) + .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))]) + .font_weight(FontWeightKeyword::Thin) .font_size(30.0) .height(Pixels(50.0)) .child_top(Stretch(1.0)) diff --git a/plugins/diopser/src/editor.rs b/plugins/diopser/src/editor.rs index b8a462f0..e8cebb8e 100644 --- a/plugins/diopser/src/editor.rs +++ b/plugins/diopser/src/editor.rs @@ -15,7 +15,7 @@ // along with this program. If not, see . use atomic_float::AtomicF32; -use nih_plug::nih_debug_assert_failure; +use nih_plug::debug::*; use nih_plug::prelude::{Editor, Plugin}; use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::widgets::*; @@ -68,7 +68,9 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc) -> Option assets::register_noto_sans_light(cx); assets::register_noto_sans_thin(cx); - cx.add_theme(include_str!("editor/theme.css")); + if let Err(err) = cx.add_stylesheet(include_style!("src/editor/theme.css")) { + nih_error!("Failed to load stylesheet: {err:?}") + } editor_data.clone().build(cx); @@ -86,9 +88,8 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc) -> Option fn top_bar(cx: &mut Context) { HStack::new(cx, |cx| { Label::new(cx, "Diopser") - .font_family(vec![FamilyOwned::Name(String::from( - assets::NOTO_SANS_THIN, - ))]) + .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))]) + .font_weight(FontWeightKeyword::Thin) .font_size(37.0) .top(Pixels(2.0)) .left(Pixels(8.0)) diff --git a/plugins/spectral_compressor/src/editor.rs b/plugins/spectral_compressor/src/editor.rs index 73abb339..3b8a92d7 100644 --- a/plugins/spectral_compressor/src/editor.rs +++ b/plugins/spectral_compressor/src/editor.rs @@ -83,7 +83,9 @@ pub(crate) fn create(editor_state: Arc, editor_data: Data) -> Option assets::register_noto_sans_light(cx); assets::register_noto_sans_thin(cx); - cx.add_theme(include_str!("editor/theme.css")); + if let Err(err) = cx.add_stylesheet(include_style!("src/editor/theme.css")) { + nih_error!("Failed to load stylesheet: {err:?}") + } editor_data.clone().build(cx); @@ -113,9 +115,8 @@ fn main_column(cx: &mut Context) { HStack::new(cx, |cx| { Label::new(cx, "Spectral Compressor") - .font_family(vec![FamilyOwned::Name(String::from( - assets::NOTO_SANS_THIN, - ))]) + .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))]) + .font_weight(FontWeightKeyword::Thin) .font_size(30.0) .on_mouse_down(|_, _| { // FIXME: On Windows this blocks, and while this is blocking a timer may @@ -244,9 +245,8 @@ fn analyzer_column(cx: &mut Context) { fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context)) { VStack::new(cx, |cx| { Label::new(cx, title) - .font_family(vec![FamilyOwned::Name(String::from( - assets::NOTO_SANS_THIN, - ))]) + .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))]) + .font_weight(FontWeightKeyword::Thin) .font_size(23.0) .left(Stretch(1.0)) // This should align nicely with the right edge of the slider