1
0
Fork 0

Use ParamFlags::HIDE_IN_GENERIC_UI in generic UIs

This commit is contained in:
Robbert van der Helm 2022-03-23 13:16:56 +01:00
parent e9983cf71c
commit 144e30239e
3 changed files with 28 additions and 6 deletions

View file

@ -4,8 +4,7 @@
use std::pin::Pin;
use egui::{TextStyle, Ui, Vec2};
use nih_plug::context::ParamSetter;
use nih_plug::prelude::{Param, ParamPtr, Params};
use nih_plug::prelude::{Param, ParamFlags, ParamPtr, ParamSetter, Params};
use super::ParamSlider;
@ -45,14 +44,22 @@ pub fn create(
// Take up all remaining space, use a wrapper container to adjust how much space that is
.auto_shrink([false, false])
.show(ui, |ui| {
for (widget_idx, (_, param_ptr, _)) in params.param_map().into_iter().enumerate() {
let mut first_widget = true;
for (_, param_ptr, _) in params.param_map().into_iter() {
let flags = unsafe { param_ptr.flags() };
if flags.contains(ParamFlags::HIDE_IN_GENERIC_UI) {
continue;
}
// This list looks weird without a little padding
if widget_idx > 0 {
if !first_widget {
ui.allocate_space(padding);
}
ui.label(unsafe { param_ptr.name() });
unsafe { widget.add_widget_raw(ui, &param_ptr, setter) };
first_widget = false;
}
});
}

View file

@ -7,7 +7,7 @@ use std::collections::HashMap;
use std::marker::PhantomData;
use std::pin::Pin;
use nih_plug::prelude::{Param, ParamPtr, Params};
use nih_plug::prelude::{Param, ParamFlags, ParamPtr, Params};
use super::{ParamMessage, ParamSlider};
use crate::backend::Renderer;
@ -160,12 +160,22 @@ where
// Make sure we already have widget state for each widget
let param_map = self.params.param_map();
for (_, param_ptr, _) in &param_map {
let flags = unsafe { param_ptr.flags() };
if flags.contains(ParamFlags::HIDE_IN_GENERIC_UI) {
continue;
}
if !widget_state.contains_key(param_ptr) {
widget_state.insert(*param_ptr, Default::default());
}
}
for (_, param_ptr, _) in param_map {
let flags = unsafe { param_ptr.flags() };
if flags.contains(ParamFlags::HIDE_IN_GENERIC_UI) {
continue;
}
// SAFETY: We only borrow each item once, and the plugin framework statically asserted
// that parameter indices are unique and this widget state cannot outlive this
// function

View file

@ -2,7 +2,7 @@
use std::{ops::Deref, pin::Pin};
use nih_plug::prelude::{ParamPtr, Params};
use nih_plug::prelude::{ParamFlags, ParamPtr, Params};
use vizia::*;
use super::{ParamSlider, ParamSliderExt, ParamSliderStyle};
@ -86,6 +86,11 @@ impl GenericUi {
// map `params` to some `impl Param` and everything would have been a lot neater
let param_map = &*params.map(|params| params.as_ref().param_map()).get(cx);
for (_, param_ptr, _) in param_map {
let flags = unsafe { param_ptr.flags() };
if flags.contains(ParamFlags::HIDE_IN_GENERIC_UI) {
continue;
}
make_widget(cx, *param_ptr);
}
})