The single 1700-line app.slint becomes a design system and screens that later waves can compose: - theme.slint: colour, radius, spacing and type tokens (dark and light, a runtime font scale); icons.slint: Lucide icons as tintable images. - components/: Button, IconButton, TextField, SearchBox, Select, Toggle, Slider, SegmentedTabs, Avatar, badges, Card, Meter, NavItem, ListItem, PopupMenu, Tooltip, Modal, Toast, ResizeHandle, Spinner, RichText and the EmojiPicker. - shells/: the desktop frame (server rail, top bar, sidebar with the user card) and the phone frame with a bottom navigation, switched at a breakpoint from the settings. - screens/: today's screens re-skinned (channels, chat, streams panel and viewer, settings page, home, dialogs, phone pages); all callbacks and properties keep their behaviour. Navigation state is the Nav global. On the Rust side app.rs keeps setup and event glue; servers.rs, chat.rs, settings_page.rs and appearance.rs hold the logic, vm/ the pure view models, bind/ the callbacks, dev.rs the development switches. Models are created once and updated row by row (vm::list::sync); each chat tab owns its lines model, so a message appends one row. Emoji come from the bundled Twemoji archive through a size-bounded image cache, split into runs that wrap with the text. New settings ui.theme, ui.font_scale, ui.narrow_breakpoint and ui.image_cache_mb apply live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
151 lines
5.3 KiB
Plaintext
151 lines
5.3 KiB
Plaintext
// Emoji as images (Twemoji through Rust's image cache): chat text with
|
|
// inline emoji, and the picker.
|
|
|
|
import { Theme } from "../theme.slint";
|
|
import { Icons } from "../icons.slint";
|
|
import { Images, Emoji, TextRun, EmojiCell } from "../bridge.slint";
|
|
import { Icon } from "icon.slint";
|
|
import { SearchBox } from "text-field.slint";
|
|
import { ListView } from "std-widgets.slint";
|
|
|
|
// Text with inline emoji: the runs flow and wrap like text (a flexbox of
|
|
// words and emoji). Plain text needs no runs: use a Text then (faster).
|
|
export component RichText inherits FlexboxLayout {
|
|
in property <[TextRun]> runs;
|
|
in property <length> font-size: Theme.font-body;
|
|
in property <color> color: Theme.text;
|
|
in property <length> emoji-size: font-size * 1.4;
|
|
spacing: 0px;
|
|
cross-axis-alignment: center;
|
|
for run in root.runs: HorizontalLayout {
|
|
if run.emoji == "": Text {
|
|
text: run.text;
|
|
font-size: root.font-size;
|
|
color: root.color;
|
|
accessible-role: AccessibleRole.none;
|
|
}
|
|
if run.emoji != "": Image {
|
|
width: root.emoji-size;
|
|
height: root.emoji-size;
|
|
source: Images.emoji(run.emoji);
|
|
image-fit: contain;
|
|
accessible-role: AccessibleRole.image;
|
|
accessible-label: run.text;
|
|
}
|
|
}
|
|
}
|
|
|
|
// One emoji of the picker grid.
|
|
component EmojiButton inherits Rectangle {
|
|
in property <EmojiCell> cell;
|
|
in property <length> size: 36px;
|
|
callback picked(EmojiCell);
|
|
width: size;
|
|
height: size;
|
|
border-radius: Theme.radius-sm;
|
|
background: touch.has-hover ? Theme.surface-4 : transparent;
|
|
accessible-role: AccessibleRole.button;
|
|
accessible-label: cell.name;
|
|
accessible-action-default => { picked(cell); }
|
|
touch := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => { root.picked(root.cell); }
|
|
}
|
|
Image {
|
|
width: root.size - 10px;
|
|
height: root.size - 10px;
|
|
source: Images.emoji(root.cell.key);
|
|
image-fit: contain;
|
|
}
|
|
}
|
|
|
|
// The emoji picker: search, categories, a scrolling grid (only the visible
|
|
// rows are built). Rust fills `Emoji.rows` for the category or search.
|
|
export component EmojiPicker inherits Rectangle {
|
|
callback picked(EmojiCell);
|
|
callback close();
|
|
property <[image]> category-icons: [
|
|
Icons.smile, Icons.hand, Icons.leaf, Icons.coffee, Icons.gamepad-2,
|
|
Icons.plane, Icons.lightbulb, Icons.heart, Icons.flag,
|
|
];
|
|
property <[string]> category-names: [
|
|
@tr("Smileys"), @tr("People"), @tr("Nature"), @tr("Food"), @tr("Activities"),
|
|
@tr("Travel"), @tr("Objects"), @tr("Symbols"), @tr("Flags"),
|
|
];
|
|
property <length> cell: 36px;
|
|
property <string> hovered;
|
|
|
|
init => { Emoji.load(); }
|
|
|
|
width: Emoji.columns * cell + 2 * Theme.space-3 + 14px;
|
|
height: 400px;
|
|
border-radius: Theme.radius-lg;
|
|
background: Theme.surface;
|
|
border-width: 1px;
|
|
border-color: Theme.border-strong;
|
|
accessible-role: AccessibleRole.groupbox;
|
|
accessible-label: @tr("Emoji");
|
|
FocusScope {
|
|
key-pressed(event) => {
|
|
if event.text == Key.Escape {
|
|
root.close();
|
|
return accept;
|
|
}
|
|
reject
|
|
}
|
|
}
|
|
VerticalLayout {
|
|
padding: Theme.space-3;
|
|
spacing: Theme.space-3;
|
|
search := SearchBox {
|
|
placeholder: @tr("Search emoji");
|
|
show-shortcut: false;
|
|
edited(text) => { Emoji.search(text); }
|
|
}
|
|
HorizontalLayout {
|
|
spacing: 2px;
|
|
for icon[i] in root.category-icons: Rectangle {
|
|
height: 30px;
|
|
horizontal-stretch: 1;
|
|
border-radius: Theme.radius-sm;
|
|
background: Emoji.category == i ? Theme.accent-soft : cat.has-hover ? Theme.surface-3 : transparent;
|
|
accessible-role: AccessibleRole.tab;
|
|
accessible-label: root.category-names[i];
|
|
accessible-item-selectable: true;
|
|
accessible-item-selected: Emoji.category == i;
|
|
accessible-action-default => { Emoji.show-category(i); }
|
|
cat := TouchArea {
|
|
mouse-cursor: MouseCursor.pointer;
|
|
clicked => {
|
|
search.clear();
|
|
Emoji.show-category(i);
|
|
}
|
|
}
|
|
Icon {
|
|
source: icon;
|
|
size: Theme.icon-sm;
|
|
tint: Emoji.category == i ? Theme.accent-text : Theme.icon;
|
|
}
|
|
}
|
|
}
|
|
Text {
|
|
text: Emoji.category >= 0 ? root.category-names[Emoji.category] : Emoji.rows.length == 0 ? @tr("No emoji found") : @tr("Search results");
|
|
font-size: Theme.font-sm;
|
|
color: Theme.text-muted;
|
|
font-weight: Theme.weight-semibold;
|
|
}
|
|
ListView {
|
|
vertical-stretch: 1;
|
|
for row in Emoji.rows: HorizontalLayout {
|
|
height: root.cell;
|
|
alignment: start;
|
|
for cell in row.cells: EmojiButton {
|
|
cell: cell;
|
|
size: root.cell;
|
|
picked(c) => { root.picked(c); }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|