Skip to content

Commit 60bb9a7

Browse files
committed
Update callout tooltip positioning to be visually nicer
Also, the widget's rectangle is no longer optional and has no default value, so it must be specified by every caller, which is more correct.
1 parent afeb0fb commit 60bb9a7

10 files changed

Lines changed: 170 additions & 132 deletions

src/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl MatchEvent for App {
342342

343343
// Handle actions for showing or hiding the tooltip.
344344
match action.as_widget_action().cast() {
345-
TooltipAction::HoverIn(text, callout_tooltip_options) => {
345+
TooltipAction::HoverIn { text, widget_rect, options } => {
346346
// Don't show any tooltips if the message context menu is currently shown.
347347
if self.ui.new_message_context_menu(ids!(new_message_context_menu)).is_currently_shown(cx) {
348348
self.ui.callout_tooltip(ids!(app_tooltip)).hide(cx);
@@ -351,7 +351,8 @@ impl MatchEvent for App {
351351
self.ui.callout_tooltip(ids!(app_tooltip)).show_with_options(
352352
cx,
353353
&text,
354-
callout_tooltip_options,
354+
widget_rect,
355+
options,
355356
);
356357
}
357358
continue;

src/home/edited_indicator.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use chrono::{DateTime, Local};
1111
use makepad_widgets::*;
1212
use matrix_sdk_ui::timeline::EventTimelineItem;
1313

14-
use crate::{shared::callout_tooltip::{CalloutTooltipOptions, TooltipAction}, utils::unix_time_millis_to_datetime};
14+
use crate::{shared::callout_tooltip::{CalloutTooltipOptions, TooltipAction, TooltipPosition}, utils::unix_time_millis_to_datetime};
1515

1616
live_design! {
1717
use link::theme::*;
@@ -84,10 +84,14 @@ impl Widget for EditedIndicator {
8484
cx.widget_action(
8585
self.widget_uid(),
8686
&scope.path,
87-
TooltipAction::HoverIn(text, CalloutTooltipOptions {
87+
TooltipAction::HoverIn {
88+
text,
8889
widget_rect: area.rect(cx),
89-
..Default::default()
90-
}),
90+
options: CalloutTooltipOptions {
91+
position: TooltipPosition::Right,
92+
..Default::default()
93+
}
94+
},
9195
);
9296
}
9397
}

src/home/event_reaction_list.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ impl ReactionList {
217217
&scope.path,
218218
RoomScreenTooltipActions::HoverInReactionButton {
219219
widget_rect: button_ref.area().rect(cx),
220-
bg_color: None,
221220
reaction_data,
222221
},
223222
);
@@ -319,31 +318,25 @@ impl ReactionListRef {
319318
inner.timeline_event_id = Some(timeline_event_item_id);
320319
}
321320

322-
/// Handles hover in action and returns the appropriate `RoomScreenTooltipActions`.
321+
/// Returns any `RoomScreenTooltipActions` that occurred in the given list of `actions`.
323322
///
324323
/// This function checks if there is a widget action associated with the current
325-
/// widget's unique identifier in the provided `actions`. If an action exists,
326-
/// it is cast to `RoomScreenTooltipActions` and returned. Otherwise, it returns
327-
/// `RoomScreenTooltipActions::None`.
328-
///
329-
/// # Arguments
330-
///
331-
/// * `actions` - A reference to the `Actions` that may contain widget actions
332-
/// relevant to this widget.
333-
pub fn hover_in(&self, actions: &Actions) -> RoomScreenTooltipActions {
324+
/// widget's unique identifier in the provided `actions`.
325+
/// If an action exists, it is cast to `RoomScreenTooltipActions` and returned.
326+
/// Otherwise, it returns `RoomScreenTooltipActions::None`.
327+
pub fn hovered_in(&self, actions: &Actions) -> RoomScreenTooltipActions {
334328
if let Some(item) = actions.find_widget_action(self.widget_uid()) {
335329
item.cast()
336330
} else {
337331
RoomScreenTooltipActions::None
338332
}
339333
}
340-
/// Handles widget actions and returns `true` if the hover out action was found in the provided `actions`.
341-
/// Otherwise, returns `false`.
342-
pub fn hover_out(&self, actions: &Actions) -> bool {
334+
/// Returns whether the given `actions` contained a `RoomScreenTooltipActions::HoverOut` action.
335+
pub fn hovered_out(&self, actions: &Actions) -> bool {
343336
if let Some(item) = actions.find_widget_action(self.widget_uid()) {
344337
matches!(item.cast(), RoomScreenTooltipActions::HoverOut)
345338
} else {
346339
false
347340
}
348341
}
349-
}
342+
}

src/home/navigation_tab_bar.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::{
3939
user_profile_cache::{self, UserProfileUpdate},
4040
}, shared::{
4141
avatar::AvatarWidgetExt,
42-
callout_tooltip::{CalloutTooltipOptions, TooltipAction},
42+
callout_tooltip::{CalloutTooltipOptions, TooltipAction, TooltipPosition},
4343
styles::*,
4444
verification_badge::VerificationBadgeWidgetExt,
4545
}, sliding_sync::current_user_id, utils
@@ -367,15 +367,21 @@ impl Widget for ProfileIcon {
367367
|| format!("Not logged in.\n\n{}", verification_str),
368368
|p| format!("Logged in as \"{}\".\n\n{}", p.displayable_name(), verification_str)
369369
);
370-
let rect = area.rect(cx);
370+
let mut options = CalloutTooltipOptions {
371+
position: if cx.display_context.is_desktop() { TooltipPosition::Right} else { TooltipPosition::Top},
372+
..Default::default()
373+
};
374+
if let Some(c) = bg_color {
375+
options.bg_color = c;
376+
}
371377
cx.widget_action(
372378
self.widget_uid(),
373379
&scope.path,
374-
TooltipAction::HoverIn(text, CalloutTooltipOptions {
375-
widget_rect: rect,
376-
bg_color,
377-
..Default::default()
378-
}),
380+
TooltipAction::HoverIn {
381+
text,
382+
widget_rect: area.rect(cx),
383+
options,
384+
},
379385
);
380386
}
381387
Hit::FingerHoverOut(_) => {

src/home/room_read_receipt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ impl Widget for AvatarRow {
116116
&scope.path,
117117
RoomScreenTooltipActions::HoverInReadReceipt {
118118
widget_rect,
119-
bg_color: None,
120119
read_receipts: read_receipts.clone(),
121120
},
122121
);

src/home/room_screen.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,8 @@ impl Widget for RoomScreen {
606606
let reaction_list = wr.reaction_list(ids!(reaction_list));
607607
if let RoomScreenTooltipActions::HoverInReactionButton {
608608
widget_rect,
609-
bg_color,
610609
reaction_data,
611-
} = reaction_list.hover_in(actions) {
610+
} = reaction_list.hovered_in(actions) {
612611
let Some(_tl_state) = self.tl_state.as_ref() else { continue };
613612
let tooltip_text_arr: Vec<String> = reaction_data.reaction_senders.iter().map(|(sender, _react_info)| {
614613
user_profile_cache::get_user_profile_and_room_member(cx, sender.clone(), &reaction_data.room_id, true).0
@@ -620,40 +619,46 @@ impl Widget for RoomScreen {
620619
cx.widget_action(
621620
room_screen_widget_uid,
622621
&scope.path,
623-
TooltipAction::HoverIn(tooltip_text, CalloutTooltipOptions{
622+
TooltipAction::HoverIn {
623+
text: tooltip_text,
624624
widget_rect,
625-
bg_color,
626-
position: TooltipPosition::Bottom,
627-
..Default::default()
628-
})
625+
options: CalloutTooltipOptions {
626+
position: TooltipPosition::Bottom,
627+
..Default::default()
628+
},
629+
},
629630
);
630631
}
631-
if reaction_list.hover_out(actions) {
632+
633+
if reaction_list.hovered_out(actions) {
632634
cx.widget_action(
633635
room_screen_widget_uid,
634636
&scope.path,
635-
TooltipAction::HoverOut
637+
TooltipAction::HoverOut,
636638
);
637639
}
640+
638641
let avatar_row_ref = wr.avatar_row(ids!(avatar_row));
639642
if let RoomScreenTooltipActions::HoverInReadReceipt {
640643
widget_rect,
641-
bg_color,
642644
read_receipts
643645
} = avatar_row_ref.hover_in(actions) {
644646
let Some(room_id) = &self.room_id else { return; };
645647
let tooltip_text= room_read_receipt::populate_tooltip(cx, read_receipts, room_id);
646648
cx.widget_action(
647649
room_screen_widget_uid,
648650
&scope.path,
649-
TooltipAction::HoverIn(tooltip_text, CalloutTooltipOptions {
651+
TooltipAction::HoverIn {
652+
text: tooltip_text,
650653
widget_rect,
651-
bg_color,
652-
position: TooltipPosition::Bottom,
653-
..Default::default()
654-
})
654+
options: CalloutTooltipOptions {
655+
position: TooltipPosition::Left,
656+
..Default::default()
657+
},
658+
},
655659
);
656660
}
661+
657662
if avatar_row_ref.hover_out(actions) {
658663
cx.widget_action(
659664
room_screen_widget_uid,
@@ -2320,18 +2325,14 @@ pub enum RoomScreenTooltipActions {
23202325
HoverInReadReceipt {
23212326
/// The rect of the moused over widget
23222327
widget_rect: Rect,
2323-
/// Color of the background, default is black
2324-
bg_color: Option<Vec4>,
23252328
/// Includes the list of users who have seen this event
23262329
read_receipts: indexmap::IndexMap<matrix_sdk::ruma::OwnedUserId, Receipt>,
23272330
},
23282331
/// Mouse over event when the mouse is over the reaction button.
23292332
HoverInReactionButton {
2330-
/// The rect of the moused over widget
2333+
/// The rectangle (bounds) of the hovered-over widget.
23312334
widget_rect: Rect,
2332-
/// Color of the background, default is black
2333-
bg_color: Option<Vec4>,
2334-
/// Includes the list of users who have reacted to the emoji
2335+
/// Includes the list of users who have reacted to the emoji.
23352336
reaction_data: ReactionData,
23362337
},
23372338
/// Mouse out event and clear tooltip.

src/home/spaces_bar.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,18 @@ impl Widget for SpacesBarEntry {
274274
cx.widget_action(
275275
this.widget_uid(),
276276
&scope.path,
277-
TooltipAction::HoverIn(this.space_name.clone(), CalloutTooltipOptions {
277+
TooltipAction::HoverIn {
278+
text: this.space_name.clone(),
278279
widget_rect: area.rect(cx),
279-
position: if !is_desktop {
280-
TooltipPosition::Top
281-
} else {
282-
TooltipPosition::Bottom
280+
options: CalloutTooltipOptions {
281+
position: if is_desktop {
282+
TooltipPosition::Right
283+
} else {
284+
TooltipPosition::Top
285+
},
286+
..Default::default()
283287
},
284-
..Default::default()
285-
}),
288+
},
286289
);
287290
};
288291

0 commit comments

Comments
 (0)