UI Toolbox logoUI Toolbox
Support

Knob

A Knob is a rotary control that sets a number between a minimum and a maximum on a 270 degree scale, as on the knobs of audio software. A ring around the cap shows the value, and the pointer on the cap points at it. Use it for a volume, a pan, a filter cutoff or any setting that you want to turn rather than slide. For two values at once, see XYPad.

A Synth panel with Cutoff, Resonance and Drive knobs, and a Wave knob with steps set to SawA Synth panel with Cutoff, Resonance and Drive knobs, and a Wave knob with steps set to Saw

<UIToolbox.Knob
    label="Cutoff"
    min-value="0"
    max-value="100"
    value="40"
    default-value="40" />
<UIToolbox.Knob
    label="Pan"
    min-value="-100"
    max-value="100"
    whole-numbers="true" />
<UIToolbox.Knob
    label="Wave"
    max-value="3"
    whole-numbers="true"
    detents="4"
    show-value="false" />
<UIToolbox.Knob
    label="Drive"
    max-value="10"
    drag-mode="Circular"
    format-string="F1" />
var cutoff = new Knob("Cutoff")
{
    MinValue = 0,
    MaxValue = 100,
    DefaultValue = 40
};
cutoff.value = 40;
cutoff.RegisterValueChangedCallback(evt => filter.Cutoff = evt.newValue);

A knob needs no setup. Without limits it goes from 0 to 100 and takes any value in between.

Member Description
MinValue (min-value) The value at the start of the scale (0). A minimum above the maximum moves the maximum up.
MaxValue (max-value) The value at the end of the scale (100). A maximum below the minimum moves the minimum down.
Step (step) The distance between the values that the knob takes, counted from MinValue. 0 (the default) takes any value.
WholeNumbers (whole-numbers) Rounds the value to a whole number. A step is then at least 1.
Detents (detents) The number of evenly spaced stops, from the minimum to the maximum, that the knob clicks into. The stops show as ticks around the ring. 0 (the default) and 1 turn the detents off. Detents replace Step.
DefaultValue (default-value) The value that a double click, Enter and Space set (0). It stays between the limits.
DragMode (drag-mode) A KnobDragMode: Either (the default), Vertical, Horizontal or Circular. See below.
DragDistance (drag-distance) How far a straight drag goes for the whole range, in pixels (200). A larger distance turns the knob more slowly.
UseWheel (use-wheel) The mouse wheel over the knob changes the value (on).
ShowValue (show-value) Shows the value as text under the knob (on).
FormatString (format-string) A .NET numeric format for the value text, such as F1 or 0 dB. The default shows no decimals with WholeNumbers and up to two otherwise. The text rounds the value to hundredths and uses the current culture.
value The value. A set snaps it to the step or to a detent and clamps it to the limits.

A change of a limit, the step or the detents applies to the current value again. The UXML value attribute comes after the limits and the step, whatever the order of the attributes.

Pointer

A drag keeps its exact position when Step or Detents snap the value, so a slow drag still gets from one stop to the next.

Keyboard and gamepad

The knob is a focus stop. Tab (or a gamepad move to the next control) focuses it.

Key Action
Right, Up Raises the value by Step, by one detent, or by 1% of the range.
Left, Down Lowers the value by the same. A key at the end of the way moves the focus on.
Page Up, Page Down Changes the value by 10% of the range.
Home, End Goes to the minimum or the maximum.
Enter, Space Sets DefaultValue. The submit button of a gamepad does the same.
Escape Ends a drag and puts the value back.

The D-pad and the left stick of a gamepad only move the focus. While the knob has the focus, the right stick turns it: a full push sweeps the whole range in 2 seconds. A (Submit) sets DefaultValue. The right stick does not scroll a ScrollView around the knob while the knob has the focus.

The ring

The ring shows the value as an arc. When the range holds zero, for example a pan from -100 to 100 or a gain from -12 to 12 dB, the arc starts at zero and goes either way, so the knob shows left and right. Otherwise it starts at the minimum.

Events

A change of the value from the pointer, the wheel, the keys or value sends one ChangeEvent<float>. A key or a drag step that changes nothing sends none, and SetValueWithoutNotify sends none.

A knob makes no garbage while it is idle, animating or dragged: the text of each value is made once and kept, so a drag over a fine range allocates nothing after the first pass. Setting FormatString clears the kept texts.

Styling

Class Element
tb-knob The field.
tb-knob__dial The element that holds the ring, the cap and the pointer. Its size is the size of the knob (56 by 56).
tb-knob__value The value text under the knob.

The ring, the cap and the ticks are drawn from custom properties on .tb-knob, so a theme or a class can change them:

Property Default Used for
--tb-knob-track --tb-color-border The ring behind the value.
--tb-knob-arc --tb-color-accent The part of the ring that shows the value.
--tb-knob-cap --tb-color-surface-alt The fill of the cap.
--tb-knob-cap-border --tb-color-border The outline of the cap. It turns lighter on hover and takes the accent color on focus.
--tb-knob-pointer --tb-color-text The line on the cap.
--tb-knob-tick --tb-color-text-muted The ticks of the detents.
--tb-knob-ring-width 4 The width of the ring, in pixels.
.big-knob .tb-knob__dial { width: 96px; height: 96px; }
.big-knob { --tb-knob-ring-width: 6; --tb-knob-arc: #ff8a3d; }