voelin-gpui: a banner row shows its selection and its hover over the picture
A channel row paints its selected and hover backgrounds on the row, and the banner picture, drawn from the indent on, covers them: a banner row showed a strip of hover left of the picture and no selection at all. channels.slint tints the hover over the picture with a translucent child (surface-3 at 50 %), as the own channel's tint is drawn here; the row now does the same, with a child above the veil for the selected row (surface 3 at 75 %, a state Slint has none for) and one for the hover (50 %, through the row's group, so the pointer anywhere on the row tints it). Our own channel keeps its accent tint. A test selects two banner rows of the sample server in turn and finds the tint on the selected one only; docs/ui/gpui-tree-banner-selected-dark.png shows Raid Night selected and the pointer on Music (release build, lavapipe on Xvfb :233 with openbox). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc143f312d
commit
f28c02a18c
4 files changed
+73
-6
No files matched your search
@@ -19,8 +19,9 @@ use gpui_kit::component::menu::ContextMenuExt as _;
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::{
|
||||
AnyElement, Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ListAlignment,
|
||||
ListState, ObjectFit, ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _,
|
||||
StyledImage as _, Subscription, Window, div, list, px,
|
||||
ListState, ObjectFit, ParentElement as _, Render, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, StyledImage as _, Subscription, Window, div,
|
||||
list, px,
|
||||
};
|
||||
use voelin_ui_vm::bridge::TreeItem;
|
||||
use voelin_ui_vm::tree::ChannelId;
|
||||
@@ -37,6 +38,13 @@ use crate::theme::{VoelinTheme, hsla};
|
||||
/// How far each level of the tree is indented.
|
||||
const INDENT: f32 = 14.0;
|
||||
|
||||
/// How opaque the hover and selection tints of a row with a banner are over
|
||||
/// the banner and its veil: the hover is `channels.slint`'s (`Theme.surface-3.
|
||||
/// transparentize(0.5)`), the selection, which Slint has no state for, is a
|
||||
/// stronger one of the same colour.
|
||||
const BANNER_HOVER: f32 = 0.5;
|
||||
const BANNER_SELECTED: f32 = 0.75;
|
||||
|
||||
/// The channel tree.
|
||||
pub struct ChannelTree {
|
||||
rows: Arc<Vec<TreeItem>>,
|
||||
@@ -201,9 +209,11 @@ fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyEleme
|
||||
} else {
|
||||
item.members.to_string()
|
||||
};
|
||||
let group = SharedString::from(format!("tree-row-{id}"));
|
||||
let row = div()
|
||||
.id(("tree-channel", id))
|
||||
.debug_selector(move || format!("tree-channel-{id}"))
|
||||
.group(group.clone())
|
||||
.relative()
|
||||
.w_full()
|
||||
.h(px(34.0 * m.font_scale))
|
||||
@@ -216,8 +226,21 @@ fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyEleme
|
||||
.when(!own && !selected, |row| row.hover(move |style| style.bg(hover)))
|
||||
// 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.
|
||||
// any picture, and under the tints of the row: our own channel's, the
|
||||
// selected one and the one the pointer is over. The artwork covers the
|
||||
// row's own background (which only the indent shows), so the tints
|
||||
// are translucent children above the veil, as `channels.slint` does
|
||||
// for the hover.
|
||||
.when_some(banner, |row, key| {
|
||||
let tint = || {
|
||||
div()
|
||||
.absolute()
|
||||
.top(px(0.0))
|
||||
.bottom(px(0.0))
|
||||
.left(px(indent))
|
||||
.right(px(0.0))
|
||||
.rounded(px(m.radius_md))
|
||||
};
|
||||
row.child(
|
||||
div()
|
||||
.absolute()
|
||||
@@ -250,6 +273,18 @@ fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyEleme
|
||||
.bg(accent_soft.opacity(0.65)),
|
||||
)
|
||||
})
|
||||
.when(!own && selected, |row| {
|
||||
row.child(
|
||||
tint()
|
||||
.debug_selector(move || format!("tree-selected-{id}"))
|
||||
.bg(selected_fill.opacity(BANNER_SELECTED)),
|
||||
)
|
||||
})
|
||||
.when(!own && !selected, |row| {
|
||||
row.child(
|
||||
tint().group_hover(group, move |style| style.bg(hover.opacity(BANNER_HOVER))),
|
||||
)
|
||||
})
|
||||
})
|
||||
.flex()
|
||||
.flex_row()
|
||||
|
||||
@@ -1216,7 +1216,8 @@ mod tests {
|
||||
|
||||
/// 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.
|
||||
/// others have none. The picture covers the row's own background, so a
|
||||
/// selected banner row is tinted by a child above the veil.
|
||||
#[gpui::test]
|
||||
fn a_banner_is_drawn_under_a_veil(cx: &mut TestAppContext) {
|
||||
let switches = Switches { demo_ui: true, demo_pictures: true, ..Switches::default() };
|
||||
@@ -1237,6 +1238,23 @@ mod tests {
|
||||
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 click selects a row; a banner row shows it by a tint over its picture.
|
||||
let tinted =
|
||||
|cx: &mut VisualTestContext, id: i32| at(cx, &format!("tree-selected-{id}")).is_some();
|
||||
// (Our own channel has the accent tint of its own instead.)
|
||||
let others: Vec<i32> = rows
|
||||
.iter()
|
||||
.filter(|r| r.is_channel && banners.contains(&r.id) && !r.own)
|
||||
.map(|r| r.id)
|
||||
.collect();
|
||||
let [first, second, ..] = others[..] else { panic!("two other banners: {others:?}") };
|
||||
assert!(!tinted(cx, first) && !tinted(cx, second), "nothing is selected yet");
|
||||
click(cx, &format!("tree-channel-{first}"));
|
||||
assert!(tinted(cx, first), "the selected banner row is tinted");
|
||||
assert!(!tinted(cx, second));
|
||||
click(cx, &format!("tree-channel-{second}"));
|
||||
assert!(tinted(cx, second) && !tinted(cx, first), "and the tint follows the selection");
|
||||
}
|
||||
|
||||
/// A person who changes channel makes the rows between the two places
|
||||
|
||||
+16
-2
@@ -1425,6 +1425,15 @@ through Vulkan on Xvfb `:201` of 3840 by 2160 with openbox, 1440 by 960): the
|
||||
banner rows, Raid Night and Music, are under the veil, and the avatars of the
|
||||
tree show one letter.
|
||||
|
||||

|
||||
|
||||
`gpui-tree-banner-selected-dark.png` is the same window with Raid Night selected
|
||||
(a click) and the pointer on Music: a banner row shows its selection and its
|
||||
hover as a tint over the picture, as the speaking ring and bars show on Kairo's
|
||||
row (release build of the commit that tinted them, lavapipe through Vulkan on
|
||||
Xvfb `:233` of 3840 by 2160 with openbox, 1440 by 960, two `xdotool` moves and
|
||||
`xwd`, the state under the checkout's `.scratch/`).
|
||||
|
||||
What is on screen:
|
||||
|
||||
- **The channel tree** (`channels.rs`, in the sidebar between the server card
|
||||
@@ -1437,9 +1446,14 @@ What is on screen:
|
||||
the banner picture behind it and our channel highlighted. The banner has the
|
||||
veil of `components/banner-picture.slint` over it (`widgets::banner_scrim`:
|
||||
the surface colour, 74 % opaque on the left to 66 % on the right, under the
|
||||
tint of our channel), so the name keeps more than 4.5 to 1 against any
|
||||
tints of the row), so the name keeps more than 4.5 to 1 against any
|
||||
picture in both themes (a test states it for the weakest end over a black
|
||||
and a white picture). A person's row has their avatar (the first letter
|
||||
and a white picture). The row's own background (the selected one's and the
|
||||
hover's) is under the picture, which covers it from the indent on, so a row
|
||||
with a banner shows its states as translucent tints over the veil: our
|
||||
channel's accent tint, the selected row's (surface 3 at 75 %) and the hover's
|
||||
(surface 3 at 50 %, as `channels.slint` tints it). A person's row has their
|
||||
avatar (the first letter
|
||||
only, at half the size, under 28 pixels as `avatar.slint` does), name (ours
|
||||
in the accent colour, someone away muted), badges, a
|
||||
LIVE tag while they stream, the marks of local mute (or volume) and of their
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
Reference in new issue
Block a user