Slice 1 of plan section 6 step 3 (docs/ui.md, "The GPUI front end"). The window
is the shell of ui/shells/desktop.slint, as entities that observe the root
state and tell the window only when what they show changed (they compare their
view of the state, so an engine event about a talker, a tick or a setting that
is not the theme's draws nothing):
- shell/rail.rs: the saved servers as avatars with their tints, initials,
presence dots, unread and live marks, the selection pill and ring, the plus
that adds a server and the settings button; a second click edits a server,
as the Slint rail's double click does.
- shell/sidebar.rs: the server on screen with its stats, the place of the
channel tree (slice 2), the voice card (disconnect, copy an invite, hold to
talk) while voice is connecting or connected, and the user card with the
microphone and sound buttons.
- shell/topbar.rs: the page's title, the search box and the settings button;
the last two are logged until their slices exist.
- shell/main_panel.rs: "No server selected" with the way to add one, or the
server on screen with Connect, Disconnect and Edit.
- shell/form.rs: the server form (address, name, nickname, password; Save,
Save and connect, Cancel, and a Remove that asks twice) in the place of the
main area until the dialogs slice.
- shell/toast.rs: the status line as a toast for a few seconds.
The eleven callbacks of bind/servers.rs that the shell has are GPUI actions
(shell/actions.rs: select, connect, disconnect, mute the microphone, mute the
sound, push to talk, edit, save, save and connect, delete, invite): a click
dispatches one, the window's root view handles it by asking the root state.
The window takes its title from the server on screen ("Voelin - Nightfall"),
keeps a focus of its own so that actions always find their handlers, tells the
root state where it is (ui.window), and opens where it was left (the size
always; the position where a screen still shows it and the window manager
honours one). The logo is served by the assets.
scripts/gpui-shot.sh finds the window by its title's prefix now that the title
follows the server.
Tests on GPUI's test platform draw the window and click it: a server added
appears in the rail, a click selects it and titles the window, a connect
reaches the engine, an engine event updates the rail and the cards, the form
adds, edits and removes, the toast goes, the window's place round-trips, an
idle window is not told, the sample servers fill the shell.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
86 lines
2.9 KiB
Rust
86 lines
2.9 KiB
Rust
//! What `svg()` and gpui-component's `Icon` load by path. The client's own
|
|
//! Lucide 1.48 icons (the 147 SVGs of the Slint front end, embedded by
|
|
//! `build.rs`) answer `icons/<name>.svg` first, so every widget draws the
|
|
//! icons the client draws; anything else (the rest of gpui-kit-assets'
|
|
//! Lucide 1.43 catalogue, which gpui-component's `IconName` names) comes from
|
|
//! gpui-kit-assets.
|
|
|
|
use std::borrow::Cow;
|
|
|
|
use gpui_kit::{AssetSource, Result, SharedString};
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/icons.rs"));
|
|
|
|
/// The client's icons first, then gpui-kit-assets'.
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
pub struct Assets;
|
|
|
|
/// The client's icon of a file name (`mic.svg`), if it has one.
|
|
pub fn client_icon(name: &str) -> Option<&'static [u8]> {
|
|
ICONS.binary_search_by_key(&name, |(n, _)| n).ok().map(|i| ICONS[i].1)
|
|
}
|
|
|
|
/// The names of the client's icons, sorted.
|
|
pub fn client_icon_names() -> impl Iterator<Item = &'static str> {
|
|
ICONS.iter().map(|(name, _)| *name)
|
|
}
|
|
|
|
/// The app's mark, the Slint front end's `logo.svg`.
|
|
const LOGO: &[u8] = include_bytes!("../../voelin-ui/ui/assets/logo.svg");
|
|
|
|
impl AssetSource for Assets {
|
|
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
|
|
if let Some(bytes) = path.strip_prefix("icons/").and_then(client_icon) {
|
|
return Ok(Some(Cow::Borrowed(bytes)));
|
|
}
|
|
if path == "logo.svg" {
|
|
return Ok(Some(Cow::Borrowed(LOGO)));
|
|
}
|
|
gpui_kit::assets::AllAssets.load(path)
|
|
}
|
|
|
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
|
gpui_kit::assets::AllAssets.list(path)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn the_client_set_is_embedded_and_sorted() {
|
|
assert!(ICONS.len() >= 140, "{} icons", ICONS.len());
|
|
assert!(ICONS.windows(2).all(|pair| pair[0].0 < pair[1].0));
|
|
for (name, bytes) in ICONS {
|
|
assert!(std::str::from_utf8(bytes).is_ok_and(|text| text.contains("<svg")), "{name}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_client_icon_answers_before_gpui_kit_assets() {
|
|
let name = client_icon_names().find(|n| *n == "mic.svg").expect("the client has a mic");
|
|
let ours = client_icon(name).unwrap();
|
|
let kit = gpui_kit::assets::AllAssets
|
|
.load(&format!("icons/{name}"))
|
|
.unwrap()
|
|
.expect("gpui-kit-assets has a mic too");
|
|
let served = Assets.load(&format!("icons/{name}")).unwrap().unwrap();
|
|
assert_eq!(&*served, ours);
|
|
assert_ne!(&*kit, ours, "Lucide 1.43 and 1.48 draw it differently, or this test is moot");
|
|
}
|
|
|
|
#[test]
|
|
fn other_icons_and_other_paths_fall_through_to_gpui_kit_assets() {
|
|
let kit = gpui_kit::assets::AllAssets.list("icons/").unwrap();
|
|
let only_in_kit = kit
|
|
.iter()
|
|
.find(|path| client_icon(path.trim_start_matches("icons/")).is_none())
|
|
.expect("the catalogue has icons the client lacks");
|
|
assert!(Assets.load(only_in_kit).unwrap().is_some(), "{only_in_kit}");
|
|
// gpui-kit-assets answers a path it does not have with an error, so do we.
|
|
assert!(Assets.load("icons/no-such-icon.svg").is_err());
|
|
assert!(Assets.load("nothing/here").is_err());
|
|
}
|
|
}
|