Update vizia fork

This commit is contained in:
Robbert van der Helm
2022-04-07 18:44:37 +02:00
parent 4d8a515e9a
commit 5b03ae8d0e
7 changed files with 59 additions and 59 deletions

View File

@@ -13,8 +13,6 @@ nih_plug_assets = { git = "https://github.com/robbert-vdh/nih_plug_assets.git" }
baseview = { git = "https://github.com/robbert-vdh/baseview.git", branch = "feature/resize" }
crossbeam = "0.8"
# Vizia doesn't re-export this, we will
femtovg = { version = "0.3.0", default-features = false, features = ["image-loading"] }
# This fork contains changed for better keyboard modifier handling and DPI
# scaling, window scaling, and a lot more fixes and improvements
vizia = { git = "https://github.com/robbert-vdh/vizia.git", branch = "patched", default_features = false, features = ["baseview", "clipboard"] }

View File

@@ -8,7 +8,6 @@ use std::sync::Arc;
use vizia::{Application, Color, Context, Entity, Model, PropSet, WindowDescription};
// Re-export for convenience
pub use femtovg;
pub use vizia;
pub mod assets;

View File

@@ -78,17 +78,17 @@ impl GenericUi {
Ps: Params + 'static,
{
// Basic styling is done in the `theme.css` style sheet
Self.build2(cx, |cx| {
Self.build(cx, |cx| {
// Rust does not have existential types, otherwise we could have passed functions that
// map `params` to some `impl Param` and everything would have been a lot neater
let param_map = &*params.map(|params| params.as_ref().param_map()).get(cx);
let param_map = params.map(|params| params.as_ref().param_map()).get(cx);
for (_, param_ptr, _) in param_map {
let flags = unsafe { param_ptr.flags() };
if flags.contains(ParamFlags::HIDE_IN_GENERIC_UI) {
continue;
}
make_widget(cx, *param_ptr);
make_widget(cx, param_ptr);
}
})
}

View File

@@ -112,13 +112,13 @@ impl ParamSlider {
// this appraoch looks a bit jarring.
// We need to do a bit of a nasty and erase the lifetime bound by going through the raw
// GuiContext and a ParamPtr.
let param_ptr = *params
let param_ptr = params
.map(move |params| params_to_param(params).as_ptr())
.get(cx);
let default_value = *params
let default_value = params
.map(move |params| params_to_param(params).default_normalized_value())
.get(cx);
let step_count = *params
let step_count = params
.map(move |params| params_to_param(params).step_count())
.get(cx);
@@ -129,7 +129,7 @@ impl ParamSlider {
is_double_click: false,
granular_drag_start_x_value: None,
}
.build2(cx, move |cx| {
.build(cx, move |cx| {
ParamSliderInternal {
style: ParamSliderStyle::Centered,
text_input_active: false,
@@ -137,7 +137,7 @@ impl ParamSlider {
.build(cx);
Binding::new(cx, ParamSliderInternal::style, move |cx, style| {
let style = *style.get(cx);
let style = style.get(cx);
let draw_fill_from_default = matches!(style, ParamSliderStyle::Centered)
&& step_count.is_none()
&& (0.45..=0.55).contains(&default_value);
@@ -161,7 +161,7 @@ impl ParamSlider {
let normalized_param_value_lens =
params.map(move |params| params_to_param(params).normalized_value());
if *text_input_active.get(cx) {
if text_input_active.get(cx) {
Textbox::new(cx, param_display_value_lens)
.class("value-entry")
.on_submit(|cx, string| {
@@ -174,7 +174,10 @@ impl ParamSlider {
cx.emit(TextEvent::StartEdit);
cx.emit(TextEvent::SelectAll);
})
.child_space(Stretch(1.0))
// `.child_space(Stretch(1.0))` no longer works
.class("align_center")
.child_top(Stretch(1.0))
.child_bottom(Stretch(1.0))
.height(Stretch(1.0))
.width(Stretch(1.0));
} else {
@@ -186,7 +189,7 @@ impl ParamSlider {
.class("fill")
.height(Stretch(1.0))
.bind(normalized_param_value_lens, move |handle, value| {
let current_value = *value.get(handle.cx);
let current_value = value.get(handle.cx);
let (start_t, delta) = match style {
ParamSliderStyle::Centered
if draw_fill_from_default =>
@@ -264,6 +267,7 @@ impl ParamSlider {
)
.class("value")
.class("value--multiple")
.child_space(Stretch(1.0))
.height(Stretch(1.0))
.width(Stretch(1.0))
.hoverable(false);
@@ -277,6 +281,7 @@ impl ParamSlider {
Label::new(cx, param_display_value_lens)
.class("value")
.class("value--single")
.child_space(Stretch(1.0))
.height(Stretch(1.0))
.width(Stretch(1.0))
.hoverable(false);

View File

@@ -1,6 +1,5 @@
//! A super simple peak meter widget.
use femtovg::{Paint, Path};
use nih_plug::prelude::util;
use std::cell::Cell;
use std::time::Duration;
@@ -43,7 +42,7 @@ impl PeakMeter {
where
L: Lens<Target = f32>,
{
Self.build2(cx, |cx| {
Self.build(cx, |cx| {
// Now for something that may be illegal under some jurisdictions. If a hold time is
// given, then we'll build a new lens that always gives the held peak level for the
// current moment in time by mutating some values captured into the mapping closure.
@@ -77,7 +76,7 @@ impl PeakMeter {
level_dbfs,
peak_dbfs,
}
.build(cx)
.build(cx, |_| {})
.class("bar");
ZStack::new(cx, |cx| {
@@ -98,7 +97,7 @@ impl PeakMeter {
Element::new(cx).class("ticks__tick");
}
let font_size = *cx.style.font_size.get(cx.current).unwrap_or(&15.0)
let font_size = cx.style.font_size.get(cx.current).unwrap_or(&15.0)
* cx.style.dpi_factor as f32;
let label = if first_tick {
Label::new(cx, "-inf")
@@ -145,8 +144,8 @@ where
P: Lens<Target = f32>,
{
fn draw(&self, cx: &mut Context, canvas: &mut Canvas) {
let level_dbfs = *self.level_dbfs.get(cx);
let peak_dbfs = *self.peak_dbfs.get(cx);
let level_dbfs = self.level_dbfs.get(cx);
let peak_dbfs = self.peak_dbfs.get(cx);
// These basics are taken directly from the default implementation of this function
let entity = cx.current;
@@ -170,9 +169,9 @@ where
.cloned()
.unwrap_or_default();
let opacity = cx.cache.get_opacity(entity);
let mut background_color: femtovg::Color = background_color.into();
let mut background_color: vg::Color = background_color.into();
background_color.set_alphaf(background_color.a * opacity);
let mut border_color: femtovg::Color = border_color.into();
let mut border_color: vg::Color = border_color.into();
border_color.set_alphaf(border_color.a * opacity);
let border_width = match cx
@@ -187,7 +186,7 @@ where
_ => 0.0,
};
let mut path = Path::new();
let mut path = vg::Path::new();
{
let x = bounds.x + border_width / 2.0;
let y = bounds.y + border_width / 2.0;
@@ -202,7 +201,7 @@ where
}
// Fill with background color
let paint = Paint::color(background_color);
let paint = vg::Paint::color(background_color);
canvas.fill_path(&mut path, paint);
// And now for the fun stuff. We'll try to not overlap the border, but we'll draw that last
@@ -226,12 +225,12 @@ where
// femtovg draws paths centered on these coordinates, so in order to be pixel perfect we
// need to account for that. Otherwise the ticks will be 2px wide instead of 1px.
let mut path = Path::new();
let mut path = vg::Path::new();
path.move_to(tick_x as f32 + (dpi_scale / 2.0), bar_bounds.top());
path.line_to(tick_x as f32 + (dpi_scale / 2.0), bar_bounds.bottom());
let grayscale_color = 0.3 + ((1.0 - tick_fraction) * 0.5);
let mut paint = Paint::color(femtovg::Color::rgbaf(
let mut paint = vg::Paint::color(vg::Color::rgbaf(
grayscale_color,
grayscale_color,
grayscale_color,
@@ -251,17 +250,17 @@ where
// femtovg draws paths centered on these coordinates, so in order to be pixel perfect we
// need to account for that. Otherwise the ticks will be 2px wide instead of 1px.
let peak_x = db_to_x_coord(peak_dbfs);
let mut path = Path::new();
let mut path = vg::Path::new();
path.move_to(peak_x + (dpi_scale / 2.0), bar_bounds.top());
path.line_to(peak_x + (dpi_scale / 2.0), bar_bounds.bottom());
let mut paint = Paint::color(femtovg::Color::rgbaf(0.3, 0.3, 0.3, opacity));
let mut paint = vg::Paint::color(vg::Color::rgbaf(0.3, 0.3, 0.3, opacity));
paint.set_line_width(TICK_WIDTH * dpi_scale);
canvas.stroke_path(&mut path, paint);
}
// Draw border last
let mut paint = Paint::color(border_color);
let mut paint = vg::Paint::color(border_color);
paint.set_line_width(border_width);
canvas.stroke_path(&mut path, paint);
}

View File

@@ -1,6 +1,5 @@
//! A resize handle for uniformly scaling a plugin GUI.
use femtovg::{Paint, Path};
use vizia::*;
/// A resize handle placed at the bottom right of the window that lets you resize the window.
@@ -26,7 +25,7 @@ impl ResizeHandle {
start_scale_factor: 1.0,
start_physical_coordinates: (0.0, 0.0),
}
.build(cx)
.build(cx, |_| {})
}
}
@@ -125,9 +124,9 @@ impl View for ResizeHandle {
.cloned()
.unwrap_or_default();
let opacity = cx.cache.get_opacity(entity);
let mut background_color: femtovg::Color = background_color.into();
let mut background_color: vg::Color = background_color.into();
background_color.set_alphaf(background_color.a * opacity);
let mut border_color: femtovg::Color = border_color.into();
let mut border_color: vg::Color = border_color.into();
border_color.set_alphaf(border_color.a * opacity);
let border_width = match cx
@@ -142,7 +141,7 @@ impl View for ResizeHandle {
_ => 0.0,
};
let mut path = Path::new();
let mut path = vg::Path::new();
let x = bounds.x + border_width / 2.0;
let y = bounds.y + border_width / 2.0;
let w = bounds.w - border_width;
@@ -155,17 +154,17 @@ impl View for ResizeHandle {
path.close();
// Fill with background color
let paint = Paint::color(background_color);
let paint = vg::Paint::color(background_color);
canvas.fill_path(&mut path, paint);
// Borders are only supported to make debugging easier
let mut paint = Paint::color(border_color);
let mut paint = vg::Paint::color(border_color);
paint.set_line_width(border_width);
canvas.stroke_path(&mut path, paint);
// We'll draw a simple triangle, since we're going flat everywhere anyways and that style
// tends to not look too tacky
let mut path = Path::new();
let mut path = vg::Path::new();
let x = bounds.x + border_width / 2.0;
let y = bounds.y + border_width / 2.0;
let w = bounds.w - border_width;
@@ -191,15 +190,15 @@ impl View for ResizeHandle {
// path.move_to(x + (w / 3.0 * 1.5), y + h);
// path.close();
let mut color: femtovg::Color = cx
let mut color: vg::Color = cx
.style
.font_color
.get(entity)
.cloned()
.unwrap_or(crate::Color::white())
.unwrap_or(Color::white())
.into();
color.set_alphaf(color.a * opacity);
let paint = Paint::color(color);
let paint = vg::Paint::color(color);
canvas.fill_path(&mut path, paint);
}
}