voelin-gpui: a channel's banner is drawn under the surface veil, as the Slint tree's

A channel row drew its banner picture at full strength under the name, so
Theme.text could sit on a picture of its own colour (dark text on the sample
server's dark banners in the light theme, light text on a bright TS6 banner in
the dark one). banner-picture.slint lays the surface colour over the picture,
74 % opaque on the left and 66 % on the right; the row now does the same, over
the picture and under the tint of our own channel.

A test keeps the veil: the text of both themes has more than 4.5 to 1 against
the weakest end over a black and over a white picture, and the gradient is the
surface colour at those two opacities; another finds the veil on the sample
server's banner rows and on no other.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-28 03:48:31 +03:00
1 parent 0e01b60930
commit f8cf6a3561
3 files changed
+93 -4

No files matched your search

+15 -2
View File
@@ -29,7 +29,7 @@ use super::actions::{
EditChannel, JoinChannel, MoveClient, OpenClient, OpenMember, SelectChannel, ToggleChannel,
};
use super::tree_model::{Emptiness, TreeEvent, TreeModel};
use super::widgets::{Avatar, icon, live_badge, small_picture};
use super::widgets::{Avatar, banner_scrim, icon, live_badge, small_picture};
use crate::meter::Counters;
use crate::pictures::{PictureKey, picture};
use crate::theme::{VoelinTheme, hsla};
@@ -215,7 +215,9 @@ fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyEleme
.when(own, |row| row.bg(accent_soft).border_1().border_color(accent))
.when(!own && selected, |row| row.bg(selected_fill))
.when(!own && !selected, |row| row.hover(move |style| style.bg(hover)))
// Artwork behind the same compact row as its title, from the indent on.
// Artwork behind the same compact row as its title, from the indent on,
// under a veil of the surface colour that keeps the text readable over
// any picture, and under the tint of our own channel.
.when_some(banner, |row, key| {
row.child(
div()
@@ -226,6 +228,17 @@ fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyEleme
.right(px(0.0))
.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
)
.child(
div()
.id(("tree-scrim", id))
.debug_selector(move || format!("tree-scrim-{id}"))
.absolute()
.top(px(0.0))
.bottom(px(0.0))
.left(px(indent))
.right(px(0.0))
.bg(banner_scrim(theme)),
)
.when(own, |row| {
row.child(
div()
+54 -2
View File
@@ -5,9 +5,9 @@
//! `shells/common.slint`'s `Panel`.
use gpui_kit::{
AnyElement, App, ClickEvent, FontWeight, InteractiveElement as _, IntoElement,
AnyElement, App, Background, ClickEvent, FontWeight, InteractiveElement as _, IntoElement,
ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _, Styled as _,
Window, div, px, svg,
Window, div, linear_color_stop, linear_gradient, px, svg,
};
use gpui_kit::{ElementId, ObjectFit, StyledImage as _};
use voelin_ui_vm::Rgb;
@@ -72,6 +72,24 @@ pub fn tint(color: Rgb) -> Rgba {
Rgba(color.0 << 8 | 0xff)
}
/// How opaque the veil over a banner is at its left edge and at its right
/// (`components/banner-picture.slint`: `transparentize(0.26)` and `(0.34)`).
const BANNER_VEIL: (f32, f32) = (0.74, 0.66);
/// The veil over a banner picture: the surface colour, left to right from 74 %
/// to 66 % opaque. A row's text (`text`) keeps more than 4.5 to 1 against it
/// whatever the picture, even white behind the dark theme's light text or
/// black behind the light theme's dark text. It lies over the picture and
/// under the row's own tint.
pub fn banner_scrim(theme: &VoelinTheme) -> Background {
let surface = hsla(theme.colors.surface);
linear_gradient(
90.0,
linear_color_stop(surface.opacity(BANNER_VEIL.0), 0.0),
linear_color_stop(surface.opacity(BANNER_VEIL.1), 1.0),
)
}
/// An avatar: the picture when there is one (a file of the engine's cache),
/// else the initials on `tint`, square with rounded corners for a server
/// and round for a person, with a presence dot and a green ring while the
@@ -445,3 +463,37 @@ pub fn chip(
.children(picture)
.child(text.into())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::theme::Choice;
#[test]
fn the_banner_veil_keeps_the_text_readable_over_any_picture() {
for choice in [Choice::Dark, Choice::Light] {
let theme = VoelinTheme::new(choice, choice == Choice::Dark, 1.0);
let c = &theme.colors;
// The weakest end of the veil, over the two pictures that are the
// worst for light and dark text.
for picture in [Rgba(0x0000_00ff), Rgba(0xffff_ffff)] {
let seen = c.surface.mix(picture, 1.0 - BANNER_VEIL.1);
assert!(
c.text.contrast(seen) > 4.5,
"{choice:?}: text on {picture:?} under the veil is {}",
c.text.contrast(seen)
);
}
// Left to right, from the stronger end to the weaker, in the surface's colour.
let surface = hsla(c.surface);
assert_eq!(
banner_scrim(&theme),
linear_gradient(
90.0,
linear_color_stop(surface.opacity(0.74), 0.0),
linear_color_stop(surface.opacity(0.66), 1.0),
)
);
}
}
}
+24
View File
@@ -1168,6 +1168,30 @@ mod tests {
assert!(shell.app.read_with(cx, |app, _| app.vm.join_target.is_none()));
}
/// The channels with a banner picture are drawn with the veil of the
/// surface colour over it (so that their text reads over any picture); the
/// others have none.
#[gpui::test]
fn a_banner_is_drawn_under_a_veil(cx: &mut TestAppContext) {
let switches = Switches { demo_ui: true, demo_pictures: true, ..Switches::default() };
let (shell, cx) = open(cx, Backend::in_memory().unwrap(), switches);
let rows = tree_rows(&shell, cx);
let banners: Vec<_> = rows
.iter()
.filter(|r| r.is_channel && PictureKey::of(&r.banner).is_some())
.map(|r| r.id)
.collect();
assert!(banners.len() >= 2, "the sample server has banners: {banners:?}");
for id in &banners {
assert!(at(cx, &format!("tree-scrim-{id}")).is_some(), "channel {id} has a veil");
}
let plain = rows.iter().find(|r| {
r.is_channel && r.spacer == 0 && !banners.contains(&r.id) && !r.name.is_empty()
});
let plain = plain.expect("a channel without a banner");
assert!(at(cx, &format!("tree-channel-{}", plain.id)).is_some(), "it is on screen");
assert!(at(cx, &format!("tree-scrim-{}", plain.id)).is_none(), "and has no veil");
}
/// A person who changes channel makes the rows between the two places
/// change and none outside them: the channels' counts, the person's row
/// moved; a person who mutes their microphone changes one row.