1
0
Fork 0

Simplify ParamButton

This commit is contained in:
Robbert van der Helm 2022-11-06 19:25:28 +01:00
parent 14cb1cb679
commit a73f76fbcf

View file

@ -32,24 +32,23 @@ impl ParamButton {
P: Param + 'static, P: Param + 'static,
FMap: Fn(&Params) -> &P + Copy + 'static, FMap: Fn(&Params) -> &P + Copy + 'static,
{ {
// We'll add the `:checked` pseudoclass when the button is pressed
// NOTE: We use the normalized value _with modulation_ for this. There's no convenient way
// to show both modulated and unmodulated values here.
let param_value_lens =
ParamWidgetBase::make_lens(params.clone(), params_to_param, |param| {
param.normalized_value()
});
Self { Self {
param_base: ParamWidgetBase::new(cx, params.clone(), params_to_param), param_base: ParamWidgetBase::new(cx, params.clone(), params_to_param),
} }
.build( .build(
cx, cx,
ParamWidgetBase::view(params, params_to_param, move |cx, param_data| { ParamWidgetBase::view(params.clone(), params_to_param, move |cx, param_data| {
Label::new(cx, param_data.param().name()); Label::new(cx, param_data.param().name());
}), }),
) )
.checked(param_value_lens.map(|v| v >= &0.5)) // We'll add the `:checked` pseudoclass when the button is pressed
// NOTE: We use the normalized value _with modulation_ for this. There's no convenient way
// to show both modulated and unmodulated values here.
.checked(ParamWidgetBase::make_lens(
params,
params_to_param,
|param| param.normalized_value() >= 0.5,
))
} }
/// Set the parameter's normalized value to either 0.0 or 1.0 depending on its current value. /// Set the parameter's normalized value to either 0.0 or 1.0 depending on its current value.