S004: base animated controls on a shared state layer, gallery screenshots

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-18 09:50:34 -06:00
commit 2a16df174e
21 changed files with 1223 additions and 36 deletions

View file

@ -83,6 +83,7 @@ Never modify: `PROMPT.md` (the user's brief), the reference app checkout (`/home
| `busctl --user call org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings ReadOne ss org.freedesktop.appearance accent-color` | inspect portal values | now |
| `fc-list` | check bundled/system fonts | now |
| `cargo run -p tunal -- --screenshot <png> [--dark] [--size WxH]` (software renderer, offscreen, default 960x640; env `TUNAL_SEED=#rrggbb`, `TUNAL_REDUCED_MOTION=1`) | single-PNG visual check; full state matrix in phase 12 | S003 |
| `cargo run -p tunal -- --gallery --screenshot <png> [--dark] --size 1200x1000` (`--gallery` alone opens it in a window) | every control in rest/hover/pressed/focused/disabled; press squeeze not drawn by the software renderer | S004 |
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.

View file

@ -10,13 +10,13 @@ Own controls on the token globals: every control has hover tint, press squeeze,
CLAUDE.md §2 Motion rules, §3; `app-taste` and `animate` skills; crates/tunal/ui/theme.slint, motion.slint.
## Steps
- [ ] `StateLayer`: hover/press/focus tint and press squeeze shared by all controls; force-state properties for screenshots.
- [ ] `Button` (filled, tonal, outlined, text, with optional icon) and `IconButton` (standard, toggle) with tooltip text.
- [ ] `Chip` (filter with animated check, assist) and `Switch` (thumb slides, track tints).
- [ ] `ListRow` (leading icon, title, supporting text, trailing slot, animated selection indicator) and `Tab` (label, icon, close button; active indicator owned by a `TabBar` so it slides).
- [ ] `TextField`: std `LineEdit` styled through tokens (label, error, clear button).
- [ ] Gallery: `tunal --gallery --screenshot <png>` renders every control in rest, hover, pressed, focused, disabled.
- [ ] PROGRESS entry, INDEX line, commit `S004: …`
- [x] `StateLayer`: hover/press/focus tint and press squeeze shared by all controls; force-state properties for screenshots.
- [x] `Button` (filled, tonal, outlined, text, with optional icon) and `IconButton` (standard, toggle) with tooltip text.
- [x] `Chip` (filter with animated check, assist) and `Switch` (thumb slides, track tints).
- [x] `ListRow` (leading icon, title, supporting text, trailing slot, animated selection indicator) and `Tab` (label, icon, close button; active indicator owned by a `TabBar` so it slides).
- [x] `TextField`: std `LineEdit` styled through tokens (label, error, clear button).
- [x] Gallery: `tunal --gallery --screenshot <png>` renders every control in rest, hover, pressed, focused, disabled.
- [x] PROGRESS entry, INDEX line, commit `S004: …`
## End criteria
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass.

View file

@ -12,7 +12,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
- [x] [S002 — Portal theme and Material schemes](02%20App%20skeleton/S002-theme-portal.md) · Opus high
- [x] [S003 — Window, Theme and Motion globals, screenshot command](02%20App%20skeleton/S003-window-tokens.md) · Opus high
- [ ] [S004 — Base animated controls](02%20App%20skeleton/S004-base-controls.md) · Opus high
- [x] [S004 — Base animated controls](02%20App%20skeleton/S004-base-controls.md) · Opus high
- [ ] [S005 — Menus, dialogs and toasts](02%20App%20skeleton/S005-menus-dialogs.md) · Opus high
## 03 File browsing

View file

@ -3,19 +3,17 @@ mod theme_bridge;
use std::process::ExitCode;
use slint::ComponentHandle;
slint::include_modules!();
const USAGE: &str = "usage: tunal [--screenshot <png> [--dark] [--size WxH]]";
const USAGE: &str = "usage: tunal [--gallery] [--screenshot <png> [--dark] [--size WxH]]";
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
let result = if args.is_empty() {
run().map_err(|e| e.to_string())
} else {
parse_screenshot(&args).and_then(screenshot::run)
};
let result = parse(std::env::args().skip(1)).and_then(|args| match args.screenshot {
None if args.gallery => Gallery::new().and_then(run).map_err(|e| e.to_string()),
None => MainWindow::new().and_then(run).map_err(|e| e.to_string()),
Some(options) if args.gallery => screenshot::run(options, Gallery::new),
Some(options) => screenshot::run(options, MainWindow::new),
});
match result {
Ok(()) => ExitCode::SUCCESS,
Err(message) => {
@ -25,22 +23,30 @@ fn main() -> ExitCode {
}
}
fn run() -> Result<(), slint::PlatformError> {
let ui = MainWindow::new()?;
fn run(ui: impl theme_bridge::Themed) -> Result<(), slint::PlatformError> {
theme_bridge::start(&ui, theme_bridge::Overrides::from_env());
ui.run()
}
fn parse_screenshot(args: &[String]) -> Result<screenshot::Options, String> {
struct Args {
gallery: bool,
screenshot: Option<screenshot::Options>,
}
fn parse(mut args: impl Iterator<Item = String>) -> Result<Args, String> {
let mut gallery = false;
let mut options = screenshot::Options {
path: String::new(),
dark: false,
size: (960, 640),
reduced_motion: false,
};
let mut args = args.iter();
let mut screenshot_flags = false;
while let Some(arg) = args.next() {
screenshot_flags |= arg != "--gallery";
match arg.as_str() {
"--screenshot" => options.path = args.next().ok_or(USAGE)?.clone(),
"--gallery" => gallery = true,
"--screenshot" => options.path = args.next().ok_or(USAGE)?,
"--dark" => options.dark = true,
"--size" => {
let size = args.next().ok_or(USAGE)?;
@ -51,8 +57,18 @@ fn parse_screenshot(args: &[String]) -> Result<screenshot::Options, String> {
_ => return Err(USAGE.into()),
}
}
if !screenshot_flags {
return Ok(Args {
gallery,
screenshot: None,
});
}
if options.path.is_empty() {
return Err(USAGE.into());
}
Ok(options)
options.reduced_motion = gallery;
Ok(Args {
gallery,
screenshot: Some(options),
})
}

View file

@ -3,7 +3,7 @@
use std::{fs::File, io::BufWriter, path::Path, rc::Rc};
use slint::{
ComponentHandle, PhysicalSize,
PhysicalSize,
platform::{
Platform, PlatformError, WindowAdapter,
software_renderer::{MinimalSoftwareWindow, PremultipliedRgbaColor, RepaintBufferType},
@ -11,10 +11,7 @@ use slint::{
};
use tunal_theme::ColorScheme;
use crate::{
MainWindow,
theme_bridge::{self, Overrides},
};
use crate::theme_bridge::{self, Overrides, Themed};
struct Offscreen(Rc<MinimalSoftwareWindow>);
@ -28,21 +25,29 @@ pub struct Options {
pub path: String,
pub dark: bool,
pub size: (u32, u32),
/// Draw every state change at once (the gallery forces its states at creation).
pub reduced_motion: bool,
}
pub fn run(options: Options) -> Result<(), String> {
/// Renders the window `new` creates; `new` runs after the offscreen platform is set.
pub fn run<C: Themed>(
options: Options,
new: impl FnOnce() -> Result<C, PlatformError>,
) -> Result<(), String> {
let window = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
slint::platform::set_platform(Box::new(Offscreen(window.clone())))
.map_err(|e| e.to_string())?;
let ui = MainWindow::new().map_err(|e| e.to_string())?;
let ui = new().map_err(|e| e.to_string())?;
let scheme = if options.dark {
ColorScheme::Dark
} else {
ColorScheme::Light
};
let env = Overrides::from_env();
let overrides = Overrides {
scheme: Some(scheme),
..Overrides::from_env()
reduced_motion: options.reduced_motion || env.reduced_motion,
..env
};
theme_bridge::apply(&ui, &tunal_theme::read(), overrides);

View file

@ -3,7 +3,7 @@
use slint::{Color, ComponentHandle};
use tunal_theme::{Appearance, ColorScheme, Palette, Palettes};
use crate::{MainWindow, MotionPrefs, Theme};
use crate::{Gallery, MainWindow, MotionPrefs, Theme};
/// Overrides for agents and screenshots: `TUNAL_SEED=#rrggbb`, `TUNAL_SCHEME=light|dark`,
/// `TUNAL_REDUCED_MOTION=1`. Unset or invalid values leave the portal value in place.
@ -42,8 +42,29 @@ impl Overrides {
}
}
/// A window with the `Theme` and `MotionPrefs` globals.
pub trait Themed: ComponentHandle + 'static {
fn theme(&self) -> Theme<'_>;
fn motion_prefs(&self) -> MotionPrefs<'_>;
}
macro_rules! themed {
($($window:ty),*) => {
$(impl Themed for $window {
fn theme(&self) -> Theme<'_> {
self.global::<Theme>()
}
fn motion_prefs(&self) -> MotionPrefs<'_> {
self.global::<MotionPrefs>()
}
})*
};
}
themed!(MainWindow, Gallery);
/// Reads the portal, applies it, and keeps the UI in step with later changes.
pub fn start(ui: &MainWindow, overrides: Overrides) {
pub fn start(ui: &impl Themed, overrides: Overrides) {
apply(ui, &tunal_theme::read(), overrides);
let weak = ui.as_weak();
tunal_theme::watch(move |appearance| {
@ -52,7 +73,7 @@ pub fn start(ui: &MainWindow, overrides: Overrides) {
});
}
pub fn apply(ui: &MainWindow, appearance: &Appearance, overrides: Overrides) {
pub fn apply(ui: &impl Themed, appearance: &Appearance, overrides: Overrides) {
let seed = overrides.seed.unwrap_or_else(|| appearance.seed());
let scheme = overrides.scheme.unwrap_or(appearance.scheme);
let palettes = Palettes::from_seed(seed);
@ -60,11 +81,11 @@ pub fn apply(ui: &MainWindow, appearance: &Appearance, overrides: Overrides) {
ColorScheme::Light => palettes.light,
ColorScheme::Dark => palettes.dark,
};
let theme = ui.global::<Theme>();
let theme = ui.theme();
theme.set_dark(scheme == ColorScheme::Dark);
set_colors(&theme, &palette);
let reduced = overrides.reduced_motion || appearance.animations == Some(false);
ui.global::<MotionPrefs>().set_reduced(reduced);
ui.motion_prefs().set_reduced(reduced);
}
macro_rules! colors {

View file

@ -4,6 +4,7 @@ import { Motion, MotionPrefs } from "motion.slint";
import { Icon, Icons } from "components/icon.slint";
export { Theme, MotionPrefs }
export { Gallery } from "gallery.slint";
// Placeholder shell (sidebar + content) until the views land.
export component MainWindow inherits Window {

View file

@ -0,0 +1,67 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon } from "icon.slint";
import { StateLayer } from "state-layer.slint";
// Emphasis, from the main action of a screen (filled) down to the least (text).
export enum ButtonKind { filled, tonal, outlined, text }
// A labelled button with an optional leading icon.
export component Button inherits StateLayer {
in property <string> text;
// Glyph from `Icons`; empty for none.
in property <string> icon;
in property <ButtonKind> kind: ButtonKind.filled;
property <bool> contained: root.kind == ButtonKind.filled || root.kind == ButtonKind.tonal;
property <color> content: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.kind == ButtonKind.filled ? Theme.on-primary
: root.kind == ButtonKind.tonal ? Theme.on-secondary-container
: Theme.primary;
height: 40px;
border-radius: Theme.corner-full(self.height);
background: !root.contained ? transparent
: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-container)
: root.kind == ButtonKind.filled ? Theme.primary
: Theme.secondary-container;
border-width: root.kind == ButtonKind.outlined ? Theme.hairline : 0;
border-color: root.enabled ? Theme.outline : Theme.on-surface.with-alpha(Theme.disabled-container);
tint: root.content;
animate background, border-color {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
accessible-role: button;
accessible-label: root.text;
accessible-enabled: root.enabled;
accessible-action-default => {
self.activate();
}
HorizontalLayout {
padding-left: root.kind == ButtonKind.text ? Theme.space-3 : root.icon != "" ? Theme.space-4 : Theme.space-6;
padding-right: root.kind == ButtonKind.text ? (root.icon != "" ? Theme.space-4 : Theme.space-3) : Theme.space-6;
spacing: Theme.space-2;
if root.icon != "": VerticalLayout {
alignment: center;
Icon {
glyph: root.icon;
size: 18px;
color: root.content;
}
}
Text {
text: root.text;
color: root.content;
font-size: Theme.label-large.size;
font-weight: Theme.label-large.weight;
vertical-alignment: center;
overflow: elide;
}
}
}

View file

@ -0,0 +1,87 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon, Icons } from "icon.slint";
import { StateLayer } from "state-layer.slint";
// Filter chips toggle `checked`; assist chips run an action and may carry an icon.
export enum ChipKind { filter, assist }
// The chip's width is fixed by its label: the leading slot is always reserved. When the
// check (or icon) is hidden the label sits centred, so checking it slides the label over
// instead of resizing the chip and pushing its neighbours.
export component Chip inherits StateLayer {
in property <string> text;
// Assist chips: leading glyph from `Icons`; empty for none.
in property <string> icon;
in property <ChipKind> kind: ChipKind.filter;
in-out property <bool> checked;
property <bool> on: root.kind == ChipKind.filter && root.checked;
property <bool> lead-shown: root.kind == ChipKind.filter ? root.checked : root.icon != "";
property <length> lead-size: 18px;
property <length> label-x: Theme.space-2 + root.lead-size + Theme.space-2;
property <color> content: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.on ? Theme.on-secondary-container
: root.kind == ChipKind.assist ? Theme.on-surface
: Theme.on-surface-variant;
height: 32px;
min-width: root.label-x + label.preferred-width + Theme.space-4;
preferred-width: self.min-width;
horizontal-stretch: 0;
border-radius: Theme.corner-sm;
background: !root.on ? transparent : root.enabled ? Theme.secondary-container : Theme.on-surface.with-alpha(Theme.disabled-container);
border-width: root.on ? 0 : Theme.hairline;
border-color: root.enabled ? Theme.outline-variant : Theme.on-surface.with-alpha(Theme.disabled-container);
tint: root.content;
animate background, border-color {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
activated => {
if root.kind == ChipKind.filter {
root.checked = !root.checked;
}
}
// Role must be constant; checkable tells filter chips apart.
accessible-role: button;
accessible-label: root.text;
accessible-enabled: root.enabled;
accessible-checkable: root.kind == ChipKind.filter;
accessible-checked: root.on;
accessible-action-default => {
self.activate();
}
Icon {
x: Theme.space-2;
y: (root.height - self.height) / 2;
glyph: root.kind == ChipKind.filter ? Icons.check : root.icon;
size: root.lead-size;
color: !root.enabled ? root.content : root.kind == ChipKind.assist ? Theme.primary : root.content;
opacity: root.lead-shown ? 1 : 0;
transform-scale: root.lead-shown ? 1 : 0.6;
animate opacity, transform-scale {
duration: Motion.time(Motion.short4);
easing: Motion.emphasized-decelerate;
}
}
label := Text {
x: root.lead-shown ? root.label-x : (root.width - self.width) / 2;
y: 0;
height: root.height;
width: self.preferred-width;
text: root.text;
color: root.content;
font-size: Theme.label-large.size;
font-weight: Theme.label-large.weight;
vertical-alignment: center;
animate x {
duration: Motion.time(Motion.short4);
easing: Motion.emphasized;
}
}
}

View file

@ -0,0 +1,63 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon } from "icon.slint";
import { StateLayer } from "state-layer.slint";
// An icon-only button. Always give it a `tooltip` naming its action. With `toggle` it flips
// `checked` on click and shows a tonal container while checked.
export component IconButton inherits StateLayer {
// Glyph from `Icons`.
in property <string> icon;
in property <bool> toggle;
in-out property <bool> checked;
in property <length> size: 40px;
in property <length> icon-size: 24px;
property <bool> on: root.toggle && root.checked;
property <color> content: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.on ? Theme.on-secondary-container
: Theme.on-surface-variant;
width: root.size;
height: root.size;
// Pressed, the circle squashes towards a squircle on top of the squeeze.
border-radius: root.pressed ? (root.size >= 40px ? Theme.corner-md : Theme.corner-sm) : Theme.corner-full(root.size);
background: !root.on ? transparent : root.enabled ? Theme.secondary-container : Theme.on-surface.with-alpha(Theme.disabled-container);
tint: root.content;
squeeze: Motion.squeeze-small;
animate border-radius {
duration: Motion.time(root.pressed ? Motion.short2 : Motion.short3);
easing: Motion.standard;
}
animate background {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
activated => {
if root.toggle {
root.checked = !root.checked;
}
}
accessible-role: button;
accessible-label: root.tooltip;
accessible-enabled: root.enabled;
accessible-checkable: root.toggle;
accessible-checked: root.checked;
accessible-action-default => {
self.activate();
}
Icon {
x: (root.width - self.width) / 2;
y: (root.height - self.height) / 2;
glyph: root.icon;
size: root.icon-size;
color: root.content;
animate color {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
}
}

View file

@ -23,4 +23,13 @@ export component Icon inherits Text {
export global Icons {
out property <string> folder: "\u{e2c7}";
out property <string> home: "\u{e88a}";
out property <string> check: "\u{e5ca}";
out property <string> close: "\u{e5cd}";
out property <string> cancel: "\u{e5c9}";
out property <string> add: "\u{e145}";
out property <string> search: "\u{e8b6}";
out property <string> star: "\u{e838}";
out property <string> grid-view: "\u{e9b0}";
out property <string> music-note: "\u{e405}";
out property <string> description: "\u{e873}";
}

View file

@ -0,0 +1,85 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon } from "icon.slint";
import { StateLayer } from "state-layer.slint";
// One row of a list: leading icon, title, optional supporting line, and a trailing slot for
// the row's children. Selection grows a tonal fill from the centre.
export component ListRow inherits StateLayer {
// Glyph from `Icons`; empty for none.
in property <string> icon;
in property <string> title;
in property <string> supporting;
in property <bool> selected;
property <color> title-color: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.selected ? Theme.on-secondary-container
: Theme.on-surface;
property <color> detail-color: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.selected ? Theme.on-secondary-container
: Theme.on-surface-variant;
height: root.supporting == "" ? 40px : 56px;
border-radius: Theme.corner-full(self.height);
squeeze: Motion.squeeze-large;
ring-offset: -Theme.focus-ring-width;
accessible-role: list-item;
accessible-label: root.title;
accessible-description: root.supporting;
accessible-enabled: root.enabled;
accessible-item-selectable: true;
accessible-item-selected: root.selected;
accessible-action-default => {
self.activate();
}
Rectangle {
border-radius: root.border-radius;
background: root.enabled ? Theme.secondary-container : Theme.on-surface.with-alpha(Theme.disabled-container);
opacity: root.selected ? 1 : 0;
transform-scale-x: root.selected ? 1 : Motion.squeeze;
animate opacity, transform-scale-x {
duration: Motion.time(Motion.short4);
easing: Motion.emphasized-decelerate;
}
}
HorizontalLayout {
padding-left: Theme.space-4;
padding-right: Theme.space-2;
spacing: Theme.space-3;
if root.icon != "": VerticalLayout {
alignment: center;
Icon {
glyph: root.icon;
color: root.detail-color;
}
}
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
Text {
text: root.title;
color: root.title-color;
font-size: Theme.body-medium.size;
font-weight: Theme.body-medium.weight;
overflow: elide;
}
if root.supporting != "": Text {
text: root.supporting;
color: root.detail-color;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
overflow: elide;
}
}
@children
}
}

View file

@ -0,0 +1,155 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
// A state shown regardless of the pointer and focus, for gallery screenshots.
export enum ForceState { none, hover, pressed, focused }
// The small label an icon-only control shows on hover.
export component Tooltip inherits Rectangle {
in property <string> text;
background: Theme.inverse-surface;
border-radius: Theme.corner-xs;
height: 24px;
HorizontalLayout {
padding-left: Theme.space-2;
padding-right: Theme.space-2;
Text {
text: root.text;
color: Theme.inverse-on-surface;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
vertical-alignment: center;
}
}
}
// Shared by every control: hover and press tint, press squeeze, keyboard focus ring and
// tooltip. A control inherits it, sets its shape (`border-radius`) and container colours, and
// puts its content in as children. Space and Enter activate the control when it has focus.
export component StateLayer inherits Rectangle {
in property <bool> enabled: true;
in property <ForceState> force-state: ForceState.none;
// Colour role the tint is mixed from: the control's content colour.
in property <color> tint: Theme.on-surface;
// Off when the control draws the tint itself from `tint-opacity` (the switch halo).
in property <bool> fill-tint: true;
// Scale while pressed; 1 for no squeeze.
in property <float> squeeze: Motion.squeeze;
in property <string> tooltip;
// Gap between shape and focus ring; `-Theme.focus-ring-width` draws the ring inside the
// shape, for controls stacked edge to edge (rows, tabs).
in property <length> ring-offset: Theme.focus-ring-offset;
out property <bool> hovered: enabled && (touch.has-hover || force-state == ForceState.hover);
out property <bool> pressed: enabled && (touch.pressed || force-state == ForceState.pressed);
out property <bool> focused: enabled && (keyboard-focus || force-state == ForceState.focused);
out property <float> tint-opacity: pressed ? Theme.state-press : focused ? Theme.state-focus : hovered ? Theme.state-hover : 0;
// For users of the control.
callback clicked;
// For the control itself (toggle its own state), called before `clicked`.
callback activated;
property <bool> keyboard-focus;
property <length> ring-inset: Theme.focus-ring-width + root.ring-offset;
animate tint-opacity {
duration: Motion.time(root.hovered || root.pressed ? Motion.short3 : Motion.short2);
easing: Motion.standard;
}
// Scales from the centre; the layout size stays fixed so neighbours don't move.
transform-scale: pressed ? squeeze : 1;
animate transform-scale {
duration: Motion.time(root.pressed ? Motion.short2 : Motion.short3);
easing: Motion.standard;
}
public function activate() {
root.activated();
root.clicked();
}
FocusScope {
x: 0;
width: 0;
enabled: root.enabled;
focus-on-click: false;
// Only keyboard focus shows the ring.
focus-gained(reason) => {
root.keyboard-focus = reason == FocusReason.tab-navigation;
}
focus-lost => {
root.keyboard-focus = false;
}
key-pressed(event) => {
if event.text == Key.Space || event.text == Key.Return {
root.activate();
return accept;
}
reject
}
}
touch := TouchArea {
enabled: root.enabled;
clicked => {
root.activate();
}
changed has-hover => {
if !self.has-hover {
root.tip-due = false;
tip.close();
}
}
changed pressed => {
if self.pressed {
tip.close();
}
}
}
@children
// Above the content so it also shows over a selection fill; 8–10 % barely touches text.
Rectangle {
visible: root.fill-tint;
border-radius: root.border-radius;
background: root.tint.with-alpha(root.tint-opacity);
}
if root.focused: Rectangle {
x: -root.ring-inset;
y: -root.ring-inset;
width: root.width + 2 * root.ring-inset;
height: root.height + 2 * root.ring-inset;
border-width: Theme.focus-ring-width;
border-color: Theme.secondary;
border-radius: root.border-radius + root.ring-inset;
}
// Runs only while hovered and the tooltip is not yet shown: nothing ticks when idle.
property <bool> tip-due;
Timer {
interval: Motion.tooltip-delay;
running: root.tooltip != "" && touch.has-hover && !touch.pressed && !root.tip-due;
triggered => {
root.tip-due = true;
tip.show();
}
}
tip := PopupWindow {
close-policy: no-auto-close;
x: (root.width - self.width) / 2;
y: root.height + Theme.space-1;
Tooltip {
text: root.tooltip;
}
}
}

View file

@ -0,0 +1,75 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { StateLayer } from "state-layer.slint";
// An on/off switch. The thumb slides and grows when on, grows further while pressed, and a
// halo behind it carries the hover and press tint.
export component Switch inherits StateLayer {
in-out property <bool> checked;
property <length> halo-size: 40px;
property <length> thumb-size: root.pressed ? 28px : root.checked ? 24px : 16px;
// Centre of the thumb.
property <length> thumb-x: root.checked ? root.width - root.height / 2 : root.height / 2;
width: 52px;
height: 32px;
border-radius: Theme.corner-full(self.height);
background: root.checked
? (root.enabled ? Theme.primary : Theme.on-surface.with-alpha(Theme.disabled-container))
: (root.enabled ? Theme.surface-container-highest : Theme.surface-container-highest.with-alpha(Theme.disabled-container));
border-width: root.checked ? 0 : 2px;
border-color: root.enabled ? Theme.outline : Theme.on-surface.with-alpha(Theme.disabled-container);
// The thumb grows instead of the whole switch squeezing.
squeeze: 1;
fill-tint: false;
animate background, border-color {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
animate thumb-x {
duration: Motion.time(Motion.short4);
easing: Motion.emphasized;
}
animate thumb-size {
duration: Motion.time(root.pressed ? Motion.short2 : Motion.short3);
easing: Motion.standard;
}
activated => {
root.checked = !root.checked;
}
accessible-role: switch;
accessible-enabled: root.enabled;
accessible-checkable: true;
accessible-checked: root.checked;
accessible-action-default => {
self.activate();
}
Rectangle {
x: root.thumb-x - self.width / 2;
y: (root.height - self.height) / 2;
width: root.halo-size;
height: root.halo-size;
border-radius: Theme.corner-full(self.height);
background: (root.checked ? Theme.primary : Theme.on-surface).with-alpha(root.tint-opacity);
}
Rectangle {
x: root.thumb-x - self.width / 2;
y: (root.height - self.height) / 2;
width: root.thumb-size;
height: root.thumb-size;
border-radius: Theme.corner-full(self.height);
background: !root.enabled
? (root.checked ? Theme.surface : Theme.on-surface.with-alpha(Theme.disabled-content))
: root.checked ? (root.hovered || root.pressed ? Theme.primary-container : Theme.on-primary)
: (root.hovered || root.pressed ? Theme.on-surface-variant : Theme.outline);
animate background {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
}
}

View file

@ -0,0 +1,128 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon, Icons } from "icon.slint";
import { IconButton } from "icon-button.slint";
import { StateLayer } from "state-layer.slint";
// One tab: icon, title and close button. The active indicator belongs to `TabBar` so it can
// slide between tabs.
export component Tab inherits StateLayer {
in property <string> title;
// Glyph from `Icons`; empty for none.
in property <string> icon;
in property <bool> active;
in property <bool> closable: true;
callback close();
property <color> content: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-content)
: root.active ? Theme.primary
: Theme.on-surface-variant;
height: 40px;
border-radius: Theme.corner-sm;
squeeze: Motion.squeeze-large;
ring-offset: -Theme.focus-ring-width;
accessible-role: tab;
accessible-label: root.title;
accessible-enabled: root.enabled;
accessible-item-selectable: true;
accessible-item-selected: root.active;
accessible-action-default => {
self.activate();
}
HorizontalLayout {
padding-left: Theme.space-3;
padding-right: root.closable ? Theme.space-1 : Theme.space-3;
spacing: Theme.space-2;
if root.icon != "": VerticalLayout {
alignment: center;
Icon {
glyph: root.icon;
size: 18px;
color: root.content;
}
}
Text {
horizontal-stretch: 1;
text: root.title;
color: root.content;
font-size: Theme.label-large.size;
font-weight: Theme.label-large.weight;
vertical-alignment: center;
overflow: elide;
animate color {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
}
if root.closable: VerticalLayout {
alignment: center;
IconButton {
icon: Icons.close;
size: 28px;
icon-size: 18px;
tooltip: "Close tab";
enabled: root.enabled;
clicked => {
root.close();
}
}
}
}
}
export struct TabItem {
title: string,
icon: string,
}
// A row of equal-width tabs with one indicator that slides to the active tab.
export component TabBar {
in property <[TabItem]> tabs;
in-out property <int> current;
in property <length> max-tab-width: 240px;
callback selected(index: int);
callback close(index: int);
property <length> tab-width: tabs.length == 0 ? 0 : min(max-tab-width, root.width / tabs.length);
property <length> indicator-height: 3px;
height: 40px + indicator-height;
accessible-role: tab-list;
for tab[index] in root.tabs: Tab {
x: index * root.tab-width;
y: 0;
width: root.tab-width;
title: tab.title;
icon: tab.icon;
active: index == root.current;
clicked => {
root.current = index;
root.selected(index);
}
close => {
root.close(index);
}
}
if root.tabs.length > 0: Rectangle {
x: root.current * root.tab-width + Theme.space-2;
y: root.height - self.height;
width: root.tab-width - 2 * Theme.space-2;
height: root.indicator-height;
border-radius: Theme.corner-full(self.height);
background: Theme.primary;
animate x, width {
duration: Motion.time(Motion.medium2);
easing: Motion.emphasized;
}
}
}

View file

@ -0,0 +1,127 @@
import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icons } from "icon.slint";
import { IconButton } from "icon-button.slint";
import { ForceState } from "state-layer.slint";
// A single-line text field: label above, outlined frame, clear button while there is text,
// and a message line below (supporting text, or the error in its place). The message line
// is always reserved so an error never pushes the content under the field.
export component TextField {
in property <string> label;
in property <string> placeholder;
in property <string> supporting;
in property <string> error;
in property <bool> enabled: true;
in property <ForceState> force-state: ForceState.none;
in-out property <string> text;
callback edited(text: string);
callback accepted(text: string);
out property <bool> focused: enabled && (input.has-focus || force-state == ForceState.focused);
property <bool> hovered: enabled && (touch.has-hover || force-state == ForceState.hover);
property <bool> failed: enabled && error != "";
property <color> disabled: Theme.on-surface.with-alpha(Theme.disabled-content);
// The input itself is the accessible text field.
forward-focus: input;
VerticalLayout {
spacing: Theme.space-1;
if root.label != "": Text {
text: root.label;
color: !root.enabled ? root.disabled : root.failed ? Theme.error : root.focused ? Theme.primary : Theme.on-surface-variant;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
overflow: elide;
}
Rectangle {
height: 40px;
border-radius: Theme.corner-xs;
border-width: root.focused ? 2px : Theme.hairline;
border-color: !root.enabled ? Theme.on-surface.with-alpha(Theme.disabled-container)
: root.failed ? Theme.error
: root.focused ? Theme.primary
: root.hovered ? Theme.on-surface
: Theme.outline;
animate border-color {
duration: Motion.time(Motion.short3);
easing: Motion.standard;
}
// Hover only; the input below takes the clicks.
touch := TouchArea {
enabled: root.enabled;
mouse-cursor: MouseCursor.text;
}
HorizontalLayout {
padding-left: Theme.space-4;
padding-right: Theme.space-1;
spacing: Theme.space-1;
Rectangle {
horizontal-stretch: 1;
if root.text == "": Text {
width: 100%;
text: root.placeholder;
color: root.enabled ? Theme.on-surface-variant : root.disabled;
font-size: Theme.body-medium.size;
font-weight: Theme.body-medium.weight;
vertical-alignment: center;
overflow: elide;
}
input := TextInput {
width: 100%;
text <=> root.text;
accessible-label: root.label;
accessible-placeholder-text: root.placeholder;
enabled: root.enabled;
single-line: true;
color: root.enabled ? Theme.on-surface : root.disabled;
selection-background-color: Theme.primary-container;
selection-foreground-color: Theme.on-primary-container;
font-size: Theme.body-medium.size;
font-weight: Theme.body-medium.weight;
vertical-alignment: center;
edited => {
root.edited(self.text);
}
accepted => {
root.accepted(self.text);
}
}
}
if root.text != "" && root.enabled: VerticalLayout {
alignment: center;
IconButton {
icon: Icons.cancel;
size: 32px;
icon-size: 20px;
tooltip: "Clear";
clicked => {
root.text = "";
root.edited("");
input.focus();
}
}
}
}
}
Text {
text: root.failed ? root.error : root.supporting;
color: !root.enabled ? root.disabled : root.failed ? Theme.error : Theme.on-surface-variant;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
min-height: Theme.body-small.line-height;
overflow: elide;
}
}
}

View file

@ -0,0 +1,326 @@
import { Theme } from "theme.slint";
import { Icon, Icons } from "components/icon.slint";
import { ForceState, Tooltip } from "components/state-layer.slint";
import { Button, ButtonKind } from "components/button.slint";
import { IconButton } from "components/icon-button.slint";
import { Chip, ChipKind } from "components/chip.slint";
import { Switch } from "components/switch.slint";
import { ListRow } from "components/list-row.slint";
import { Tab, TabBar } from "components/tab.slint";
import { TextField } from "components/text-field.slint";
// Every control in every state, for screenshots: `tunal --gallery --screenshot <png>`.
// Columns force the state; the last one is the disabled control.
component Caption inherits Text {
color: Theme.on-surface-variant;
font-size: Theme.label-medium.size;
font-weight: Theme.label-medium.weight;
vertical-alignment: center;
}
component Row {
in property <string> name;
HorizontalLayout {
spacing: Theme.space-4;
Caption {
width: 120px;
text: root.name;
}
@children
}
}
component Cell {
width: 184px;
HorizontalLayout {
alignment: start;
VerticalLayout {
alignment: center;
@children
}
}
}
export component Gallery inherits Window {
title: "Tunal controls";
icon: @image-url("../../../assets/tunal.png");
preferred-width: 1200px;
preferred-height: 1100px;
background: Theme.surface;
property <[ForceState]> states: [ForceState.none, ForceState.hover, ForceState.pressed, ForceState.focused, ForceState.none];
property <int> disabled-column: 4;
VerticalLayout {
padding: Theme.space-6;
spacing: Theme.space-3;
alignment: start;
Row {
for caption in ["Rest", "Hover", "Pressed", "Focused", "Disabled"]: Cell {
Caption {
text: caption;
}
}
}
Row {
name: "Filled button";
for state[i] in root.states: Cell {
Button {
text: "New folder";
icon: Icons.add;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
Row {
name: "Tonal button";
for state[i] in root.states: Cell {
Button {
kind: ButtonKind.tonal;
text: "Copy";
force-state: state;
enabled: i != root.disabled-column;
}
}
}
Row {
name: "Outlined button";
for state[i] in root.states: Cell {
Button {
kind: ButtonKind.outlined;
text: "Cancel";
force-state: state;
enabled: i != root.disabled-column;
}
}
}
Row {
name: "Text button";
for state[i] in root.states: Cell {
Button {
kind: ButtonKind.text;
text: "Rename";
force-state: state;
enabled: i != root.disabled-column;
}
}
}
Row {
name: "Icon buttons";
for state[i] in root.states: Cell {
HorizontalLayout {
spacing: Theme.space-2;
IconButton {
icon: Icons.search;
tooltip: "Search";
force-state: state;
enabled: i != root.disabled-column;
}
IconButton {
icon: Icons.grid-view;
tooltip: "Icon view";
toggle: true;
force-state: state;
enabled: i != root.disabled-column;
}
IconButton {
icon: Icons.grid-view;
tooltip: "Icon view";
toggle: true;
checked: true;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
}
Row {
name: "Filter chips";
for state[i] in root.states: Cell {
HorizontalLayout {
spacing: Theme.space-2;
Chip {
text: "Music";
force-state: state;
enabled: i != root.disabled-column;
}
Chip {
text: "Music";
checked: true;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
}
Row {
name: "Assist chip";
for state[i] in root.states: Cell {
Chip {
kind: ChipKind.assist;
text: "Add tag";
icon: Icons.add;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
Row {
name: "Switches";
for state[i] in root.states: Cell {
HorizontalLayout {
spacing: Theme.space-4;
Switch {
force-state: state;
enabled: i != root.disabled-column;
}
Switch {
checked: true;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
}
Row {
name: "List rows";
for state[i] in root.states: Cell {
VerticalLayout {
spacing: Theme.space-1;
width: 176px;
ListRow {
icon: Icons.folder;
title: "Documents";
force-state: state;
enabled: i != root.disabled-column;
}
ListRow {
icon: Icons.folder;
title: "Pictures";
selected: true;
force-state: state;
enabled: i != root.disabled-column;
}
ListRow {
icon: Icons.music-note;
title: "A very long track name that does not fit.flac";
supporting: "4.2 MB";
force-state: state;
enabled: i != root.disabled-column;
VerticalLayout {
alignment: center;
Icon {
glyph: Icons.star;
size: 18px;
}
}
}
}
}
}
Row {
name: "Tabs";
for state[i] in root.states: Cell {
VerticalLayout {
spacing: Theme.space-1;
width: 176px;
Tab {
title: "Home";
icon: Icons.home;
active: true;
force-state: state;
enabled: i != root.disabled-column;
}
Tab {
title: "Downloads";
icon: Icons.folder;
force-state: state;
enabled: i != root.disabled-column;
}
}
}
}
Row {
name: "Text fields";
for state[i] in root.states: Cell {
VerticalLayout {
spacing: Theme.space-1;
width: 176px;
TextField {
label: "Name";
placeholder: "Folder name";
force-state: state;
enabled: i != root.disabled-column;
}
TextField {
label: "Name";
text: "notes/2026.txt";
error: "Names can't contain /";
force-state: state;
enabled: i != root.disabled-column;
}
}
}
}
Row {
name: "Tab bar";
TabBar {
width: 600px;
current: 1;
tabs: [
{ title: "Home", icon: Icons.home },
{ title: "Downloads", icon: Icons.folder },
{ title: "Music", icon: Icons.music-note },
];
}
}
Row {
name: "Tooltip";
Cell {
Tooltip {
text: "Search";
}
}
}
}
}

View file

@ -31,6 +31,14 @@ export global Motion {
out property <easing> standard-decelerate: cubic-bezier(0, 0, 0, 1);
out property <easing> standard-accelerate: cubic-bezier(0.3, 0, 1, 1);
// Press squeeze (scale while held): small controls squeeze most, wide ones least.
out property <float> squeeze-small: 0.9;
out property <float> squeeze: 0.96;
out property <float> squeeze-large: 0.985;
// Hover time before a tooltip shows. A delay, not motion: reduced motion keeps it.
out property <duration> tooltip-delay: 500ms;
public pure function time(d: duration) -> duration {
reduced ? 0ms : d
}

View file

@ -68,6 +68,10 @@ export global Theme {
// Hairline borders.
out property <length> hairline: 1px;
// Keyboard focus ring, drawn outside the control's shape.
out property <length> focus-ring-width: 2px;
out property <length> focus-ring-offset: 2px;
// Type: the system UI face plus the icon font; four sizes.
out property <string> icon-font: "Material Symbols Rounded";
out property <TypeStyle> title-large: { size: 22px, weight: 400, line-height: 28px };

View file

@ -26,3 +26,4 @@ D-021 — 2026-11-18 — Playlist sort: a sort option "Playlist sort" offered on
D-022 — 2026-11-18 — Fallback theme seed `#3F6FB5` (muted blue) when the portal gives no accent; palettes are `material-colors` 0.5 `ThemeBuilder` defaults (tonal spot, spec 2021) exported as ARGB `Palette` structs; library warnings go to stderr as one `tunal-theme: …` line (no logging crate yet) — S002 — S002, S003.
D-023 — 2026-11-18 — Window minimum size 720×480 px (preferred 960×640): fits a 240 px sidebar plus a usable content column; Slint 1.19 can't drive the icon font's variation axes (font-weight doesn't reach `wght`), so `Icon` has size only and draws the default instance (wght 400, FILL 0); easing tokens live in an internal `Motion` global and Rust sets the reduced flag through `MotionPrefs` (easing properties can't be exported) — S003 — S003 and every UI plan.
D-024 — 2026-11-18 — Location URIs are `scheme://authority/path` with the path as raw bytes (percent-encoded only in Display); every backend implements the object-safe blocking `Location` trait in `tunal-core` (chunked `list` with a `ControlFlow` sink, `watch` returning a drop guard), unsupported ops return `Error::Unsupported`, and views gate actions on `capabilities()` — S006 — S007–S014, S024–S029.
D-025 — 2026-11-18 — Controls: every control inherits `StateLayer` (tint drawn above content, `clicked` for users and `activated` for the control's own toggling; inherited properties must be written `root.x`); `TextField` is built on the builtin `TextInput` because std `LineEdit` (material) takes its colours from the fixed `MaterialPalette` and can't use our tokens; the software renderer ignores `transform-scale`, so press squeeze shows only in a real window — S004 — every UI plan, S035.

Some files were not shown because too many files have changed in this diff Show more