Introduce egui window resizability

This commit is contained in:
Jakub Turowski
2024-07-14 22:09:36 +02:00
committed by Robbert van der Helm
parent bba7064441
commit 91a0ff745e
6 changed files with 208 additions and 50 deletions

View File

@@ -1,5 +1,10 @@
use nih_plug::prelude::*;
use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
use nih_plug_egui::{
create_egui_editor,
egui::{self, Vec2},
resizable_window::ResizableWindow,
widgets, EguiState,
};
use std::sync::Arc;
/// The time it takes for the peak meter to decay by 12 dB after switching to complete silence.
@@ -102,62 +107,65 @@ impl Plugin for Gain {
fn editor(&mut self, _async_executor: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> {
let params = self.params.clone();
let peak_meter = self.peak_meter.clone();
let egui_state = params.editor_state.clone();
create_egui_editor(
self.params.editor_state.clone(),
(),
|_, _| {},
move |egui_ctx, setter, _state| {
egui::CentralPanel::default().show(egui_ctx, |ui| {
// NOTE: See `plugins/diopser/src/editor.rs` for an example using the generic UI widget
ResizableWindow::new("res-wind")
.min_size(Vec2::new(128.0, 128.0))
.show(egui_ctx, egui_state.as_ref(), |ui| {
// NOTE: See `plugins/diopser/src/editor.rs` for an example using the generic UI widget
// This is a fancy widget that can get all the information it needs to properly
// display and modify the parameter from the parametr itself
// It's not yet fully implemented, as the text is missing.
ui.label("Some random integer");
ui.add(widgets::ParamSlider::for_param(&params.some_int, setter));
// This is a fancy widget that can get all the information it needs to properly
// display and modify the parameter from the parametr itself
// It's not yet fully implemented, as the text is missing.
ui.label("Some random integer");
ui.add(widgets::ParamSlider::for_param(&params.some_int, setter));
ui.label("Gain");
ui.add(widgets::ParamSlider::for_param(&params.gain, setter));
ui.label("Gain");
ui.add(widgets::ParamSlider::for_param(&params.gain, setter));
ui.label(
ui.label(
"Also gain, but with a lame widget. Can't even render the value correctly!",
);
// This is a simple naieve version of a parameter slider that's not aware of how
// the parameters work
ui.add(
egui::widgets::Slider::from_get_set(-30.0..=30.0, |new_value| {
match new_value {
Some(new_value_db) => {
let new_value = util::gain_to_db(new_value_db as f32);
// This is a simple naieve version of a parameter slider that's not aware of how
// the parameters work
ui.add(
egui::widgets::Slider::from_get_set(-30.0..=30.0, |new_value| {
match new_value {
Some(new_value_db) => {
let new_value = util::gain_to_db(new_value_db as f32);
setter.begin_set_parameter(&params.gain);
setter.set_parameter(&params.gain, new_value);
setter.end_set_parameter(&params.gain);
setter.begin_set_parameter(&params.gain);
setter.set_parameter(&params.gain, new_value);
setter.end_set_parameter(&params.gain);
new_value_db
new_value_db
}
None => util::gain_to_db(params.gain.value()) as f64,
}
None => util::gain_to_db(params.gain.value()) as f64,
}
})
.suffix(" dB"),
);
})
.suffix(" dB"),
);
// TODO: Add a proper custom widget instead of reusing a progress bar
let peak_meter =
util::gain_to_db(peak_meter.load(std::sync::atomic::Ordering::Relaxed));
let peak_meter_text = if peak_meter > util::MINUS_INFINITY_DB {
format!("{peak_meter:.1} dBFS")
} else {
String::from("-inf dBFS")
};
// TODO: Add a proper custom widget instead of reusing a progress bar
let peak_meter =
util::gain_to_db(peak_meter.load(std::sync::atomic::Ordering::Relaxed));
let peak_meter_text = if peak_meter > util::MINUS_INFINITY_DB {
format!("{peak_meter:.1} dBFS")
} else {
String::from("-inf dBFS")
};
let peak_meter_normalized = (peak_meter + 60.0) / 60.0;
ui.allocate_space(egui::Vec2::splat(2.0));
ui.add(
egui::widgets::ProgressBar::new(peak_meter_normalized)
.text(peak_meter_text),
);
});
let peak_meter_normalized = (peak_meter + 60.0) / 60.0;
ui.allocate_space(egui::Vec2::splat(2.0));
ui.add(
egui::widgets::ProgressBar::new(peak_meter_normalized)
.text(peak_meter_text),
);
});
},
)
}