Expand description
The slider family, in the manner of darktable’s bauhaus sliders: the label and the value inside the bar, a soft range the bar spans and a hard range a typed value may reach, fine and coarse adjustment, reset on a double click, and a value typed with its unit or as an expression.
Slider: one value, linear or logarithmic (Curve), on a plain or a gradient track (Gradient: hue, temperature), with an optional quad button at its end (a colour picker, a toggle).- A colour ramp (
Ramp,Slider::ramp,Knob::ramp): a colour for the minimum and one for the maximum (and stops between), the value drawn in the colour between them, blended in Oklab; the colour at the value (RampMode::Value) or the whole ramp on the track (RampMode::Track). The number and the thumb still say the value; a high-contrast theme keeps the theme’s own fill. RangeSlider: two values on one bar, a low and a high thumb.
Gestures:
- Drag anywhere on the bar: the value follows the pointer’s motion over the soft range; a click never makes it jump. A drag is one gesture (one undo step when bound to a store); Escape during it puts the value back with no trace.
- Fine and coarse: ten times finer and ten times coarser with
the pointer profile’s modifiers (
gesture.value.fineandgesture.value.coarse; Ctrl (Cmd) finer and Shift coarser by default), for drags, arrows and the wheel alike, unless the profile gives the arrows their own (value_keys: Lightroom’s Shift drag is finer, its Shift with the arrows coarser). - Keys when focused: the arrows step, Page Up and Page Down take coarse steps, Home and End go to the soft ends, Enter opens the typed entry.
- Wheel, as the pointer profile says
(
crate::pointer): guarded (the default), it scrolls the panel and steps a slider only when the slider has the focus or the step modifiers are held over it (Alt by default), so scrolling past sliders never changes a value; on values (darktable), it steps the slider under the pointer, and the panel scrolls with the panel modifiers (Ctrl+Alt). - Typed entry: a number or an expression (
expr:x * 2,1,5 EV); units after it are ignored; a value past the soft range is kept up to the hard one. Enter or leaving the entry (a click elsewhere, Tab, the focus taken by another widget) commits it; Escape closes it with nothing. It takes the keyboard when it opens, and after only when nobody holds the focus for a frame (a panel redrawn), which does not commit it. While open it owns Escape and Enter (crate::focus::text_input_owns_keyboard): key dispatchers leave them to it. - Double click: back to the default; so does a click with the
profile’s
gesture.value.resetmodifiers (Ctrl+PrimaryClickfor 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
(
Slider::menuturns it off;request_typed_entryopens the entry from a host’s own menu).
The keys are Gestures, data a profile may remap. The value text
is written in the interface’s language (crate::strings::number),
and so is the space before its unit (crate::strings::quantity).
Hooks. Slider::on_change sees every change before it is
written, as a Change (which thumb, from, to, the Cause, and
whether the gesture is done), and answers a Verdict: go, veto or
redirect to another value. A drag’s frames come with done: false;
its end comes once more, from the value before the drag to the last
one, with done: true, and a veto then puts the value back. The
application API turns the done changes into the slider.change step
(egui_pop_api::sliders). Slider::show says what changed.
Accessibility. The bar is an AccessKit slider named by its label, with its value, its value text (unit included), its range and step, and the increment, decrement and set-value actions.
Owned: egui’s Slider has no soft and hard range, no fine adjustment,
no reset, no gradient and no range (see docs/widgets.md).
use egui_pop_core::slider::{Gradient, RangeSlider, Slider};
fn sliders(ui: &mut egui::Ui, ev: &mut f64, hue: &mut f64, iso: &mut (f64, f64)) {
ui.add(Slider::new(ev, "Exposure", -3.0..=4.0).hard(-18.0..=18.0).step(0.01).unit("EV").signed().default(0.0));
ui.add(Slider::new(hue, "Hue", 0.0..=360.0).unit("°").gradient(Gradient::hue()));
ui.add(RangeSlider::new(&mut iso.0, &mut iso.1, "ISO", 50.0..=25600.0).logarithmic().integer());
}Modules§
- expr
- What a slider’s typed entry accepts: a number or a simple expression, written as the user’s locale writes numbers, with an optional unit after it.
Structs§
- Change
- A change a slider proposes, or made.
- Gestures
- The slider’s gestures, as data so a profile can remap them: by
default they follow the pointer profile (
Gestures::from_map);set_gesturessets them outright. The invariants hold whatever the keys: a click never makes the value jump, a drag is relative and one gesture, a modifier scales the step and never changes what is adjusted. - Gradient
- Colours at places along the bar, from 0 (the soft start) to 1 (its end), blended in between.
- Ramp
- Colours along the soft range, from 0 (its start) to 1 (its end), blended in Oklab in between.
- Range
Slider - Two values on one bar,
low <= high. - Slider
- A slider over an
f64. - Slider
Output - What a slider did in a frame.
Enums§
- Cause
- What changed a value.
- Curve
- How the bar maps values to positions.
- Ramp
Color - A ramp’s colour: a theme token, read in the theme drawn now, or an explicit colour. A token the theme lacks shows as the accent.
- Ramp
Mode - How a ramp is drawn (
Slider::ramp_track,Knob::ramp_track). - Thumb
- Which value of a slider.
- Verdict
- What an
on_changehook decides.
Constants§
- MIN_
WIDTH - The least width a horizontal slider takes, whatever its room: below
it the bar is clipped. In a narrow room the label goes first (into
the tooltip), then the unit (
Slider::compact). - VERTICAL_
LENGTH - A vertical slider’s length when no size is given.
Functions§
- gestures
- The sliders’ gestures in a context: those set, else the pointer
profile’s (
crate::pointer::map). - oklab_
mix atobatt(0 to 1, clamped), blended in Oklab; alpha blended straight.- parse_
typed - Parses a typed number or expression (
expr::eval, with no current value): units after it are ignored, a comma is a point. - request_
typed_ entry - Asks the slider or knob whose response is
widgetto open its typed entry, with its value, in its next pass: what the “Type a value” item of its menu does, for a host that gives it a menu of its own (Slider::menu). - set_
gestures - Sets the sliders’ gestures in a context, over the pointer profile’s.
- typing_
id - The id of a slider’s typed entry (for tests).