2022-03-06 05:39:52 +11:00
|
|
|
// Diopser: a phase rotation plugin
|
|
|
|
// Copyright (C) 2021-2022 Robbert van der Helm
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
use nih_plug::prelude::Editor;
|
|
|
|
use nih_plug_vizia::vizia::*;
|
|
|
|
use nih_plug_vizia::widgets::*;
|
|
|
|
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState};
|
2022-03-06 05:39:52 +11:00
|
|
|
use std::pin::Pin;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use crate::DiopserParams;
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
/// VIZIA uses points instead of pixels for text
|
|
|
|
const POINT_SCALE: f32 = 0.75;
|
2022-03-06 05:39:52 +11:00
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
#[derive(Lens)]
|
2022-03-24 09:29:49 +11:00
|
|
|
struct Data {
|
2022-03-06 05:39:52 +11:00
|
|
|
params: Pin<Arc<DiopserParams>>,
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
impl Model for Data {}
|
2022-03-16 11:20:02 +11:00
|
|
|
|
2022-03-23 04:32:02 +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> {
|
2022-03-23 23:17:47 +11:00
|
|
|
ViziaState::from_size(380, 270)
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
pub(crate) fn create(
|
|
|
|
params: Pin<Arc<DiopserParams>>,
|
|
|
|
editor_state: Arc<ViziaState>,
|
|
|
|
) -> Option<Box<dyn Editor>> {
|
|
|
|
create_vizia_editor(editor_state, move |cx| {
|
|
|
|
Data {
|
|
|
|
params: params.clone(),
|
2022-03-16 11:20:02 +11:00
|
|
|
}
|
2022-03-23 04:32:02 +11:00
|
|
|
.build(cx);
|
|
|
|
|
2022-03-29 09:49:31 +11:00
|
|
|
ResizeHandle::new(cx);
|
|
|
|
|
2022-03-23 04:32:02 +11:00
|
|
|
VStack::new(cx, |cx| {
|
|
|
|
Label::new(cx, "Diopser")
|
|
|
|
.font(assets::NOTO_SANS_THIN)
|
|
|
|
.font_size(40.0 * POINT_SCALE)
|
|
|
|
.height(Pixels(50.0))
|
|
|
|
.child_top(Stretch(1.0))
|
|
|
|
.child_bottom(Pixels(0.0))
|
|
|
|
// Make this more or less align with the parameters column
|
2022-03-23 04:49:46 +11:00
|
|
|
.right(Percentage(12.0));
|
2022-03-23 04:32:02 +11:00
|
|
|
|
2022-03-23 04:49:46 +11:00
|
|
|
// See the Crisp generic UI for an example using a ScrollView
|
2022-03-23 04:50:50 +11:00
|
|
|
GenericUi::new(cx, Data::params)
|
2022-03-23 04:49:46 +11:00
|
|
|
.width(Percentage(100.0))
|
2022-03-23 23:17:47 +11:00
|
|
|
.height(Auto)
|
2022-03-23 04:49:46 +11:00
|
|
|
.child_top(Pixels(5.0));
|
2022-03-23 04:32:02 +11:00
|
|
|
})
|
2022-03-23 04:49:46 +11:00
|
|
|
.width(Percentage(100.0))
|
2022-03-23 04:32:02 +11:00
|
|
|
.row_between(Pixels(0.0))
|
|
|
|
.child_left(Stretch(1.0))
|
|
|
|
.child_right(Stretch(1.0));
|
|
|
|
})
|
2022-03-06 05:39:52 +11:00
|
|
|
}
|