Scroll Bar for Slint
KitScrollBar · Slint Kit 0.9.0
Themed scroll bar for a viewport the application scrolls.
The still preview and demo follow the documentation theme. You can change it before or during the demo.

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.
Drag the bar or click its track: Rust reports how far through the notes you have scrolled.
ui/app.slint
import { KitMetrics, KitThemeContext, TypographyRole } from "@kit";
import { InterFont } from "@kit-fonts/inter.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { KitScrollBar, KitTheme, KitThemes } from "@kit";
export component App inherits Window {
default-font-family: InterFont.family;
default-font-size: KitMetrics.font-size(root.theme, TypographyRole.body);
title: "KitScrollBar example";
preferred-width: 420px;
preferred-height: 280px;
max-width: 100000px;
max-height: 100000px;
background: root.theme.canvas;
in-out property <KitTheme> theme: KitThemeContext.current;
in property <string> status: "Drag the bar or click its track.";
// The distance scrolled and the scrollable distance.
callback notes-scrolled(length, length);
VerticalLayout {
padding: 24px; spacing: 16px; alignment: start;
Text { text: "Scroll Bar"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
// The viewport is shorter than its notes, so the bar shows and scrolls them.
HorizontalLayout {
height: 120px; spacing: 8px;
notes := Flickable {
content-height: column.preferred-height;
column := VerticalLayout {
width: notes.width; spacing: 8px; alignment: start;
for note in ["Team workspace", "Keep observations and decisions together.", "Monday: kickoff with the design team.", "Tuesday: review the onboarding flow.", "Wednesday: draft the release notes.", "Thursday: test the import on large files.", "Friday: publish the weekly summary.", "Ready to publish your changes?"]: Text {
text: note; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap;
}
}
}
KitScrollBar {
theme: root.theme;
maximum: notes.content-height - notes.height; page-size: notes.height;
value <=> notes.content-y;
scrolled => { root.notes-scrolled(-notes.content-y, notes.content-height - notes.height); }
}
}
Text { text: root.status; color: root.theme.text-secondary; wrap: word-wrap; }
}
}
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.on_notes_scrolled(slint_kit::event2(&app, |app, offset: f32, range: f32| {
if range > 0.0 {
let percent = (offset / range * 100.0).round().clamp(0.0, 100.0);
app.set_status(format!("Rust: {percent}% of the notes read").into());
}
}));
app.run()
}
Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs
Bind maximum to the content length minus the page, page-size to the visible page and value two-way to a Flickable's content-y. Choose orientation and policy (ScrollBarPolicy). Set recipe to replace track, thumb, spacing and transition defaults together. Start with KitThemes.scroll-bar-recipe(theme); omitted struct fields become zero. Theme-wide dimensions live in theme.geometry.scroll-*.
The thumb follows the visible page proportion; dragging, the wheel and a track press (one page toward the pointer) keep the position in bounds. Holding the track button repeats the paging after theme.motion.repeat-delay, every theme.motion.repeat-interval, until release, until the thumb reaches the pointer or while the pointer is off the bar; scrolled fires for each page. Like the std-widgets bar it replaces, it takes no focus and stays out of the accessibility tree: keyboard and semantics belong to the viewport.
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

import { InterFont } from "@kit-fonts/inter.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { KitScrollBar, KitTheme, KitThemes } from "@kit";
export component Example inherits Window {
default-font-family: InterFont.family;
title: "KitScrollBar example";
preferred-width: 420px;
preferred-height: 260px;
max-width: 100000px;
max-height: 100000px;
background: root.theme.canvas;
in-out property <KitTheme> theme: KitThemes.light;
in-out property <string> status;
VerticalLayout {
padding: 24px; spacing: 16px; alignment: start;
Text { text: "Scroll Bar"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
HorizontalLayout { height: 120px; spacing: 8px; notes := Flickable { content-height: column.preferred-height; column := VerticalLayout { width: notes.width; spacing: 8px; alignment: start; Text { text: "Team workspace"; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Keep observations and decisions together."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Monday: kickoff with the design team."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Tuesday: review the onboarding flow."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Wednesday: draft the release notes."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Thursday: test the import on large files."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Friday: publish the weekly summary."; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; }Text { text: "Ready to publish your changes?"; color: root.theme.text-primary; font-size: 14px * root.theme.text-scale; wrap: word-wrap; } } } KitScrollBar { recipe: KitThemes.scroll-bar-recipe(root.theme); theme: root.theme; maximum: notes.content-height - notes.height; page-size: notes.height; value <=> notes.content-y; scrolled => { root.status = "Notes scrolled"; } } }
if root.status != "": Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; wrap: word-wrap; }
}
}
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 |
orientation |
Orientation |
in |
Orientation.vertical |
policy |
ScrollBarPolicy |
in |
ScrollBarPolicy.as-needed |
enabled |
bool |
in |
true |
maximum |
length |
in |
— |
page-size |
length |
in |
— |
value |
length |
in-out |
— |
active |
bool |
out |
— |
recipe |
ScrollBarRecipe |
in |
KitThemes.scroll-bar-recipe(root.theme) |
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.
recipe
Complete track and thumb presentation, dimensions and animation.
- Default
KitThemes.scroll-bar-recipe(theme).
KitScrollBar { recipe: KitThemes.scroll-bar-recipe(theme); }
Types and variants
| Type | Declaration |
|---|---|
struct ScrollBarRecipe |
thickness: length, thumb-thickness: length, active-thumb-thickness: length, inset: length, min-thumb-length: length, thumb: color, active-thumb: color, track: color, active-track: color, transition: duration, |
Callbacks
scrolled()