Update resize handle for upstream vizia changes
This commit is contained in:
parent
27763d2632
commit
193ec70b8a
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -18,10 +18,15 @@ 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). Notably, font handling and
|
[#291](https://github.com/vizia/vizia/pull/291). Some notable breaking changes
|
||||||
choosing between different variations of the same font (e.g. `Noto Sans`
|
include:
|
||||||
versus `Noto Sans Light` versus `Noto Sans Light Italic`) works very
|
|
||||||
differently now.
|
- 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.
|
||||||
|
- `ResizeHandle` now needs to be the last element in a GUI because of changes
|
||||||
|
to Vizia's event targetting mechanism.
|
||||||
|
|
||||||
- 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.
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
//! A resize handle for uniformly scaling a plugin GUI.
|
//! A resize handle for uniformly scaling a plugin GUI.
|
||||||
|
|
||||||
use vizia::cache::BoundingBox;
|
|
||||||
use vizia::prelude::*;
|
use vizia::prelude::*;
|
||||||
use vizia::vg;
|
use vizia::vg;
|
||||||
|
|
||||||
/// A resize handle placed at the bottom right of the window that lets you resize the window.
|
/// A resize handle placed at the bottom right of the window that lets you resize the window.
|
||||||
|
///
|
||||||
|
/// Needs to be the last element in the GUI because of how event targetting in Vizia works right
|
||||||
|
/// now.
|
||||||
pub struct ResizeHandle {
|
pub struct ResizeHandle {
|
||||||
/// Will be set to `true` if we're dragging the parameter. Resetting the parameter or entering a
|
/// Will be set to `true` if we're dragging the parameter. Resetting the parameter or entering a
|
||||||
/// text value should not initiate a drag.
|
/// text value should not initiate a drag.
|
||||||
|
@ -15,7 +17,7 @@ pub struct ResizeHandle {
|
||||||
start_scale_factor: f64,
|
start_scale_factor: f64,
|
||||||
/// The DPI factor when we started dragging, includes both the HiDPI scaling and the user
|
/// The DPI factor when we started dragging, includes both the HiDPI scaling and the user
|
||||||
/// scaling factor. This is kept track of separately to avoid accumulating rounding errors.
|
/// scaling factor. This is kept track of separately to avoid accumulating rounding errors.
|
||||||
start_dpi_factor: f64,
|
start_dpi_factor: f32,
|
||||||
/// The cursor position in physical screen pixels when the drag started.
|
/// The cursor position in physical screen pixels when the drag started.
|
||||||
start_physical_coordinates: (f32, f32),
|
start_physical_coordinates: (f32, f32),
|
||||||
}
|
}
|
||||||
|
@ -47,17 +49,17 @@ impl View for ResizeHandle {
|
||||||
// triangle
|
// triangle
|
||||||
if intersects_triangle(
|
if intersects_triangle(
|
||||||
cx.cache.get_bounds(cx.current()),
|
cx.cache.get_bounds(cx.current()),
|
||||||
(cx.mouse.cursorx, cx.mouse.cursory),
|
(cx.mouse().cursorx, cx.mouse().cursory),
|
||||||
) {
|
) {
|
||||||
cx.capture();
|
cx.capture();
|
||||||
cx.set_active(true);
|
cx.set_active(true);
|
||||||
|
|
||||||
self.drag_active = true;
|
self.drag_active = true;
|
||||||
self.start_scale_factor = cx.user_scale_factor();
|
self.start_scale_factor = cx.user_scale_factor();
|
||||||
self.start_dpi_factor = cx.style.dpi_factor;
|
self.start_dpi_factor = cx.scale_factor();
|
||||||
self.start_physical_coordinates = (
|
self.start_physical_coordinates = (
|
||||||
cx.mouse.cursorx * cx.style.dpi_factor as f32,
|
cx.mouse().cursorx * self.start_dpi_factor,
|
||||||
cx.mouse.cursory * cx.style.dpi_factor as f32,
|
cx.mouse().cursory * self.start_dpi_factor,
|
||||||
);
|
);
|
||||||
|
|
||||||
meta.consume();
|
meta.consume();
|
||||||
|
@ -86,10 +88,8 @@ impl View for ResizeHandle {
|
||||||
// to the same absoltue screen spotion.
|
// to the same absoltue screen spotion.
|
||||||
// TODO: This may start doing fun things when the window grows so large that it
|
// TODO: This may start doing fun things when the window grows so large that it
|
||||||
// gets pushed upwards or leftwards
|
// gets pushed upwards or leftwards
|
||||||
let (compensated_physical_x, compensated_physical_y) = (
|
let (compensated_physical_x, compensated_physical_y) =
|
||||||
x * self.start_dpi_factor as f32,
|
(x * self.start_dpi_factor, y * self.start_dpi_factor);
|
||||||
y * self.start_dpi_factor as f32,
|
|
||||||
);
|
|
||||||
let (start_physical_x, start_physical_y) = self.start_physical_coordinates;
|
let (start_physical_x, start_physical_y) = self.start_physical_coordinates;
|
||||||
let new_scale_factor = (self.start_scale_factor
|
let new_scale_factor = (self.start_scale_factor
|
||||||
* (compensated_physical_x / start_physical_x)
|
* (compensated_physical_x / start_physical_x)
|
||||||
|
@ -116,19 +116,14 @@ impl View for ResizeHandle {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let background_color = cx.background_color().copied().unwrap_or_default();
|
let background_color = cx.background_color();
|
||||||
let border_color = cx.border_color().copied().unwrap_or_default();
|
let border_color = cx.border_color();
|
||||||
let opacity = cx.opacity();
|
let opacity = cx.opacity();
|
||||||
let mut background_color: vg::Color = background_color.into();
|
let mut background_color: vg::Color = background_color.into();
|
||||||
background_color.set_alphaf(background_color.a * opacity);
|
background_color.set_alphaf(background_color.a * opacity);
|
||||||
let mut border_color: vg::Color = border_color.into();
|
let mut border_color: vg::Color = border_color.into();
|
||||||
border_color.set_alphaf(border_color.a * opacity);
|
border_color.set_alphaf(border_color.a * opacity);
|
||||||
|
let border_width = cx.border_width();
|
||||||
let border_width = match cx.border_width().unwrap_or_default() {
|
|
||||||
Units::Pixels(val) => val,
|
|
||||||
Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0),
|
|
||||||
_ => 0.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut path = vg::Path::new();
|
let mut path = vg::Path::new();
|
||||||
let x = bounds.x + border_width / 2.0;
|
let x = bounds.x + border_width / 2.0;
|
||||||
|
@ -144,12 +139,12 @@ impl View for ResizeHandle {
|
||||||
|
|
||||||
// Fill with background color
|
// Fill with background color
|
||||||
let paint = vg::Paint::color(background_color);
|
let paint = vg::Paint::color(background_color);
|
||||||
canvas.fill_path(&mut path, &paint);
|
canvas.fill_path(&path, &paint);
|
||||||
|
|
||||||
// Borders are only supported to make debugging easier
|
// Borders are only supported to make debugging easier
|
||||||
let mut paint = vg::Paint::color(border_color);
|
let mut paint = vg::Paint::color(border_color);
|
||||||
paint.set_line_width(border_width);
|
paint.set_line_width(border_width);
|
||||||
canvas.stroke_path(&mut path, &paint);
|
canvas.stroke_path(&path, &paint);
|
||||||
|
|
||||||
// We'll draw a simple triangle, since we're going flat everywhere anyways and that style
|
// We'll draw a simple triangle, since we're going flat everywhere anyways and that style
|
||||||
// tends to not look too tacky
|
// tends to not look too tacky
|
||||||
|
@ -179,10 +174,10 @@ impl View for ResizeHandle {
|
||||||
// path.move_to(x + (w / 3.0 * 1.5), y + h);
|
// path.move_to(x + (w / 3.0 * 1.5), y + h);
|
||||||
// path.close();
|
// path.close();
|
||||||
|
|
||||||
let mut color: vg::Color = cx.font_color().copied().unwrap_or(Color::white()).into();
|
let mut color: vg::Color = cx.font_color().into();
|
||||||
color.set_alphaf(color.a * opacity);
|
color.set_alphaf(color.a * opacity);
|
||||||
let paint = vg::Paint::color(color);
|
let paint = vg::Paint::color(color);
|
||||||
canvas.fill_path(&mut path, &paint);
|
canvas.fill_path(&path, &paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,6 @@ pub(crate) fn create(
|
||||||
}
|
}
|
||||||
.build(cx);
|
.build(cx);
|
||||||
|
|
||||||
ResizeHandle::new(cx);
|
|
||||||
|
|
||||||
VStack::new(cx, |cx| {
|
VStack::new(cx, |cx| {
|
||||||
Label::new(cx, "Crisp")
|
Label::new(cx, "Crisp")
|
||||||
.font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
|
.font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
|
||||||
|
@ -71,5 +69,7 @@ pub(crate) fn create(
|
||||||
.row_between(Pixels(0.0))
|
.row_between(Pixels(0.0))
|
||||||
.child_left(Stretch(1.0))
|
.child_left(Stretch(1.0))
|
||||||
.child_right(Stretch(1.0));
|
.child_right(Stretch(1.0));
|
||||||
|
|
||||||
|
ResizeHandle::new(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,13 +74,13 @@ pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option
|
||||||
|
|
||||||
editor_data.clone().build(cx);
|
editor_data.clone().build(cx);
|
||||||
|
|
||||||
ResizeHandle::new(cx);
|
|
||||||
|
|
||||||
VStack::new(cx, |cx| {
|
VStack::new(cx, |cx| {
|
||||||
top_bar(cx);
|
top_bar(cx);
|
||||||
spectrum_analyzer(cx);
|
spectrum_analyzer(cx);
|
||||||
other_params(cx);
|
other_params(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ResizeHandle::new(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ pub(crate) fn create(
|
||||||
}
|
}
|
||||||
.build(cx);
|
.build(cx);
|
||||||
|
|
||||||
ResizeHandle::new(cx);
|
|
||||||
|
|
||||||
VStack::new(cx, |cx| {
|
VStack::new(cx, |cx| {
|
||||||
Label::new(cx, "Gain GUI")
|
Label::new(cx, "Gain GUI")
|
||||||
.font_family(vec![FamilyOwned::Name(String::from(
|
.font_family(vec![FamilyOwned::Name(String::from(
|
||||||
|
@ -64,5 +62,7 @@ pub(crate) fn create(
|
||||||
.row_between(Pixels(0.0))
|
.row_between(Pixels(0.0))
|
||||||
.child_left(Stretch(1.0))
|
.child_left(Stretch(1.0))
|
||||||
.child_right(Stretch(1.0));
|
.child_right(Stretch(1.0));
|
||||||
|
|
||||||
|
ResizeHandle::new(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,8 +89,6 @@ pub(crate) fn create(editor_state: Arc<ViziaState>, editor_data: Data) -> Option
|
||||||
|
|
||||||
editor_data.clone().build(cx);
|
editor_data.clone().build(cx);
|
||||||
|
|
||||||
ResizeHandle::new(cx);
|
|
||||||
|
|
||||||
HStack::new(cx, |cx| {
|
HStack::new(cx, |cx| {
|
||||||
main_column(cx);
|
main_column(cx);
|
||||||
|
|
||||||
|
@ -102,6 +100,8 @@ pub(crate) fn create(editor_state: Arc<ViziaState>, editor_data: Data) -> Option
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ResizeHandle::new(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue