Files
client/native/ui/shell.slint
T

339 lines
24 KiB
Plaintext

import { ScrollView, ListView, Slider } from "std-widgets.slint";
import { Theme } from "theme.slint";
import { ActionButton, TextField } from "controls.slint";
import { ChatScreen } from "chat.slint";
import { SettingsScreen } from "settings.slint";
export struct ShellRow { id: string, title: string, subtitle: string, depth: int, selected: bool, expanded: bool, expandable: bool, talking: bool, muted: bool, unread: string }
export struct ShellTab { id: string, title: string, selected: bool, microphone-owner: bool, connected: bool, unread: string }
export struct ShellCommand { id: string, label: string, enabled: bool, reason: string, destructive: bool }
export struct ShellInfo { label: string, value: string }
export struct ShellStream { id: string, title: string, status: string, frame: image, has-frame: bool, volume: float, actions: [ShellCommand] }
export global ShellBridge {
in-out property <[ShellTab]> tabs;
in-out property <[ShellRow]> tree;
in-out property <[ShellRow]> bookmarks;
in-out property <[ShellRow]> contacts;
in-out property <[ShellRow]> entries;
in-out property <[ShellInfo]> info;
in-out property <[ShellCommand]> actions;
in-out property <[ShellCommand]> detail-actions;
in-out property <[ShellCommand]> menu-actions;
in-out property <[ShellStream]> streams;
in-out property <[string]> destinations;
in-out property <int> destination;
in-out property <int> depth;
in-out property <int> stage;
in-out property <string> title;
in-out property <string> subtitle;
in-out property <string> description;
in-out property <string> status;
in-out property <string> error;
in-out property <string> detail-error;
in-out property <bool> loading;
in-out property <bool> detail-loading;
in-out property <bool> menu-visible;
in-out property <string> menu-title;
in-out property <bool> has-voice;
in-out property <bool> muted;
in-out property <bool> deafened;
in-out property <bool> transmitting;
in-out property <bool> ptt-enabled;
in-out property <string> voice-title;
in-out property <string> voice-status;
in-out property <bool> searchable;
in-out property <string> search;
in-out property <bool> has-previous;
in-out property <bool> has-next;
in-out property <string> label-back;
in-out property <string> label-more;
in-out property <string> label-close;
in-out property <string> label-loading;
in-out property <string> label-empty;
in-out property <string> label-tree-empty;
in-out property <string> label-stream-empty;
in-out property <string> label-stream-waiting;
in-out property <string> label-mute;
in-out property <string> label-deafen;
in-out property <string> label-ptt;
in-out property <string> label-bookmarks;
in-out property <string> label-search;
in-out property <string> label-next;
in-out property <string> label-previous;
in-out property <string> label-volume;
in-out property <string> label-resize;
in-out property <[string]> stages;
in-out property <length> sidebar-width: 270px;
in-out property <length> server-width: 500px;
callback navigate(int);
callback back();
callback select(string);
callback expand(string);
callback context(string);
callback menu();
callback close-menu();
callback invoke(string);
callback row-press(string,bool);
callback voice(int);
callback held(bool);
callback search-edited(string);
callback page(bool);
in-out property <string> fullscreen-stream;
callback stream-volume(string,float);
callback resized(float,float);
}
component EntryRow inherits Rectangle {
in property <ShellRow> item;
property <length> indent: Theme.android ? min(item.depth * 14px, max(0px, self.width - 220px)) : item.depth * 14px;
height: max(44px, Theme.touch-target);
border-radius: 9px;
background: item.selected ? Theme.contrast : (touch.has-hover ? Theme.bg : transparent);
border-width: item.selected || focus.has-focus ? 1.5px : 0px;
border-color: Theme.tint;
accessible-role: list-item;
accessible-label: item.title + ". " + item.subtitle;
accessible-item-selectable: true;
accessible-item-selected: item.selected;
accessible-expandable: item.expandable;
accessible-expanded: item.expanded;
accessible-action-expand => { if root.item.expandable { ShellBridge.expand(root.item.id); } }
accessible-action-default => { ShellBridge.select(root.item.id); }
HorizontalLayout {
padding-left: 10px + root.indent; padding-right: 4px; spacing: 8px;
if root.item.expandable: ActionButton { width: Theme.android ? 48px : 44px; text: root.item.expanded ? ShellBridge.label-close : ShellBridge.label-more; clicked => { ShellBridge.expand(root.item.id); } }
Rectangle { width: 6px; height: 6px; border-radius: 3px; background: root.item.talking ? Theme.success : (root.item.muted ? Theme.error : Theme.muted); }
VerticalLayout {
spacing: 0px; alignment: center;
Text { text: root.item.title; color: Theme.fg; font-size: Theme.font-size; overflow: elide; }
if root.item.subtitle != "": Text { text: root.item.subtitle; color: Theme.muted; font-size: Theme.font-size * 0.86; overflow: elide; }
}
if root.item.unread != "": Text { text: root.item.unread; color: Theme.tint; vertical-alignment: center; }
ActionButton { text: ShellBridge.label-more; width: 70px; clicked => { ShellBridge.context(root.item.id); } }
}
focus := FocusScope { key-pressed(e) => { if e.text == "\n" { ShellBridge.select(root.item.id); return accept; } if e.text == Key.F10 && e.modifiers.shift { ShellBridge.context(root.item.id); return accept; } return reject; } }
// Explicit overflow is always available on touch; right click never selects a row.
touch := TouchArea {
x: root.item.expandable ? 10px + (Theme.android ? 48px : 44px) + root.indent : 0px;
width: max(0px,parent.width - self.x - 78px);
clicked => { focus.focus(); ShellBridge.select(root.item.id); }
pointer-event(e) => {
if e.button == PointerEventButton.right && e.kind == PointerEventKind.down { ShellBridge.context(root.item.id); }
if e.button == PointerEventButton.left && e.kind == PointerEventKind.down { ShellBridge.row-press(root.item.id,true); }
if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel { ShellBridge.row-press(root.item.id,false); }
if e.kind == PointerEventKind.move && (abs((self.mouse-x - self.pressed-x)/1px)>8 || abs((self.mouse-y - self.pressed-y)/1px)>8) { ShellBridge.row-press(root.item.id,false); }
}
}
}
component CommandList inherits VerticalLayout {
in property <[ShellCommand]> commands;
spacing: 4px;
for command in root.commands: VerticalLayout {
ActionButton { text: command.label; enabled: command.enabled; destructive: command.destructive; clicked => { ShellBridge.invoke(command.id); } }
if command.reason != "": Text { text: command.reason; color: Theme.muted; wrap: word-wrap; }
}
}
component StreamTile inherits Rectangle {
in property <ShellStream> item;
min-height: 230px;
background: Theme.contrast;
border-radius: 8px;
border-width: 2px;
border-color: Theme.bg;
VerticalLayout {
padding: 8px; spacing: 4px;
Text { text: root.item.title; color: Theme.fg; overflow: elide; }
Rectangle {
min-height: 150px;
if root.item.has-frame: Image { source: root.item.frame; image-fit: contain; }
if !root.item.has-frame: Text { text: root.item.status != "" ? root.item.status : ShellBridge.label-stream-waiting; color: Theme.muted; horizontal-alignment: center; vertical-alignment: center; wrap: word-wrap; }
}
Text { text: root.item.status; color: Theme.muted; overflow: elide; }
Slider { minimum: 0; maximum: 2; value: root.item.volume; accessible-label: ShellBridge.label-volume; changed(value) => { ShellBridge.stream-volume(root.item.id,value); } }
CommandList { commands: root.item.actions; }
}
}
export component ShellScreen inherits Rectangle {
background: Theme.shaded;
min-width: 0px; min-height: 0px;
preferred-width: 100%; preferred-height: 100%;
property <bool> compact: self.width < 600px;
property <bool> desktop: self.width >= 1024px;
property <bool> typing: Theme.android && Theme.ime-inset > 0px;
property <length> sidebar-width <=> ShellBridge.sidebar-width;
property <length> server-width <=> ShellBridge.server-width;
property <length> actual-sidebar: desktop ? min(sidebar-width, max(62px,self.width - 515px)) : 0px;
property <length> actual-server: desktop ? min(server-width,max(220px,self.width - actual-sidebar - 295px)) : min(300px,self.width * 0.4);
property <length> main-width: max(0px, self.width - actual-sidebar - (desktop ? 4px : 0px));
property <length> detail-width: max(0px, main-width - (ShellBridge.destination == 0 && !compact ? actual-server + (desktop ? 4px : 0px) : 0px));
VerticalLayout {
spacing: 0px;
Rectangle {
height: max(44px, Theme.touch-target); background: Theme.header;
HorizontalLayout {
padding-left: 10px; padding-right: 10px; spacing: 8px;
if !root.desktop: ActionButton { text: ShellBridge.label-back; enabled: ShellBridge.depth > 0 || ShellBridge.destination != 0; clicked => { ShellBridge.back(); } }
Text { text: "TeamsPeach"; color: Theme.fg; font-weight: 600; vertical-alignment: center; }
Rectangle { horizontal-stretch: 1; }
if !root.compact && !root.desktop: HorizontalLayout {
spacing: 8px;
for label[index] in ShellBridge.destinations: ActionButton { text: label; primary: ShellBridge.destination == index; clicked => { ShellBridge.navigate(index); } }
}
ActionButton { text: ShellBridge.label-more; clicked => { ShellBridge.menu(); } }
}
}
if ShellBridge.error != "": Text { text: ShellBridge.error; color: Theme.error; wrap: word-wrap; }
if ShellBridge.loading: Text { text: ShellBridge.label-loading; color: Theme.muted; }
HorizontalLayout {
spacing: 0px;
if root.desktop: Rectangle {
width: root.actual-sidebar; background: Theme.header;
VerticalLayout {
padding: 10px; spacing: 4px;
for label[index] in ShellBridge.destinations: ActionButton { text: label; primary: ShellBridge.destination == index; clicked => { ShellBridge.navigate(index); } }
Text { text: ShellBridge.label-bookmarks; color: Theme.muted; font-size: Theme.font-size * 0.86; }
ListView { for item in ShellBridge.bookmarks: EntryRow { item: item; } }
CommandList { commands: ShellBridge.actions; }
}
}
if root.desktop: Rectangle {
width: 4px; background: split1.pressed ? Theme.tint : Theme.contrast;
accessible-role: slider; accessible-label: ShellBridge.label-resize;
split1 := TouchArea { mouse-cursor: ew-resize; moved => { if self.pressed { root.sidebar-width = clamp(root.sidebar-width + self.mouse-x - self.pressed-x,62px,420px); } } pointer-event(e) => { if e.kind == PointerEventKind.up { if root.sidebar-width < 200px { root.sidebar-width = 62px; } ShellBridge.resized(root.sidebar-width/1px,root.server-width/1px); } } }
}
if ShellBridge.destination == 3: SettingsScreen { width: root.main-width; }
if ShellBridge.destination == 2: Rectangle {
background: Theme.shaded;
VerticalLayout { padding: 12px; Text { text: ShellBridge.destinations[2]; color: Theme.fg; font-size: Theme.font-size * 1.6; font-weight: 700; } ListView { for item in ShellBridge.contacts: EntryRow { item: item; } } if ShellBridge.contacts.length == 0: Text { text: ShellBridge.label-empty; color: Theme.muted; } }
}
if ShellBridge.destination == 0 || ShellBridge.destination == 1: HorizontalLayout {
spacing: 0px;
if ShellBridge.destination == 0 && (!root.compact || ShellBridge.depth == 0): Rectangle {
width: root.compact ? root.width : root.actual-server;
background: Theme.bg;
VerticalLayout {
spacing: 0px;
if !Theme.android: ScrollView { height: Theme.touch-target; HorizontalLayout { for tab in ShellBridge.tabs: ActionButton {
text: tab.title + (tab.microphone-owner ? " · " + ShellBridge.label-mute : "") + (tab.unread != "" ? " (" + tab.unread + ")" : ""); primary: tab.selected; clicked => { ShellBridge.select(tab.id); }
} } }
if Theme.android: ScrollView { height: Theme.touch-target; HorizontalLayout { for tab in ShellBridge.tabs: HorizontalLayout {
ActionButton { text: tab.title + (tab.microphone-owner ? " · " + ShellBridge.label-mute : "") + (tab.unread != "" ? " (" + tab.unread + ")" : ""); primary: tab.selected; clicked => { ShellBridge.select(tab.id); } }
ActionButton { text: ShellBridge.label-more; clicked => { ShellBridge.context(tab.id); } }
} } }
if root.compact && (ShellBridge.tabs.length == 0 || Theme.android) && ShellBridge.bookmarks.length > 0: ListView { max-height: Theme.android && ShellBridge.tabs.length > 0 ? root.height * 0.25 : root.height; for item in ShellBridge.bookmarks: EntryRow { item: item; } }
ListView { for item in ShellBridge.tree: EntryRow { item: item; } }
if ShellBridge.tree.length == 0: Text { text: ShellBridge.label-tree-empty; color: Theme.muted; wrap: word-wrap; }
if !root.desktop && !Theme.android: CommandList { commands: ShellBridge.actions; }
if !root.desktop && Theme.android: ScrollView { height: min(Theme.touch-target * 2, root.height * 0.22); CommandList { commands: ShellBridge.actions; } }
}
}
if root.desktop && ShellBridge.destination == 0: Rectangle {
width: 4px; background: split2.pressed ? Theme.tint : Theme.contrast;
accessible-role: slider; accessible-label: ShellBridge.label-resize;
split2 := TouchArea { mouse-cursor: ew-resize; moved => { if self.pressed { root.server-width = clamp(root.server-width + self.mouse-x - self.pressed-x,220px,max(220px,root.width - root.actual-sidebar - 295px)); } } pointer-event(e) => { if e.kind == PointerEventKind.up { ShellBridge.resized(root.sidebar-width/1px,root.server-width/1px); } } }
}
if !root.compact || ShellBridge.depth > 0 || ShellBridge.destination == 1: Rectangle {
background: Theme.shaded;
VerticalLayout {
spacing: 4px;
if !Theme.android || !root.compact || (ShellBridge.stage != 1 && ShellBridge.destination != 1): Rectangle { min-height: 71px; background: Theme.shaded;
VerticalLayout { padding: 12px; Text { text: ShellBridge.title; color: Theme.fg; font-size: Theme.font-size * 1.6; font-weight: 700; overflow: elide; } Text { text: ShellBridge.subtitle; color: Theme.muted; overflow: elide; } }
}
if !Theme.android: HorizontalLayout { for name[index] in ShellBridge.stages: ActionButton { text: name; primary: ShellBridge.stage == index; clicked => { ShellBridge.stage = index; } } }
if Theme.android && !root.typing: ScrollView { height: Theme.touch-target; vertical-stretch: 0; HorizontalLayout { for name[index] in ShellBridge.stages: ActionButton { text: name; primary: ShellBridge.stage == index; clicked => { ShellBridge.stage = index; } } } }
if ShellBridge.stage == 1 || ShellBridge.destination == 1: ChatScreen { width: root.detail-width; }
if ShellBridge.stage == 2 && ShellBridge.destination != 1: ScrollView {
VerticalLayout { padding: 10px; spacing: 10px;
if ShellBridge.streams.length == 0: Text { text: ShellBridge.label-stream-empty; color: Theme.muted; wrap: word-wrap; }
for stream in ShellBridge.streams: StreamTile { item: stream; }
CommandList { commands: ShellBridge.detail-actions; }
}
}
if ShellBridge.stage == 0 && ShellBridge.destination != 1: VerticalLayout {
if ShellBridge.detail-loading: Text { text: ShellBridge.label-loading; color: Theme.muted; }
if ShellBridge.detail-error != "": Text { text: ShellBridge.detail-error; color: Theme.error; wrap: word-wrap; }
if ShellBridge.searchable: TextField { text: ShellBridge.search; placeholder: ShellBridge.label-search; edited(value) => { ShellBridge.search-edited(value); } }
ScrollView { VerticalLayout { padding: 12px; spacing: 12px;
if ShellBridge.description != "": Text { text: ShellBridge.description; color: Theme.fg; wrap: word-wrap; }
for row in ShellBridge.info: VerticalLayout { Text { text: row.label; color: Theme.muted; } Text { text: row.value; color: Theme.fg; wrap: word-wrap; } }
CommandList { commands: ShellBridge.detail-actions; }
} }
if !Theme.android || ShellBridge.entries.length > 0: ListView { for item in ShellBridge.entries: EntryRow { item: item; } }
if ShellBridge.has-previous || ShellBridge.has-next: HorizontalLayout {
ActionButton { text: ShellBridge.label-previous; enabled: ShellBridge.has-previous; clicked => { ShellBridge.page(false); } }
ActionButton { text: ShellBridge.label-next; enabled: ShellBridge.has-next; clicked => { ShellBridge.page(true); } }
}
}
}
}
}
}
if ShellBridge.has-voice: Rectangle {
min-height: Theme.touch-target + 12px; background: Theme.contrast;
VerticalLayout {
if !root.typing: Text { text: ShellBridge.voice-title + " · " + ShellBridge.voice-status; color: ShellBridge.transmitting ? Theme.success : Theme.fg; overflow: elide; }
HorizontalLayout {
spacing: 4px;
ActionButton { min-width: Theme.android ? 48px : 0px; horizontal-stretch: 1; text: ShellBridge.label-mute; primary: Theme.android && ShellBridge.muted; destructive: ShellBridge.muted; clicked => { ShellBridge.voice(0); } }
ActionButton { min-width: Theme.android ? 48px : 0px; horizontal-stretch: 1; text: ShellBridge.label-deafen; primary: Theme.android && ShellBridge.deafened; destructive: ShellBridge.deafened; clicked => { ShellBridge.voice(1); } }
if !Theme.android: Rectangle { min-height: Theme.touch-target; background: desktop-ptt.pressed ? Theme.tint : Theme.bg; border-radius: 4px; accessible-role: button; accessible-label: ShellBridge.label-ptt;
Text { text: ShellBridge.label-ptt; color: Theme.fg; vertical-alignment: center; horizontal-alignment: center; wrap: word-wrap; }
desktop-ptt := TouchArea { enabled: ShellBridge.ptt-enabled; pointer-event(e) => { if e.kind == PointerEventKind.down { ShellBridge.held(true); } else if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel { ShellBridge.held(false); } } }
}
if Theme.android: Rectangle { min-width: 48px; horizontal-stretch: 1; min-height: Theme.touch-target; background: ptt.pressed ? Theme.tint : Theme.bg; border-radius: 4px; opacity: ShellBridge.ptt-enabled ? 1 : 0.45;
accessible-role: button; accessible-label: ShellBridge.label-ptt; accessible-enabled: ShellBridge.ptt-enabled;
border-width: ptt-focus.has-focus ? 2px : 0px; border-color: Theme.outline;
Text { text: ShellBridge.label-ptt; color: Theme.fg; vertical-alignment: center; horizontal-alignment: center; wrap: word-wrap; }
ptt-focus := FocusScope {
enabled: ShellBridge.ptt-enabled;
changed has-focus => { if !self.has-focus { ShellBridge.held(false); } }
key-pressed(e) => { if e.text == " " || e.text == Key.Return { ShellBridge.held(true); return accept; } return reject; }
key-released(e) => { if e.text == " " || e.text == Key.Return { ShellBridge.held(false); return accept; } return reject; }
}
ptt := TouchArea {
enabled: ShellBridge.ptt-enabled;
pointer-event(e) => { if e.button == PointerEventButton.left && e.kind == PointerEventKind.down { ptt-focus.focus(); ShellBridge.held(true); } else if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel { ShellBridge.held(false); } }
moved => { if self.pressed && (self.mouse-x < 0px || self.mouse-y < 0px || self.mouse-x > self.width || self.mouse-y > self.height) { ShellBridge.held(false); } }
}
}
}
}
}
if ShellBridge.status != "": Text { text: ShellBridge.status; color: Theme.muted; overflow: elide; }
if root.compact && !root.typing: HorizontalLayout { for label[index] in ShellBridge.destinations: ActionButton { min-width: Theme.android ? 48px : 0px; horizontal-stretch: 1; text: label; primary: ShellBridge.destination == index; clicked => { ShellBridge.navigate(index); } } }
}
if ShellBridge.fullscreen-stream != "": Rectangle {
background: Theme.contrast;
VerticalLayout {
ActionButton { text: ShellBridge.label-close; clicked => { ShellBridge.fullscreen-stream = ""; } }
for stream in ShellBridge.streams: StreamTile { visible: stream.id == ShellBridge.fullscreen-stream; height: self.visible ? parent.height - Theme.touch-target : 0px; item: stream; }
}
}
if ShellBridge.menu-visible: Rectangle {
background: Theme.contrast.with-alpha(0.7);
TouchArea { clicked => { ShellBridge.close-menu(); } }
Rectangle {
width: min(parent.width - 24px,360px); height: min(parent.height - 24px, menu.preferred-height);
x: parent.width - self.width - 12px; y: root.compact ? parent.height - self.height - 12px : 12px;
background: Theme.header; border-radius: 8px; border-width: 1px; border-color: Theme.outline;
menu := VerticalLayout { padding: 12px; spacing: 8px; Text { text: ShellBridge.menu-title; color: Theme.fg; font-weight: 600; wrap: word-wrap; } ScrollView { min-height: Theme.android ? min(Theme.touch-target * 3, max(0px, root.height - 160px)) : 0px; CommandList { commands: ShellBridge.menu-actions; } } ActionButton { text: ShellBridge.label-close; clicked => { ShellBridge.close-menu(); } } }
}
}
}
export component StreamWindow inherits Window {
in property <ShellStream> item;
title: item.title;
preferred-width: 960px;
preferred-height: 640px;
min-width: 320px;
min-height: 240px;
background: Theme.contrast;
default-font-family: Theme.font-family;
default-font-size: Theme.font-size;
StreamTile { item: root.item; }
}