Handle parameter edit begin and release
This commit is contained in:
parent
a1c6d1d30a
commit
8e7a86262f
1 changed files with 12 additions and 3 deletions
|
@ -24,17 +24,20 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||||
self.param.normalized_value()
|
self.param.normalized_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_normalized_value(&self, normalized: f32) {
|
fn begin_drag(&self) {
|
||||||
// TODO: The gesture should start on mouse down and end up mouse up
|
|
||||||
self.setter.begin_set_parameter(self.param);
|
self.setter.begin_set_parameter(self.param);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_normalized_value(&self, normalized: f32) {
|
||||||
// This snaps to the nearest plain value if the parameter is stepped in some wayA
|
// This snaps to the nearest plain value if the parameter is stepped in some wayA
|
||||||
// TODO: As an optimization, we could add a `const CONTINUOUS: bool` to the parameter to
|
// TODO: As an optimization, we could add a `const CONTINUOUS: bool` to the parameter to
|
||||||
// avoid this normalized->plain->normalized conversion for parameters that don't need
|
// avoid this normalized->plain->normalized conversion for parameters that don't need
|
||||||
// it
|
// it
|
||||||
let value = self.param.preview_plain(normalized);
|
let value = self.param.preview_plain(normalized);
|
||||||
self.setter.set_parameter(self.param, value);
|
self.setter.set_parameter(self.param, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end_drag(&self) {
|
||||||
self.setter.end_set_parameter(self.param);
|
self.setter.end_set_parameter(self.param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +69,10 @@ impl<P: Param> Widget for ParamSlider<'_, P> {
|
||||||
.inner;
|
.inner;
|
||||||
|
|
||||||
// Handle user input
|
// Handle user input
|
||||||
// TODO: We only show the position now
|
// TODO: As mentioned above, handle double click and ctrl+click, maybe also value entry
|
||||||
|
if response.drag_started() {
|
||||||
|
self.begin_drag();
|
||||||
|
}
|
||||||
if let Some(click_pos) = response.interact_pointer_pos() {
|
if let Some(click_pos) = response.interact_pointer_pos() {
|
||||||
let aim_radius = ui.input().aim_radius();
|
let aim_radius = ui.input().aim_radius();
|
||||||
let proportion = egui::emath::smart_aim::best_in_range_f64(
|
let proportion = egui::emath::smart_aim::best_in_range_f64(
|
||||||
|
@ -84,6 +90,9 @@ impl<P: Param> Widget for ParamSlider<'_, P> {
|
||||||
|
|
||||||
self.set_normalized_value(proportion as f32);
|
self.set_normalized_value(proportion as f32);
|
||||||
}
|
}
|
||||||
|
if response.drag_released() {
|
||||||
|
self.end_drag();
|
||||||
|
}
|
||||||
|
|
||||||
// And finally draw the thing
|
// And finally draw the thing
|
||||||
if ui.is_rect_visible(response.rect) {
|
if ui.is_rect_visible(response.rect) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue