Actively developed · Breaking changes are still expected.

Slint Kit Documentation

Search the documentation

    ↑ ↓ to browse · Enter to open · Escape to close

    Keypads and codes

    Code Indicator for Slint

    KitCodeIndicator · Slint Kit 0.9.0

    Progress of a code entry: one mark per expected digit, the first ones filled.

    The still preview and demo follow the documentation theme. You can change it before or during the demo.

    Progress of a code entry: one mark per expected digit, the first ones filled.
    Slint components with their built-in Tailwind appearance, rendered in the browser.

    This preview runs the actual Slint components and their Rust code compiled to WebAssembly. Slint draws the interface in the browser; the downloadable project compiles the same example into a native application for your platform.

    Try the component

    Download the complete project, extract it and run cargo run --locked in its folder. To add this component to an application, follow Project setup, then copy the two files below.

    The kit supplies the component's behavior and styles; Rust callbacks connect its typed values to your application.

    Press digits on the keypad to fill up to six marks, then use Delete or Backspace to remove one. Rust owns the count and updates the indicator’s accessible label. This example demonstrates progress only: it does not store or verify a code, and Verify stays disabled.

    ui/app.slint

    
    // SPDX-License-Identifier: GPL-3.0-or-later
    import { InterFont } from "@kit-fonts/inter.slint";
    import { KitCodeIndicator, KitKeypad, KitTheme, KitThemeContext, KitMetrics, TypographyRole } from "@kit";
    export component App inherits Window {
        default-font-family: InterFont.family;
        default-font-size: KitMetrics.font-size(root.theme, TypographyRole.body);
        title: "Code Indicator";
        preferred-width: 440px; preferred-height: 560px;
        max-width: 100000px; max-height: 100000px;
        in-out property <KitTheme> theme: KitThemeContext.current;
        background: root.theme.canvas;
        // Rust counts the digits; the marks follow that count, never the digits.
        in property <int> entered;
        in property <int> code-length;
        callback digit();
        callback delete-requested();
        VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
            Text { text: "Verification progress"; color: root.theme.text-primary; font-size: 22px * root.theme.text-scale; font-weight: 600; }
            indicator := KitCodeIndicator { theme: root.theme; length: root.code-length; filled: root.entered; label: root.entered + " of " + root.code-length + " digits entered"; }
            HorizontalLayout { alignment: center;
                KitKeypad { theme: root.theme; label: "Verification code"; confirm-label: "Verify"; can-confirm: false;
                    digit(value) => { root.digit(); }
                    delete-requested => { root.delete-requested(); }
                }
            }
        }
    }
    
    

    src/main.rs

    // SPDX-License-Identifier: GPL-3.0-or-later
    slint::include_modules!();
    fn main() -> Result<(), slint::PlatformError> {
        let app = App::new()?;
        slint_kit::install(&app);
        app.set_code_length(6);
        app.on_digit(slint_kit::action(&app, |app| app.set_entered((app.get_entered() + 1).min(6))));
        app.on_delete_requested(slint_kit::action(&app, |app| app.set_entered((app.get_entered() - 1).max(0))));
        app.run()
    }
    
    

    Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs

    Supply length, the number of expected digits, filled, the number already entered, and a localized accessible label, such as “2 of 4 digits”. Pair it with KitKeypad.

    The indicator shows how many digits the host holds, never which. The host supplies filled, validation and a localized label; invalid/valid use danger/success tokens while pristine/checking remain neutral. control-size changes the marks and text-scale enlarges them. The text role exposes label with standard accessible-live-region: polite; a composition may override that inherited Slint property without a new live-mode enum. There is no built-in validation message, code acceptance or keypad connection.

    Control accessibility

    The label is a polite live-region text: update it with progress and localized error/success feedback when those changes should be announced. Mark colors alone do not communicate that message. Keep the code itself out of the label; qualify the target backend and screen reader separately, since metadata/headless checks do not establish physical AT announcements.

    Choose between built-in options and custom composition

    Shared options

    Visual composition

    The file below describes the captured scene. For controller-driven components, it shows the displayed state without supplying the Rust wiring. Create a project.

    Show the screenshot source
    Progress of a code entry: one mark per expected digit, the first ones filled.
    Browser capture of the same Slint example, femtovg renderer.
    // SPDX-License-Identifier: GPL-3.0-or-later
    import { InterFont } from "@kit-fonts/inter.slint";
    import { KitCodeIndicator, ValidationPresentation, ControlSize, KitButton, KitTheme, KitThemes, KitMetrics, TypographyRole } from "@kit";
    export component Example inherits Window {
        default-font-family: InterFont.family;
        default-font-size: KitMetrics.font-size(root.theme, TypographyRole.body);
        title: "Code Indicator";
        preferred-width: 440px; preferred-height: 240px;
        max-width: 100000px; max-height: 100000px;
        in-out property <KitTheme> theme: KitThemes.light;
        background: root.theme.canvas;
        in-out property <int> entered: 2;
        // The host supplies validation and localized feedback; the label never contains the code.
        in-out property <ValidationPresentation> validation: ValidationPresentation.pristine;
        in-out property <string> feedback;
        VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
            Text { text: "Verification progress"; color: root.theme.text-primary; font-size: 22px * root.theme.text-scale; font-weight: 600; }
            Text { text: "Six marks for a six-digit code; the marks show how many digits are entered, never which."; color: root.theme.text-secondary; wrap: word-wrap; }
            KitCodeIndicator { theme: root.theme; validation: root.validation; control-size: ControlSize.medium; length: 6; filled: root.entered; label: root.entered + " of 6 digits entered" + (root.feedback == "" ? "" : ". " + root.feedback); }
            HorizontalLayout { spacing: 12px; alignment: center;
                KitButton { theme: root.theme; text: "Add a digit"; activated => { root.entered = min(6, root.entered + 1); root.validation = ValidationPresentation.pristine; root.feedback = ""; } }
                KitButton { theme: root.theme; text: "Remove a digit"; activated => { root.entered = max(0, root.entered - 1); root.validation = ValidationPresentation.pristine; root.feedback = ""; } }
            }
        }
    }
    
    

    Download this example

    Public API

    Inherits Rectangle.

    Properties

    The "Default" column repeats the initializer declared in the source; "—" is the zero value of the type, and a composite expression points to the source.

    Name Type Direction Default
    theme KitTheme in KitThemeContext.current
    length int in —
    filled int in —
    label string in —
    control-size ControlSize in ControlSize.medium
    validation ValidationPresentation in ValidationPresentation.pristine

    Property details

    Effect, default, states and constraints of the central properties, with a snippet that uses public mechanisms. Inherited properties carry the explanation of the component that declares them. The complete typed example and the Forms guide wire these properties end to end.

    filled int · in

    Number of filled marks supplied by the host; the indicator does not retain the entered digits.

    label string · in

    Host-localized accessible progress and optional validation feedback, for example “2 of 4 digits entered. Try again.” The indicator exposes it through a text role and standard polite live region.

    Constraints
    Describe count/state without revealing the entered secret. No internal error/success message or automatic keypad association is added.

    control-size ControlSize · in

    Mark diameter for ControlSize.compact, medium or comfortable, scaled with text.

    Default
    ControlSize.medium
    Constraints
    Uses 2/3/4 theme spacing units times text-scale. Medium preserves 12px marks at 100% with the shipped spacing.

    validation ValidationPresentation · in

    Host-owned ValidationPresentation: invalid paints the marks with danger tokens, valid with success tokens; pristine and checking keep the neutral presentation. It does not validate or accept the code.

    Default
    ValidationPresentation.pristine
    Constraints
    Put localized error/success feedback in label as well if it should be announced; changing mark color alone does not add a message.

    Types and variants

    Type Declaration
    enum ControlSize compact, medium, comfortable
    enum ValidationPresentation pristine, checking, valid, invalid

    See also