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.


<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
- Either drag (the default). Press the cap and drag up or right to raise the value, down or left to lower it. The first move picks the way: after the pointer goes 3 pixels from the press, the drag keeps to up and down or to left and right until the release, and a move on the other way does nothing. The pointer can leave the knob during the drag, so a long drag goes past the edge of the knob.
- Vertical drag. Only up and down change the value. Use it when the knob sits in a row that scrolls left and right, or for the feel of audio software.
- Horizontal drag. Only left and right change the value.
- Distance. In a straight drag,
DragDistancepixels turn the knob over its whole range. A drag past an end keeps the value at that end, and a move back changes it at once. - Circular drag. The knob turns with the pointer as it moves around the center of the knob. A press does not move the value: the knob turns by the angle that the pointer turns. Near the center of the knob the value holds, because a small move there is a big turn, so a drag across the center does not jump. In the gap at the bottom of the scale the knob stays at the end that is nearer. A circular drag turns the knob round like a real dial; an up and down drag does not change the value much.
- Shift. A straight drag with Shift held turns the knob ten times slower, for fine settings.
- Double click. Sets
DefaultValue. - Wheel. A notch away from the user raises the value by one step, one detent, or 1% of the range when both are off.
- Escape. Escape during a drag puts the value back to what it was when the drag began.
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; }