2022-03-18 11:28:18 +11:00
|
|
|
use atomic_float::AtomicF32;
|
|
|
|
use nih_plug::prelude::Editor;
|
|
|
|
use nih_plug_vizia::vizia::*;
|
2022-03-19 11:17:36 +11:00
|
|
|
use nih_plug_vizia::widgets::*;
|
2022-03-18 11:28:18 +11:00
|
|
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState};
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use crate::GainParams;
|
|
|
|
|
|
|
|
/// VIZIA uses points instead of pixels for text
|
|
|
|
const POINT_SCALE: f32 = 0.75;
|
|
|
|
|
2022-03-19 05:12:38 +11:00
|
|
|
const STYLE: &str = r#""#;
|
2022-03-18 11:28:18 +11:00
|
|
|
|
2022-03-19 11:17:36 +11:00
|
|
|
#[derive(Lens)]
|
2022-03-20 01:28:58 +11:00
|
|
|
// TODO: Lens requires everything to be marked as `pub`
|
2022-03-19 11:17:36 +11:00
|
|
|
pub struct Data {
|
|
|
|
params: Pin<Arc<GainParams>>,
|
|
|
|
peak_meter: Arc<AtomicF32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Model for Data {}
|
|
|
|
|
2022-03-18 11:28:18 +11:00
|
|
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
|
|
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
|
|
|
ViziaState::from_size(200, 150)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn create(
|
|
|
|
params: Pin<Arc<GainParams>>,
|
|
|
|
peak_meter: Arc<AtomicF32>,
|
|
|
|
editor_state: Arc<ViziaState>,
|
|
|
|
) -> Option<Box<dyn Editor>> {
|
2022-03-19 11:17:36 +11:00
|
|
|
create_vizia_editor(editor_state, move |cx, setter| {
|
2022-03-18 11:28:18 +11:00
|
|
|
cx.add_theme(STYLE);
|
|
|
|
|
2022-03-19 11:17:36 +11:00
|
|
|
Data {
|
|
|
|
params: params.clone(),
|
|
|
|
peak_meter: peak_meter.clone(),
|
|
|
|
}
|
|
|
|
.build(cx);
|
2022-03-18 11:28:18 +11:00
|
|
|
|
2022-03-19 11:17:36 +11:00
|
|
|
VStack::new(cx, move |cx| {
|
2022-03-18 11:28:18 +11:00
|
|
|
Label::new(cx, "Gain GUI")
|
2022-03-18 11:37:24 +11:00
|
|
|
.font(assets::NOTO_SANS_THIN)
|
2022-03-18 11:28:18 +11:00
|
|
|
.font_size(40.0 * POINT_SCALE)
|
|
|
|
.height(Pixels(50.0))
|
|
|
|
.child_top(Stretch(1.0))
|
|
|
|
.child_bottom(Pixels(0.0));
|
2022-03-19 11:22:38 +11:00
|
|
|
// NOTE: VIZIA adds 1 pixel of additional height to these labels, so we'll need to
|
|
|
|
// compensate for that
|
2022-03-19 11:17:36 +11:00
|
|
|
Label::new(cx, "Gain").bottom(Pixels(-1.0));
|
|
|
|
|
|
|
|
ParamSlider::new(cx, Data::params, setter, |params| ¶ms.gain);
|
|
|
|
|
|
|
|
// TODO: Add a peak meter
|
2022-03-18 11:28:18 +11:00
|
|
|
})
|
2022-03-19 11:17:36 +11:00
|
|
|
.row_between(Pixels(0.0))
|
2022-03-18 11:28:18 +11:00
|
|
|
.child_left(Stretch(1.0))
|
|
|
|
.child_right(Stretch(1.0));
|
|
|
|
})
|
|
|
|
}
|