Skip to main content

Module knob

Module knob 

Source
Expand description

A knob: one value on a rotary dial, from the same terms as a Slider (soft and hard range, step, unit, default, the on_change hook) and under the same history contract: a drag is one gesture, its frames done: false and its end once more done: true from the value before it; Escape during it puts the value back with no trace.

Experimental: may change in any release (docs/stability.md).

Gestures:

  • Drag, in one mode per knob (KnobDrag): right and up both add (Both, the default: some people drag up, others sideways), up only (Vertical), right only (Horizontal), or around the centre (Circular, relative to the press). The knob’s own mode (Knob::drag), else the pointer profile’s (options.knob_drag). Where the press lands never changes the mode, and a click never makes the value jump. The linear modes move over the soft range in Knob::travel points (200 by default), whatever the knob’s size; the circular one over the dial’s 270° sweep, still near the centre.
  • Fine and coarse: the pointer profile’s modifiers (gesture.value.fine, Ctrl by default; gesture.value.coarse, Shift by default) make a drag, the wheel and the arrows ten times finer or coarser, as on a slider; pressed mid-drag, from where the value is (no jump).
  • Wheel: as the slider’s, by the pointer profile (in the guarded profiles the panel scrolls unless the knob has the focus or the step modifier is held), or over the knob whenever the pointer is, with KnobWheel::Hover, for places that do not scroll. A notch is a step; a touchpad’s scroll steps once a line’s length.
  • Keys (arrows, Page Up and Page Down, Home and End), typed entry (Enter) and assistive actions: as the slider’s, from the same pointer profile.
  • Endless (Knob::endless): no arc and no ends, ticks turning with the value; the value wraps around the soft range (Endless::Wrap, an angle, a hue) or has no bounds (Endless::Unbounded), and each change says how far it moved (Change::delta, unwrapped), for a host that maps it to nudges.
  • Hidden pointer (opt-in, Knob::hide_pointer or Gestures::knob_hide_pointer): a linear drag hides the pointer and puts it back where the press was at its end (ViewportCommand::CursorVisible and CursorPosition). Windows, macOS and X11 do both; Wayland hides it but refuses to move an unlocked pointer, so it reappears where the drag ended; on the web neither command applies and the pointer stays visible.
  • Double click: back to the default; so does a click with the profile’s gesture.value.reset modifiers (Ctrl+PrimaryClick for one), which no shipped profile binds.
  • Right click (or the context menu key): a menu, “Type a value” (the typed entry) and “Reset” when there is a default (Knob::menu turns it off).

Layout. The dial takes the largest square of its room. In a room at least twice as wide as high, the label and the value stand beside it; in one taller than wide, the value is above and the label below (as a fader’s); else the value is inside the dial and the label in the tooltip.

Accessibility. An AccessKit slider named by its label, with its value, value text, range, step and the increment, decrement and set-value actions, as the slider’s.

use egui_pop_core::knob::Knob;

fn knob(ui: &mut egui::Ui, ev: &mut f64) {
    Knob::new(ev, "Exposure", -3.0..=4.0).step(0.01).unit("EV").signed().default(0.0).show(ui);
}

Structs§

Knob
A rotary knob over an f64.

Enums§

Endless
How an endless knob’s value goes past its soft range (Knob::endless).
KnobDrag
How a drag turns a knob. The same travel, in points, covers the soft range in every mode; where the press lands never changes the mode.
KnobWheel
When the wheel turns a knob.

Constants§

SWEEP
The dial’s sweep, in radians: from 7:30 to 4:30 through 12.
TRAVEL
Points of drag over the soft range, by default.