Servers took their colour from a palette of people's colours by a hash of the name, so two of the three sample servers were the same blue. vm::servers::tints gives each server, in the rail's order, a colour from ten hues around the wheel: its name's, or the next free one when an earlier server has it. The rail, Home, search, live rooms and the server chats in the chat lists use it. A server icon at most half as wide as its avatar (TeamSpeak's 16 px ones) is drawn at twice its size, sharp, on that colour instead of stretched. Avatars under 28 px show one letter (Images.first-letter, as Slint cannot cut a string). Channels show the speaker (Icons.channel) everywhere the hash or the volume icon stood for one, and tab titles, notifications and subtitles name them without a '#' (vm::chat::tab_title; private chats keep '@'). Member rows showed everyone's talk power as a bare number. They now show a muted hand, "Needs talk power to speak", only on those whose channel needs more than they have and who are no talker (vm::tree::cannot_talk); the member card keeps the number. The sample's Raid Night needs 50. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
375 lines
14 KiB
Plaintext
375 lines
14 KiB
Plaintext
// The server's sidebar: the server card, connect, and the channel tree
|
|
// with its clients. Selecting a server observes it invisibly (through its
|
|
// gateway) on its own, so there is no button for it.
|
|
|
|
import { Theme } from "../theme.slint";
|
|
import { Icons } from "../icons.slint";
|
|
import { Bridge, TreeItem } from "../bridge.slint";
|
|
import { Nav } from "../nav.slint";
|
|
import { Icon, Button, ButtonKind, IconButton, Avatar, LiveBadge, Chip, BadgeIcons, SectionHeader, SpeakingBars, PopupMenu, MenuEntry, ListView, BannerPicture } from "../components/index.slint";
|
|
|
|
// The banner at the top of the sidebar: server name, counts, a menu.
|
|
export component ServerHeader inherits Rectangle {
|
|
height: 76px * Theme.font-scale;
|
|
border-radius: Theme.radius-lg;
|
|
clip: true;
|
|
background: Theme.surface-2;
|
|
accessible-role: AccessibleRole.groupbox;
|
|
accessible-label: Bridge.server-title;
|
|
if Bridge.server-banner.width > 0: BannerPicture {
|
|
source: Bridge.server-banner;
|
|
}
|
|
HorizontalLayout {
|
|
padding: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
Rectangle {
|
|
width: 42px;
|
|
height: 42px;
|
|
y: (parent.height - self.height) / 2;
|
|
if Bridge.server-icon.width > 0: Image {
|
|
width: 100%;
|
|
height: 100%;
|
|
source: Bridge.server-icon;
|
|
image-fit: contain;
|
|
accessible-role: AccessibleRole.none;
|
|
}
|
|
if Bridge.server-icon.width == 0: Icon {
|
|
source: Icons.server;
|
|
size: 32px;
|
|
tint: Theme.text-secondary;
|
|
x: (parent.width - self.width) / 2;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
alignment: center;
|
|
horizontal-stretch: 1;
|
|
spacing: 3px;
|
|
Text {
|
|
text: Bridge.server-title;
|
|
font-size: Theme.font-md;
|
|
font-weight: Theme.weight-semibold;
|
|
color: Theme.text;
|
|
overflow: elide;
|
|
}
|
|
HorizontalLayout {
|
|
spacing: Theme.space-2;
|
|
Rectangle {
|
|
width: 7px;
|
|
height: 7px;
|
|
y: (parent.height - self.height) / 2;
|
|
border-radius: 4px;
|
|
background: Bridge.voice-connected ? Theme.success : Bridge.observing ? Theme.info : Bridge.voice-connecting ? Theme.warning : Theme.offline;
|
|
}
|
|
Text {
|
|
text: Bridge.server-stats != "" ? Bridge.server-stats
|
|
: Bridge.voice-connecting ? @tr("Connecting…")
|
|
: Bridge.current-server >= 0 ? @tr("Not connected") : @tr("Add a server to start");
|
|
font-size: Theme.font-xs;
|
|
color: Bridge.server-banner.width > 0 ? Theme.text : Theme.text-secondary;
|
|
overflow: elide;
|
|
}
|
|
}
|
|
}
|
|
if Bridge.current-server >= 0: IconButton {
|
|
icon: Icons.chevron-down;
|
|
label: @tr("Server menu");
|
|
size: 24px;
|
|
icon-size: Theme.icon-sm;
|
|
y: (parent.height - self.height) / 2;
|
|
clicked => { menu.show(self.x + self.width - 220px, self.y + self.height + 4px); }
|
|
}
|
|
}
|
|
menu := PopupMenu {
|
|
entries: [
|
|
{ text: @tr("Edit server"), icon: Icons.pencil, enabled: Bridge.current-server >= 0 },
|
|
{ text: @tr("Add a server"), icon: Icons.plus, enabled: true, separator: true },
|
|
];
|
|
activated(i) => {
|
|
if i == 0 {
|
|
Nav.edit-server(Bridge.current-server);
|
|
} else {
|
|
Nav.add-server();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Connect while not connected.
|
|
export component ConnectActions inherits HorizontalLayout {
|
|
spacing: Theme.space-3;
|
|
Button {
|
|
horizontal-stretch: 1;
|
|
kind: ButtonKind.primary;
|
|
icon: Icons.log-in;
|
|
text: Bridge.voice-connecting ? @tr("Connecting…") : @tr("Connect");
|
|
enabled: Bridge.current-server >= 0 && !Bridge.voice-connecting;
|
|
clicked => { Bridge.connect-voice(); }
|
|
}
|
|
}
|
|
|
|
// A server-provided icon in its own colours.
|
|
component RowIcon inherits VerticalLayout {
|
|
in property <image> source;
|
|
alignment: center;
|
|
Image {
|
|
width: 16px;
|
|
height: 16px;
|
|
source: root.source;
|
|
image-fit: contain;
|
|
accessible-role: AccessibleRole.none;
|
|
}
|
|
}
|
|
|
|
// One row of the tree: a channel or a client.
|
|
component TreeRow inherits Rectangle {
|
|
in property <TreeItem> item;
|
|
callback client-clicked(int);
|
|
property <length> indent: item.depth * 14px;
|
|
// A spacer that only separates: a line, or no text.
|
|
property <bool> separator: item.is-channel && (item.spacer == 4 || (item.spacer != 0 && item.name == ""));
|
|
height: item.is-channel ? 34px * Theme.font-scale : 30px * Theme.font-scale;
|
|
clip: true;
|
|
border-radius: Theme.radius-md;
|
|
background: item.is-channel && item.own ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : transparent;
|
|
border-width: item.is-channel && item.own ? 1px : 0px;
|
|
border-color: Theme.accent;
|
|
accessible-role: AccessibleRole.list-item;
|
|
accessible-label: !item.is-channel ? item.name : root.separator ? @tr("Separator") : @tr("Channel {}", item.name);
|
|
accessible-description: (item.talking ? @tr("talking") + " " : "") + (item.streaming ? @tr("streaming") + " " : "") + (item.muted ? @tr("microphone off") + " " : "") + (item.local-muted ? @tr("muted for you") : "");
|
|
accessible-action-default => {
|
|
if item.is-channel {
|
|
Bridge.open-channel-chat(item.id);
|
|
} else {
|
|
client-clicked(item.id);
|
|
}
|
|
}
|
|
// Artwork is clipped behind the same compact row as its title.
|
|
if item.is-channel && item.banner.width > 0: BannerPicture {
|
|
x: root.indent;
|
|
width: max(0px, root.width - root.indent);
|
|
y: 0;
|
|
source: item.banner;
|
|
}
|
|
// The artwork covers the row's own background: tint it as that would
|
|
// be for our channel and on hover, translucent so the picture shows.
|
|
if item.is-channel && item.banner.width > 0 && (item.own || area.has-hover): Rectangle {
|
|
x: root.indent;
|
|
width: max(0px, root.width - root.indent);
|
|
border-radius: root.border-radius;
|
|
background: item.own ? Theme.accent-soft.transparentize(0.35) : Theme.surface-3.transparentize(0.5);
|
|
}
|
|
area := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
double-clicked => {
|
|
if item.is-channel {
|
|
Bridge.join-channel(item.id);
|
|
}
|
|
}
|
|
clicked => {
|
|
if item.is-channel {
|
|
Bridge.open-channel-chat(item.id);
|
|
} else if !item.myself {
|
|
client-clicked(item.id);
|
|
}
|
|
}
|
|
}
|
|
if item.is-channel: HorizontalLayout {
|
|
height: 34px * Theme.font-scale;
|
|
padding-left: Theme.space-2 + root.indent;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-2;
|
|
// Spacers have no icon; a centred one is balanced against the
|
|
// chevron.
|
|
if item.spacer == 2: Rectangle { width: 18px; }
|
|
if item.spacer == 0 && item.icon.width > 0: RowIcon {
|
|
source: item.icon;
|
|
}
|
|
if item.spacer == 0 && item.icon.width == 0: Icon {
|
|
source: item.locked ? Icons.lock : Icons.channel;
|
|
size: 18px;
|
|
tint: item.banner.width > 0 || item.own ? Theme.text : Theme.icon;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: item.name;
|
|
horizontal-alignment: item.spacer == 2 ? center : item.spacer == 3 ? right : left;
|
|
// Full contrast over a banner.
|
|
color: item.own || item.banner.width > 0 ? Theme.text : Theme.text-secondary;
|
|
font-weight: item.own || item.banner.width > 0 ? Theme.weight-semibold : Theme.weight-medium;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 1;
|
|
// A line is cut where the row ends; it must not widen the list.
|
|
overflow: item.spacer == 4 ? clip : elide;
|
|
min-width: 0px;
|
|
}
|
|
// At the end where the start shows the channel's icon, or nothing
|
|
// (a spacer).
|
|
if item.locked && (item.icon.width > 0 || item.spacer != 0): Icon {
|
|
source: Icons.lock;
|
|
size: 14px;
|
|
tint: item.banner.width > 0 ? Theme.text : Theme.icon;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
if item.spacer == 0 && (item.members > 0 || item.max-members >= 0): HorizontalLayout {
|
|
spacing: 3px;
|
|
if item.own: Icon {
|
|
source: Icons.users;
|
|
size: 14px;
|
|
tint: Theme.text-secondary;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
Text {
|
|
text: item.max-members >= 0 ? item.members + "/" + item.max-members : item.members;
|
|
color: item.own || item.banner.width > 0 ? Theme.text : Theme.text-muted;
|
|
font-size: Theme.font-sm;
|
|
vertical-alignment: center;
|
|
}
|
|
}
|
|
Rectangle {
|
|
width: 18px;
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: item.collapsed ? @tr("Expand") : @tr("Collapse");
|
|
accessible-action-default => { Bridge.toggle-collapse(item.id); }
|
|
Icon {
|
|
source: item.collapsed ? Icons.chevron-right : Icons.chevron-down;
|
|
size: 14px;
|
|
tint: item.banner.width > 0 ? Theme.text : Theme.text-muted;
|
|
y: (parent.height - self.height) / 2;
|
|
}
|
|
TouchArea {
|
|
clicked => { Bridge.toggle-collapse(item.id); }
|
|
}
|
|
}
|
|
}
|
|
if !item.is-channel: HorizontalLayout {
|
|
padding-left: Theme.space-2 + root.indent + 12px;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
VerticalLayout {
|
|
alignment: center;
|
|
Avatar {
|
|
size: 22px;
|
|
initials: item.initials;
|
|
tint: item.tint;
|
|
image: item.avatar;
|
|
speaking: item.talking;
|
|
label: item.name;
|
|
}
|
|
}
|
|
// The name elides first; its badges follow it, then the free room.
|
|
Text {
|
|
text: item.name;
|
|
color: item.away ? Theme.text-muted : item.myself ? Theme.accent-text : Theme.text-secondary;
|
|
font-weight: item.myself ? Theme.weight-semibold : Theme.weight-regular;
|
|
vertical-alignment: center;
|
|
horizontal-stretch: 0;
|
|
overflow: elide;
|
|
}
|
|
BadgeIcons {
|
|
horizontal-stretch: 1;
|
|
alignment: start;
|
|
first: item.badge;
|
|
second: item.badge-2;
|
|
third: item.badge-3;
|
|
}
|
|
if item.talking: VerticalLayout {
|
|
alignment: center;
|
|
SpeakingBars { }
|
|
}
|
|
// A click on someone's LIVE mark watches their stream.
|
|
if item.streaming: VerticalLayout {
|
|
alignment: center;
|
|
LiveBadge {
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: item.myself ? @tr("Your stream") : @tr("Watch {}'s stream", item.name);
|
|
accessible-action-default => {
|
|
if !item.myself {
|
|
Bridge.watch-client(item.id);
|
|
}
|
|
}
|
|
TouchArea {
|
|
mouse-cursor: item.myself ? MouseCursor.default : MouseCursor.pointer;
|
|
clicked => {
|
|
if !item.myself {
|
|
Bridge.watch-client(item.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if item.local-muted: Icon {
|
|
source: Icons.volume-x;
|
|
size: 14px;
|
|
tint: Theme.warning;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("muted for you");
|
|
}
|
|
if !item.local-muted && item.local-volume != 100: Text {
|
|
text: @tr("{}%", item.local-volume);
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-xs;
|
|
vertical-alignment: center;
|
|
}
|
|
if item.muted: Icon {
|
|
source: Icons.mic-off;
|
|
size: 14px;
|
|
tint: Theme.danger;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("mic off");
|
|
}
|
|
if item.sound-off: Icon {
|
|
source: Icons.headphone-off;
|
|
size: 14px;
|
|
tint: Theme.danger;
|
|
y: (parent.height - self.height) / 2;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: @tr("sound off");
|
|
}
|
|
if item.away: Text {
|
|
text: @tr("away");
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-xs;
|
|
vertical-alignment: center;
|
|
}
|
|
// Group and client icons.
|
|
if item.icon.width > 0: RowIcon {
|
|
source: item.icon;
|
|
}
|
|
if item.icon-2.width > 0: RowIcon {
|
|
source: item.icon-2;
|
|
}
|
|
if item.icon-3.width > 0: RowIcon {
|
|
source: item.icon-3;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Channels and the clients in them. Click a channel for its chat,
|
|
// double-click to join; click a client for its volume.
|
|
export component ChannelTree inherits VerticalLayout {
|
|
spacing: Theme.space-2;
|
|
SectionHeader {
|
|
text: @tr("Channels");
|
|
icon: Icons.channel;
|
|
small: true;
|
|
}
|
|
if Bridge.tree.length == 0: Text {
|
|
text: Bridge.current-server < 0 ? @tr("No server yet.") : Bridge.observing ? @tr("Loading the channels…") : @tr("Connect to see the channels.");
|
|
color: Theme.text-muted;
|
|
font-size: Theme.font-sm;
|
|
wrap: word-wrap;
|
|
}
|
|
ListView {
|
|
vertical-stretch: 1;
|
|
accessible-role: AccessibleRole.list;
|
|
accessible-label: @tr("Channels and clients");
|
|
for row in Bridge.tree: TreeRow {
|
|
item: row;
|
|
client-clicked(id) => { Nav.open-client(id); }
|
|
}
|
|
}
|
|
}
|