Tunal/crates/tunal/ui/components/icon-button.slint
astar76 62422d582d fix: tooltips no longer swallow clicks; split toggle keeps pane views
Each control opened its own PopupWindow as tooltip. While one showed, Slint
dropped every press outside it, so after resting on a button (the split toggle
above all) the next click did nothing. Tooltips are now one input-transparent
layer per window (Tips + TooltipLayer), filled in by StateLayer.

Toggle buttons whose state the shell owns (sidebar, previews, split) no longer
flip `checked` themselves, which broke their binding. Switching tabs or the
split now updates, adds or removes single pane rows instead of rebuilding every
pane view. xdnd_probe gains a `click` mode for real clicks under Xvfb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 10:00:41 -06:00

75 lines
2.7 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;
// The owner keeps `checked` (bound to its own state): a click only reports, so the
// binding is never broken by the button flipping it.
in property <bool> bound;
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.bound {
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;
}
}
}