1
0
Fork 0

Remove Copy bound on ParamSlider

This commit is contained in:
Robbert van der Helm 2022-07-23 18:58:41 +02:00
parent f812374ad0
commit 8ae93cc6ab

View file

@ -102,7 +102,7 @@ impl ParamSlider {
/// See [`ParamSliderExt`] for additonal options. /// See [`ParamSliderExt`] for additonal options.
pub fn new<L, Params, P, F>(cx: &mut Context, params: L, params_to_param: F) -> Handle<Self> pub fn new<L, Params, P, F>(cx: &mut Context, params: L, params_to_param: F) -> Handle<Self>
where where
L: Lens<Target = Params> + Copy, L: Lens<Target = Params> + Clone,
F: 'static + Fn(&Params) -> &P + Copy, F: 'static + Fn(&Params) -> &P + Copy,
Params: 'static, Params: 'static,
P: Param, P: Param,
@ -113,12 +113,15 @@ impl ParamSlider {
// We need to do a bit of a nasty and erase the lifetime bound by going through the raw // We need to do a bit of a nasty and erase the lifetime bound by going through the raw
// GuiContext and a ParamPtr. // GuiContext and a ParamPtr.
let param_ptr = params let param_ptr = params
.clone()
.map(move |params| params_to_param(params).as_ptr()) .map(move |params| params_to_param(params).as_ptr())
.get(cx); .get(cx);
let default_value = params let default_value = params
.clone()
.map(move |params| params_to_param(params).default_normalized_value()) .map(move |params| params_to_param(params).default_normalized_value())
.get(cx); .get(cx);
let step_count = params let step_count = params
.clone()
.map(move |params| params_to_param(params).step_count()) .map(move |params| params_to_param(params).step_count())
.get(cx); .get(cx);
@ -146,27 +149,32 @@ impl ParamSlider {
// label with the slider. Creating the textbox based on // label with the slider. Creating the textbox based on
// `ParamSliderInternal::text_input_active` lets us focus the textbox when it gets // `ParamSliderInternal::text_input_active` lets us focus the textbox when it gets
// created. // created.
let params = params.clone();
Binding::new( Binding::new(
cx, cx,
ParamSliderInternal::text_input_active, ParamSliderInternal::text_input_active,
move |cx, text_input_active| { move |cx, text_input_active| {
// Can't use `.to_string()` here as that would include the modulation. // Can't use `.to_string()` here as that would include the modulation.
let param_display_value_lens = params.map(move |params| { let param_display_value_lens = params.clone().map(move |params| {
let param = params_to_param(params); let param = params_to_param(params);
param.normalized_value_to_string( param.normalized_value_to_string(
param.unmodulated_normalized_value(), param.unmodulated_normalized_value(),
true, true,
) )
}); });
let param_preview_display_value_lens = |normalized_value| { let param_preview_display_value_lens = {
params.map(move |params| { let params = params.clone();
params_to_param(params) move |normalized_value| {
.normalized_value_to_string(normalized_value, true) params.clone().map(move |params| {
}) params_to_param(params)
.normalized_value_to_string(normalized_value, true)
})
}
}; };
let unmodulated_normalized_param_value_lens = params.map(move |params| { let unmodulated_normalized_param_value_lens =
params_to_param(params).unmodulated_normalized_value() params.clone().map(move |params| {
}); params_to_param(params).unmodulated_normalized_value()
});
// The resulting tuple `(start_t, delta)` corresponds to the start and the // The resulting tuple `(start_t, delta)` corresponds to the start and the
// signed width of the bar. `start_t` is in `[0, 1]`, and `delta` is in // signed width of the bar. `start_t` is in `[0, 1]`, and `delta` is in
@ -220,7 +228,7 @@ impl ParamSlider {
// plugins with hosts that support this), then this is the difference // plugins with hosts that support this), then this is the difference
// between the 'true' value and the current value after modulation has been // between the 'true' value and the current value after modulation has been
// applied. // applied.
let modulation_start_delta_lens = params.map(move |params| { let modulation_start_delta_lens = params.clone().map(move |params| {
match style { match style {
// Don't show modulation for stepped parameters since it wouldn't // Don't show modulation for stepped parameters since it wouldn't
// make a lot of sense visually // make a lot of sense visually