Actively developed · Breaking changes are still expected.

Slint Kit Documentation

Search the documentation

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

    Colors

    Color Wheel for Slint

    KitColorWheel · Slint Kit 0.9.0

    A hue/saturation wheel that proposes opaque RGB colors.

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

    A hue/saturation wheel that proposes opaque RGB colors.
    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.

    Click the spectrum or use arrow keys to change the typed RGB draft. Apply color submits that same Rust value and shows its hexadecimal form.

    ui/app.slint

    // SPDX-License-Identifier: GPL-3.0-or-later
    import { KitColorWheel, KitStack, KitButton, KitFieldDescription, KitTheme, KitThemeContext, SrgbColorView, LayoutSpace } from "@kit";
    export component App inherits Window {
        preferred-width: 420px; preferred-height: 400px;
        max-width: 100000px; max-height: 100000px;
        in-out property <KitTheme> theme <=> KitThemeContext.current;
        background: root.theme.canvas;
        title: "Color wheel";
        in property <SrgbColorView> draft-color;
        in property <string> status;
        callback color-chosen(SrgbColorView);
        callback submit-color();
        KitStack { inset: LayoutSpace.roomy;
            KitColorWheel { theme: root.theme; label: "Accent color"; value: root.draft-color; chosen(value) => { root.color-chosen(value); } }
            KitFieldDescription { theme: root.theme; text: root.status; }
            KitButton { theme: root.theme; text: "Apply color"; activated => { root.submit-color(); } }
        }
    }
    
    

    src/main.rs

    // SPDX-License-Identifier: GPL-3.0-or-later
    use slint::ComponentHandle;
    use slint_kit::{AlphaPolicy, SrgbColor, action, event};
    slint::include_modules!();
    fn main() -> Result<(), slint::PlatformError> {
        let app = App::new()?;
        slint_kit::install(&app);
        let initial = SrgbColor { red: 124, green: 108, blue: 240, alpha: 255 };
        app.set_draft_color(initial.into());
        app.set_status(format!("Draft: {}", initial.hex(AlphaPolicy::Opaque)).into());
        app.on_color_chosen(event(&app, |app, view| { if let Ok(color) = SrgbColor::try_from(view) { app.set_draft_color(color.into()); app.set_status(format!("Draft: {}", color.hex(AlphaPolicy::Opaque)).into()); } }));
        app.on_submit_color(action(&app, |app| { if let Ok(color) = SrgbColor::try_from(app.get_draft_color()) { app.set_status(format!("Applied: {}", color.hex(AlphaPolicy::Opaque)).into()); } }));
        app.run()
    }
    
    

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

    Set value: SrgbColorView, known, access and generation. Install the kit services once per window. Handle chosen(SrgbColorView) as a local draft; the owner submits explicitly. Increase generation on rebind. Read hue for the local editing hue and call choose-hue(float degrees, 0..360) to share it with another control. Known white/gray retains this hue without altering RGB; an explicit hue choice on an unknown color proposes a saturated opaque RGB color. Reset generation or known on replacement; Escape and access changes also discard local hue.

    Pointer movement and arrow keys edit hue/saturation at full HSV value. Left/right adjust hue; up/down adjust saturation. Escape cancels, Enter commits the local gesture. Unknown color hides the marker. Read-only and disabled access emit no edits. Generation changes cancel held input. The spectrum is built lazily and shared on the UI thread; pure-Slint previews without install() have no generated spectrum.

    Control states

    Known values show a marker; unknown values hide it. Read-only and disabled controls emit no proposals. Access, generation and known-state changes cancel held input.

    Control accessibility

    A named keyboard focus group describes both hue and saturation; it does not claim a one-axis numeric slider range. Arrow keys edit the two axes, Enter commits and Escape cancels. All descriptions are localizable through KitStrings or per-instance properties. Headless coverage is not native screen-reader qualification.

    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
    A hue/saturation wheel that proposes opaque RGB colors.
    Browser capture of the same Slint example, femtovg renderer.
    import { KitColorWheel, KitTheme, KitThemeContext, KitThemes, SrgbColorView } from "@kit";
    export component Example inherits Window {
        in-out property <KitTheme> theme: KitThemes.light;
        changed theme => { KitThemeContext.current = root.theme; }
        preferred-width: 300px * root.theme.text-scale; preferred-height: 340px * root.theme.text-scale;
        max-width: 100000px; max-height: 100000px;
        private property <SrgbColorView> draft: {red:124,green:108,blue:240,alpha:255};
        VerticalLayout {
            KitColorWheel { theme: root.theme; label: "Accent color"; value: root.draft; chosen(value) => { root.draft = value; } }
        }
    }
    
    

    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
    modal-layer int in —
    theme KitTheme in KitThemeContext.current
    access FieldAccess in FieldAccess.editable
    value SrgbColorView in expression in the source
    known bool in true
    label string in KitStrings.color-wheel-label
    unknown-label string in KitStrings.color-wheel-unknown-label
    value-format string in KitStrings.color-wheel-value-format
    value-text string out —
    generation int in —
    hue float out —

    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.

    modal-layer int · in

    The modal layer this component belongs to; 0 is the window. While a KitDialogSurface or KitDrawer with a positive modal-layer is open and topmost, the component is inert: its keyboard scope and pointer area take no focus and ignore pointer and keys. Give a component placed inside a modal that modal’s layer number.

    Default
    0 (window).
    KitColorWheel {
        modal-layer: 1;
    }

    theme KitTheme · in

    Complete theme used for geometry, focus and disabled presentation.

    access FieldAccess · in

    Editable emits draft proposals; read-only preserves a focusable description; disabled refuses interaction.

    value SrgbColorView · in

    Controlled sRGB byte projection. The owner applies chosen values; proposals always have alpha 255 and full HSV value.

    Default
    Opaque white; set known: false for an unknown value.

    known bool · in

    False hides the marker and uses unknown-label; choose-hue establishes a saturated opaque proposal.

    label string · in

    Accessible name of the focus group, inherited from KitStrings.color-wheel-label by default.

    unknown-label string · in

    Description for unknown values; defaults to KitStrings.color-wheel-unknown-label.

    value-format string · in

    Accessible description template with {hue} and {saturation}; defaults to KitStrings.color-wheel-value-format.

    value-text string · out

    Formatted description of the current known hue/saturation or the unknown-value label.

    generation int · in

    Change the epoch when rebinding the editor; this discards a held gesture and local achromatic hue.

    hue float · out

    Current local editing hue in degrees. Gray/white can preserve hue without emitting a changed RGB value.

    Types and variants

    Type Declaration
    enum FieldAccess editable, read-only, disabled
    struct SrgbColorView red: int, green: int, blue: int, alpha: int

    Callbacks

    Functions

    See also