Allow resetting parameters by double clicking
This commit is contained in:
parent
882ba8f61d
commit
cd683187e0
|
@ -37,6 +37,13 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
|||
self.setter.set_parameter(self.param, value);
|
||||
}
|
||||
|
||||
// This still needs to be part of a drag gestur
|
||||
fn reset_param(&self) {
|
||||
let normalized_default = self.setter.default_normalized_param_value(self.param);
|
||||
self.setter
|
||||
.set_parameter_normalized(self.param, normalized_default);
|
||||
}
|
||||
|
||||
fn end_drag(&self) {
|
||||
self.setter.end_set_parameter(self.param);
|
||||
}
|
||||
|
@ -70,6 +77,7 @@ impl<P: Param> Widget for ParamSlider<'_, P> {
|
|||
|
||||
// Handle user input
|
||||
// TODO: As mentioned above, handle double click and ctrl+click, maybe also value entry
|
||||
// TODO: Handle shift+drag being more granular
|
||||
if response.drag_started() {
|
||||
self.begin_drag();
|
||||
}
|
||||
|
@ -78,6 +86,10 @@ impl<P: Param> Widget for ParamSlider<'_, P> {
|
|||
egui::emath::remap_clamp(click_pos.x, response.rect.x_range(), 0.0..=1.0) as f64;
|
||||
self.set_normalized_value(proportion as f32);
|
||||
}
|
||||
// TODO: Also handle ctrl+click
|
||||
if response.double_clicked() {
|
||||
self.reset_param();
|
||||
}
|
||||
if response.drag_released() {
|
||||
self.end_drag();
|
||||
}
|
||||
|
|
|
@ -157,14 +157,18 @@ impl<'a> ParamSetter<'a> {
|
|||
unsafe { self.context.raw_end_set_parameter(param.as_ptr()) };
|
||||
}
|
||||
|
||||
/// Retrieve the default value for a parameter, in case you forgot. This is useful when
|
||||
/// implementing GUIs, and it does not perform a callback.
|
||||
fn raw_default_normalized_param_value<P: Param>(&self, param: &P) -> P::Plain {
|
||||
let normalized = unsafe {
|
||||
/// Retrieve the default value for a parameter, in case you forgot. The value is already
|
||||
/// normalized to `[0, 1]`. This is useful when implementing GUIs, and it does not perform a callback.
|
||||
pub fn default_normalized_param_value<P: Param>(&self, param: &P) -> f32 {
|
||||
unsafe {
|
||||
self.context
|
||||
.raw_default_normalized_param_value(param.as_ptr())
|
||||
};
|
||||
param.preview_plain(normalized)
|
||||
}
|
||||
}
|
||||
|
||||
/// The same as [Self::default_normalized_param_value], but without the normalization.
|
||||
pub fn default_param_value<P: Param>(&self, param: &P) -> P::Plain {
|
||||
param.preview_plain(self.default_normalized_param_value(param))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue