Add back a ParamWidgetBase::view with explicit cx
The version that returns a callback is nice, but it's a bit awkward when dealing with multiple parameters.
This commit is contained in:
parent
3cdae526fd
commit
7d42788be2
|
@ -117,13 +117,12 @@ impl ParamWidgetBase {
|
||||||
/// Create a view using the a parameter's data. This is not tied to a particular
|
/// Create a view using the a parameter's data. This is not tied to a particular
|
||||||
/// [`ParamWidgetBase`] instance, but it allows you to easily create lenses for the parameter's
|
/// [`ParamWidgetBase`] instance, but it allows you to easily create lenses for the parameter's
|
||||||
/// values and access static parameter data.
|
/// values and access static parameter data.
|
||||||
///
|
pub fn view<L, Params, P, FMap, F, R>(
|
||||||
/// This can be used directly as an argument to [`View::build()`].
|
cx: &mut Context,
|
||||||
pub fn build_view<L, Params, P, FMap, F, R>(
|
|
||||||
params: L,
|
params: L,
|
||||||
params_to_param: FMap,
|
params_to_param: FMap,
|
||||||
content: F,
|
content: F,
|
||||||
) -> impl FnOnce(&mut Context) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
L: Lens<Target = Params> + Clone,
|
L: Lens<Target = Params> + Clone,
|
||||||
Params: 'static,
|
Params: 'static,
|
||||||
|
@ -131,7 +130,6 @@ impl ParamWidgetBase {
|
||||||
FMap: Fn(&Params) -> &P + Copy + 'static,
|
FMap: Fn(&Params) -> &P + Copy + 'static,
|
||||||
F: FnOnce(&mut Context, ParamWidgetData<L, Params, P, FMap>) -> R,
|
F: FnOnce(&mut Context, ParamWidgetData<L, Params, P, FMap>) -> R,
|
||||||
{
|
{
|
||||||
move |cx| {
|
|
||||||
// We'll provide the raw `&P` to the callbacks to make creating parameter widgets more
|
// We'll provide the raw `&P` to the callbacks to make creating parameter widgets more
|
||||||
// convenient.
|
// convenient.
|
||||||
// SAFETY: This &P won't outlive this function, and in the context of NIH-plug &P will
|
// SAFETY: This &P won't outlive this function, and in the context of NIH-plug &P will
|
||||||
|
@ -153,6 +151,22 @@ impl ParamWidgetBase {
|
||||||
|
|
||||||
content(cx, param_data)
|
content(cx, param_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A shorthand for [`view()`][Self::view()] that can be used directly as an argument to
|
||||||
|
/// [`View::build()`].
|
||||||
|
pub fn build_view<L, Params, P, FMap, F, R>(
|
||||||
|
params: L,
|
||||||
|
params_to_param: FMap,
|
||||||
|
content: F,
|
||||||
|
) -> impl FnOnce(&mut Context) -> R
|
||||||
|
where
|
||||||
|
L: Lens<Target = Params> + Clone,
|
||||||
|
Params: 'static,
|
||||||
|
P: Param + 'static,
|
||||||
|
FMap: Fn(&Params) -> &P + Copy + 'static,
|
||||||
|
F: FnOnce(&mut Context, ParamWidgetData<L, Params, P, FMap>) -> R,
|
||||||
|
{
|
||||||
|
move |cx| Self::view(cx, params, params_to_param, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function for using [`ParamWidgetData::make_lens()`]. Whenever possible,
|
/// Convenience function for using [`ParamWidgetData::make_lens()`]. Whenever possible,
|
||||||
|
|
Loading…
Reference in a new issue