Skip to content

Commit

Permalink
consistent roomscreentooltipActions
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoon committed Dec 10, 2024
1 parent 33a2437 commit bc19f96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/home/event_reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -408,11 +410,4 @@ fn human_readable_list(names: Vec<String>) -> 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,
}
12 changes: 12 additions & 0 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bc19f96

Please sign in to comment.