1
0
Fork 0
nih-plug/plugins/crisp/src/editor.rs

77 lines
2.5 KiB
Rust
Raw Normal View History

2022-03-09 15:15:09 +01:00
// Crisp: a distortion plugin but not quite
// Copyright (C) 2022-2023 Robbert van der Helm
2022-03-09 15:15:09 +01:00
//
// 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-22 18:53:32 +01:00
use nih_plug::prelude::Editor;
use nih_plug_vizia::vizia::prelude::*;
2022-03-22 18:53:32 +01:00
use nih_plug_vizia::widgets::*;
use nih_plug_vizia::{assets, create_vizia_editor, ViziaState, ViziaTheming};
2022-03-09 15:15:09 +01:00
use std::sync::Arc;
use crate::CrispParams;
2022-03-22 18:53:32 +01:00
#[derive(Lens)]
struct Data {
params: Arc<CrispParams>,
2022-03-16 01:29:08 +01:00
}
2022-03-22 18:53:32 +01:00
impl Model for Data {}
2022-03-16 01:29:08 +01:00
2022-03-22 18:53:32 +01:00
// Makes sense to also define this here, makes it a bit easier to keep track of
pub(crate) fn default_state() -> Arc<ViziaState> {
2023-03-07 21:22:15 +01:00
ViziaState::new(|| (400, 390))
2022-03-16 01:29:08 +01:00
}
2022-03-22 18:53:32 +01:00
pub(crate) fn create(
params: Arc<CrispParams>,
2022-03-22 18:53:32 +01:00
editor_state: Arc<ViziaState>,
) -> Option<Box<dyn Editor>> {
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
assets::register_noto_sans_light(cx);
assets::register_noto_sans_thin(cx);
2022-03-22 18:53:32 +01:00
Data {
params: params.clone(),
2022-03-16 01:29:08 +01:00
}
2022-03-22 18:53:32 +01:00
.build(cx);
2022-03-29 00:49:31 +02:00
ResizeHandle::new(cx);
2022-03-22 18:53:32 +01:00
VStack::new(cx, |cx| {
Label::new(cx, "Crisp")
.font_family(vec![FamilyOwned::Name(String::from(
assets::NOTO_SANS_THIN,
))])
.font_size(30.0)
2022-03-22 18:53:32 +01:00
.height(Pixels(50.0))
.child_top(Stretch(1.0))
2023-01-12 19:01:22 +01:00
.child_bottom(Pixels(1.0))
2022-03-22 18:53:32 +01:00
// Make this more or less align with the parameters column
2022-03-22 19:49:05 +01:00
.right(Pixels(67.0));
2022-03-22 18:53:32 +01:00
ScrollView::new(cx, 0.0, 0.0, false, true, |cx| {
// This looks better if it's flush at the top, and then we'll just add some padding
// at the top of the scroll view
GenericUi::new(cx, Data::params).child_top(Pixels(0.0));
})
.width(Percentage(100.0))
.top(Pixels(5.0));
})
.row_between(Pixels(0.0))
.child_left(Stretch(1.0))
.child_right(Stretch(1.0));
})
2022-03-09 15:15:09 +01:00
}