fix(ui): hover toolbar above the bubble, flips below when there is no room
- Toolbar bottom 4 px above the bubble, never covers text; the gap is part of the hover zone - Topmost visible message: toolbar flips below the bubble instead of covering header and pin banner - Same placement for post cards and scheduled messages; the ... menu hangs under its button and the toolbar stays put Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -35,6 +35,7 @@ use super::message_actions::{Action, MessageMenu, QUICK_REACTION_COUNT};
35
35
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
36
36
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};
37
37
use super::post_card::render_post;
38
use super::toolbar_placement::{TimelineBounds, record_bounds};
38
39
use super::profile_card::opens_profile;
39
40
use super::reaction_picker::{PickHandler, ReactionPicker};
40
41
use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -167,6 +168,7 @@ pub struct ConversationView {
167
168
downloads: Downloads,
168
169
hovered_message: Option<String>,
169
170
toolbar_hovered: Option<String>,
171
timeline_bounds: TimelineBounds,
170
172
toolbar_pinned: Option<String>,
171
173
toolbar_suppressed: Option<String>,
172
174
recent: Entity<emoji::Recent>,
@@ -467,6 +469,7 @@ impl ConversationView {
467
469
downloads: Downloads::default(),
468
470
hovered_message: None,
469
471
toolbar_hovered: None,
472
timeline_bounds: TimelineBounds::default(),
470
473
toolbar_pinned: None,
471
474
toolbar_suppressed: None,
472
475
recent,
@@ -3098,6 +3101,7 @@ impl Render for ConversationView {
3098
3101
highlighted: self.highlighted_message.clone(),
3099
3102
drafting,
3100
3103
reply_editor: self.reply_root.clone().zip(self.reply_composer.clone()),
3104
timeline: self.timeline_bounds.clone(),
3101
3105
};
3102
3106
let scroller = MessageScroller::new(
3103
3107
"messages",
@@ -3233,8 +3237,10 @@ impl Render for ConversationView {
3233
3237
.children(new_post)
3234
3238
.child(
3235
3239
div()
3240
.relative()
3236
3241
.flex_1()
3237
3242
.min_h_0()
3243
.child(record_bounds(&self.timeline_bounds))
3238
3244
.on_scroll_wheel(
3239
3245
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3240
3246
)
@@ -35,6 +35,7 @@ use super::message_actions::{Action, MessageMenu, QUICK_REACTION_COUNT};35
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};35
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};36
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};36
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};37
use super::post_card::render_post;37
use super::post_card::render_post;38
use super::toolbar_placement::{TimelineBounds, record_bounds};38
use super::profile_card::opens_profile;39
use super::profile_card::opens_profile;39
use super::reaction_picker::{PickHandler, ReactionPicker};40
use super::reaction_picker::{PickHandler, ReactionPicker};40
use super::reaction_pills::{ReactionControls, ReactionPopover};41
use super::reaction_pills::{ReactionControls, ReactionPopover};@@ -167,6 +168,7 @@ pub struct ConversationView {167
downloads: Downloads,168
downloads: Downloads,168
hovered_message: Option<String>,169
hovered_message: Option<String>,169
toolbar_hovered: Option<String>,170
toolbar_hovered: Option<String>,171
timeline_bounds: TimelineBounds,170
toolbar_pinned: Option<String>,172
toolbar_pinned: Option<String>,171
toolbar_suppressed: Option<String>,173
toolbar_suppressed: Option<String>,172
recent: Entity<emoji::Recent>,174
recent: Entity<emoji::Recent>,@@ -467,6 +469,7 @@ impl ConversationView {467
downloads: Downloads::default(),469
downloads: Downloads::default(),468
hovered_message: None,470
hovered_message: None,469
toolbar_hovered: None,471
toolbar_hovered: None,472
timeline_bounds: TimelineBounds::default(),470
toolbar_pinned: None,473
toolbar_pinned: None,471
toolbar_suppressed: None,474
toolbar_suppressed: None,472
recent,475
recent,@@ -3098,6 +3101,7 @@ impl Render for ConversationView {3098
highlighted: self.highlighted_message.clone(),3101
highlighted: self.highlighted_message.clone(),3099
drafting,3102
drafting,3100
reply_editor: self.reply_root.clone().zip(self.reply_composer.clone()),3103
reply_editor: self.reply_root.clone().zip(self.reply_composer.clone()),3104
timeline: self.timeline_bounds.clone(),3101
};3105
};3102
let scroller = MessageScroller::new(3106
let scroller = MessageScroller::new(3103
"messages",3107
"messages",@@ -3233,8 +3237,10 @@ impl Render for ConversationView {3233
.children(new_post)3237
.children(new_post)3234
.child(3238
.child(3235
div()3239
div()3240
.relative()3236
.flex_1()3241
.flex_1()3237
.min_h_0()3242
.min_h_0()3243
.child(record_bounds(&self.timeline_bounds))3238
.on_scroll_wheel(3244
.on_scroll_wheel(3239
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),3245
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),3240
)3246
)@@ -17,6 +17,7 @@ use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
17
17
use crate::views::composer::Composer;
18
18
use crate::views::message_row::{DeliveryActions, RowActions};
19
19
use crate::views::post_card::{PostAction, PostActions};
20
use crate::views::toolbar_placement::TimelineBounds;
20
21
use crate::views::translation_line::{LineAction, TranslationActions};
21
22
22
23
pub(super) struct RenderEnv {
@@ -25,6 +26,7 @@ pub(super) struct RenderEnv {
25
26
pub highlighted: Option<String>,
26
27
pub drafting: bool,
27
28
pub reply_editor: Option<(String, Entity<Composer>)>,
29
pub timeline: TimelineBounds,
28
30
}
29
31
30
32
fn boxed(action: impl Fn(&mut App) + 'static) -> Box<dyn Fn(&mut App)> {
@@ -237,6 +239,7 @@ impl RenderEnv {
237
239
.read(cx)
238
240
.is_saved(&message.conversation_id, &message.key),
239
241
translation,
242
timeline: self.timeline.clone(),
240
243
}
241
244
}
242
245
@@ -17,6 +17,7 @@ use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};17
use crate::views::composer::Composer;17
use crate::views::composer::Composer;18
use crate::views::message_row::{DeliveryActions, RowActions};18
use crate::views::message_row::{DeliveryActions, RowActions};19
use crate::views::post_card::{PostAction, PostActions};19
use crate::views::post_card::{PostAction, PostActions};20
use crate::views::toolbar_placement::TimelineBounds;20
use crate::views::translation_line::{LineAction, TranslationActions};21
use crate::views::translation_line::{LineAction, TranslationActions};21
22
22
pub(super) struct RenderEnv {23
pub(super) struct RenderEnv {@@ -25,6 +26,7 @@ pub(super) struct RenderEnv {25
pub highlighted: Option<String>,26
pub highlighted: Option<String>,26
pub drafting: bool,27
pub drafting: bool,27
pub reply_editor: Option<(String, Entity<Composer>)>,28
pub reply_editor: Option<(String, Entity<Composer>)>,29
pub timeline: TimelineBounds,28
}30
}29
31
30
fn boxed(action: impl Fn(&mut App) + 'static) -> Box<dyn Fn(&mut App)> {32
fn boxed(action: impl Fn(&mut App) + 'static) -> Box<dyn Fn(&mut App)> {@@ -237,6 +239,7 @@ impl RenderEnv {237
.read(cx)239
.read(cx)238
.is_saved(&message.conversation_id, &message.key),240
.is_saved(&message.conversation_id, &message.key),239
translation,241
translation,242
timeline: self.timeline.clone(),240
}243
}241
}244
}242
245
@@ -13,6 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _;
13
13
use gpui_kit::*;
14
14
15
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};
16
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};
16
17
use super::widgets::icon;
17
18
use crate::rows::reaction_glyph;
18
19
use crate::theme;
@@ -236,19 +237,16 @@ pub fn message_toolbar(menu: MessageMenu, cx: &App) -> AnyElement {
236
237
);
237
238
}
238
239
children.push(more_button(&menu, cx));
239
h_flex()
240
.id(element_id("message-toolbar", &menu.key))
241
.h(px(BAR_BUTTON + 2. * BAR_PADDING))
240
let bar = h_flex()
241
.h(px(TOOLBAR_HEIGHT))
242
242
.p(px(BAR_PADDING))
243
243
.gap(px(1.))
244
244
.items_center()
245
245
.rounded(px(10.))
246
246
.bg(theme::popup())
247
.occlude()
248
.on_hover(move |hovered, _, cx| hover(*hovered, cx))
249
247
.on_mouse_down(MouseButton::Left, |_, _, cx| {
250
248
GlobalState::suppress_text_selection(cx)
251
249
})
252
.children(children)
253
.into_any_element()
250
.children(children);
251
toolbar_slot(element_id("message-toolbar", &menu.key), hover, bar).into_any_element()
254
252
}
@@ -13,6 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _;13
use gpui_kit::*;13
use gpui_kit::*;14
14
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};16
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};16
use super::widgets::icon;17
use super::widgets::icon;17
use crate::rows::reaction_glyph;18
use crate::rows::reaction_glyph;18
use crate::theme;19
use crate::theme;@@ -236,19 +237,16 @@ pub fn message_toolbar(menu: MessageMenu, cx: &App) -> AnyElement {236
);237
);237
}238
}238
children.push(more_button(&menu, cx));239
children.push(more_button(&menu, cx));239
h_flex()240
let bar = h_flex()240
.id(element_id("message-toolbar", &menu.key))241
.h(px(TOOLBAR_HEIGHT))241
.h(px(BAR_BUTTON + 2. * BAR_PADDING))242
.p(px(BAR_PADDING))242
.p(px(BAR_PADDING))243
.gap(px(1.))243
.gap(px(1.))244
.items_center()244
.items_center()245
.rounded(px(10.))245
.rounded(px(10.))246
.bg(theme::popup())246
.bg(theme::popup())247
.occlude()248
.on_hover(move |hovered, _, cx| hover(*hovered, cx))249
.on_mouse_down(MouseButton::Left, |_, _, cx| {247
.on_mouse_down(MouseButton::Left, |_, _, cx| {250
GlobalState::suppress_text_selection(cx)248
GlobalState::suppress_text_selection(cx)251
})249
})252
.children(children)250
.children(children);253
.into_any_element()251
toolbar_slot(element_id("message-toolbar", &menu.key), hover, bar).into_any_element()254
}252
}@@ -13,6 +13,7 @@ use super::profile_card::opens_profile;
13
13
use super::reaction_picker::PickHandler;
14
14
use super::reaction_pills::{ReactionControls, reaction_pills};
15
15
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
16
use super::toolbar_placement::{TimelineBounds, placed_toolbar};
16
17
use super::translation_line::{TranslationActions, translation_line};
17
18
use super::widgets::{icon, symbol};
18
19
use crate::card_state::BotIdentity;
@@ -58,9 +59,10 @@ pub struct RowActions {
58
59
pub highlighted: bool,
59
60
pub saved: bool,
60
61
pub translation: Option<TranslationActions>,
62
pub timeline: TimelineBounds,
61
63
}
62
64
63
const TOOLBAR_LIFT: f32 = 22.;
65
const TOOLBAR_RIGHT_INSET: f32 = 0.;
64
66
65
67
fn separator_pill(label: &str, fill: Hsla, text_color: Hsla) -> Div {
66
68
h_flex().w_full().justify_center().mt(px(12.)).mb(px(6.)).child(
@@ -234,22 +236,18 @@ fn bubble(
234
236
);
235
237
}
236
238
if let Some(menu) = extras.menu {
237
element = element.child(
238
div()
239
.absolute()
240
.top(px(-TOOLBAR_LIFT))
241
.right(px(8.))
242
.child(deferred(message_toolbar(menu, cx)).with_priority(1)),
243
);
239
element = element.child(placed_toolbar(
240
message_toolbar(menu, cx),
241
extras.timeline.clone(),
242
TOOLBAR_RIGHT_INSET,
243
));
244
244
}
245
245
if let Some(menu) = extras.scheduled_menu {
246
element = element.child(
247
div()
248
.absolute()
249
.top(px(-TOOLBAR_LIFT))
250
.right(px(8.))
251
.child(deferred(scheduled_toolbar(menu)).with_priority(1)),
252
);
246
element = element.child(placed_toolbar(
247
scheduled_toolbar(menu),
248
extras.timeline.clone(),
249
TOOLBAR_RIGHT_INSET,
250
));
253
251
}
254
252
element
255
253
}
@@ -265,6 +263,7 @@ struct BubbleExtras {
265
263
open_image: Option<ImageOpen>,
266
264
saved: bool,
267
265
translation: Option<TranslationActions>,
266
timeline: TimelineBounds,
268
267
}
269
268
270
269
pub(super) fn forwarded_header() -> Div {
@@ -568,6 +567,7 @@ pub fn render_message_row(
568
567
highlighted,
569
568
saved,
570
569
translation,
570
timeline,
571
571
} = actions;
572
572
let extras = BubbleExtras {
573
573
hover: hovered,
@@ -579,6 +579,7 @@ pub fn render_message_row(
579
579
open_image,
580
580
saved,
581
581
translation,
582
timeline,
582
583
};
583
584
let own = row.own;
584
585
let spacing = if row.series.has_prev {
@@ -13,6 +13,7 @@ use super::profile_card::opens_profile;13
use super::reaction_picker::PickHandler;13
use super::reaction_picker::PickHandler;14
use super::reaction_pills::{ReactionControls, reaction_pills};14
use super::reaction_pills::{ReactionControls, reaction_pills};15
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};15
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};16
use super::toolbar_placement::{TimelineBounds, placed_toolbar};16
use super::translation_line::{TranslationActions, translation_line};17
use super::translation_line::{TranslationActions, translation_line};17
use super::widgets::{icon, symbol};18
use super::widgets::{icon, symbol};18
use crate::card_state::BotIdentity;19
use crate::card_state::BotIdentity;@@ -58,9 +59,10 @@ pub struct RowActions {58
pub highlighted: bool,59
pub highlighted: bool,59
pub saved: bool,60
pub saved: bool,60
pub translation: Option<TranslationActions>,61
pub translation: Option<TranslationActions>,62
pub timeline: TimelineBounds,61
}63
}62
64
63
const TOOLBAR_LIFT: f32 = 22.;65
const TOOLBAR_RIGHT_INSET: f32 = 0.;64
66
65
fn separator_pill(label: &str, fill: Hsla, text_color: Hsla) -> Div {67
fn separator_pill(label: &str, fill: Hsla, text_color: Hsla) -> Div {66
h_flex().w_full().justify_center().mt(px(12.)).mb(px(6.)).child(68
h_flex().w_full().justify_center().mt(px(12.)).mb(px(6.)).child(@@ -234,22 +236,18 @@ fn bubble(234
);236
);235
}237
}236
if let Some(menu) = extras.menu {238
if let Some(menu) = extras.menu {237
element = element.child(239
element = element.child(placed_toolbar(238
div()240
message_toolbar(menu, cx),239
.absolute()241
extras.timeline.clone(),240
.top(px(-TOOLBAR_LIFT))242
TOOLBAR_RIGHT_INSET,241
.right(px(8.))243
));242
.child(deferred(message_toolbar(menu, cx)).with_priority(1)),243
);244
}244
}245
if let Some(menu) = extras.scheduled_menu {245
if let Some(menu) = extras.scheduled_menu {246
element = element.child(246
element = element.child(placed_toolbar(247
div()247
scheduled_toolbar(menu),248
.absolute()248
extras.timeline.clone(),249
.top(px(-TOOLBAR_LIFT))249
TOOLBAR_RIGHT_INSET,250
.right(px(8.))250
));251
.child(deferred(scheduled_toolbar(menu)).with_priority(1)),252
);253
}251
}254
element252
element255
}253
}@@ -265,6 +263,7 @@ struct BubbleExtras {265
open_image: Option<ImageOpen>,263
open_image: Option<ImageOpen>,266
saved: bool,264
saved: bool,267
translation: Option<TranslationActions>,265
translation: Option<TranslationActions>,266
timeline: TimelineBounds,268
}267
}269
268
270
pub(super) fn forwarded_header() -> Div {269
pub(super) fn forwarded_header() -> Div {@@ -568,6 +567,7 @@ pub fn render_message_row(568
highlighted,567
highlighted,569
saved,568
saved,570
translation,569
translation,570
timeline,571
} = actions;571
} = actions;572
let extras = BubbleExtras {572
let extras = BubbleExtras {573
hover: hovered,573
hover: hovered,@@ -579,6 +579,7 @@ pub fn render_message_row(579
open_image,579
open_image,580
saved,580
saved,581
translation,581
translation,582
timeline,582
};583
};583
let own = row.own;584
let own = row.own;584
let spacing = if row.series.has_prev {585
let spacing = if row.series.has_prev {@@ -43,6 +43,7 @@ pub mod reaction_picker;
43
43
pub mod reaction_pills;
44
44
pub mod saved_panel;
45
45
pub mod scheduled_toolbar;
46
pub mod toolbar_placement;
46
47
pub mod share_bar;
47
48
pub mod shared_tab;
48
49
pub mod shell;
@@ -43,6 +43,7 @@ pub mod reaction_picker;43
pub mod reaction_pills;43
pub mod reaction_pills;44
pub mod saved_panel;44
pub mod saved_panel;45
pub mod scheduled_toolbar;45
pub mod scheduled_toolbar;46
pub mod toolbar_placement;46
pub mod share_bar;47
pub mod share_bar;47
pub mod shared_tab;48
pub mod shared_tab;48
pub mod shell;49
pub mod shell;@@ -12,6 +12,7 @@ use super::message_actions::message_toolbar;
12
12
use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};
13
13
use super::reaction_pills::reaction_pills;
14
14
use super::scheduled_toolbar::scheduled_toolbar;
15
use super::toolbar_placement::placed_toolbar;
15
16
use super::translation_line::translation_line;
16
17
use super::widgets::{icon, symbol};
17
18
use crate::data::Directory;
@@ -26,7 +27,7 @@ const CARD_PADDING: f32 = 12.;
26
27
const CARD_RADIUS: f32 = 10.;
27
28
const CARD_GAP: f32 = 12.;
28
29
const SLOTS_PER_POST: usize = 64;
29
const TOOLBAR_LIFT: f32 = 22.;
30
const TOOLBAR_RIGHT_INSET: f32 = 8.;
30
31
const SUBJECT_SIZE: f32 = 14.;
31
32
32
33
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;
@@ -206,6 +207,7 @@ fn message_block(
206
207
scheduled_menu,
207
208
highlighted,
208
209
translation: translation_actions,
210
timeline,
209
211
..
210
212
} = actions;
211
213
let note = delivery_note(row, delivery, index);
@@ -263,22 +265,18 @@ fn message_block(
263
265
.child(body),
264
266
)
265
267
.when_some(menu, |block, menu| {
266
block.child(
267
div()
268
.absolute()
269
.top(px(-TOOLBAR_LIFT))
270
.right(px(8.))
271
.child(deferred(message_toolbar(menu, cx)).with_priority(1)),
272
)
268
block.child(placed_toolbar(
269
message_toolbar(menu, cx),
270
timeline.clone(),
271
TOOLBAR_RIGHT_INSET,
272
))
273
273
})
274
274
.when_some(scheduled_menu, |block, menu| {
275
block.child(
276
div()
277
.absolute()
278
.top(px(-TOOLBAR_LIFT))
279
.right(px(8.))
280
.child(deferred(scheduled_toolbar(menu)).with_priority(1)),
281
)
275
block.child(placed_toolbar(
276
scheduled_toolbar(menu),
277
timeline.clone(),
278
TOOLBAR_RIGHT_INSET,
279
))
282
280
})
283
281
}
284
282
@@ -12,6 +12,7 @@ use super::message_actions::message_toolbar;12
use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};12
use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};13
use super::reaction_pills::reaction_pills;13
use super::reaction_pills::reaction_pills;14
use super::scheduled_toolbar::scheduled_toolbar;14
use super::scheduled_toolbar::scheduled_toolbar;15
use super::toolbar_placement::placed_toolbar;15
use super::translation_line::translation_line;16
use super::translation_line::translation_line;16
use super::widgets::{icon, symbol};17
use super::widgets::{icon, symbol};17
use crate::data::Directory;18
use crate::data::Directory;@@ -26,7 +27,7 @@ const CARD_PADDING: f32 = 12.;26
const CARD_RADIUS: f32 = 10.;27
const CARD_RADIUS: f32 = 10.;27
const CARD_GAP: f32 = 12.;28
const CARD_GAP: f32 = 12.;28
const SLOTS_PER_POST: usize = 64;29
const SLOTS_PER_POST: usize = 64;29
const TOOLBAR_LIFT: f32 = 22.;30
const TOOLBAR_RIGHT_INSET: f32 = 8.;30
const SUBJECT_SIZE: f32 = 14.;31
const SUBJECT_SIZE: f32 = 14.;31
32
32
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;33
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;@@ -206,6 +207,7 @@ fn message_block(206
scheduled_menu,207
scheduled_menu,207
highlighted,208
highlighted,208
translation: translation_actions,209
translation: translation_actions,210
timeline,209
..211
..210
} = actions;212
} = actions;211
let note = delivery_note(row, delivery, index);213
let note = delivery_note(row, delivery, index);@@ -263,22 +265,18 @@ fn message_block(263
.child(body),265
.child(body),264
)266
)265
.when_some(menu, |block, menu| {267
.when_some(menu, |block, menu| {266
block.child(268
block.child(placed_toolbar(267
div()269
message_toolbar(menu, cx),268
.absolute()270
timeline.clone(),269
.top(px(-TOOLBAR_LIFT))271
TOOLBAR_RIGHT_INSET,270
.right(px(8.))272
))271
.child(deferred(message_toolbar(menu, cx)).with_priority(1)),272
)273
})273
})274
.when_some(scheduled_menu, |block, menu| {274
.when_some(scheduled_menu, |block, menu| {275
block.child(275
block.child(placed_toolbar(276
div()276
scheduled_toolbar(menu),277
.absolute()277
timeline.clone(),278
.top(px(-TOOLBAR_LIFT))278
TOOLBAR_RIGHT_INSET,279
.right(px(8.))279
))280
.child(deferred(scheduled_toolbar(menu)).with_priority(1)),281
)282
})280
})283
}281
}284
282
@@ -4,6 +4,7 @@ use gpui_kit::component::h_flex;
4
4
use gpui_kit::*;
5
5
6
6
use super::message_actions::{Action, HoverChange, bar_button};
7
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};
7
8
use super::widgets::icon;
8
9
use crate::theme;
9
10
@@ -36,16 +37,13 @@ pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement {
36
37
delete,
37
38
hover,
38
39
} = menu;
39
h_flex()
40
.id(element_id("scheduled-toolbar", &key))
41
.h(px(36.))
40
let bar = h_flex()
41
.h(px(TOOLBAR_HEIGHT))
42
42
.p(px(3.))
43
43
.gap(px(1.))
44
44
.items_center()
45
45
.rounded(px(10.))
46
46
.bg(theme::popup())
47
.occlude()
48
.on_hover(move |hovered, _, cx| hover(*hovered, cx))
49
47
.on_mouse_down(MouseButton::Left, |_, _, cx| {
50
48
GlobalState::suppress_text_selection(cx)
51
49
})
@@ -72,6 +70,6 @@ pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement {
72
70
cx.stop_propagation();
73
71
delete(window, cx);
74
72
}),
75
)
76
.into_any_element()
73
);
74
toolbar_slot(element_id("scheduled-toolbar", &key), hover, bar).into_any_element()
77
75
}
@@ -4,6 +4,7 @@ use gpui_kit::component::h_flex;4
use gpui_kit::*;4
use gpui_kit::*;5
5
6
use super::message_actions::{Action, HoverChange, bar_button};6
use super::message_actions::{Action, HoverChange, bar_button};7
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};7
use super::widgets::icon;8
use super::widgets::icon;8
use crate::theme;9
use crate::theme;9
10
@@ -36,16 +37,13 @@ pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement {36
delete,37
delete,37
hover,38
hover,38
} = menu;39
} = menu;39
h_flex()40
let bar = h_flex()40
.id(element_id("scheduled-toolbar", &key))41
.h(px(TOOLBAR_HEIGHT))41
.h(px(36.))42
.p(px(3.))42
.p(px(3.))43
.gap(px(1.))43
.gap(px(1.))44
.items_center()44
.items_center()45
.rounded(px(10.))45
.rounded(px(10.))46
.bg(theme::popup())46
.bg(theme::popup())47
.occlude()48
.on_hover(move |hovered, _, cx| hover(*hovered, cx))49
.on_mouse_down(MouseButton::Left, |_, _, cx| {47
.on_mouse_down(MouseButton::Left, |_, _, cx| {50
GlobalState::suppress_text_selection(cx)48
GlobalState::suppress_text_selection(cx)51
})49
})@@ -72,6 +70,6 @@ pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement {72
cx.stop_propagation();70
cx.stop_propagation();73
delete(window, cx);71
delete(window, cx);74
}),72
}),75
)73
);76
.into_any_element()74
toolbar_slot(element_id("scheduled-toolbar", &key), hover, bar).into_any_element()77
}75
}@@ -0,0 +1,128 @@
1
use std::cell::Cell;
2
use std::rc::Rc;
3
4
use gpui_kit::*;
5
6
use super::message_actions::HoverChange;
7
8
pub type TimelineBounds = Rc<Cell<Option<Bounds<Pixels>>>>;
9
10
pub const TOOLBAR_HEIGHT: f32 = 36.;
11
const TOOLBAR_GAP: f32 = 4.;
12
const SLOT_HEIGHT: f32 = TOOLBAR_HEIGHT + 2. * TOOLBAR_GAP;
13
14
pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) -> Stateful<Div> {
15
div()
16
.id(id)
17
.py(px(TOOLBAR_GAP))
18
.occlude()
19
.on_hover(move |hovered, _, cx| hover(*hovered, cx))
20
.child(bar)
21
}
22
23
pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {
24
let timeline = timeline.clone();
25
canvas(
26
move |bounds, _, _| timeline.set(Some(bounds)),
27
|_, _, _, _| {},
28
)
29
.absolute()
30
.top_0()
31
.left_0()
32
.size_full()
33
}
34
35
pub fn placed_toolbar(
36
toolbar: impl IntoElement,
37
timeline: TimelineBounds,
38
right_inset: f32,
39
) -> impl IntoElement {
40
PlacedToolbar {
41
timeline,
42
overlay: div()
43
.absolute()
44
.top_0()
45
.left_0()
46
.size_full()
47
.child(
48
div()
49
.absolute()
50
.top(px(-SLOT_HEIGHT))
51
.right(px(right_inset))
52
.child(deferred(toolbar).with_priority(1)),
53
)
54
.into_any_element(),
55
}
56
}
57
58
struct PlacedToolbar {
59
timeline: TimelineBounds,
60
overlay: AnyElement,
61
}
62
63
impl PlacedToolbar {
64
fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {
65
let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);
66
match self.timeline.get() {
67
Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),
68
_ => px(0.),
69
}
70
}
71
}
72
73
impl Element for PlacedToolbar {
74
type RequestLayoutState = ();
75
type PrepaintState = ();
76
77
fn id(&self) -> Option<ElementId> {
78
None
79
}
80
81
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
82
None
83
}
84
85
fn request_layout(
86
&mut self,
87
_id: Option<&GlobalElementId>,
88
_inspector_id: Option<&InspectorElementId>,
89
window: &mut Window,
90
cx: &mut App,
91
) -> (LayoutId, ()) {
92
(self.overlay.request_layout(window, cx), ())
93
}
94
95
fn prepaint(
96
&mut self,
97
_id: Option<&GlobalElementId>,
98
_inspector_id: Option<&InspectorElementId>,
99
bounds: Bounds<Pixels>,
100
_request_layout: &mut (),
101
window: &mut Window,
102
cx: &mut App,
103
) {
104
let offset = point(px(0.), self.flip_offset(bounds));
105
window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));
106
}
107
108
fn paint(
109
&mut self,
110
_id: Option<&GlobalElementId>,
111
_inspector_id: Option<&InspectorElementId>,
112
_bounds: Bounds<Pixels>,
113
_request_layout: &mut (),
114
_prepaint: &mut (),
115
window: &mut Window,
116
cx: &mut App,
117
) {
118
self.overlay.paint(window, cx);
119
}
120
}
121
122
impl IntoElement for PlacedToolbar {
123
type Element = Self;
124
125
fn into_element(self) -> Self::Element {
126
self
127
}
128
}
@@ -0,0 +1,128 @@1
use std::cell::Cell;2
use std::rc::Rc;3
4
use gpui_kit::*;5
6
use super::message_actions::HoverChange;7
8
pub type TimelineBounds = Rc<Cell<Option<Bounds<Pixels>>>>;9
10
pub const TOOLBAR_HEIGHT: f32 = 36.;11
const TOOLBAR_GAP: f32 = 4.;12
const SLOT_HEIGHT: f32 = TOOLBAR_HEIGHT + 2. * TOOLBAR_GAP;13
14
pub fn toolbar_slot(id: ElementId, hover: HoverChange, bar: impl IntoElement) -> Stateful<Div> {15
div()16
.id(id)17
.py(px(TOOLBAR_GAP))18
.occlude()19
.on_hover(move |hovered, _, cx| hover(*hovered, cx))20
.child(bar)21
}22
23
pub fn record_bounds(timeline: &TimelineBounds) -> impl IntoElement {24
let timeline = timeline.clone();25
canvas(26
move |bounds, _, _| timeline.set(Some(bounds)),27
|_, _, _, _| {},28
)29
.absolute()30
.top_0()31
.left_0()32
.size_full()33
}34
35
pub fn placed_toolbar(36
toolbar: impl IntoElement,37
timeline: TimelineBounds,38
right_inset: f32,39
) -> impl IntoElement {40
PlacedToolbar {41
timeline,42
overlay: div()43
.absolute()44
.top_0()45
.left_0()46
.size_full()47
.child(48
div()49
.absolute()50
.top(px(-SLOT_HEIGHT))51
.right(px(right_inset))52
.child(deferred(toolbar).with_priority(1)),53
)54
.into_any_element(),55
}56
}57
58
struct PlacedToolbar {59
timeline: TimelineBounds,60
overlay: AnyElement,61
}62
63
impl PlacedToolbar {64
fn flip_offset(&self, anchor: Bounds<Pixels>) -> Pixels {65
let bar_top = anchor.top() - px(SLOT_HEIGHT - TOOLBAR_GAP);66
match self.timeline.get() {67
Some(timeline) if bar_top < timeline.top() => anchor.size.height + px(SLOT_HEIGHT),68
_ => px(0.),69
}70
}71
}72
73
impl Element for PlacedToolbar {74
type RequestLayoutState = ();75
type PrepaintState = ();76
77
fn id(&self) -> Option<ElementId> {78
None79
}80
81
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {82
None83
}84
85
fn request_layout(86
&mut self,87
_id: Option<&GlobalElementId>,88
_inspector_id: Option<&InspectorElementId>,89
window: &mut Window,90
cx: &mut App,91
) -> (LayoutId, ()) {92
(self.overlay.request_layout(window, cx), ())93
}94
95
fn prepaint(96
&mut self,97
_id: Option<&GlobalElementId>,98
_inspector_id: Option<&InspectorElementId>,99
bounds: Bounds<Pixels>,100
_request_layout: &mut (),101
window: &mut Window,102
cx: &mut App,103
) {104
let offset = point(px(0.), self.flip_offset(bounds));105
window.with_element_offset(offset, |window| self.overlay.prepaint(window, cx));106
}107
108
fn paint(109
&mut self,110
_id: Option<&GlobalElementId>,111
_inspector_id: Option<&InspectorElementId>,112
_bounds: Bounds<Pixels>,113
_request_layout: &mut (),114
_prepaint: &mut (),115
window: &mut Window,116
cx: &mut App,117
) {118
self.overlay.paint(window, cx);119
}120
}121
122
impl IntoElement for PlacedToolbar {123
type Element = Self;124
125
fn into_element(self) -> Self::Element {126
self127
}128
}