You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Slider readout: open signal, typed range, readout-only control, tone #328
Feature gaps found by a consumer (the bugs are filed separately):
No signal that the readout is open. Proposal: on_edit Began/Ended when the field opens and closes, as the stepper does, or an "is the readout open" query.
A typed value is clamped to the slider's range; typing should reach a wider range (e.g. ±380 dB behind a 60 dB slider). Proposal: .typed_range(..).
No readout without a slider (a typed number with no track). Proposal: the editable readout as a control of its own.
No per-readout tone or colour; the preset's default readout colour is muted where the consumer wants the label's. Proposal: .readout_tone(..) or a colour override.
This note has no code yet. It's written against main 584e09e and builds on #353 (#292), which already moved the readout's and stepper's shared opening rule (Opening, select_number) into prim::text_field. The build should wait for #353.
The one shared path: a number field core
Today the slider's readout (Row::show in owned/slider.rs) and the stepper's field (Spec::run_field in owned/stepper.rs) each keep their own editing state. Each has its own editing temp string and its own parse, clamp, snap and commit, and the two have already drifted:
stepper
slider readout
applies a value
as it parses
on Enter, if the text changed
Escape
commits what was typed
discards it
on_edit
Began at the first change, Ended at blur
once at the commit
All three features below need that logic again: the open signal, the typed range, and the standalone readout. So the first step is to pull it into one crate-internal type in a new module, owned/number_field.rs:
pub(super)structNumberField<A>{value:f64,accept:Accept,// the parse, the typed range, and the step latticecommit:Commit,// Live (the stepper) | OnEnter (the readout)edits:Edits<A>,autofocus:Autofocus,// Select from #292}impl<A>NumberField<A>{fnshow(&self,app:&mutA,ui:&mutUi,field:&Field,set:implFn(&mutA,f64)) -> Response;}
It owns the temp state, the opening rule, the session's Edits and the commit. The stepper, the slider's readout and the new standalone readout all call it. The two commit policies stay a two-variant enum, because they're the behaviours the user already approved for each control. Whether they should converge is a question below.
This sharing is also why all four features belong in core. The slider is core, so its readout can't depend on extras, and a standalone readout in extras would need a second copy of this code. That copy is the drift the table above already shows.
1. An open signal
Recommendation: the readout's open session is one Edit.Began comes when the readout opens and Ended when it closes, and the committed value, if any, is set between them. Escape gives Began then Ended with no value, which Edit's docs already allow ("before the first value it sets").
This needs no new API, and it follows what an edit already means: one gesture, with the open click as the gesture. It differs from the stepper, whose edit begins at the first change, not at focus. The difference is deliberate. The stepper's field is always there, so focusing it isn't an edit, while opening the readout is an explicit act.
The alternative is a query, Slider::is_editing(ctx, id). It needs the caller to know the slider's id, and it can't tell a handler when the state changed. I don't recommend it.
2. .typed_range(..)
b.slider("gain", gain, -60.0..=0.0).readout(|v| format!("{v:.1} dB")).editable(parse_db).typed_range(-380.0..=380.0).on_change(|app, v| app.gain = v);
Accept: a typed value is clamped to the typed range and snapped on the step's lattice, still anchored at the drag range's start. With step 7 and a typed start that isn't on the drag lattice, anchoring at the typed start would put typed values off the lattice that dragged values use. This needs a crate-internal Step::snap_from(origin, value, range), with snap calling it.
Out of range: the thumb pins at its end (the fraction is already clamped), and the readout shows the true value.
A typed range that doesn't contain the drag range: reported through report (Problem::BadRange), with the union of the two as the fallback. No panic.
Assistive technology:aria-valuemin and aria-valuemax are the drag range, widened to include the value, so the value is never outside them.
The stepper: it doesn't take typed_range, because it has only one range. Its typed values go through the same Accept with the typed range equal to its range.
3. The editable readout as a control of its own
b.readout("gain", gain, -380.0..=380.0).format(|v| format!("{v:.1} dB")).editable(parse_db)// without this it's a plain number.step(Step::new(0.1)).named("Gain").on_change(|app, v| app.gain = v);
It draws exactly the slider's readout: the same node tree, with the click opening the box past its edge. The slider's header becomes a label plus this control, so there is one implementation.
Its single range is what the slider calls the typed range.
It has no label. The caller lays one out, as for a stepper.
Name:readout collides with SliderChain::readout (the format). An alternative is number, but it's vaguer. That's a question below.
4. Tone or colour per readout
#358 already makes this possible without any new API:
b.styled(|s| s.slider.readout = s.slider.label, |b| {
b.slider("gain", gain, range).label("Gain").readout(fmt).on_change(set);});
The override follows the theme, because it reads the style of the frame, light or dark. It also costs one style clone per scope per frame and adds no node.
The case for a chain method anyway: a one-off readout colour is common enough that .readout_tone(..) reads better at the call site. If it's wanted, it should be a token, not a Color32, so it keeps working across themes:
The standalone readout also needs a default colour. I recommend it inherits the text colour around it, as b.text does, rather than the slider's muted readout. Next to a label it should look like the label.
Questions for the user, with my recommendations
The open signal: Began when the readout opens and Ended when it closes, through the existing on_edit? Recommend yes.
Arrow keys from a typed value outside the drag range (for example ArrowRight at 380 with a −60..=0 slider): jump to the nearest end of the drag range, or step within the typed range? Recommend stepping within the typed range from where the value is: one press moves one step, never a 380-unit jump. Home and End still go to the drag range's ends.
The standalone control's name:b.readout(..), b.number(..) or b.number_readout(..)? Recommend b.number(..), because readout is already the slider's format method.
Its default colour: the surrounding text, or the slider's muted readout colour? Recommend the surrounding text.
Tone: is b.styled enough, or add .readout_tone(ReadoutTone)? Recommend styled for now, with a doctest showing it, and adding the token method if a second consumer asks.
Out of scope unless you want it: should the standalone readout also scrub when dragged, as egui's DragValue does? Recommend no, as a separate issue if wanted.
Should the two commit policies converge (stepper live, readout on Enter, and Escape discarding in one and keeping in the other)? Recommend leaving them as they are in this work, and filing it as its own question.
From a consumer's widget review: three sites (a compensator's Gain and Norm frequency, a biquad grid's coefficient terms) each rebuild the readout's rules by hand: Return commits, blur commits or reverts, unparseable text reverts, and a button face swaps to a field. They need the standalone number control (item 3) with a tone (item 4); the grid shows changed terms in orange.
One commit policy for the stepper and the slider readout: on Enter (or leaving the field); Escape reverts. The stepper changes from applying as you type; that's a behaviour change, so list it.
The standalone control is named b.number(..): b.number(key, value, range).format(..).editable(parse), and the slider's header becomes a label plus this control.
The note's other recommendations are accepted:
the open signal via on_edit Began/Ended;
.typed_range(..), with the thumb pinning;
arrows step from where the value is, Home/End go to the drag ends;
the standalone control's default colour is the surrounding text;
tone via b.styled for now;
no drag-to-scrub in v1.
The PRs:
the shared NumberField extraction plus the commit-policy change (a user trial);
Activity
samitbasu commentedon Nov 18, 2026
Design note: the four readout features
This note has no code yet. It's written against main 584e09e and builds on #353 (#292), which already moved the readout's and stepper's shared opening rule (
Opening,select_number) intoprim::text_field. The build should wait for #353.The one shared path: a number field core
Today the slider's readout (
Row::showinowned/slider.rs) and the stepper's field (Spec::run_fieldinowned/stepper.rs) each keep their own editing state. Each has its owneditingtemp string and its own parse, clamp, snap and commit, and the two have already drifted:on_editonceat the commitAll three features below need that logic again: the open signal, the typed range, and the standalone readout. So the first step is to pull it into one crate-internal type in a new module,
owned/number_field.rs:It owns the temp state, the opening rule, the session's
Edits and the commit. The stepper, the slider's readout and the new standalone readout all call it. The two commit policies stay a two-variant enum, because they're the behaviours the user already approved for each control. Whether they should converge is a question below.This sharing is also why all four features belong in core. The slider is core, so its readout can't depend on extras, and a standalone readout in extras would need a second copy of this code. That copy is the drift the table above already shows.
1. An open signal
Recommendation: the readout's open session is one
Edit.Begancomes when the readout opens andEndedwhen it closes, and the committed value, if any, is set between them. Escape givesBeganthenEndedwith no value, whichEdit's docs already allow ("before the first value it sets").This needs no new API, and it follows what an edit already means: one gesture, with the open click as the gesture. It differs from the stepper, whose edit begins at the first change, not at focus. The difference is deliberate. The stepper's field is always there, so focusing it isn't an edit, while opening the readout is an explicit act.
The alternative is a query,
Slider::is_editing(ctx, id). It needs the caller to know the slider's id, and it can't tell a handler when the state changed. I don't recommend it.2.
.typed_range(..)Step::snap_from(origin, value, range), withsnapcalling it.report(Problem::BadRange), with the union of the two as the fallback. No panic.aria-valueminandaria-valuemaxare the drag range, widened to include the value, so the value is never outside them.typed_range, because it has only one range. Its typed values go through the sameAcceptwith the typed range equal to its range.3. The editable readout as a control of its own
on_edit(with the item 1 semantics),size,classes,enablement,tooltip,on_response, andfocus_on_appear_selectingfrom Text field: select all text when focused programmatically #292.readoutcollides withSliderChain::readout(the format). An alternative isnumber, but it's vaguer. That's a question below.4. Tone or colour per readout
#358 already makes this possible without any new API:
The override follows the theme, because it reads the style of the frame, light or dark. It also costs one style clone per scope per frame and adds no node.
The case for a chain method anyway: a one-off readout colour is common enough that
.readout_tone(..)reads better at the call site. If it's wanted, it should be a token, not aColor32, so it keeps working across themes:The standalone readout also needs a default colour. I recommend it inherits the text colour around it, as
b.textdoes, rather than the slider's muted readout. Next to a label it should look like the label.Questions for the user, with my recommendations
on_edit? Recommend yes.b.readout(..),b.number(..)orb.number_readout(..)? Recommendb.number(..), becausereadoutis already the slider's format method.b.styledenough, or add.readout_tone(ReadoutTone)? Recommendstyledfor now, with a doctest showing it, and adding the token method if a second consumer asks.DragValuedoes? Recommend no, as a separate issue if wanted.Suggested PRs (after #353)
NumberFieldextracted, with no behaviour change and every existing test unchanged, plus the open signal (1).typed_range(2).samitbasu commentedon Nov 18, 2026
From a consumer's widget review: three sites (a compensator's Gain and Norm frequency, a biquad grid's coefficient terms) each rebuild the readout's rules by hand: Return commits, blur commits or reverts, unparseable text reverts, and a button face swaps to a field. They need the standalone number control (item 3) with a tone (item 4); the grid shows changed terms in orange.
samitbasu commentedon Nov 18, 2026
Decisions (user, 2026-11-18):
b.number(..):b.number(key, value, range).format(..).editable(parse), and the slider's header becomes a label plus this control.on_editBegan/Ended;.typed_range(..), with the thumb pinning;b.styledfor now;b.number.Merge pull request #403 from samitbasu/numberfield-328
Merge pull request #407 from samitbasu/typed-range-328
Merge pull request #414 from samitbasu/number-328
Merge pull request #418 from samitbasu/number-refused-328