Stepper field

A stepper adjusts a value in increments so people can repeat small changes. It suits quantities such as an item count or a dimension when each increase or decrease has a predictable size.

day-pieces binds the value to app state and uses a native numeric control where available, with a composed control on other targets.

Add to your app

This control is included in day-pieces and re-exported through day::prelude::*. No additional crate or control feature is required. The selected toolkit supplies its native implementation; day::stepper::support() reports its availability after the Day runtime starts.

Platforms / toolkitsAvailability
AppKit, GTK, QtNative numeric stepper.
UIKit, Android, WinUI, ArkUI, WebComposed control. Forcing .native() on these targets shows a placeholder.

stepper(value) is a numeric stepper field: a text field with increment/decrement arrows, bound two-way to any Binding<f64> (a Signal<f64>, a day-model Field, or an app’s own binding over a selection). Each arrow click, and each settled edit (Return, focus loss), lands through write_commit, so under an undo stack every click is one undoable step.

The UI snippets use generated res::str accessors from an app’s Fluent catalog; see the example messages and catalog setup.

Authoring

use day::stepper::stepper;

let width = Signal::new(1.0f64);

labeled(
    res::str::stroke_width(),
    stepper(width)
        .range(0.0..=64.0) // typed and stepped values both clamp (default 0..=100)
        .step(1.0) // one arrow click (default 1)
        .decimals(0) // fraction digits shown (default 0)
        .id(id!(insp_stroke_w)), // the field's dayscript id, both idioms
)
  • .native() / .composed() / .idiom(…) pin one idiom; the default is Automatic: native where an arm exists (support() answers Native on appkit, gtk, qt), composed everywhere else. Native is literal: pinned on a toolkit with no renderer it draws Day’s visible placeholder. A custom .format() uses the composed control regardless of this setting.
  • .id(…) names the interactive field for dayscript on both idioms, wherever it sits in the chain.

StepperBuilder keeps .range(...), .step(...), formatting, and idiom selection available after layout modifiers such as .padding(...). Use number_field for the same numeric editing behavior without step buttons.

Formatted values

Use .format(NumberFormat::percent()) to display and edit percentages while storing a fraction:

let value = Signal::new(0.4);
stepper(value)
    .range(0.0..=1.0)
    .step(0.01)
    .format(NumberFormat::percent())

NumberFormat::decimal() defaults to two fraction digits; NumberFormat::percent() defaults to none. Set a different precision with .fraction_digits(1). Formatting and parsing use the current locale’s separators and digits. ASCII digits are accepted too. For percentages, 40 and 40% both represent 0.4; in German, 40,5 % represents 0.405.

Return or focus loss commits the edit and restores formatted text. While typing, unfinished input leaves the number unchanged. Invalid input, non-finite numbers, and malformed grouping are rejected; valid numbers clamp to the configured range. A locale or bound-value change refreshes the displayed text, including during editing. Arrow clicks and DayScript set_value use the stored units (0.01 is one percentage point here).

Formatted steppers use Day’s composed −/field/+ control on every toolkit, overriding .native(), .idiom(), and .decimals(). The field and buttons remain native controls.

For application-specific notation, .format_with(display, parse) accepts a display function returning a string or generated Fluent message and a parser returning Option<f64>. Earlier code passed these callbacks to the format method; rename those calls to format_with. Keep units and other application-owned text in the Fluent catalog.

Use number_field(value) for the same locale-aware editing without step buttons. See numeric formats for the accepted notation and explicit-locale methods.

Platform guidance

The AppKit renderer combines NSTextField and NSStepper; GTK uses GtkSpinButton, and Qt uses QDoubleSpinBox. Other targets compose the control from ordinary Day pieces.