The user wants to appear as their TeamSpeak identity. Until now the
official client's default became Voelin's only on a store without
identities, so anyone who had started Voelin once kept the identity the
app had created on its own, which nobody chose.
The store now records where each identity came from and which one is
the default (schema 4: identities.origin created/imported/user and
is_default; the migration marks the first identity named Default as
created, the rest as imported, the first as the default). When the
import on start finds the official client's default while Voelin's
default is still the created one, that identity becomes the default,
once: the created one is kept, and choosing it again later makes it the
user's own, which no import replaces. The status says so ("You now use
your TeamSpeak identity "X"; your previous one is kept").
The toast wrapped nothing and was cut at 560 pixels, wider than a phone;
it now wraps within the window. voelinctl identity list shows the origin
and the default. Tested with synthetic databases and in the app headless
with a fake home: created, then replaced once, then left alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
310 lines
11 KiB
Plaintext
310 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;
|
|
// 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;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|