diff --git a/crates/voelin-gpui/src/shell/channels.rs b/crates/voelin-gpui/src/shell/channels.rs index 013c150..378c073 100644 --- a/crates/voelin-gpui/src/shell/channels.rs +++ b/crates/voelin-gpui/src/shell/channels.rs @@ -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>, @@ -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() diff --git a/crates/voelin-gpui/src/view.rs b/crates/voelin-gpui/src/view.rs index a8014ec..34dee06 100644 --- a/crates/voelin-gpui/src/view.rs +++ b/crates/voelin-gpui/src/view.rs @@ -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 = 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 diff --git a/docs/ui.md b/docs/ui.md index bf7a59c..c37082b 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -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. +![the tree with a banner row selected and one under the pointer, dark](ui/gpui-tree-banner-selected-dark.png) + +`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 diff --git a/docs/ui/gpui-tree-banner-selected-dark.png b/docs/ui/gpui-tree-banner-selected-dark.png new file mode 100644 index 0000000..29197ef Binary files /dev/null and b/docs/ui/gpui-tree-banner-selected-dark.png differ