From bc19f969d5a683540f7df87ea45f8d2905f66791 Mon Sep 17 00:00:00 2001 From: alanpoon Date: Tue, 10 Dec 2024 16:57:29 +0800 Subject: [PATCH] consistent roomscreentooltipActions --- src/home/event_reaction.rs | 17 ++++++----------- src/home/room_screen.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/home/event_reaction.rs b/src/home/event_reaction.rs index 45c5682..98689dc 100644 --- a/src/home/event_reaction.rs +++ b/src/home/event_reaction.rs @@ -3,6 +3,8 @@ use makepad_widgets::*; use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId}; use matrix_sdk_ui::timeline::{ReactionsByKeyBySender, TimelineEventItemId}; use crate::profile::user_profile_cache::get_user_profile; +use crate::home::room_screen::RoomScreenTooltipActions; + live_design! { import makepad_widgets::base::*; import makepad_widgets::theme_desktop_dark::*; @@ -270,13 +272,13 @@ impl Widget for ReactionList { if !widget_ref.area().rect(cx).contains(e.abs) { if self.event_reaction_list.get(id.0 as usize).is_some() { reset_tooltip_state = true; - cx.widget_action(uid, &scope.path, ReactionListAction::HoverOut); + cx.widget_action(uid, &scope.path, RoomScreenTooltipActions::HoverOut); } } }); // If the mouse does not leave this particular reaction button, post a HoverIn action if !reset_tooltip_state { - cx.widget_action(uid, &scope.path, ReactionListAction::HoverIn(*tooltip_area, tooltip_text.clone())); + cx.widget_action(uid, &scope.path, RoomScreenTooltipActions::HoverIn(*tooltip_area, tooltip_text.clone())); } } if reset_tooltip_state { @@ -373,7 +375,7 @@ impl ReactionListRef { pub fn hover_in(&self, actions: &Actions) -> Option<(Rect, String)> { if let Some(item) = actions.find_widget_action(self.widget_uid()) { match item.cast() { - ReactionListAction::HoverIn(rect, tooltip_text) => Some((rect, tooltip_text)), + RoomScreenTooltipActions::HoverIn(rect, tooltip_text) => Some((rect, tooltip_text)), _ => None, } } else { @@ -383,7 +385,7 @@ impl ReactionListRef { /// Handles hover out action pub fn hover_out(&self, actions: &Actions) -> bool { if let Some(item) = actions.find_widget_action(self.widget_uid()) { - matches!(item.cast(), ReactionListAction::HoverOut) + matches!(item.cast(), RoomScreenTooltipActions::HoverOut) } else { false } @@ -408,11 +410,4 @@ fn human_readable_list(names: Vec) -> String { format!("{}, and {}", rest.join(", "), last) } } -} -#[derive(Clone, Debug, DefaultNone)] -pub enum ReactionListAction { - // Tooltip Position and tooltip text to display - HoverIn(Rect, String), - HoverOut, - None, } \ No newline at end of file diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 2a77847..54f32e1 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -2139,6 +2139,18 @@ impl RoomScreenRef { } } +/// Actions for the room screen's tooltip +#[derive(Clone, Debug, DefaultNone)] +pub enum RoomScreenTooltipActions { + // Mouse over event when the mouse is over the reaction button + // First parameter is rect containing tooltip position and its size + // Todo! implement tooltip resizing + // The second parameter is tooltip text + HoverIn(Rect, String), + HoverOut, + None, +} + /// A message that is sent from a background async task to a room's timeline view /// for the purpose of update the Timeline UI contents or metadata. pub enum TimelineUpdate {