BlueGit

ict rusty-teams

fix(messages): hover toolbar never covers the pinned banner

- measured timeline viewport starts below the pinned banner
- toolbar_side: above, else below the message, else stuck to the viewport top
- unit tests for the placement decision
- deviation from Teams (look only): Teams keeps the bar above (pinned, z-index 999) and lets it cover the banner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
e6be8cd7adce15e734e07962dd12634a38cc6180
Parent
4bb89d42
2 files changed +88 −21
crates/app/src/views/conversation.rs +7 −7
@@ -42,8 +42,8 @@ use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPrevi
42 42 use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
43 43 use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
44 44 use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
45 use super::post_card::render_post;
46 45 use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
46 use super::post_card::render_post;
47 47 use super::profile_card::opens_profile;
48 48 use super::reaction_picker::{PickHandler, ReactionPicker};
49 49 use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -69,10 +69,9 @@ use crate::read_state::{ReadTrigger, plan_read};
69 69 use crate::rows::{
70 70 Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
71 71 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
72 forward_sender_ids,
73 has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,
74 placeholder_rows,
75 reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,
72 forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
73 place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
74 thread_list_rows, thread_rows,
76 75 };
77 76 use crate::runtime;
78 77 use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
@@ -3427,6 +3426,7 @@ impl Render for ConversationView {
3427 3426 let pin_banner = self
3428 3427 .render_pin_banner(cx)
3429 3428 .filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3429 let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3430 3430 let scroller = MessageScroller::new(
3431 3431 "messages",
3432 3432 self.scroller.clone(),
@@ -3530,7 +3530,7 @@ impl Render for ConversationView {
3530 3530 })
3531 3531 })
3532 3532 .with_bottom_fade(background)
3533 .with_top_inset(pin_banner_inset(pin_banner.is_some()));
3533 .with_top_inset(timeline_top_inset);
3534 3534
3535 3535 root = match self.current.as_ref().filter(|_| !drafting) {
3536 3536 Some(current) => root.child(self.render_header(current, cx)),
@@ -3601,7 +3601,7 @@ impl Render for ConversationView {
3601 3601 .relative()
3602 3602 .flex_1()
3603 3603 .min_h_0()
3604 .child(record_bounds(&self.timeline_bounds))
3604 .child(record_bounds(&self.timeline_bounds, timeline_top_inset))
3605 3605 .on_scroll_wheel(
3606 3606 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3607 3607 )
@@ -42,8 +42,8 @@ use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPrevi
42use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
42use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
43use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
43use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
44use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
44use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
45use super::post_card::render_post;
46use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
45use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
46use super::post_card::render_post;
47use super::profile_card::opens_profile;
47use super::profile_card::opens_profile;
48use super::reaction_picker::{PickHandler, ReactionPicker};
48use super::reaction_picker::{PickHandler, ReactionPicker};
49use super::reaction_pills::{ReactionControls, ReactionPopover};
49use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -69,10 +69,9 @@ use crate::read_state::{ReadTrigger, plan_read};
69use crate::rows::{
69use crate::rows::{
70 Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
70 Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
71 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
71 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
72 forward_sender_ids,
72 forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
73 has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,
73 place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
74 placeholder_rows,
74 thread_list_rows, thread_rows,
75 reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,
76};
75};
77use crate::runtime;
76use crate::runtime;
78use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
77use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
@@ -3427,6 +3426,7 @@ impl Render for ConversationView {
3427 let pin_banner = self
3426 let pin_banner = self
3428 .render_pin_banner(cx)
3427 .render_pin_banner(cx)
3429 .filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3428 .filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3429 let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3430 let scroller = MessageScroller::new(
3430 let scroller = MessageScroller::new(
3431 "messages",
3431 "messages",
3432 self.scroller.clone(),
3432 self.scroller.clone(),
@@ -3530,7 +3530,7 @@ impl Render for ConversationView {
3530 })
3530 })
3531 })
3531 })
3532 .with_bottom_fade(background)
3532 .with_bottom_fade(background)
3533 .with_top_inset(pin_banner_inset(pin_banner.is_some()));
3533 .with_top_inset(timeline_top_inset);
3534
3534
3535 root = match self.current.as_ref().filter(|_| !drafting) {
3535 root = match self.current.as_ref().filter(|_| !drafting) {
3536 Some(current) => root.child(self.render_header(current, cx)),
3536 Some(current) => root.child(self.render_header(current, cx)),
@@ -3601,7 +3601,7 @@ impl Render for ConversationView {
3601 .relative()
3601 .relative()
3602 .flex_1()
3602 .flex_1()
3603 .min_h_0()
3603 .min_h_0()
3604 .child(record_bounds(&self.timeline_bounds))
3604 .child(record_bounds(&self.timeline_bounds, timeline_top_inset))
3605 .on_scroll_wheel(
3605 .on_scroll_wheel(
3606 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3606 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3607 )
3607 )
crates/app/src/views/toolbar_placement.rs +81 −14
@@ -19,16 +19,47 @@ pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) ->
19 19 .child(bar)
20 20 }
21 21
22 pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {
22 pub fn record_bounds(timeline: &TimelineBounds, top_inset: Pixels) -> impl IntoElement {
23 23 let timeline = timeline.clone();
24 24 canvas(
25 25 move |bounds, _, _| timeline.set(Some(bounds)),
26 26 |_, _, _, _| {},
27 27 )
28 28 .absolute()
29 .top_0()
29 .top(top_inset)
30 30 .left_0()
31 .size_full()
31 .right_0()
32 .bottom_0()
33 }
34
35 #[derive(Clone, Copy, Debug, PartialEq)]
36 pub enum ToolbarSide {
37 Above,
38 Below,
39 ViewportTop,
40 }
41
42 pub fn toolbar_side(anchor: Bounds<Pixels>, viewport: Bounds<Pixels>) -> ToolbarSide {
43 let above_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
44 let below_bottom = anchor.bottom() + px(SLOT_HEIGHT - TOOLBAR_GAP);
45 if above_top >= viewport.top() {
46 ToolbarSide::Above
47 } else if below_bottom <= viewport.bottom() {
48 ToolbarSide::Below
49 } else {
50 ToolbarSide::ViewportTop
51 }
52 }
53
54 fn toolbar_offset(anchor: Bounds<Pixels>, viewport: Option<Bounds<Pixels>>) -> Pixels {
55 let Some(viewport) = viewport else {
56 return px(0.);
57 };
58 match toolbar_side(anchor, viewport) {
59 ToolbarSide::Above => px(0.),
60 ToolbarSide::Below => anchor.size.height + px(SLOT_HEIGHT),
61 ToolbarSide::ViewportTop => viewport.top() - anchor.top() + px(SLOT_HEIGHT),
62 }
32 63 }
33 64
34 65 pub fn placed_toolbar(
@@ -59,16 +90,6 @@ struct PlacedToolbar {
59 90 overlay: AnyElement,
60 91 }
61 92
62 impl PlacedToolbar {
63 fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {
64 let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
65 match self.timeline.get() {
66 Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),
67 _ => px(0.),
68 }
69 }
70 }
71
72 93 impl Element for PlacedToolbar {
73 94 type RequestLayoutState = ();
74 95 type PrepaintState = ();
@@ -100,7 +121,7 @@ impl Element for PlacedToolbar {
100 121 window: &mut Window,
101 122 cx: &mut App,
102 123 ) {
103 let offset = point(px(0.), self.flip_offset(bounds));
124 let offset = point(px(0.), toolbar_offset(bounds, self.timeline.get()));
104 125 window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));
105 126 }
106 127
@@ -125,3 +146,49 @@ impl IntoElement for PlacedToolbar {
125 146 self
126 147 }
127 148 }
149
150 #[cfg(test)]
151 mod tests {
152 use super::{SLOT_HEIGHT, TOOLBAR_GAP, ToolbarSide, toolbar_offset, toolbar_side};
153 use gpui_kit::{Bounds, point, px, size};
154
155 fn span(top: f32, bottom: f32) -> Bounds<gpui_kit::Pixels> {
156 Bounds::new(point(px(0.), px(top)), size(px(400.), px(bottom - top)))
157 }
158
159 const VIEWPORT: (f32, f32) = (100., 600.);
160 const BAR_ROOM: f32 = SLOT_HEIGHT - TOOLBAR_GAP;
161
162 #[test]
163 fn stays_above_with_room_below_the_viewport_top() {
164 let viewport = span(VIEWPORT.0, VIEWPORT.1);
165 let message = span(VIEWPORT.0 + BAR_ROOM, 300.);
166 assert_eq!(toolbar_side(message, viewport), ToolbarSide::Above);
167 assert_eq!(toolbar_offset(message, Some(viewport)), px(0.));
168 }
169
170 #[test]
171 fn flips_below_when_the_bar_would_cross_the_viewport_top() {
172 let viewport = span(VIEWPORT.0, VIEWPORT.1);
173 let message = span(VIEWPORT.0 + BAR_ROOM - 1., 300.);
174 assert_eq!(toolbar_side(message, viewport), ToolbarSide::Below);
175 assert_eq!(
176 toolbar_offset(message, Some(viewport)),
177 message.size.height + px(SLOT_HEIGHT)
178 );
179 }
180
181 #[test]
182 fn sticks_to_the_viewport_top_when_neither_side_fits() {
183 let viewport = span(VIEWPORT.0, VIEWPORT.1);
184 let message = span(VIEWPORT.0 - 50., VIEWPORT.1 - BAR_ROOM + 1.);
185 assert_eq!(toolbar_side(message, viewport), ToolbarSide::ViewportTop);
186 let bar_top = message.top() - px(SLOT_HEIGHT) + toolbar_offset(message, Some(viewport));
187 assert_eq!(bar_top, viewport.top());
188 }
189
190 #[test]
191 fn stays_above_without_measured_viewport() {
192 assert_eq!(toolbar_offset(span(0., 100.), None), px(0.));
193 }
194 }
@@ -19,16 +19,47 @@ pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) ->
19 .child(bar)
19 .child(bar)
20}
20}
21
21
22pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {
22pub fn record_bounds(timeline: &TimelineBounds, top_inset: Pixels) -> impl IntoElement {
23 let timeline = timeline.clone();
23 let timeline = timeline.clone();
24 canvas(
24 canvas(
25 move |bounds, _, _| timeline.set(Some(bounds)),
25 move |bounds, _, _| timeline.set(Some(bounds)),
26 |_, _, _, _| {},
26 |_, _, _, _| {},
27 )
27 )
28 .absolute()
28 .absolute()
29 .top_0()
29 .top(top_inset)
30 .left_0()
30 .left_0()
31 .size_full()
31 .right_0()
32 .bottom_0()
33}
34
35#[derive(Clone, Copy, Debug, PartialEq)]
36pub enum ToolbarSide {
37 Above,
38 Below,
39 ViewportTop,
40}
41
42pub fn toolbar_side(anchor: Bounds<Pixels>, viewport: Bounds<Pixels>) -> ToolbarSide {
43 let above_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
44 let below_bottom = anchor.bottom() + px(SLOT_HEIGHT - TOOLBAR_GAP);
45 if above_top >= viewport.top() {
46 ToolbarSide::Above
47 } else if below_bottom <= viewport.bottom() {
48 ToolbarSide::Below
49 } else {
50 ToolbarSide::ViewportTop
51 }
52}
53
54fn toolbar_offset(anchor: Bounds<Pixels>, viewport: Option<Bounds<Pixels>>) -> Pixels {
55 let Some(viewport) = viewport else {
56 return px(0.);
57 };
58 match toolbar_side(anchor, viewport) {
59 ToolbarSide::Above => px(0.),
60 ToolbarSide::Below => anchor.size.height + px(SLOT_HEIGHT),
61 ToolbarSide::ViewportTop => viewport.top() - anchor.top() + px(SLOT_HEIGHT),
62 }
32}
63}
33
64
34pub fn placed_toolbar(
65pub fn placed_toolbar(
@@ -59,16 +90,6 @@ struct PlacedToolbar {
59 overlay: AnyElement,
90 overlay: AnyElement,
60}
91}
61
92
62impl PlacedToolbar {
63 fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {
64 let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
65 match self.timeline.get() {
66 Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),
67 _ => px(0.),
68 }
69 }
70}
71
72impl Element for PlacedToolbar {
93impl Element for PlacedToolbar {
73 type RequestLayoutState = ();
94 type RequestLayoutState = ();
74 type PrepaintState = ();
95 type PrepaintState = ();
@@ -100,7 +121,7 @@ impl Element for PlacedToolbar {
100 window: &mut Window,
121 window: &mut Window,
101 cx: &mut App,
122 cx: &mut App,
102 ) {
123 ) {
103 let offset = point(px(0.), self.flip_offset(bounds));
124 let offset = point(px(0.), toolbar_offset(bounds, self.timeline.get()));
104 window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));
125 window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));
105 }
126 }
106
127
@@ -125,3 +146,49 @@ impl IntoElement for PlacedToolbar {
125 self
146 self
126 }
147 }
127}
148}
149
150#[cfg(test)]
151mod tests {
152 use super::{SLOT_HEIGHT, TOOLBAR_GAP, ToolbarSide, toolbar_offset, toolbar_side};
153 use gpui_kit::{Bounds, point, px, size};
154
155 fn span(top: f32, bottom: f32) -> Bounds<gpui_kit::Pixels> {
156 Bounds::new(point(px(0.), px(top)), size(px(400.), px(bottom - top)))
157 }
158
159 const VIEWPORT: (f32, f32) = (100., 600.);
160 const BAR_ROOM: f32 = SLOT_HEIGHT - TOOLBAR_GAP;
161
162 #[test]
163 fn stays_above_with_room_below_the_viewport_top() {
164 let viewport = span(VIEWPORT.0, VIEWPORT.1);
165 let message = span(VIEWPORT.0 + BAR_ROOM, 300.);
166 assert_eq!(toolbar_side(message, viewport), ToolbarSide::Above);
167 assert_eq!(toolbar_offset(message, Some(viewport)), px(0.));
168 }
169
170 #[test]
171 fn flips_below_when_the_bar_would_cross_the_viewport_top() {
172 let viewport = span(VIEWPORT.0, VIEWPORT.1);
173 let message = span(VIEWPORT.0 + BAR_ROOM - 1., 300.);
174 assert_eq!(toolbar_side(message, viewport), ToolbarSide::Below);
175 assert_eq!(
176 toolbar_offset(message, Some(viewport)),
177 message.size.height + px(SLOT_HEIGHT)
178 );
179 }
180
181 #[test]
182 fn sticks_to_the_viewport_top_when_neither_side_fits() {
183 let viewport = span(VIEWPORT.0, VIEWPORT.1);
184 let message = span(VIEWPORT.0 - 50., VIEWPORT.1 - BAR_ROOM + 1.);
185 assert_eq!(toolbar_side(message, viewport), ToolbarSide::ViewportTop);
186 let bar_top = message.top() - px(SLOT_HEIGHT) + toolbar_offset(message, Some(viewport));
187 assert_eq!(bar_top, viewport.top());
188 }
189
190 #[test]
191 fn stays_above_without_measured_viewport() {
192 assert_eq!(toolbar_offset(span(0., 100.), None), px(0.));
193 }
194}