IconButton names itself in a tooltip after a moment of hover, also while it is disabled (mute or deafen when not connected), and can show a neutral count at its top right (for pins and topics later). Tooltips are desktop only: the new Bridge.desktop is false in the Android app. Tooltip showed once (its Timer turned off its own binding) and stayed open after the pointer left. Both now use Slint's Tooltip element with our TooltipBubble: it opens at the pointer, closes when the pointer leaves, and lets clicks and hover through, which a PopupWindow of our own does not while it is open. A press closes it until the pointer leaves. The bubble sets its own preferred width, up to 400px, so long text wraps: the tooltip's popup takes that width, and a max-width would not narrow it. IconButton's look moves onto an inner rectangle: with an opacity and an animation on its root, Slint inlined it at each of its 100-odd uses, and the tooltip and count alone added 3.3 MB of generated code to a crate whose compile already peaks near 14 GB. Now the generated code is 1.1 MB smaller than before (70.7 MB). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
287 lines
10 KiB
Plaintext
287 lines
10 KiB
Plaintext
// Floating things: menus, tooltips, modal dialogs, toasts, the resize
|
|
// handle of side panels.
|
|
|
|
import { Theme } from "../theme.slint";
|
|
import { Icons } from "../icons.slint";
|
|
import { Icon } from "icon.slint";
|
|
import { IconButton } from "button.slint";
|
|
import { HoverTooltip } from "tooltip.slint";
|
|
|
|
// An entry of a `PopupMenu`.
|
|
export struct MenuEntry {
|
|
text: string,
|
|
icon: image,
|
|
// Red (leave, delete).
|
|
danger: bool,
|
|
enabled: bool,
|
|
// A line above this entry.
|
|
separator: bool,
|
|
}
|
|
|
|
// A themed menu: open with `show(x, y)` (relative to the element that
|
|
// contains it); `activated(index)` when an entry is chosen. For right-click
|
|
// menus wrap a `TouchArea` and call `show` on `pointer-event` of the right
|
|
// button.
|
|
export component PopupMenu inherits Rectangle {
|
|
in property <[MenuEntry]> entries;
|
|
in property <length> menu-width: 220px;
|
|
callback activated(int);
|
|
property <length> px;
|
|
property <length> py;
|
|
property <length> row-height: Theme.control-height;
|
|
|
|
public function show(x: length, y: length) {
|
|
px = x;
|
|
py = y;
|
|
popup.show();
|
|
}
|
|
|
|
width: 0;
|
|
height: 0;
|
|
popup := PopupWindow {
|
|
x: root.px;
|
|
y: root.py;
|
|
width: root.menu-width;
|
|
close-policy: PopupClosePolicy.close-on-click-outside;
|
|
Rectangle {
|
|
border-radius: Theme.radius-md;
|
|
background: Theme.surface-3;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
accessible-role: AccessibleRole.list;
|
|
VerticalLayout {
|
|
padding: Theme.space-2;
|
|
for entry[i] in root.entries: VerticalLayout {
|
|
if entry.separator: Rectangle {
|
|
height: 9px;
|
|
Rectangle {
|
|
height: 1px;
|
|
background: Theme.border;
|
|
}
|
|
}
|
|
Rectangle {
|
|
height: root.row-height;
|
|
border-radius: Theme.radius-sm;
|
|
background: item.has-hover && entry.enabled ? (entry.danger ? Theme.danger-soft : Theme.surface-4) : transparent;
|
|
opacity: entry.enabled ? 1.0 : 0.5;
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: entry.text;
|
|
accessible-enabled: entry.enabled;
|
|
accessible-action-default => {
|
|
root.activated(i);
|
|
popup.close();
|
|
}
|
|
item := TouchArea {
|
|
enabled: entry.enabled;
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => {
|
|
root.activated(i);
|
|
popup.close();
|
|
}
|
|
}
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-3;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
if entry.icon.width > 0: Icon {
|
|
source: entry.icon;
|
|
size: Theme.icon-sm;
|
|
tint: entry.danger ? Theme.danger : Theme.icon;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: entry.text;
|
|
color: entry.danger ? Theme.danger : Theme.text;
|
|
vertical-alignment: center;
|
|
overflow: elide;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Hover help: wraps @children and shows `text` in a bubble near the
|
|
// pointer after a moment, until the pointer leaves (desktop only).
|
|
export component Tooltip inherits Rectangle {
|
|
in property <string> text;
|
|
@children
|
|
HoverTooltip {
|
|
text: root.text;
|
|
}
|
|
}
|
|
|
|
// A modal dialog: a dimmed backdrop and a card with a title, a close button,
|
|
// the content (@children) and usually a footer row inside the content.
|
|
// Clicking the backdrop or Escape dismisses it.
|
|
export component Modal inherits Rectangle {
|
|
in property <string> title;
|
|
in property <string> subtitle;
|
|
in property <image> icon;
|
|
// Tint the icon with the accent (off for full-colour images).
|
|
in property <bool> tint-icon: true;
|
|
in property <length> card-width: 520px;
|
|
in property <length> card-height: 520px;
|
|
callback dismissed();
|
|
|
|
background: Theme.scrim;
|
|
accessible-role: AccessibleRole.none;
|
|
TouchArea {
|
|
clicked => { root.dismissed(); }
|
|
}
|
|
FocusScope {
|
|
key-pressed(event) => {
|
|
if event.text == Key.Escape {
|
|
root.dismissed();
|
|
return accept;
|
|
}
|
|
reject
|
|
}
|
|
}
|
|
card := Rectangle {
|
|
width: min(root.width - 32px, root.card-width);
|
|
height: min(root.height - 32px, root.card-height);
|
|
background: Theme.surface;
|
|
border-radius: Theme.radius-xl;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
accessible-role: AccessibleRole.groupbox;
|
|
accessible-label: root.title;
|
|
// Clicks inside the card do not dismiss it.
|
|
TouchArea { }
|
|
VerticalLayout {
|
|
padding: Theme.space-6;
|
|
spacing: Theme.space-5;
|
|
HorizontalLayout {
|
|
spacing: Theme.space-4;
|
|
if root.icon.width > 0: Rectangle {
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: Theme.radius-md;
|
|
background: Theme.accent-soft;
|
|
if root.tint-icon: Icon {
|
|
source: root.icon;
|
|
tint: Theme.accent-text;
|
|
}
|
|
if !root.tint-icon: Image {
|
|
width: 28px;
|
|
height: 28px;
|
|
source: root.icon;
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
alignment: center;
|
|
horizontal-stretch: 1;
|
|
Text {
|
|
text: root.title;
|
|
font-size: Theme.font-xl;
|
|
font-weight: Theme.weight-semibold;
|
|
color: Theme.text;
|
|
overflow: elide;
|
|
}
|
|
if root.subtitle != "": Text {
|
|
text: root.subtitle;
|
|
font-size: Theme.font-sm;
|
|
color: Theme.text-muted;
|
|
wrap: word-wrap;
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
alignment: start;
|
|
IconButton {
|
|
icon: Icons.x;
|
|
label: @tr("Close");
|
|
size: 32px;
|
|
clicked => { root.dismissed(); }
|
|
}
|
|
}
|
|
}
|
|
@children
|
|
}
|
|
}
|
|
}
|
|
|
|
// A short message at the bottom of the window that hides itself.
|
|
export component Toast inherits Rectangle {
|
|
in property <string> text;
|
|
in property <image> icon: Icons.info;
|
|
in property <duration> timeout: 5s;
|
|
in-out property <bool> shown;
|
|
// Hidden for now (under the account prompt): the time to read starts later.
|
|
in property <bool> paused;
|
|
// The widest it gets (e.g. the window less a margin); longer text wraps.
|
|
in property <length> widest: 560px;
|
|
height: shown ? row.preferred-height + 16px : 0px;
|
|
width: min(row.preferred-width + 24px, widest);
|
|
visible: shown;
|
|
border-radius: Theme.radius-lg;
|
|
background: Theme.surface-3;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
accessible-role: AccessibleRole.text;
|
|
accessible-label: text;
|
|
accessible-live-region: polite;
|
|
Timer {
|
|
interval: root.timeout;
|
|
running: root.shown && !root.paused;
|
|
triggered => { root.shown = false; }
|
|
}
|
|
TouchArea {
|
|
clicked => { root.shown = false; }
|
|
}
|
|
row := HorizontalLayout {
|
|
padding-left: Theme.space-4;
|
|
padding-right: Theme.space-4;
|
|
spacing: Theme.space-3;
|
|
Icon {
|
|
source: root.icon;
|
|
size: Theme.icon-sm;
|
|
tint: Theme.accent-text;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: root.text;
|
|
color: Theme.text;
|
|
vertical-alignment: center;
|
|
wrap: word-wrap;
|
|
}
|
|
}
|
|
}
|
|
|
|
// A vertical grip between panels: drag to resize. `size` is the width of
|
|
// the panel on the `left` or right side of the handle, kept within bounds.
|
|
export component ResizeHandle inherits Rectangle {
|
|
in-out property <length> size;
|
|
in property <length> minimum: 160px;
|
|
in property <length> maximum: 600px;
|
|
// The panel is left of the handle (dragging right grows it).
|
|
in property <bool> left;
|
|
width: 8px;
|
|
horizontal-stretch: 0;
|
|
accessible-role: AccessibleRole.slider;
|
|
accessible-label: @tr("Panel width");
|
|
accessible-value: round(size / 1px);
|
|
accessible-action-increment => { size = min(maximum, size + 16px); }
|
|
accessible-action-decrement => { size = max(minimum, size - 16px); }
|
|
// Three dots, as a grip.
|
|
for i in 3: Rectangle {
|
|
y: (parent.height - 22px) / 2 + i * 9px;
|
|
width: 4px;
|
|
height: 4px;
|
|
border-radius: 2px;
|
|
background: touch.has-hover || touch.pressed ? Theme.accent : Theme.text-muted;
|
|
}
|
|
// The handle moves with the edge, so each move adds the distance from
|
|
// where it was pressed.
|
|
touch := TouchArea {
|
|
mouse-cursor: MouseCursor.col-resize;
|
|
moved => {
|
|
if self.pressed {
|
|
root.size = clamp(root.size + (root.left ? 1 : -1) * (self.mouse-x - self.pressed-x), root.minimum, root.maximum);
|
|
}
|
|
}
|
|
}
|
|
}
|