1
0
Fork 0

Update Vizia assets for font selection changes

This commit is contained in:
Robbert van der Helm 2023-11-05 22:05:28 +01:00
parent 76ef4d0ff9
commit 5a2ef860b1
9 changed files with 62 additions and 85 deletions

View file

@ -18,7 +18,10 @@ state is to list breaking changes.
system has changed a lot since the last update, so plugin GUIs and stylesheets 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 may require small changes before they behave the same again. A summary of the
most important changes can be found in Vizia PR 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 - The `raw_window_handle` version used by NIH-plug has been updated to version
0.5.x. 0.5.x.

View file

@ -4,6 +4,11 @@
background-color: #fafafa; background-color: #fafafa;
color: #0a0a0a; color: #0a0a0a;
font-size: 15; 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 { scrollview > vstack {

View file

@ -6,54 +6,36 @@ 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::*;
/// The font name for Noto Sans Regular, needs to be registered using /// The font name for the Noto Sans font family. Comes in regular, thin, light and bold versions,
/// [`register_noto_sans_regular()`] first. /// with italic variations for each. Register the variations you want to use with
pub const NOTO_SANS_REGULAR: &str = "Noto Sans Regular"; /// [`register_noto_sans_regular()`], [`register_noto_sans_regular_italic()`],
/// The font name for Noto Sans Regular Italic, needs to be registered using /// [`register_noto_sans_thin()`], [`register_noto_sans_thin_italic()`],
/// [`register_noto_sans_regular_italic()`] first. /// [`register_noto_sans_light()`], [`register_noto_sans_light_italic()`],
pub const NOTO_SANS_REGULAR_ITALIC: &str = "Noto Sans Regular Italic"; /// [`register_noto_sans_bold()`], and [`register_noto_sans_bold_italic()`], Use the font weight and
/// The font name for Noto Sans Thin, needs to be registered using [`register_noto_sans_thin()`] /// font style properties to select a specific variation.
/// first. pub const NOTO_SANS: &str = "Noto Sans";
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";
pub fn register_noto_sans_regular(cx: &mut Context) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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);
} }

View file

@ -2,6 +2,7 @@
use baseview::{WindowHandle, WindowScalePolicy}; use baseview::{WindowHandle, WindowScalePolicy};
use crossbeam::atomic::AtomicCell; use crossbeam::atomic::AtomicCell;
use nih_plug::debug::*;
use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle}; use nih_plug::prelude::{Editor, GuiContext, ParentWindowHandle};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
@ -48,10 +49,10 @@ impl Editor for ViziaEditor {
let mut application = 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 theming >= ViziaTheming::Custom { if theming >= ViziaTheming::Custom {
// NOTE: vizia's font rendering looks way too dark and thick. Going one font weight cx.set_default_font(&[assets::NOTO_SANS]);
// lower seems to compensate for this. if let Err(err) = cx.add_stylesheet(include_style!("assets/theme.css")) {
cx.set_default_font(&[assets::NOTO_SANS_LIGHT]); nih_error!("Failed to load stylesheet: {err:?}")
cx.add_theme(include_str!("../assets/theme.css")); }
// There doesn't seem to be any way to bundle styles with a widget, so we'll always // 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 // include the style sheet for our custom widgets at context creation

View file

@ -6,40 +6,24 @@ 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 vizia::fonts; pub use vizia::fonts;
/// The font name for the Roboto (Regular) font, needs to be registered using [`register_roboto()`] /// The font name for the Roboto font family. Comes in regular, bold, and italic variations.
/// first. /// 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"; pub const ROBOTO: &str = "Roboto";
/// The font name for the Roboto Bold font, needs to be registered using [`register_roboto_bold()`] /// The font name for the icon font (tabler-icons), needs to be registered using
/// first. /// [`register_tabler_icons()`] first.
pub const ROBOTO_BOLD: &str = "Roboto Bold"; pub const TABLER_ICONS: &str = "tabler-icons";
/// 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";
pub fn register_roboto(cx: &mut Context) { 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) { 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) { pub fn register_roboto_italic(cx: &mut Context) {
cx.add_fonts_mem(&[fonts::ENTYPO]); cx.add_font_mem(fonts::ROBOTO_ITALIC);
} }
pub fn register_emoji(cx: &mut Context) { pub fn register_tabler_icons(cx: &mut Context) {
cx.add_fonts_mem(&[fonts::OPEN_SANS_EMOJI]); cx.add_font_mem(fonts::TABLER_ICONS);
}
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]);
} }

View file

@ -6,7 +6,7 @@
//! to copy the widgets and modify them to your personal taste. //! to copy the widgets and modify them to your personal taste.
use crossbeam::atomic::AtomicCell; use crossbeam::atomic::AtomicCell;
use nih_plug::nih_debug_assert_eq; use nih_plug::debug::*;
use nih_plug::prelude::{GuiContext, Param, ParamPtr}; use nih_plug::prelude::{GuiContext, Param, ParamPtr};
use std::sync::Arc; use std::sync::Arc;
use vizia::prelude::*; 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 /// 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()]. /// for you when using [`create_vizia_editor()`][super::create_vizia_editor()].
pub fn register_theme(cx: &mut Context) { 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 /// An event that updates a parameter's value. Since NIH-plug manages the parameters, interacting

View file

@ -51,9 +51,8 @@ pub(crate) fn create(
VStack::new(cx, |cx| { VStack::new(cx, |cx| {
Label::new(cx, "Crisp") Label::new(cx, "Crisp")
.font_family(vec![FamilyOwned::Name(String::from( .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
assets::NOTO_SANS_THIN, .font_weight(FontWeightKeyword::Thin)
))])
.font_size(30.0) .font_size(30.0)
.height(Pixels(50.0)) .height(Pixels(50.0))
.child_top(Stretch(1.0)) .child_top(Stretch(1.0))

View file

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use atomic_float::AtomicF32; use atomic_float::AtomicF32;
use nih_plug::nih_debug_assert_failure; use nih_plug::debug::*;
use nih_plug::prelude::{Editor, Plugin}; use nih_plug::prelude::{Editor, Plugin};
use nih_plug_vizia::vizia::prelude::*; use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::widgets::*; use nih_plug_vizia::widgets::*;
@ -68,7 +68,9 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option
assets::register_noto_sans_light(cx); assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(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); editor_data.clone().build(cx);
@ -86,9 +88,8 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option
fn top_bar(cx: &mut Context) { fn top_bar(cx: &mut Context) {
HStack::new(cx, |cx| { HStack::new(cx, |cx| {
Label::new(cx, "Diopser") Label::new(cx, "Diopser")
.font_family(vec![FamilyOwned::Name(String::from( .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
assets::NOTO_SANS_THIN, .font_weight(FontWeightKeyword::Thin)
))])
.font_size(37.0) .font_size(37.0)
.top(Pixels(2.0)) .top(Pixels(2.0))
.left(Pixels(8.0)) .left(Pixels(8.0))

View file

@ -83,7 +83,9 @@ pub(crate) fn create(editor_state: Arc<ViziaState>, editor_data: Data) -> Option
assets::register_noto_sans_light(cx); assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(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); editor_data.clone().build(cx);
@ -113,9 +115,8 @@ fn main_column(cx: &mut Context) {
HStack::new(cx, |cx| { HStack::new(cx, |cx| {
Label::new(cx, "Spectral Compressor") Label::new(cx, "Spectral Compressor")
.font_family(vec![FamilyOwned::Name(String::from( .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
assets::NOTO_SANS_THIN, .font_weight(FontWeightKeyword::Thin)
))])
.font_size(30.0) .font_size(30.0)
.on_mouse_down(|_, _| { .on_mouse_down(|_, _| {
// FIXME: On Windows this blocks, and while this is blocking a timer may // 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)) { fn make_column(cx: &mut Context, title: &str, contents: impl FnOnce(&mut Context)) {
VStack::new(cx, |cx| { VStack::new(cx, |cx| {
Label::new(cx, title) Label::new(cx, title)
.font_family(vec![FamilyOwned::Name(String::from( .font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
assets::NOTO_SANS_THIN, .font_weight(FontWeightKeyword::Thin)
))])
.font_size(23.0) .font_size(23.0)
.left(Stretch(1.0)) .left(Stretch(1.0))
// This should align nicely with the right edge of the slider // This should align nicely with the right edge of the slider