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
57 lines
2.0 KiB
Rust
57 lines
2.0 KiB
Rust
//! Appearance settings (`ui.theme`, `ui.font_scale`, `ui.narrow_breakpoint`,
|
|
//! `ui.image_cache_mb`): applied to the Theme and Nav globals and the image
|
|
//! cache whenever they change, from the settings page or elsewhere.
|
|
|
|
use slint::ComponentHandle;
|
|
use tracing::warn;
|
|
|
|
use crate::app::{App, AppearanceForm, Bridge, Nav, Theme};
|
|
use crate::images;
|
|
use crate::settings::{
|
|
ThemeChoice, UI_FONT_SCALE, UI_IMAGE_CACHE_MB, UI_NARROW_BREAKPOINT, UI_THEME,
|
|
};
|
|
|
|
impl App {
|
|
/// Show the current values of the appearance keys.
|
|
pub(crate) fn apply_appearance(&self) {
|
|
let theme = self.prefs.get(&UI_THEME);
|
|
let scale = self.prefs.get(&UI_FONT_SCALE);
|
|
let breakpoint = self.prefs.get(&UI_NARROW_BREAKPOINT);
|
|
let cache_mb = self.prefs.get(&UI_IMAGE_CACHE_MB);
|
|
images::set_budget_mb(cache_mb);
|
|
let Some(ui) = self.ui.upgrade() else { return };
|
|
let t = ui.global::<Theme>();
|
|
t.set_mode(theme.as_str().into());
|
|
t.set_font_scale(scale);
|
|
ui.global::<Nav>().set_narrow_breakpoint(breakpoint as f32);
|
|
let bridge = ui.global::<Bridge>();
|
|
bridge.set_appearance(AppearanceForm {
|
|
theme: theme.as_str().into(),
|
|
font_scale: scale,
|
|
narrow_breakpoint: breakpoint as f32,
|
|
image_cache_mb: cache_mb as f32,
|
|
});
|
|
bridge.set_image_cache_usage(images::usage_text().into());
|
|
}
|
|
|
|
/// The settings page changed the form: store the keys (they apply
|
|
/// through the change events).
|
|
pub(crate) fn appearance_changed(&mut self, form: &AppearanceForm) {
|
|
let results = [
|
|
self.prefs.set(&UI_THEME, ThemeChoice::parse(&form.theme)),
|
|
self.prefs.set(&UI_FONT_SCALE, form.font_scale),
|
|
self.prefs.set(&UI_NARROW_BREAKPOINT, form.narrow_breakpoint.max(0.0).round() as u32),
|
|
self.prefs.set(&UI_IMAGE_CACHE_MB, form.image_cache_mb.max(0.0).round() as u32),
|
|
];
|
|
for result in results {
|
|
if let Err(e) = result {
|
|
warn!(%e, "appearance setting rejected");
|
|
self.set_status(e.to_string());
|
|
}
|
|
}
|
|
// Applied now too: change events come through the engine, which
|
|
// may not run the settings service (tests, a hosted engine).
|
|
self.apply_appearance();
|
|
}
|
|
}
|