Make the ParamSlider generic over all param types
This commit is contained in:
parent
857cf876e8
commit
46a7d8a261
1 changed files with 6 additions and 8 deletions
|
@ -1,23 +1,21 @@
|
||||||
use egui::{vec2, Color32, Response, Sense, Stroke, TextStyle, Ui, Widget};
|
use egui::{vec2, Color32, Response, Sense, Stroke, TextStyle, Ui, Widget};
|
||||||
|
|
||||||
use nih_plug::{FloatParam, Param, ParamSetter};
|
use nih_plug::{Param, ParamSetter};
|
||||||
|
|
||||||
/// A slider widget similar to [egui::widgets::Slider] that knows about NIH-plug parameters ranges
|
/// A slider widget similar to [egui::widgets::Slider] that knows about NIH-plug parameters ranges
|
||||||
/// and can get values for it.
|
/// and can get values for it.
|
||||||
///
|
///
|
||||||
/// TODO: To keep things simple this currently only supports FloatParam, but it should be generic
|
|
||||||
/// over any kind of parameter
|
|
||||||
/// TODO: Vertical orientation
|
/// TODO: Vertical orientation
|
||||||
/// TODO: (before I forget) mouse scrolling, ctrl+click and double click to reset
|
/// TODO: (before I forget) mouse scrolling, ctrl+click and double click to reset
|
||||||
pub struct ParamSlider<'a> {
|
pub struct ParamSlider<'a, P: Param> {
|
||||||
param: &'a FloatParam,
|
param: &'a P,
|
||||||
setter: &'a ParamSetter<'a>,
|
setter: &'a ParamSetter<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ParamSlider<'a> {
|
impl<'a, P: Param> ParamSlider<'a, P> {
|
||||||
/// Create a new slider for a parameter. Use the other methods to modify the slider before
|
/// Create a new slider for a parameter. Use the other methods to modify the slider before
|
||||||
/// passing it to [Ui::add()].
|
/// passing it to [Ui::add()].
|
||||||
pub fn for_param(param: &'a FloatParam, setter: &'a ParamSetter<'a>) -> Self {
|
pub fn for_param(param: &'a P, setter: &'a ParamSetter<'a>) -> Self {
|
||||||
Self { param, setter }
|
Self { param, setter }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +31,7 @@ impl<'a> ParamSlider<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for ParamSlider<'_> {
|
impl<P: Param> Widget for ParamSlider<'_, P> {
|
||||||
fn ui(self, ui: &mut Ui) -> Response {
|
fn ui(self, ui: &mut Ui) -> Response {
|
||||||
// Allocate space, but add some padding on the top and bottom to make it look a bit slimmer.
|
// Allocate space, but add some padding on the top and bottom to make it look a bit slimmer.
|
||||||
let height = ui
|
let height = ui
|
||||||
|
|
Loading…
Add table
Reference in a new issue