Skip to main content

Knob

Struct Knob 

Source
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>

Source

pub fn new(value: &'a mut T, range: RangeInclusive<T>) -> Self

Create a knob bound to value, constrained to range.

Source

pub fn label(self, label: impl Into<WidgetText>) -> Self

Show a label above the knob.

Source

pub fn size(self, size: KnobSize) -> Self

Pick a visual size. Default: KnobSize::Medium.

Source

pub fn accent(self, accent: Accent) -> Self

Pick the fill colour from one of the theme accents. Default: Accent::Sky.

Source

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).

Source

pub fn detents<I, S>(self, detents: I) -> Self
where I: IntoIterator<Item = (T, S)>, S: Into<String>,

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.

Source

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.

Source

pub fn log_scale(self) -> Self

Use a logarithmic value mapping. Falls back to linear if the range minimum is non-positive.

Source

pub fn value_fmt(self, fmt: impl Fn(f64) -> String + 'a) -> Self

Provide a value formatter for the optional inline display.

Source

pub fn show_value(self, show: bool) -> Self

Render the formatted value below the knob. Default: hidden.

Source

pub fn default(self, default: T) -> Self

Value to reset to on Alt+click or double-click. If unset, the reset gesture is a no-op.

Source

pub fn enabled(self, enabled: bool) -> Self

Disable the knob — no pointer, scroll, or keyboard input. Default: enabled.

Trait Implementations§

Source§

impl<'a, T: Numeric> Debug for Knob<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Numeric> Widget for Knob<'a, T>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Knob<'a, T>
where T: Freeze,

§

impl<'a, T> !RefUnwindSafe for Knob<'a, T>

§

impl<'a, T> !Send for Knob<'a, T>

§

impl<'a, T> !Sync for Knob<'a, T>

§

impl<'a, T> Unpin for Knob<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for Knob<'a, T>
where T: UnsafeUnpin,

§

impl<'a, T> !UnwindSafe for Knob<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.