Slice 3 of plan section 6 step 3, first part. VoicePage is a cached pane of its own, a sibling of the server page that MainView puts in the main area while the page is asked for (show_voice_view, through voelin-ui-vm's logic) and voice is connected, as the Slint VoiceView is. It shows the channel (name, topic, banner under the surface veil, "N in voice / limit total"), the people of our channel as TreeView::members gives them through the tree model's Voice event (the ring that is green while they talk and blue while they stream, the bars or the microphone and sound marks in the corner, the crown, "Speaking", "Streaming", "Away"; a click opens the card), and the call bar: mute, deafen, Share and the voice settings (both logged until their slices), Leave. The smaller stage, one row of small avatars, is ui.voice_compact and always in a window under 800 pixels tall, which MainView pushes into the pane (a cached pane does not see a resize); VOELIN_OPEN=voice[:compact] asks for it, the sample servers keep nothing. The server page gets a Voice channel button for the way in, and the meter counts the page's renders. Tests on the test platform: the page takes the main area and gives it back, the people and their marks, talking and mute events redraw the page once and the rail, top bar and main area not at all (one model build for three lists), Leave reaches the engine, the call bar's buttons, the stage kept in the settings and forced short, the banner. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
235 lines
6.5 KiB
Rust
235 lines
6.5 KiB
Rust
//! The main area. Until the voice page, the chat and the rest come, it is the
|
|
//! empty page: the "no server selected" state with the way to add one, and for
|
|
//! a server on screen its name, address and state with the buttons that
|
|
//! connect, disconnect and edit it. An entity of its own, drawn as a cached
|
|
//! pane: it listens to the servers' signal and tells the window only when
|
|
//! what it shows changed.
|
|
|
|
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
|
use gpui_kit::prelude::FluentBuilder as _;
|
|
use gpui_kit::{
|
|
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ParentElement as _, Render,
|
|
Styled as _, Subscription, Window, div, px,
|
|
};
|
|
use voelin_ui_vm::bridge::ServerItem;
|
|
use voelin_ui_vm::servers::logic;
|
|
|
|
use super::actions::{AddServer, ConnectVoice, DisconnectVoice, EditServer, ShowVoiceView};
|
|
use super::widgets::{Avatar, Presence, icon, panel, tagged};
|
|
use crate::app::AppState;
|
|
use crate::meter::Counters;
|
|
use crate::signals::Area;
|
|
use crate::theme::{VoelinTheme, hsla};
|
|
|
|
/// What the main area shows.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum MainState {
|
|
/// No server is on screen.
|
|
NoServer,
|
|
/// A server is.
|
|
Server(ServerItem),
|
|
}
|
|
|
|
impl MainState {
|
|
/// The main area for the state.
|
|
pub fn of(app: &AppState) -> Self {
|
|
let current = app.vm.current;
|
|
logic::rail(&app.vm, |bookmark| app.server_icon(bookmark))
|
|
.into_iter()
|
|
.find(|item| Some(i64::from(item.id)) == current)
|
|
.map_or(Self::NoServer, Self::Server)
|
|
}
|
|
}
|
|
|
|
/// The words for a server's state.
|
|
fn state_words(status: &str) -> &'static str {
|
|
match status {
|
|
"connected" => "Connected with voice",
|
|
"connecting" => "Connecting…",
|
|
"observing" => "Observed without joining",
|
|
_ => "Not connected",
|
|
}
|
|
}
|
|
|
|
/// The main area.
|
|
pub struct MainPanel {
|
|
state: MainState,
|
|
counters: Counters,
|
|
_subscriptions: Vec<Subscription>,
|
|
}
|
|
|
|
impl MainPanel {
|
|
/// A main area that follows the server on screen in `app`.
|
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
|
let (state, counters, signals) = {
|
|
let shown = app.read(cx);
|
|
(MainState::of(shown), shown.counters().clone(), shown.signals().clone())
|
|
};
|
|
let subscriptions = signals.watch(app, &[Area::Servers], cx, |this: &mut Self, app, cx| {
|
|
let state = MainState::of(app.read(cx));
|
|
if state != this.state {
|
|
this.state = state;
|
|
cx.notify();
|
|
}
|
|
});
|
|
Self { state, counters, _subscriptions: subscriptions }
|
|
}
|
|
|
|
/// What it shows now.
|
|
pub fn state(&self) -> &MainState {
|
|
&self.state
|
|
}
|
|
}
|
|
|
|
impl Render for MainPanel {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
self.counters.panes.main.incr();
|
|
let theme = VoelinTheme::global(cx).clone();
|
|
let (c, m) = (&theme.colors, &theme.metrics);
|
|
let body = match &self.state {
|
|
MainState::NoServer => div()
|
|
.id("main-empty")
|
|
.debug_selector(|| "main-empty".into())
|
|
.flex()
|
|
.flex_col()
|
|
.items_center()
|
|
.gap(px(m.space_4))
|
|
.child(
|
|
div()
|
|
.size(px(72.0))
|
|
.rounded(px(m.radius_xl))
|
|
.bg(hsla(c.surface_2))
|
|
.border_1()
|
|
.border_color(hsla(c.border))
|
|
.flex()
|
|
.items_center()
|
|
.justify_center()
|
|
.child(icon("server", 32.0, c.text_muted)),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_size(px(m.font_xl))
|
|
.font_weight(FontWeight::SEMIBOLD)
|
|
.text_color(hsla(c.text))
|
|
.child("No server selected"),
|
|
)
|
|
.child(
|
|
div()
|
|
.max_w(px(360.0))
|
|
.text_center()
|
|
.text_size(px(m.font_body))
|
|
.text_color(hsla(c.text_muted))
|
|
.child("Pick a server in the list, or add one to start talking."),
|
|
)
|
|
.child(tagged(
|
|
"main-add",
|
|
Button::new("main-add")
|
|
.primary()
|
|
.label("Add a server")
|
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(AddServer), cx)),
|
|
)),
|
|
MainState::Server(item) => {
|
|
let id = i64::from(item.id);
|
|
let connected = item.status.as_ref() == "connected";
|
|
let connecting = item.status.as_ref() == "connecting";
|
|
div()
|
|
.id("main-server")
|
|
.debug_selector(|| "main-server".into())
|
|
.flex()
|
|
.flex_col()
|
|
.items_center()
|
|
.gap(px(m.space_4))
|
|
.child(
|
|
Avatar::new("main-server-avatar", 72.0, &item.initials, item.tint)
|
|
.image(item.icon.clone())
|
|
.square()
|
|
.presence(Presence::of_server(&item.status)),
|
|
)
|
|
.child(
|
|
div()
|
|
.max_w(px(480.0))
|
|
.truncate()
|
|
.text_size(px(m.font_2xl))
|
|
.font_weight(FontWeight::SEMIBOLD)
|
|
.text_color(hsla(c.text))
|
|
.child(item.name.to_string()),
|
|
)
|
|
.child(
|
|
div()
|
|
.text_size(px(m.font_body))
|
|
.text_color(hsla(c.text_secondary))
|
|
.child(item.address.to_string()),
|
|
)
|
|
.child(
|
|
div()
|
|
.id("main-server-state")
|
|
.text_size(px(m.font_sm))
|
|
.text_color(hsla(c.text_muted))
|
|
.child(state_words(&item.status)),
|
|
)
|
|
.child(
|
|
div()
|
|
.max_w(px(360.0))
|
|
.text_center()
|
|
.text_size(px(m.font_body))
|
|
.text_color(hsla(c.text_muted))
|
|
.child("Its chat comes with a later slice."),
|
|
)
|
|
.child(
|
|
div()
|
|
.flex()
|
|
.flex_row()
|
|
.gap(px(m.space_3))
|
|
.when(connected || connecting, |row| {
|
|
row.child(tagged(
|
|
"main-disconnect",
|
|
Button::new("main-disconnect")
|
|
.danger()
|
|
.label("Disconnect")
|
|
.on_click(|_, window, cx| {
|
|
window.dispatch_action(Box::new(DisconnectVoice), cx);
|
|
}),
|
|
))
|
|
})
|
|
.when(!connected && !connecting, |row| {
|
|
row.child(tagged(
|
|
"main-connect",
|
|
Button::new("main-connect")
|
|
.primary()
|
|
.label("Connect")
|
|
.on_click(|_, window, cx| {
|
|
window.dispatch_action(Box::new(ConnectVoice), cx);
|
|
}),
|
|
))
|
|
})
|
|
.when(connected, |row| {
|
|
row.child(tagged(
|
|
"main-voice",
|
|
Button::new("main-voice")
|
|
.primary()
|
|
.label("Voice channel")
|
|
.on_click(|_, window, cx| {
|
|
window.dispatch_action(
|
|
Box::new(ShowVoiceView { on: true }),
|
|
cx,
|
|
);
|
|
}),
|
|
))
|
|
})
|
|
.child(tagged(
|
|
"main-edit",
|
|
Button::new("main-edit").label("Edit").on_click(
|
|
move |_, window, cx| {
|
|
window.dispatch_action(Box::new(EditServer { id }), cx);
|
|
},
|
|
),
|
|
)),
|
|
)
|
|
}
|
|
};
|
|
// The root of a cached pane takes the size its place gives it: laid out
|
|
// on its own, `flex_1` would be as wide as its contents.
|
|
panel(&theme).id("main").size_full().items_center().justify_center().child(body)
|
|
}
|
|
}
|