Expand description
SpinBox — numeric input with increment/decrement buttons.
A generic composite over SpinValue
(integer and floating-point primitives), pairing the
TextInputField editing
primitive with a stacked pair of up/down step buttons. Semantics
are a synthesis of Qt’s QSpinBox / QDoubleSpinBox, WinUI 3’s
NumberBox, GTK’s GtkSpinButton, and the W3C ARIA
spinbutton role.
§Behaviour
- Value binding: a
Signal<T>is the single source of truth. Typing and stepping update it; external writes re-format the editable text. - Commit model: the user can type freely (subject to the
per-character input filter). The value is committed on
Enteror on focus loss — at commit time the text is parsed, clamped into[min, max](or wrapped, perWrapMode), and reformatted. Invalid input reverts to the last known good value. - Keyboard:
Up/Down→ ±single_stepPageUp/PageDown→ ±page_step(default:10 × single_step)Enter→ commit (stays focused)Home/Endstay bound to the text cursor (Qt-compatible).
- Mouse wheel: adjusts by
single_step— wheel down decreases, wheel up increases, matchingQAbstractSpinBox,GtkSpinButtonand WinUI’sNumberBox. Gated bywheel_mode(default: only when focused, to avoid accidental scroll changes). - Buttons: up/down buttons stack to the right of the field
by default; can be hidden with
button_layout. - Special value text: when the current value equals
minandspecial_value_textis set, the field shows that string instead of the formatted number — Qt’s “Auto” / “None” / “Unlimited” affordance. - Adaptive step: with
StepType::Adaptive, the effective step tracks the decimal magnitude of the current value (Qt’sAdaptiveDecimalStepType). Useful for values that span many orders of magnitude in the same control. - Locale: the number follows the active locale’s decimal
separator, digits and minus sign
(
localized, on by default); thousands separators are opt-in (use_grouping, off by default, as in Qt). Display, commit parse and the per-character input filter all resolve from oneNumberPresentation, so they cannot disagree about which separator the field is using — a French user sees12,5, types12,5, and the numeric keypad’s.still works. Rendering is a string transform over the value’s ownDisplay, never anf64round-trip, so aSpinBox<i64>stays exact past 2^53. Turn it off for a number that is an identifier rather than a quantity (port, version component, database id). With noI18nManagerinstalled the active locale is the C locale and this is a no-op. - Custom formatter / parser: full override via
text_from_valueandvalue_from_text; together they let you implement currency, percentages with stored fraction, hex, duration, anything. A custom formatter/parser owns the whole convention — it is not re-punctuated by the locale layer.
§Accessibility
The composite exposes itself as
Role::SpinButton
with numeric value, min, max, step, and jump properties set on
the AccessKit node; the AT receives
Increment,
Decrement,
SetValue, and
Focus actions. The
step buttons are structurally part of the SpinBox and publish
no separate a11y nodes.
§Example
ⓘ
use teksilo::widgets::{SpinBox, WrapMode};
let font_size = ctx.signal(12_i32);
ctx.add(
SpinBox::new(font_size, 4, 72)
.single_step(1)
.page_step(10)
.suffix(" pt"),
);
let gain_db = ctx.signal(0.0_f32);
ctx.add(
SpinBox::new(gain_db, -60.0, 12.0)
.single_step(0.5)
.decimals(1)
.suffix(" dB")
.wrap_mode(WrapMode::Clamp),
);Structs§
- SpinBox
- Numeric input with step buttons. Generic over
SpinValue— pre-implemented fori32,i64,u32,u64,usize,f32, andf64.
Enums§
- Button
Layout - Step-button visibility / placement. Moved up from
teksilo_widgets::spin_box::ButtonLayoutso the trait config can carry it without forcing the recipe to depend on the widget crate. - Step
Type - Step-size policy for each key/button press.
- Wheel
Mode - When the mouse wheel is allowed to adjust the value.
- Width
Policy - How the SpinBox decides its horizontal size envelope.
- Wrap
Mode - Out-of-range behavior when stepping past
minormax.