1
0
Fork 0

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:
Robbert van der Helm 2022-11-11 19:23:29 +01:00
parent 3cdae526fd
commit 7d42788be2

View file

@ -117,13 +117,12 @@ impl ParamWidgetBase {
/// 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
/// values and access static parameter data.
///
/// This can be used directly as an argument to [`View::build()`].
pub fn build_view<L, Params, P, FMap, F, R>(
pub fn view<L, Params, P, FMap, F, R>(
cx: &mut Context,
params: L,
params_to_param: FMap,
content: F,
) -> impl FnOnce(&mut Context) -> R
) -> R
where
L: Lens<Target = Params> + Clone,
Params: 'static,
@ -131,7 +130,6 @@ impl ParamWidgetBase {
FMap: Fn(&Params) -> &P + Copy + 'static,
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
// convenient.
// 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)
}
/// 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,