Skip to main content

truce_iced/widgets/
mod.rs

1//! Widget library for iced-based plugin UIs.
2//!
3//! Provides parameter-bound widgets that emit `Message::Param` messages
4//! for host communication.
5
6pub mod knob;
7pub mod meter;
8pub mod selector;
9pub mod slider;
10pub mod toggle;
11pub mod xy_pad;
12
13use std::fmt::Debug;
14
15use truce_params::Params;
16
17use crate::param_cache::ParamCache;
18
19// Re-export widget types for convenience.
20pub use knob::KnobWidget;
21pub use meter::MeterWidget;
22pub use selector::SelectorWidget;
23pub use slider::SliderWidget;
24pub use toggle::ToggleWidget;
25pub use xy_pad::XYPadWidget;
26
27/// Create a rotary knob bound to a parameter.
28pub fn knob<M: Clone + Debug + 'static>(
29    id: impl Into<u32>,
30    params: &ParamCache<impl Params>,
31) -> KnobWidget<'_, M> {
32    KnobWidget::new(id.into(), params)
33}
34
35/// Create a horizontal slider bound to a parameter.
36pub fn param_slider<M: Clone + Debug + 'static>(
37    id: impl Into<u32>,
38    params: &ParamCache<impl Params>,
39) -> SliderWidget<'_, M> {
40    SliderWidget::new(id.into(), params)
41}
42
43/// Create a toggle switch bound to a parameter.
44pub fn param_toggle<M: Clone + Debug + 'static>(
45    id: impl Into<u32>,
46    params: &ParamCache<impl Params>,
47) -> ToggleWidget<'_, M> {
48    ToggleWidget::new(id.into(), params)
49}
50
51/// Create a selector (pick list) bound to an enum parameter.
52pub fn param_selector<M: Clone + Debug + 'static>(
53    id: impl Into<u32>,
54    params: &ParamCache<impl Params>,
55) -> SelectorWidget<'_, M> {
56    SelectorWidget::new(id.into(), params)
57}
58
59/// Alias for [`param_selector`].
60pub fn param_dropdown<M: Clone + Debug + 'static>(
61    id: impl Into<u32>,
62    params: &ParamCache<impl Params>,
63) -> SelectorWidget<'_, M> {
64    SelectorWidget::new(id.into(), params)
65}
66
67/// Create a level meter display.
68pub fn meter<'a, M: Clone + Debug + 'static>(
69    ids: &[impl Into<u32> + Copy],
70    params: &'a ParamCache<impl Params>,
71) -> MeterWidget<'a, M> {
72    let u32_ids: Vec<u32> = ids.iter().map(|id| (*id).into()).collect();
73    MeterWidget::new(&u32_ids, params)
74}
75
76/// Create an XY pad controlling two parameters.
77pub fn xy_pad<M: Clone + Debug + 'static>(
78    x_id: impl Into<u32>,
79    y_id: impl Into<u32>,
80    params: &ParamCache<impl Params>,
81) -> XYPadWidget<'_, M> {
82    XYPadWidget::new(x_id.into(), y_id.into(), params)
83}