1
0
Fork 0

Update Diopser for upstream vizia changes

This commit is contained in:
Robbert van der Helm 2023-11-15 00:01:51 +01:00
parent 455f651d39
commit b702b9a55e
6 changed files with 105 additions and 138 deletions

View file

@ -123,6 +123,7 @@ fn top_bar(cx: &mut Context) {
.for_bypass()
.left(Pixels(10.0));
})
.width(Auto)
.child_space(Pixels(10.0))
.left(Stretch(1.0));
})
@ -137,10 +138,7 @@ fn spectrum_analyzer(cx: &mut Context) {
HStack::new(cx, |cx| {
Label::new(cx, "Resonance")
.font_size(18.0)
// HACK: Rotating doesn't really work in vizia, but with text wrap disabled this at
// least visually does the right thing
.text_wrap(false)
.rotate(270.0f32)
.rotate(Angle::Deg(270.0f32))
.width(Pixels(LABEL_HEIGHT))
.height(Pixels(SPECTRUM_ANALYZER_HEIGHT))
// HACK: The `.space()` on the HStack doesn't seem to work correctly here
@ -185,15 +183,19 @@ fn spectrum_analyzer(cx: &mut Context) {
.height(Pixels(20.0))
.child_space(Stretch(1.0));
})
.space(Pixels(10.0))
.left(Pixels(10.0))
.right(Pixels(10.0))
.top(Pixels(10.0))
.height(Auto)
.width(Stretch(1.0));
});
})
.height(Auto);
}
/// The area below the spectrum analyzer that contains all of the other parameters.
fn other_params(cx: &mut Context) {
VStack::new(cx, |cx| {
HStack::new(cx, move |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "Filter Stages").class("param-label");
RestrictedParamSlider::new(
cx,
@ -209,25 +211,26 @@ fn other_params(cx: &mut Context) {
},
);
})
.size(Auto)
.bottom(Pixels(10.0));
HStack::new(cx, move |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "Frequency Spread").class("param-label");
ParamSlider::new(cx, Data::params, |params| &params.filter_spread_octaves);
})
.size(Auto)
.bottom(Pixels(10.0));
HStack::new(cx, move |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "Spread Style").class("param-label");
ParamSlider::new(cx, Data::params, |params| &params.filter_spread_style)
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true });
});
})
.size(Auto);
})
.id("param-sliders")
.width(Percentage(100.0))
.top(Pixels(7.0))
// This should take up all remaining space
.bottom(Stretch(1.0))
.child_space(Stretch(1.0))
.child_left(Stretch(1.0));
.height(Stretch(1.0))
.child_space(Stretch(1.0));
}

View file

@ -90,9 +90,8 @@ impl View for SpectrumAnalyzer {
// NOTE: We could do the same thing like in Spectral Compressor and draw part of this
// spectrum analyzer as a single mesh but for whatever erason the aliasing/moire
// pattern here doesn't look nearly as bad.
let line_width = cx.style.dpi_factor as f32 * 1.5;
let paint = vg::Paint::color(cx.font_color().cloned().unwrap_or_default().into())
.with_line_width(line_width);
let line_width = cx.scale_factor() * 1.5;
let paint = vg::Paint::color(cx.font_color().into()).with_line_width(line_width);
let mut path = vg::Path::new();
for (bin_idx, magnitude) in spectrum.iter().enumerate() {
// We'll match up the bin's x-coordinate with the filter frequency parameter
@ -117,6 +116,6 @@ impl View for SpectrumAnalyzer {
path.line_to(bounds.x + (bounds.w * t), bounds.y + bounds.h);
}
canvas.stroke_path(&mut path, &paint);
canvas.stroke_path(&path, &paint);
}
}

View file

@ -31,15 +31,15 @@ pub struct SafeModeButton<L: Lens<Target = SafeModeClamper>> {
impl<L: Lens<Target = SafeModeClamper>> SafeModeButton<L> {
/// Creates a new button bound to the [`SafeModeClamper`].
pub fn new<T>(cx: &mut Context, lens: L, label: impl Res<T>) -> Handle<Self>
pub fn new<T>(cx: &mut Context, lens: L, label: impl Res<T> + Clone) -> Handle<Self>
where
T: ToString,
{
Self {
lens: lens.clone(),
lens,
scrolled_lines: 0.0,
}
.build(cx, move |cx| {
.build(cx, |cx| {
Label::new(cx, label).hoverable(false);
})
.checked(lens.map(|v| v.status()))

View file

@ -91,7 +91,7 @@ impl RestrictedParamSlider {
{
// See the original `ParamSlider` implementation for more details.
Self {
param_base: ParamWidgetBase::new(cx, params.clone(), params_to_param),
param_base: ParamWidgetBase::new(cx, params, params_to_param),
renormalize_display: Box::new(renormalize_display.clone()),
renormalize_event: Box::new(renormalize_event),
@ -146,15 +146,9 @@ impl RestrictedParamSlider {
RestrictedParamSlider::text_input_active,
move |cx, text_input_active| {
if text_input_active.get(cx) {
Self::text_input_view(cx, display_value_lens.clone());
Self::text_input_view(cx, display_value_lens);
} else {
// All of this data needs to be moved into the `ZStack` closure, and
// the `Map` lens combinator isn't `Copy`
let fill_start_delta_lens = fill_start_delta_lens.clone();
let modulation_start_delta_lens = modulation_start_delta_lens.clone();
let display_value_lens = display_value_lens.clone();
ZStack::new(cx, move |cx| {
ZStack::new(cx, |cx| {
Self::slider_fill_view(
cx,
fill_start_delta_lens,
@ -204,11 +198,7 @@ impl RestrictedParamSlider {
Element::new(cx)
.class("fill")
.height(Stretch(1.0))
.left(
fill_start_delta_lens
.clone()
.map(|(start_t, _)| Percentage(start_t * 100.0)),
)
.left(fill_start_delta_lens.map(|(start_t, _)| Percentage(start_t * 100.0)))
.width(fill_start_delta_lens.map(|(_, delta)| Percentage(delta * 100.0)))
// Hovering is handled on the param slider as a whole, this
// should not affect that
@ -221,18 +211,10 @@ impl RestrictedParamSlider {
.class("fill")
.class("fill--modulation")
.height(Stretch(1.0))
.visibility(
modulation_start_delta_lens
.clone()
.map(|(_, delta)| *delta != 0.0),
)
.visibility(modulation_start_delta_lens.map(|(_, delta)| *delta != 0.0))
// Widths cannot be negative, so we need to compensate the start
// position if the width does happen to be negative
.width(
modulation_start_delta_lens
.clone()
.map(|(_, delta)| Percentage(delta.abs() * 100.0)),
)
.width(modulation_start_delta_lens.map(|(_, delta)| Percentage(delta.abs() * 100.0)))
.left(modulation_start_delta_lens.map(|(start_t, delta)| {
if *delta < 0.0 {
Percentage((start_t + delta) * 100.0)
@ -330,11 +312,11 @@ impl View for RestrictedParamSlider {
// still won't work.
WindowEvent::MouseDown(MouseButton::Left)
| WindowEvent::MouseTripleClick(MouseButton::Left) => {
if cx.modifiers.alt() {
if cx.modifiers().alt() {
// ALt+Click brings up a text entry dialog
self.text_input_active = true;
cx.set_active(true);
} else if cx.modifiers.command() {
} else if cx.modifiers().command() {
// Ctrl+Click, double click, and right clicks should reset the parameter instead
// of initiating a drag operation
self.param_base.begin_set_parameter(cx);
@ -351,16 +333,16 @@ impl View for RestrictedParamSlider {
// When holding down shift while clicking on a parameter we want to granuarly
// edit the parameter without jumping to a new value
self.param_base.begin_set_parameter(cx);
if cx.modifiers.shift() {
if cx.modifiers().shift() {
self.granular_drag_status = Some(GranularDragStatus {
starting_x_coordinate: cx.mouse.cursorx,
starting_x_coordinate: cx.mouse().cursorx,
starting_value: self.param_base.unmodulated_normalized_value(),
});
} else {
self.granular_drag_status = None;
self.set_normalized_value_drag(
cx,
util::remap_current_entity_x_coordinate(cx, cx.mouse.cursorx),
util::remap_current_entity_x_coordinate(cx, cx.mouse().cursorx),
);
}
}
@ -395,7 +377,7 @@ impl View for RestrictedParamSlider {
if self.drag_active {
// If shift is being held then the drag should be more granular instead of
// absolute
if cx.modifiers.shift() {
if cx.modifiers().shift() {
let granular_drag_status =
*self
.granular_drag_status
@ -413,7 +395,7 @@ impl View for RestrictedParamSlider {
);
let delta_x = (*x - granular_drag_status.starting_x_coordinate)
* GRANULAR_DRAG_MULTIPLIER
* cx.style.dpi_factor as f32;
* cx.scale_factor();
self.set_normalized_value_drag(
cx,
@ -436,7 +418,7 @@ impl View for RestrictedParamSlider {
self.granular_drag_status = None;
self.param_base.set_normalized_value(
cx,
util::remap_current_entity_x_coordinate(cx, cx.mouse.cursorx),
util::remap_current_entity_x_coordinate(cx, cx.mouse().cursorx),
);
}
}
@ -450,7 +432,7 @@ impl View for RestrictedParamSlider {
|value| (self.renormalize_event)((self.renormalize_display)(value));
if self.scrolled_lines.abs() >= 1.0 {
let use_finer_steps = cx.modifiers.shift();
let use_finer_steps = cx.modifiers().shift();
// Scrolling while dragging needs to be taken into account here
if !self.drag_active {

View file

@ -138,85 +138,68 @@ impl XyPad {
cx,
// We need to create lenses for both the x-parameter's values and the y-parameter's
// values
ParamWidgetBase::build_view(
params,
params_to_x_param,
move |cx, x_param_data| {
ParamWidgetBase::view(
ParamWidgetBase::build_view(params, params_to_x_param, move |cx, x_param_data| {
ParamWidgetBase::view(cx, params, params_to_y_param, move |cx, y_param_data| {
// The x-parameter's range is clamped when safe mode is enabled
let x_position_lens = {
let x_renormalize_display = x_renormalize_display.clone();
x_param_data.make_lens(move |param| {
Percentage(
x_renormalize_display(param.unmodulated_normalized_value()) * 100.0,
)
})
};
let y_position_lens = y_param_data.make_lens(|param| {
// NOTE: The y-axis increments downards, and we want high values at
// the top and low values at the bottom
Percentage((1.0 - param.unmodulated_normalized_value()) * 100.0)
});
// Another handle is drawn below the regular handle to show the
// modualted value
let modulated_x_position_lens = x_param_data.make_lens(move |param| {
Percentage(
x_renormalize_display(param.modulated_normalized_value()) * 100.0,
)
});
let modulated_y_position_lens = y_param_data.make_lens(|param| {
Percentage((1.0 - param.modulated_normalized_value()) * 100.0)
});
// Can't use `.to_string()` here as that would include the modulation.
let x_display_value_lens = x_param_data.make_lens(|param| {
param.normalized_value_to_string(param.unmodulated_normalized_value(), true)
});
let y_display_value_lens = y_param_data.make_lens(|param| {
param.normalized_value_to_string(param.unmodulated_normalized_value(), true)
});
// When the X-Y pad gets Alt+clicked, we'll replace it with a text input
// box for the frequency parameter
Binding::new(
cx,
params,
params_to_y_param,
move |cx, y_param_data| {
// The x-parameter's range is clamped when safe mode is enabled
let x_position_lens = {
let x_renormalize_display = x_renormalize_display.clone();
x_param_data.make_lens(move |param| {
Percentage(
x_renormalize_display(param.unmodulated_normalized_value())
* 100.0,
)
})
};
let y_position_lens = y_param_data.make_lens(|param| {
// NOTE: The y-axis increments downards, and we want high values at
// the top and low values at the bottom
Percentage((1.0 - param.unmodulated_normalized_value()) * 100.0)
});
// Another handle is drawn below the regular handle to show the
// modualted value
let modulated_x_position_lens = x_param_data.make_lens(move |param| {
Percentage(
x_renormalize_display(param.modulated_normalized_value())
* 100.0,
)
});
let modulated_y_position_lens = y_param_data.make_lens(|param| {
Percentage((1.0 - param.modulated_normalized_value()) * 100.0)
});
// Can't use `.to_string()` here as that would include the modulation.
let x_display_value_lens = x_param_data.make_lens(|param| {
param.normalized_value_to_string(
param.unmodulated_normalized_value(),
true,
)
});
let y_display_value_lens = y_param_data.make_lens(|param| {
param.normalized_value_to_string(
param.unmodulated_normalized_value(),
true,
)
});
// When the X-Y pad gets Alt+clicked, we'll replace it with a text input
// box for the frequency parameter
Binding::new(
cx,
XyPad::text_input_active,
move |cx, text_input_active| {
if text_input_active.get(cx) {
Self::text_input_view(cx, x_display_value_lens);
} else {
Self::xy_pad_modulation_handle_view(
cx,
modulated_x_position_lens,
modulated_y_position_lens,
);
Self::xy_pad_handle_view(
cx,
x_position_lens,
y_position_lens,
x_display_value_lens,
y_display_value_lens,
);
}
},
);
XyPad::text_input_active,
move |cx, text_input_active| {
if text_input_active.get(cx) {
Self::text_input_view(cx, x_display_value_lens);
} else {
Self::xy_pad_modulation_handle_view(
cx,
modulated_x_position_lens,
modulated_y_position_lens,
);
Self::xy_pad_handle_view(
cx,
x_position_lens,
y_position_lens,
x_display_value_lens,
y_display_value_lens,
);
}
},
);
},
),
});
}),
)
}
@ -257,7 +240,7 @@ impl XyPad {
// pad. Its position is set to the mouse coordinate in the event
// handler. If there's enough space, the tooltip is drawn at the top
// right of the mouse cursor.
VStack::new(cx, move |cx| {
VStack::new(cx, |cx| {
// The X-parameter is the 'important' one, so we'll display that at
// the bottom since it's closer to the mouse cursor. We'll also
// hardcode the `Q: ` prefix for now to make it a bit clearer and to

View file

@ -101,7 +101,7 @@ impl View for Analyzer {
// TODO: Display the frequency range below the graph
// Draw the border last
let border_width = match cx.border_width().unwrap_or_default() {
let border_width = match cx.border_width() {
Units::Pixels(val) => val,
Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0),
_ => 0.0,
@ -122,7 +122,7 @@ impl View for Analyzer {
}
let paint = vg::Paint::color(border_color).with_line_width(border_width);
canvas.stroke_path(&mut path, &paint);
canvas.stroke_path(&path, &paint);
}
}
@ -144,8 +144,8 @@ fn draw_spectrum(
) {
let bounds = cx.bounds();
let line_width = cx.style.dpi_factor as f32 * 1.5;
let text_color: vg::Color = cx.font_color().cloned().unwrap_or_default().into();
let line_width = cx.scale_factor() * 1.5;
let text_color: vg::Color = cx.font_color().into();
// This is used to draw the individual bars
let bars_paint = vg::Paint::color(text_color).with_line_width(line_width);
// And this color is used to draw the mesh part of the spectrum. We'll create a gradient paint
@ -265,7 +265,7 @@ fn draw_spectrum(
fn draw_threshold_curve(cx: &mut DrawContext, canvas: &mut Canvas, analyzer_data: &AnalyzerData) {
let bounds = cx.bounds();
let line_width = cx.style.dpi_factor as f32 * 3.0;
let line_width = cx.scale_factor() * 3.0;
let downwards_paint =
vg::Paint::color(DOWNWARDS_THRESHOLD_CURVE_COLOR).with_line_width(line_width);
let upwards_paint = vg::Paint::color(UPWARDS_THRESHOLD_CURVE_COLOR).with_line_width(line_width);
@ -301,7 +301,7 @@ fn draw_threshold_curve(cx: &mut DrawContext, canvas: &mut Canvas, analyzer_data
// This does a way better job at cutting off the tops and bottoms of the graph than we could do
// by hand
canvas.scissor(bounds.x, bounds.y, bounds.w, bounds.h);
canvas.stroke_path(&mut path, &paint);
canvas.stroke_path(&path, &paint);
canvas.reset_scissor();
};
@ -374,6 +374,6 @@ fn draw_gain_reduction(
canvas
.global_composite_blend_func(vg::BlendFactor::DstAlpha, vg::BlendFactor::OneMinusDstColor);
canvas.fill_path(&mut path, &paint);
canvas.fill_path(&path, &paint);
canvas.global_composite_blend_func(vg::BlendFactor::One, vg::BlendFactor::OneMinusSrcAlpha);
}