voelin-gpui: the sidebar's server card has the server's banner behind it
server_banner, which the tree slice left out, is behind the card as in ServerHeader of channels.slint: the picture covers the card (cropped to its padding box, so the border stays), the same surface veil as the tree's banner rows lies over it, and the stats line reads in the text colour instead of the muted one. A server without a banner, or whose picture has not arrived, has the plain card. The picture's corners are square, as the tree's banner rows': GPUI clips to rectangles. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba4fe3c8ca
commit
3bf21f1b26
3 files changed
+65
-11
No files matched your search
@@ -1,5 +1,6 @@
|
||||
//! The sidebar (`Sidebar` of `ui/shells/desktop.slint`, with the cards of
|
||||
//! `shells/common.slint`): the server on screen, its channel tree
|
||||
//! `shells/common.slint`): the server on screen (its card has the server's
|
||||
//! banner behind it, under the same veil as the tree's rows), its channel tree
|
||||
//! ([`super::ChannelTree`], a cached pane of its own), the voice card while
|
||||
//! voice is connecting or connected, and the user's own card with the voice
|
||||
//! buttons. An entity of its own: it listens to the servers' and the toolbar's
|
||||
@@ -8,8 +9,8 @@
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::{
|
||||
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, MouseButton, MouseUpEvent,
|
||||
ParentElement as _, Render, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
|
||||
Subscription, Window, div, px,
|
||||
ObjectFit, ParentElement as _, Render, StatefulInteractiveElement as _, StyleRefinement,
|
||||
Styled as _, StyledImage as _, Subscription, Window, div, px,
|
||||
};
|
||||
use voelin_core::TransmitMode;
|
||||
use voelin_ui_vm::Rgb;
|
||||
@@ -21,9 +22,10 @@ use super::actions::{
|
||||
DisconnectVoice, Invite, OpenSettings, PushToTalk, SetInputMuted, SetOutputMuted,
|
||||
};
|
||||
use super::channels::ChannelTree;
|
||||
use super::widgets::{Avatar, IconButton, Presence, card, icon, panel};
|
||||
use super::widgets::{Avatar, IconButton, Presence, banner_scrim, card, icon, panel};
|
||||
use crate::app::AppState;
|
||||
use crate::meter::Counters;
|
||||
use crate::pictures::{PictureKey, picture};
|
||||
use crate::signals::Area;
|
||||
use crate::theme::{VoelinTheme, hsla};
|
||||
|
||||
@@ -34,6 +36,8 @@ pub struct SidebarView {
|
||||
pub server: Option<ServerItem>,
|
||||
/// "9 online · 7 channels" once its presence is known, else empty.
|
||||
pub stats: String,
|
||||
/// The server's banner, behind its card; empty without one.
|
||||
pub server_banner: ImageRef,
|
||||
/// Our nickname there; empty without a server.
|
||||
pub nickname: String,
|
||||
/// The channel we are in; empty while connecting.
|
||||
@@ -68,6 +72,7 @@ impl SidebarView {
|
||||
Self {
|
||||
server,
|
||||
stats: card.server_stats,
|
||||
server_banner: card.server_banner,
|
||||
nickname: card.nickname,
|
||||
own_channel: card.own_channel,
|
||||
own_avatar: card.own_avatar,
|
||||
@@ -126,18 +131,41 @@ impl Sidebar {
|
||||
}
|
||||
}
|
||||
|
||||
/// The server's name, its icon and how many are there.
|
||||
/// The server's name, its icon and how many are there, over its banner when it
|
||||
/// has one (`ServerHeader` of `channels.slint`: the picture covers the card,
|
||||
/// the surface veil of `banner-picture.slint` lies over it, and the stats read
|
||||
/// in the text colour instead of the secondary one).
|
||||
fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> impl IntoElement {
|
||||
let (c, m) = (&theme.colors, &theme.metrics);
|
||||
let stats = if view.stats.is_empty() { item.address.to_string() } else { view.stats.clone() };
|
||||
let banner = PictureKey::of(&view.server_banner);
|
||||
let ink = if banner.is_some() { c.text } else { c.text_muted };
|
||||
card(theme, 0xff)
|
||||
.id("sidebar-server")
|
||||
.debug_selector(|| "sidebar-server".into())
|
||||
.relative()
|
||||
.overflow_hidden()
|
||||
.p(px(m.space_3))
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(px(m.space_3))
|
||||
.when_some(banner, |card, key| {
|
||||
card.child(
|
||||
div()
|
||||
.id("sidebar-server-banner")
|
||||
.debug_selector(|| "sidebar-server-banner".into())
|
||||
.absolute()
|
||||
.top(px(0.0))
|
||||
.left(px(0.0))
|
||||
.size_full()
|
||||
// The picture covers the card and is cropped to it, not past
|
||||
// its border.
|
||||
.overflow_hidden()
|
||||
.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
|
||||
)
|
||||
.child(div().absolute().top(px(0.0)).left(px(0.0)).size_full().bg(banner_scrim(theme)))
|
||||
})
|
||||
.child(
|
||||
Avatar::new("sidebar-server-avatar", 40.0, &item.initials, item.tint)
|
||||
.image(item.icon.clone())
|
||||
@@ -158,11 +186,7 @@ fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> im
|
||||
.child(item.name.to_string()),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.truncate()
|
||||
.text_size(px(m.font_sm))
|
||||
.text_color(hsla(c.text_muted))
|
||||
.child(stats),
|
||||
div().truncate().text_size(px(m.font_sm)).text_color(hsla(ink)).child(stats),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -225,6 +225,12 @@ impl MainView {
|
||||
&self.card
|
||||
}
|
||||
|
||||
/// What the sidebar shows now.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn sidebar_view(&self, cx: &gpui_kit::App) -> crate::shell::SidebarView {
|
||||
self.sidebar.read(cx).view().clone()
|
||||
}
|
||||
|
||||
/// The voice channel page.
|
||||
pub fn voice_page(&self) -> &Entity<VoicePage> {
|
||||
&self.voice
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! The voice page and the call bar on a drawn window (`crate::shell::VoicePage`):
|
||||
//! The voice page and the call bar on a drawn window (`crate::shell::VoicePage`),
|
||||
//! and the sidebar's server card with its banner:
|
||||
//! the page takes the main area while voice is connected and asked for, its
|
||||
//! people carry their marks, a talker or a mute redraws it and no pane that has
|
||||
//! nothing to show for it, the call bar's buttons reach the engine, and the
|
||||
@@ -335,3 +336,26 @@ fn a_development_switch_asks_for_the_voice_page_and_its_stage(cx: &mut TestAppCo
|
||||
assert!(!shell.app.read_with(cx, |app, _| app.backend().prefs.get(&UI_VOICE_COMPACT)));
|
||||
assert!(!shell.view.read_with(cx, |view, cx| view.voice_page().read(cx).compact_shown()));
|
||||
}
|
||||
|
||||
/// The sidebar's server card has the server's banner behind it, under the
|
||||
/// surface veil, once the picture is in the cache; a server without one has the
|
||||
/// plain card.
|
||||
#[gpui::test]
|
||||
fn the_server_card_shows_the_banner(cx: &mut TestAppContext) {
|
||||
let switches = Switches { demo_ui: true, demo_pictures: true, ..Default::default() };
|
||||
let (shell, cx) = open(cx, Backend::in_memory().unwrap(), switches);
|
||||
assert!(at(cx, "sidebar-server").is_some(), "the card");
|
||||
assert!(at(cx, "sidebar-server-banner").is_some(), "the host banner is behind it");
|
||||
let card = shell.view.read_with(cx, |view, cx| view.sidebar_view(cx));
|
||||
assert!(card.server_banner.size().width > 0, "the picture is decoded");
|
||||
|
||||
// Another server of the sample, which has no banner: the plain card.
|
||||
let other = shell.app.read_with(cx, |app, _| app.vm.bookmarks[2].id);
|
||||
click(cx, &format!("rail-server-{other}"));
|
||||
assert!(at(cx, "sidebar-server").is_some());
|
||||
assert!(at(cx, "sidebar-server-banner").is_none(), "no banner, no picture behind the card");
|
||||
|
||||
let folder = shell.app.read_with(cx, |app, _| app.demo_dir().cloned());
|
||||
shell.app.update(cx, |app, cx| app.shutdown(cx));
|
||||
assert!(!folder.is_some_and(|folder| folder.exists()), "the close removes the sample pictures");
|
||||
}
|
||||
Reference in new issue
Block a user