Files
VoelinClient/crates/voelin-ui/ui/components/overlay.slint
T
Claude 124240daea voelin-ui: account portal on Windows, demo mode, notices and one-time codes
- The account website actions said "Could not open your browser" on every
  click on Windows (explorer exits with 1 on success) and waited for the
  browser to close with a foreground xdg-open: success is that the opener
  started, as for files (open_target).
- VOELIN_DEMO_UI's account screens signed in and out for real and could
  delete or replace the developer's saved session: demo mode uses an
  in-memory secret store and its sign-in and sign-out do nothing.
- A notice from the start (an imported identity) ran out behind the account
  prompt: the toast's time starts when the prompt closes.
- After an account asked for a one-time code, signing in was blocked until
  one was typed, also for another account: the code field shows but no
  longer blocks; a 2FA account without it is asked again.
- SECURITY.md lists the myTeamSpeak secrets in the keyring, the account
  service the app talks to, and that servers get the account's id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEpqsPES27Eacue91u3d2Q
2026-10-04 18:48:11 +00:00

312 lines
11 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";
// 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 after a moment.
export component Tooltip inherits Rectangle {
in property <string> text;
// Above (default) or below the element.
in property <bool> below;
area := TouchArea {
@children
}
Timer {
interval: 600ms;
running: area.has-hover && root.text != "";
triggered => {
self.running = false;
bubble.show();
}
}
bubble := PopupWindow {
x: (root.width - self.width) / 2;
y: root.below ? root.height + 6px : -self.height - 6px;
width: label.preferred-width + 20px;
height: label.preferred-height + 12px;
close-policy: PopupClosePolicy.close-on-click-outside;
Rectangle {
border-radius: Theme.radius-sm;
background: Theme.surface-4;
border-width: 1px;
border-color: Theme.border-strong;
label := Text {
text: root.text;
color: Theme.text;
font-size: Theme.font-sm;
}
}
}
}
// 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);
}
}
}
}