Files
VoelinClient/crates/voelin-ui/ui/screens/drawers.slint
T
Claude 531334d826 ui: BBCode in chat, and the welcome message as the server chat's first line
Other clients format chat with BBCode, and it showed as raw tags; only
file links were taken out. One parser, vm/bbcode.rs, now reads every
message into a Doc of blocks (lines, quotes, code, list items, rules) of
styled spans, which the chat draws with one MessageText (also in the
pins drawer and the studio's chat), and which previews, notifications
and the home's news show on one line. Only known tags are read, so
relay prefixes such as [Nova] stay. Emoji are split per span, so a
message with emoji keeps its line breaks. [img] pictures on the web
come through the engine's picture cache (Command::FetchPicture), within
ui.image_preview_kb and only with cache.fetch_images; otherwise they
stay links. Built lines are kept per message and revision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
2026-10-07 00:56:14 +00:00

373 lines
12 KiB
Plaintext

// The pinned messages and the topics (threads) of the current chat. They
// take the place of the members panel; both need a gateway, and the chat
// header hides their buttons when the gateway does not offer them.
import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint";
import { Bridge, PinItem, TopicItem, Images } from "../bridge.slint";
import { Nav } from "../nav.slint";
import { Icon, IconButton, Button, ButtonKind, TextField, SearchBox, Avatar, MessageText, Spinner, Modal, ListView } from "../components/index.slint";
import { Reactions } from "chat.slint";
// The title row both drawers share, above their content (@children).
component Drawer inherits VerticalLayout {
in property <string> title;
in property <image> icon;
callback closed();
padding-top: Theme.space-4;
spacing: Theme.space-3;
accessible-role: AccessibleRole.groupbox;
accessible-label: title;
HorizontalLayout {
padding-left: Theme.space-5;
padding-right: Theme.space-3;
spacing: Theme.space-3;
if root.icon.width > 0: Icon {
source: root.icon;
size: Theme.icon-md;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
Text {
text: root.title;
color: Theme.text;
font-size: Theme.font-lg;
font-weight: Theme.weight-semibold;
vertical-alignment: center;
horizontal-stretch: 1;
overflow: elide;
}
IconButton {
icon: Icons.x;
label: @tr("Close");
size: 32px;
icon-size: Theme.icon-md;
y: (parent.height - self.height) / 2;
clicked => { root.closed(); }
}
}
@children
}
// A pinned message as a card: who and when, the pin (unpin), the text and
// its reactions. Clicking the card jumps to the message in the chat.
component PinCard inherits Rectangle {
in property <PinItem> pin;
min-height: body.preferred-height;
border-radius: Theme.radius-lg;
background: area.has-hover ? Theme.surface-3 : Theme.surface-2;
border-width: 1px;
border-color: Theme.border-strong;
accessible-role: AccessibleRole.list-item;
accessible-label: pin.line.author + ": " + pin.line.text;
accessible-description: pin.by;
accessible-action-default => {
Bridge.jump-to-pin(pin.line.key);
Nav.pins-open = false;
}
area := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
Bridge.jump-to-pin(pin.line.key);
Nav.pins-open = false;
}
}
body := VerticalLayout {
padding: Theme.space-4;
padding-right: Theme.space-3;
spacing: Theme.space-2;
HorizontalLayout {
spacing: Theme.space-3;
Avatar {
size: 28px;
initials: pin.line.initials;
tint: pin.line.tint;
image: pin.line.avatar;
label: pin.line.author;
y: (parent.height - self.height) / 2;
}
Text {
text: pin.line.author;
color: Theme.name-text;
font-size: Theme.font-md;
font-weight: Theme.weight-medium;
vertical-alignment: center;
overflow: elide;
}
Text {
text: pin.line.time;
color: Theme.text-muted;
font-size: Theme.font-sm;
vertical-alignment: center;
horizontal-stretch: 1;
overflow: elide;
}
IconButton {
icon: Icons.pin;
label: @tr("Unpin");
tint: Theme.accent-text;
size: 28px;
icon-size: Theme.icon-sm;
y: (parent.height - self.height) / 2;
clicked => { Bridge.pin(pin.line.key, false); }
}
}
MessageText {
line: pin.line;
jumbo-size: Theme.font-body * 1.4;
}
for file in pin.line.files: HorizontalLayout {
spacing: Theme.space-2;
Icon {
source: file.picture ? Icons.image : Icons.file-text;
size: Theme.icon-sm;
tint: Theme.accent-text;
y: (parent.height - self.height) / 2;
}
Text {
text: file.name;
color: Theme.accent-text;
font-size: Theme.font-sm;
vertical-alignment: center;
overflow: elide;
}
}
if pin.line.reactions.length > 0: VerticalLayout {
padding-top: Theme.space-2;
Reactions {
key: pin.line.key;
model: pin.line.reactions;
}
}
Text {
text: pin.by;
color: Theme.text-muted;
font-size: Theme.font-xs;
overflow: elide;
}
}
}
// The pinned messages of the current chat.
export component PinsDrawer inherits Drawer {
title: @tr("Pinned Messages");
icon: Icons.pin;
closed => { Nav.pins-open = false; }
if Bridge.pins-loading: HorizontalLayout {
padding: Theme.space-6;
alignment: center;
Spinner { size: 20px; }
}
if !Bridge.pins-loading && Bridge.pins.length == 0: VerticalLayout {
padding: Theme.space-6;
spacing: Theme.space-2;
Text {
text: @tr("Nothing pinned yet.");
color: Theme.text-secondary;
font-weight: Theme.weight-medium;
horizontal-alignment: center;
}
Text {
text: @tr("Hover a message and press the pin.");
color: Theme.text-muted;
font-size: Theme.font-sm;
horizontal-alignment: center;
wrap: word-wrap;
}
}
ListView {
vertical-stretch: 1;
accessible-label: @tr("Pinned messages");
for pin in Bridge.pins: VerticalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-3;
padding-bottom: Theme.space-3;
PinCard {
pin: pin;
}
}
}
}
// A topic: its icon, title, what is in it and when it was last active.
component TopicCard inherits Rectangle {
in property <TopicItem> topic;
min-height: body.preferred-height;
border-radius: Theme.radius-lg;
background: Bridge.current-topic == topic.id ? Theme.accent-soft : area.has-hover ? Theme.surface-3 : Theme.surface-2;
border-width: 1px;
border-color: Bridge.current-topic == topic.id ? Theme.accent : Theme.border-strong;
accessible-role: AccessibleRole.list-item;
accessible-label: topic.title;
accessible-description: topic.detail;
accessible-action-default => {
Bridge.open-topic(topic.id);
Nav.topics-open = false;
}
area := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
Bridge.open-topic(topic.id);
Nav.topics-open = false;
}
}
body := HorizontalLayout {
padding: Theme.space-4;
spacing: Theme.space-4;
VerticalLayout {
alignment: start;
Rectangle {
width: 40px;
height: 40px;
border-radius: Theme.radius-md;
background: Theme.surface-4;
Icon {
source: topic.archived ? Icons.bookmark : Icons.messages-square;
size: 22px;
tint: topic.archived ? Theme.text-muted : Theme.text-secondary;
}
}
}
VerticalLayout {
horizontal-stretch: 1;
spacing: Theme.space-1;
Text {
text: topic.title;
color: Theme.text;
font-size: Theme.font-md;
font-weight: Theme.weight-medium;
overflow: elide;
}
Text {
text: topic.detail;
color: Theme.text-secondary;
font-size: Theme.font-sm;
overflow: elide;
}
HorizontalLayout {
spacing: Theme.space-2;
padding-top: Theme.space-1;
Rectangle {
width: 7px;
height: 7px;
y: (parent.height - self.height) / 2;
border-radius: 3.5px;
background: topic.recent ? Theme.success : Theme.offline;
}
Text {
text: topic.activity;
color: Theme.text-muted;
font-size: Theme.font-sm;
overflow: elide;
}
}
}
}
}
// The topics (threads) of the current chat: search, open, create.
export component TopicsDrawer inherits Drawer {
title: @tr("Topics");
closed => { Nav.topics-open = false; }
HorizontalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-3;
SearchBox {
height: 40px;
show-shortcut: false;
placeholder: @tr("Search topics…");
label: @tr("Search topics");
edited(text) => { Bridge.search-topics(text); }
}
}
if Bridge.topics-loading: HorizontalLayout {
padding: Theme.space-6;
alignment: center;
Spinner { size: 20px; }
}
if !Bridge.topics-loading && Bridge.topics.length == 0: VerticalLayout {
padding: Theme.space-6;
spacing: Theme.space-2;
Text {
text: @tr("No topics yet.");
color: Theme.text-secondary;
font-weight: Theme.weight-medium;
horizontal-alignment: center;
}
Text {
text: @tr("Start one from a message, or below.");
color: Theme.text-muted;
font-size: Theme.font-sm;
horizontal-alignment: center;
wrap: word-wrap;
}
}
ListView {
vertical-stretch: 1;
accessible-label: @tr("Topics");
for topic in Bridge.topics: VerticalLayout {
padding-left: Theme.space-3;
padding-right: Theme.space-3;
padding-bottom: Theme.space-3;
TopicCard {
topic: topic;
}
}
}
HorizontalLayout {
padding: Theme.space-3;
padding-bottom: Theme.space-4;
Button {
horizontal-stretch: 1;
kind: ButtonKind.primary;
icon: Icons.plus;
text: @tr("Create Topic");
clicked => { Nav.start-topic(-1); }
}
}
}
// Asking for a topic's title (from a message, or standalone).
export component TopicDialog inherits Modal {
title: @tr("Start a topic");
subtitle: Nav.topic-form-key > 0 ? @tr("From the chosen message.") : @tr("A new thread in this chat.");
icon: Icons.messages-square;
card-width: 460px;
card-height: 260px;
callback done();
dismissed => { root.done(); }
VerticalLayout {
spacing: Theme.space-4;
field := TextField {
text <=> Nav.topic-form-title;
placeholder: @tr("What is it about?");
label: @tr("Title");
accepted(text) => {
if text != "" {
Bridge.create-topic(Nav.topic-form-key, text);
root.done();
}
}
}
Rectangle { vertical-stretch: 1; }
HorizontalLayout {
spacing: Theme.space-3;
alignment: end;
Button {
text: @tr("Cancel");
clicked => { root.done(); }
}
Button {
kind: ButtonKind.primary;
icon: Icons.check;
text: @tr("Create");
enabled: field.text != "";
clicked => {
Bridge.create-topic(Nav.topic-form-key, field.text);
root.done();
}
}
}
}
}