Pass the GuiContext to vizia editors
There's no clean way to expose the state save/restore functionality through events.
This commit is contained in:
parent
083885a40c
commit
56e9cd54c1
|
@ -21,10 +21,14 @@ pub mod widgets;
|
||||||
/// persisted when restoring a plugin instance, then you can store it in a `#[persist = "key"]`
|
/// persisted when restoring a plugin instance, then you can store it in a `#[persist = "key"]`
|
||||||
/// field on your parameters struct.
|
/// field on your parameters struct.
|
||||||
///
|
///
|
||||||
|
/// The [`GuiContext`] is also passed to the app function. This is only meant for saving and
|
||||||
|
/// restoring state as part of your plugin's preset handling. You should not interact with this
|
||||||
|
/// directly to set parameters. Use the `ParamEvent`s instead.
|
||||||
|
///
|
||||||
/// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this.
|
/// See [VIZIA](https://github.com/vizia/vizia)'s repository for examples on how to use this.
|
||||||
pub fn create_vizia_editor<F>(vizia_state: Arc<ViziaState>, app: F) -> Option<Box<dyn Editor>>
|
pub fn create_vizia_editor<F>(vizia_state: Arc<ViziaState>, app: F) -> Option<Box<dyn Editor>>
|
||||||
where
|
where
|
||||||
F: Fn(&mut Context) + 'static + Send + Sync,
|
F: Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync,
|
||||||
{
|
{
|
||||||
Some(Box::new(ViziaEditor {
|
Some(Box::new(ViziaEditor {
|
||||||
vizia_state,
|
vizia_state,
|
||||||
|
@ -44,7 +48,7 @@ pub fn create_vizia_editor_without_theme<F>(
|
||||||
app: F,
|
app: F,
|
||||||
) -> Option<Box<dyn Editor>>
|
) -> Option<Box<dyn Editor>>
|
||||||
where
|
where
|
||||||
F: Fn(&mut Context) + 'static + Send + Sync,
|
F: Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync,
|
||||||
{
|
{
|
||||||
Some(Box::new(ViziaEditor {
|
Some(Box::new(ViziaEditor {
|
||||||
vizia_state,
|
vizia_state,
|
||||||
|
@ -127,7 +131,7 @@ impl ViziaState {
|
||||||
struct ViziaEditor {
|
struct ViziaEditor {
|
||||||
vizia_state: Arc<ViziaState>,
|
vizia_state: Arc<ViziaState>,
|
||||||
/// The user's app function.
|
/// The user's app function.
|
||||||
app: Arc<dyn Fn(&mut Context) + 'static + Send + Sync>,
|
app: Arc<dyn Fn(&mut Context, Arc<dyn GuiContext>) + 'static + Send + Sync>,
|
||||||
/// Whether to apply `nih_plug_vizia`'s default theme. If this is disabled, then only the event
|
/// Whether to apply `nih_plug_vizia`'s default theme. If this is disabled, then only the event
|
||||||
/// handler for `ParamEvent`s is set up.
|
/// handler for `ParamEvent`s is set up.
|
||||||
apply_theming: bool,
|
apply_theming: bool,
|
||||||
|
@ -186,7 +190,7 @@ impl Editor for ViziaEditor {
|
||||||
}
|
}
|
||||||
.build(cx);
|
.build(cx);
|
||||||
|
|
||||||
app(cx)
|
app(cx, context.clone())
|
||||||
})
|
})
|
||||||
.with_scale_policy(
|
.with_scale_policy(
|
||||||
system_scaling_factor
|
system_scaling_factor
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) fn create(
|
||||||
params: Arc<CrispParams>,
|
params: Arc<CrispParams>,
|
||||||
editor_state: Arc<ViziaState>,
|
editor_state: Arc<ViziaState>,
|
||||||
) -> Option<Box<dyn Editor>> {
|
) -> Option<Box<dyn Editor>> {
|
||||||
create_vizia_editor(editor_state, move |cx| {
|
create_vizia_editor(editor_state, move |cx, _| {
|
||||||
Data {
|
Data {
|
||||||
params: params.clone(),
|
params: params.clone(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) fn create(
|
||||||
params: Arc<DiopserParams>,
|
params: Arc<DiopserParams>,
|
||||||
editor_state: Arc<ViziaState>,
|
editor_state: Arc<ViziaState>,
|
||||||
) -> Option<Box<dyn Editor>> {
|
) -> Option<Box<dyn Editor>> {
|
||||||
create_vizia_editor(editor_state, move |cx| {
|
create_vizia_editor(editor_state, move |cx, _| {
|
||||||
Data {
|
Data {
|
||||||
params: params.clone(),
|
params: params.clone(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub(crate) fn create(
|
||||||
peak_meter: Arc<AtomicF32>,
|
peak_meter: Arc<AtomicF32>,
|
||||||
editor_state: Arc<ViziaState>,
|
editor_state: Arc<ViziaState>,
|
||||||
) -> Option<Box<dyn Editor>> {
|
) -> Option<Box<dyn Editor>> {
|
||||||
create_vizia_editor(editor_state, move |cx| {
|
create_vizia_editor(editor_state, move |cx, _| {
|
||||||
cx.add_theme(STYLE);
|
cx.add_theme(STYLE);
|
||||||
|
|
||||||
Data {
|
Data {
|
||||||
|
|
Loading…
Reference in a new issue