1
0
Fork 0

Update for new vizia resize patch

This version uses a property on the context instead of events. This gets
rid of all of the problems and complexity of the previous
implementation.
This commit is contained in:
Robbert van der Helm 2022-03-29 00:02:11 +02:00
parent 4195105e43
commit 7b9eff456c
4 changed files with 24 additions and 43 deletions

8
Cargo.lock generated
View file

@ -3459,7 +3459,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "vizia" name = "vizia"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#50b8f6e8438fd0eaa3b0911839d768bd70756c49" source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#b58859c5e8befa055cc80a11e7bef32d8b311f75"
dependencies = [ dependencies = [
"vizia_baseview", "vizia_baseview",
"vizia_core", "vizia_core",
@ -3468,7 +3468,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_baseview" name = "vizia_baseview"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#50b8f6e8438fd0eaa3b0911839d768bd70756c49" source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#b58859c5e8befa055cc80a11e7bef32d8b311f75"
dependencies = [ dependencies = [
"baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)", "baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)",
"femtovg", "femtovg",
@ -3480,7 +3480,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_core" name = "vizia_core"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#50b8f6e8438fd0eaa3b0911839d768bd70756c49" source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#b58859c5e8befa055cc80a11e7bef32d8b311f75"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"copypasta", "copypasta",
@ -3503,7 +3503,7 @@ dependencies = [
[[package]] [[package]]
name = "vizia_derive" name = "vizia_derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#50b8f6e8438fd0eaa3b0911839d768bd70756c49" source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#b58859c5e8befa055cc80a11e7bef32d8b311f75"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -99,44 +99,32 @@ impl Model for WindowModel {
fn event(&mut self, cx: &mut vizia::Context, event: &mut vizia::Event) { fn event(&mut self, cx: &mut vizia::Context, event: &mut vizia::Event) {
if let Some(window_event) = event.message.downcast() { if let Some(window_event) = event.message.downcast() {
match *window_event { match *window_event {
WindowEvent::ResizeWindow(logical_width, logical_height) => { // This gets fired whenever the inner window gets resized
let logical_size = WindowEvent::WindowResize => {
(logical_width.round() as u32, logical_height.round() as u32); let logical_size = (cx.window_size.width, cx.window_size.height);
let old_size @ (old_logical_width, old_logical_height) = let old_logical_size @ (old_logical_width, old_logical_height) =
self.vizia_state.size.load(); self.vizia_state.size.load();
let scale_factor = cx.user_scale_factor;
let old_user_scale_factor = self.vizia_state.scale_factor.load();
// Don't do anything if the current size already matches the new size, this // Don't do anything if the current size already matches the new size, this
// could otherwise also cause a feedback loop on resize failure // could otherwise also cause a feedback loop on resize failure
if logical_size == old_size { if logical_size == old_logical_size && scale_factor == old_user_scale_factor {
return; return;
} }
// Our embedded baseview window will have already been resized. If the host does // Our embedded baseview window will have already been resized. If the host does
// not accept our new size, then we'll try to undo that // not accept our new size, then we'll try to undo that
self.vizia_state.size.store(logical_size); self.vizia_state.size.store(logical_size);
self.vizia_state.scale_factor.store(scale_factor);
if !self.context.request_resize() { if !self.context.request_resize() {
self.vizia_state.size.store(old_size); self.vizia_state.size.store(old_logical_size);
cx.emit(WindowEvent::ResizeWindow(
old_logical_width as f32,
old_logical_height as f32,
));
}
}
WindowEvent::SetScale(user_scale_factor) => {
let old_user_scale_factor = self.vizia_state.scale_factor.load();
// Don't do anything if the current scale already matches the new scale
if user_scale_factor == old_user_scale_factor {
return;
}
// This works the same as the `ResizeWindow` handler. The actual window size
// reported to the host gets calculated from a combination of the window's
// logical size (before user scaling) and the user scale factor.
self.vizia_state.scale_factor.store(user_scale_factor);
if !self.context.request_resize() {
self.vizia_state.scale_factor.store(old_user_scale_factor); self.vizia_state.scale_factor.store(old_user_scale_factor);
cx.emit(WindowEvent::SetScale(old_user_scale_factor));
// This will cause the window's size to be reverted on the next event loop
cx.window_size.width = old_logical_width;
cx.window_size.height = old_logical_height;
cx.user_scale_factor = old_user_scale_factor;
} }
} }

View file

@ -3,8 +3,6 @@
use femtovg::{Paint, Path}; use femtovg::{Paint, Path};
use vizia::*; use vizia::*;
use super::WindowModel;
/// 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.
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
@ -44,9 +42,8 @@ impl View for ResizeHandle {
cx.capture(); cx.capture();
cx.current.set_active(cx, true); cx.current.set_active(cx, true);
let vizia_state = WindowModel::vizia_state.get(cx);
self.drag_active = true; self.drag_active = true;
self.start_scale_factor = vizia_state.user_scale_factor(); self.start_scale_factor = cx.user_scale_factor;
self.start_physical_coordinates = ( self.start_physical_coordinates = (
cx.mouse.cursorx * cx.style.dpi_factor as f32, cx.mouse.cursorx * cx.style.dpi_factor as f32,
cx.mouse.cursory * cx.style.dpi_factor as f32, cx.mouse.cursory * cx.style.dpi_factor as f32,
@ -63,8 +60,6 @@ impl View for ResizeHandle {
WindowEvent::MouseMove(x, y) => { WindowEvent::MouseMove(x, y) => {
// TODO: Filter the hover color and dragging to the actual triangle // TODO: Filter the hover color and dragging to the actual triangle
if self.drag_active { if self.drag_active {
let vizia_state = WindowModel::vizia_state.get(cx);
// We need to convert our measurements into physical pixels relative to the // We need to convert our measurements into physical pixels relative to the
// initial drag to be able to keep a consistent ratio. This 'relative to the // initial drag to be able to keep a consistent ratio. This 'relative to the
// start' bit is important because otherwise we would be comparing the // start' bit is important because otherwise we would be comparing the
@ -82,9 +77,9 @@ impl View for ResizeHandle {
as f64) as f64)
// Prevent approaching zero here because uh // Prevent approaching zero here because uh
.max(0.25); .max(0.25);
if new_scale_factor != vizia_state.user_scale_factor() {
cx.emit(WindowEvent::SetScale(new_scale_factor)); // If this is different then the window will automatically be resized at the end of the frame
} cx.user_scale_factor = new_scale_factor;
} }
} }
_ => {} _ => {}

View file

@ -30,7 +30,7 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
fn request_resize(&self) -> bool { fn request_resize(&self) -> bool {
// Bitwig and the CLAP test host require this resize to be done from the main thread, so // Bitwig and the CLAP test host require this resize to be done from the main thread, so
// we'll use a channel as a substitute for a promise here. // we'll use a channel as a substitute for a promise here.
let (result_sender, _result_receiver) = channel::bounded(1); let (result_sender, result_receiver) = channel::bounded(1);
if !self if !self
.wrapper .wrapper
.do_maybe_async(Task::RequestResize(result_sender)) .do_maybe_async(Task::RequestResize(result_sender))
@ -43,9 +43,7 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
// rapid succession because the X11 GUI thread is not the same as the host's GUI // rapid succession because the X11 GUI thread is not the same as the host's GUI
// thread and both Bitwig and CLAP will reject (or outright SIGABRT) if this gets // thread and both Bitwig and CLAP will reject (or outright SIGABRT) if this gets
// called from any other thread // called from any other thread
// result_receiver.recv().expect("Main thread died?") result_receiver.recv().expect("Main thread died?")
true
} }
// All of these functions are supposed to be called from the main thread, so we'll put some // All of these functions are supposed to be called from the main thread, so we'll put some