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>
113 lines
3.2 KiB
Rust
113 lines
3.2 KiB
Rust
//! The bar at the top of the window: the page's title, the search box and the
|
|
//! settings button (`TopBar` of `ui/shells/desktop.slint`; the bell comes
|
|
//! with the notifications). The search and the settings are affordances until
|
|
//! their slices: a click is logged ([`OpenSearch`], [`OpenSettings`]).
|
|
|
|
use gpui_kit::{
|
|
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
|
StatefulInteractiveElement as _, Styled as _, Subscription, Window, div, px,
|
|
};
|
|
|
|
use super::actions::{OpenSearch, OpenSettings};
|
|
use super::widgets::{IconButton, icon};
|
|
use crate::app::AppState;
|
|
use crate::theme::{VoelinTheme, hsla};
|
|
|
|
/// The page title: the server on screen, else the app's name.
|
|
pub fn title(app: &AppState) -> String {
|
|
match app.current_bookmark() {
|
|
Some(bookmark) => bookmark.name.clone(),
|
|
None => voelin_platform::APP_NAME.to_owned(),
|
|
}
|
|
}
|
|
|
|
/// The top bar.
|
|
pub struct TopBar {
|
|
title: String,
|
|
_subscription: Subscription,
|
|
}
|
|
|
|
impl TopBar {
|
|
/// A top bar that follows `app`.
|
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
|
let shown = title(app.read(cx));
|
|
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
|
let shown = title(app.read(cx));
|
|
if shown != this.title {
|
|
this.title = shown;
|
|
cx.notify();
|
|
}
|
|
});
|
|
Self { title: shown, _subscription: subscription }
|
|
}
|
|
|
|
/// The title it shows now.
|
|
pub fn title(&self) -> &str {
|
|
&self.title
|
|
}
|
|
}
|
|
|
|
impl Render for TopBar {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
let theme = VoelinTheme::global(cx).clone();
|
|
let (c, m) = (&theme.colors, &theme.metrics);
|
|
div()
|
|
.id("topbar")
|
|
.w_full()
|
|
.h(px(m.topbar_height))
|
|
.flex_none()
|
|
.flex()
|
|
.flex_row()
|
|
.items_center()
|
|
// The main panel starts where the sidebar and the gaps around it end.
|
|
.pl(px(m.sidebar_width + 2.0 * m.space_3))
|
|
.pr(px(m.space_4))
|
|
.gap(px(m.space_4))
|
|
.child(
|
|
div()
|
|
.id("topbar-title")
|
|
.max_w(px(280.0 * m.font_scale.max(1.0)))
|
|
.flex_none()
|
|
.truncate()
|
|
.text_size(px(m.font_lg))
|
|
.font_weight(FontWeight::SEMIBOLD)
|
|
.text_color(hsla(c.text))
|
|
.child(self.title.clone()),
|
|
)
|
|
.child(
|
|
div().flex_1().min_w_0().flex().justify_center().child(
|
|
div()
|
|
.id("topbar-search")
|
|
.w_full()
|
|
.max_w(px(680.0))
|
|
.h(px(m.control_height))
|
|
.px(px(m.space_3))
|
|
.flex()
|
|
.flex_row()
|
|
.items_center()
|
|
.gap(px(m.space_3))
|
|
.rounded(px(m.radius_md))
|
|
.border_1()
|
|
.border_color(hsla(c.border))
|
|
.bg(hsla(c.surface_2))
|
|
.cursor_text()
|
|
.hover(|style| style.border_color(hsla(c.border_strong)))
|
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(OpenSearch), cx))
|
|
.child(icon("search", m.icon_sm, c.text_muted))
|
|
.child(
|
|
div()
|
|
.flex_1()
|
|
.truncate()
|
|
.text_size(px(m.font_body))
|
|
.text_color(hsla(c.text_muted))
|
|
.child("Search servers, channels, people or settings…"),
|
|
),
|
|
),
|
|
)
|
|
.child(
|
|
IconButton::new("topbar-settings", "settings", "Settings")
|
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(OpenSettings), cx)),
|
|
)
|
|
}
|
|
}
|