pub struct Knob<'a, T: Numeric> { /* private fields */ }Expand description
Rotary knob bound to a numeric value.
let mut gain = -12.0_f32;
ui.add(
Knob::new(&mut gain, -60.0..=12.0)
.label("Gain")
.size(KnobSize::Small)
.default(0.0_f32)
.value_fmt(|v| format!("{v:.0} dB")),
);
let mut dc = -1.4_f32;
ui.add(
Knob::new(&mut dc, -5.0..=5.0)
.label("DC offset")
.bipolar()
.accent(Accent::Purple)
.show_value(true),
);Implementations§
Source§impl<'a, T: Numeric> Knob<'a, T>
impl<'a, T: Numeric> Knob<'a, T>
Sourcepub fn new(value: &'a mut T, range: RangeInclusive<T>) -> Self
pub fn new(value: &'a mut T, range: RangeInclusive<T>) -> Self
Create a knob bound to value, constrained to range.
Sourcepub fn label(self, label: impl Into<WidgetText>) -> Self
pub fn label(self, label: impl Into<WidgetText>) -> Self
Show a label above the knob.
Sourcepub fn size(self, size: KnobSize) -> Self
pub fn size(self, size: KnobSize) -> Self
Pick a visual size. Default: KnobSize::Medium.
Sourcepub fn accent(self, accent: Accent) -> Self
pub fn accent(self, accent: Accent) -> Self
Pick the fill colour from one of the theme accents. Default: Accent::Sky.
Sourcepub fn bipolar(self) -> Self
pub fn bipolar(self) -> Self
Render as a bipolar knob: the active arc fills from the centre of the range toward the current value, suited to signed values (DC offset, pan, balance).
Sourcepub fn detents<I, S>(self, detents: I) -> Self
pub fn detents<I, S>(self, detents: I) -> Self
Snap to a fixed list of (value, label) detents and render a labeled
tick at each. Drag, scroll, and arrow keys step between detents.
Existing step is overridden.
Sourcepub fn step(self, step: f64) -> Self
pub fn step(self, step: f64) -> Self
Snap continuous values to multiples of step (in the knob’s value
units). Integer-typed knobs snap to 1.0 automatically.
Ignored if detents is set.
Sourcepub fn log_scale(self) -> Self
pub fn log_scale(self) -> Self
Use a logarithmic value mapping. Falls back to linear if the range minimum is non-positive.
Sourcepub fn value_fmt(self, fmt: impl Fn(f64) -> String + 'a) -> Self
pub fn value_fmt(self, fmt: impl Fn(f64) -> String + 'a) -> Self
Provide a value formatter for the optional inline display.
Sourcepub fn show_value(self, show: bool) -> Self
pub fn show_value(self, show: bool) -> Self
Render the formatted value below the knob. Default: hidden.