Shape library (cookies, clover, scallop) with morphing Shape component, press ripple in StateLayer, content card shell, shaped file glyphs, card grid tiles, dialog header shapes, menu pills, wavy toast progress. Co-Authored-By: Claude Opus 5.5 <[email protected]>
72 lines
2.5 KiB
Text
72 lines
2.5 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Icon } from "icon.slint";
|
|
import { StateLayer } from "state-layer.slint";
|
|
import { Shape, ShapeKind } from "shape.slint";
|
|
|
|
// An icon-only button. Always give it a `tooltip` naming its action. With `toggle` it flips
|
|
// `checked` on click; checked, its circle morphs into a tonal cookie.
|
|
export component IconButton inherits StateLayer {
|
|
// Glyph from `Icons`.
|
|
in property <string> icon;
|
|
in property <bool> toggle;
|
|
// A tonal circle at rest (toolbar buttons) instead of a bare glyph.
|
|
in property <bool> tonal;
|
|
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);
|
|
// Disabled, only the glyph dims: a darker disabled fill would read as pressed.
|
|
background: !root.tonal || root.on ? transparent : Theme.surface-container-high;
|
|
tint: root.content;
|
|
squeeze: Motion.squeeze-small;
|
|
animate border-radius {
|
|
duration: Motion.time(root.pressed ? Motion.short2 : Motion.short3);
|
|
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();
|
|
}
|
|
|
|
if root.toggle: Shape {
|
|
size: root.size;
|
|
shape: ShapeKind.circle;
|
|
active-shape: ShapeKind.cookie9;
|
|
active: root.on;
|
|
fill: transparent;
|
|
active-fill: root.enabled ? Theme.secondary-container : Theme.on-surface.with-alpha(Theme.disabled-container);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|