1
0
Fork 0

Update Vizia

Text sizes are still broken.
This commit is contained in:
Robbert van der Helm 2022-04-24 18:12:06 +02:00
parent 084d34fe5c
commit 9ab07cf4eb
4 changed files with 211 additions and 219 deletions

8
Cargo.lock generated
View file

@ -3498,7 +3498,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vizia"
version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#656a7ee5bc720c6eea23b46c8480ecc9ee826da9"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#163ae29c603c51371a8a98cca3f4434f7bf38d37"
dependencies = [
"vizia_baseview",
"vizia_core",
@ -3507,7 +3507,7 @@ dependencies = [
[[package]]
name = "vizia_baseview"
version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#656a7ee5bc720c6eea23b46c8480ecc9ee826da9"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#163ae29c603c51371a8a98cca3f4434f7bf38d37"
dependencies = [
"baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)",
"femtovg",
@ -3519,7 +3519,7 @@ dependencies = [
[[package]]
name = "vizia_core"
version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#656a7ee5bc720c6eea23b46c8480ecc9ee826da9"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#163ae29c603c51371a8a98cca3f4434f7bf38d37"
dependencies = [
"bitflags",
"copypasta",
@ -3544,7 +3544,7 @@ dependencies = [
[[package]]
name = "vizia_derive"
version = "0.1.0"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#656a7ee5bc720c6eea23b46c8480ecc9ee826da9"
source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#163ae29c603c51371a8a98cca3f4434f7bf38d37"
dependencies = [
"proc-macro2",
"quote",

View file

@ -77,42 +77,39 @@ pub(crate) struct WindowModel {
impl Model for ParamModel {
fn event(&mut self, _cx: &mut vizia::Context, event: &mut vizia::Event) {
if let Some(param_event) = event.message.downcast() {
// `ParamEvent` gets downcast into `NormalizedParamEvent` by the `Message`
// implementation below
match *param_event {
event.map(|param_event, _| match *param_event {
RawParamEvent::BeginSetParameter(p) => unsafe {
self.context.raw_begin_set_parameter(p)
},
RawParamEvent::SetParameterNormalized(p, v) => unsafe {
self.context.raw_set_parameter_normalized(p, v)
},
RawParamEvent::EndSetParameter(p) => unsafe {
self.context.raw_end_set_parameter(p)
},
}
}
RawParamEvent::EndSetParameter(p) => unsafe { self.context.raw_end_set_parameter(p) },
});
}
}
impl Model for WindowModel {
fn event(&mut self, cx: &mut vizia::Context, event: &mut vizia::Event) {
// This gets fired whenever the inner window gets resized
if let Some(WindowEvent::WindowResize) = event.message.downcast() {
event.map(|window_event, _| {
if let WindowEvent::WindowResize = window_event {
let logical_size = (cx.window_size.width, cx.window_size.height);
let old_logical_size @ (old_logical_width, old_logical_height) =
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
// could otherwise also cause a feedback loop on resize failure
// Don't do anything if the current size already matches the new size, this could
// otherwise also cause a feedback loop on resize failure
if logical_size == old_logical_size && scale_factor == old_user_scale_factor {
return;
}
// 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
// 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
self.vizia_state.size.store(logical_size);
self.vizia_state.scale_factor.store(scale_factor);
if !self.context.request_resize() {
@ -125,6 +122,7 @@ impl Model for WindowModel {
cx.user_scale_factor = old_user_scale_factor;
}
}
});
}
}

View file

@ -78,16 +78,16 @@ enum ParamSliderInternalEvent {
impl Model for ParamSliderInternal {
fn event(&mut self, _cx: &mut Context, event: &mut Event) {
if let Some(param_slider_internal_event) = event.message.downcast() {
match param_slider_internal_event {
event.map(
|param_slider_internal_event, _| match param_slider_internal_event {
ParamSliderInternalEvent::SetStyle(style) => self.style = *style,
ParamSliderInternalEvent::SetTextInputActive(active) => {
// When this gets set to `true` the textbox widget will be created, and when it
// gets created we'll focus it and select all text
self.text_input_active = *active;
}
}
}
},
);
}
}
@ -350,8 +350,7 @@ impl View for ParamSlider {
}
fn event(&mut self, cx: &mut Context, event: &mut Event) {
if let Some(param_slider_event) = event.message.downcast() {
match param_slider_event {
event.map(|param_slider_event, _| match param_slider_event {
ParamSliderEvent::CancelTextInput => {
cx.emit(ParamSliderInternalEvent::SetTextInputActive(false));
cx.current.set_active(cx, false);
@ -367,11 +366,9 @@ impl View for ParamSlider {
cx.emit(ParamSliderInternalEvent::SetTextInputActive(false));
}
}
}
});
if let Some(window_event) = event.message.downcast() {
match window_event {
event.map(|window_event, _| match window_event {
WindowEvent::MouseDown(MouseButton::Left) => {
if cx.modifiers.alt() {
// ALt+Click brings up a text entry dialog
@ -393,8 +390,8 @@ impl View for ParamSlider {
cx.focused = cx.current;
cx.current.set_active(cx, true);
// When holding down shift while clicking on a parameter we want to
// granuarly edit the parameter without jumping to a new value
// When holding down shift while clicking on a parameter we want to granuarly
// edit the parameter without jumping to a new value
cx.emit(RawParamEvent::BeginSetParameter(self.param_ptr));
if cx.modifiers.shift() {
self.granular_drag_start_x_value = Some((cx.mouse.cursorx, unsafe {
@ -409,13 +406,12 @@ impl View for ParamSlider {
}
}
// We'll set this here because weird things like Alt+double click should not
// cause the next click to become a reset
// We'll set this here because weird things like Alt+double click should not cause
// the next click to become a reset
self.is_double_click = false;
}
WindowEvent::MouseDoubleClick(MouseButton::Left) => {
// Vizia will send a regular mouse down after this, so we'll handle the reset
// there
// Vizia will send a regular mouse down after this, so we'll handle the reset there
self.is_double_click = true;
}
WindowEvent::MouseUp(MouseButton::Left) => {
@ -470,8 +466,7 @@ impl View for ParamSlider {
}
}
_ => {}
}
}
});
}
}

View file

@ -35,8 +35,7 @@ impl View for ResizeHandle {
}
fn event(&mut self, cx: &mut Context, event: &mut Event) {
if let Some(window_event) = event.message.downcast() {
match *window_event {
event.map(|window_event, meta| match *window_event {
WindowEvent::MouseDown(MouseButton::Left) => {
// The handle is a triangle, so we should also interac twith it as if it was a
// triangle
@ -54,7 +53,7 @@ impl View for ResizeHandle {
cx.mouse.cursory * cx.style.dpi_factor as f32,
);
event.consume();
meta.consume();
} else {
// TODO: The click should be forwarded to the element behind the triangle
}
@ -76,10 +75,10 @@ impl View for ResizeHandle {
if self.drag_active {
// 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
// start' bit is important because otherwise we would be comparing the
// position to the same absoltue screen spotion.
// TODO: This may start doing fun things when the window grows so large that
// it gets pushed upwards or leftwards
// start' bit is important because otherwise we would be comparing the position
// to the same absoltue screen spotion.
// TODO: This may start doing fun things when the window grows so large that it
// gets pushed upwards or leftwards
let (compensated_physical_x, compensated_physical_y) = (
x * self.start_scale_factor as f32,
y * self.start_scale_factor as f32,
@ -92,13 +91,13 @@ impl View for ResizeHandle {
// Prevent approaching zero here because uh
.max(0.25);
// If this is different then the window will automatically be resized at the end of the frame
// If this is different then the window will automatically be resized at the end
// of the frame
cx.user_scale_factor = new_scale_factor;
}
}
_ => {}
}
}
});
}
fn draw(&self, cx: &mut DrawContext, canvas: &mut Canvas) {