Skip to content

Commit

Permalink
remove hide for first draw in event_reaction_list
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoon committed Jan 3, 2025
1 parent b261b5d commit 84d5e51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
34 changes: 14 additions & 20 deletions src/home/event_reaction_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ live_design! {
instance border_width: 1.5
instance border_color: (#001A11)
instance radius: 3.0
// The first draw is to get the width of the button, so that we can use it in the second draw
// If hide >= 0.5, the button is hidden.
// Without hiding, the buttons layout may appear glitched at the start
instance hide: 0.0
fn get_color(self) -> vec4 {
return mix(self.color, mix(self.color, self.color_hover, 0.2), self.hover)
}

fn pixel(self) -> vec4 {
let sdf = Sdf2d::viewport(self.pos * self.rect_size)
if self.hide >= 0.5 {
return sdf.result;
}
sdf.box(
self.border_width,
self.border_width,
Expand Down Expand Up @@ -135,14 +128,13 @@ impl Widget for ReactionList {
// Renders Grey button for reaction that does not include client user.
let node_to_apply = if reaction_data.includes_user {
live! {
draw_bg: { hide: 0.0 , color: (EMOJI_BG_COLOR_INCLUDE_SELF) }
draw_bg: { color: (EMOJI_BG_COLOR_INCLUDE_SELF) }
}
} else {
live! {
draw_bg: { hide: 0.0, color: (EMOJI_BG_COLOR_NOT_INCLUDE_SELF) }
draw_bg: { color: (EMOJI_BG_COLOR_NOT_INCLUDE_SELF) }
}
};
// Unhide the button as we have the width of the buttons
target.apply_over(
cx,
node_to_apply
Expand All @@ -159,13 +151,13 @@ impl Widget for ReactionList {
let Some(timeline_event_id) = &self.timeline_event_id else {
return;
};
// Apply mouse-in tooltip effect on the reaction buttons
// Apply mouse-in tooltip effect on the reaction buttons.
// Currently handling mouse-in effect using "event.hits(cx, widget_ref.area())" does not work.
if let Event::MouseMove(e) = event {
let uid = self.widget_uid();
if self.tooltip_state.is_none() {
for (id, widget_ref) in self.children.iter() {
// Widget.handle_event here does not cause the button to be highlighted when mouse over
// Widget.handle_event here does not cause the button to be highlighted when mouse over.
// To make the button highlighted when mouse over, the iteration over the children needs to be done
// outside Event::MouseMove.
let widget_rect = widget_ref.area().rect(cx);
Expand All @@ -175,8 +167,9 @@ impl Widget for ReactionList {
x: widget_rect.pos.x + widget_rect.size.x,
y: widget_rect.pos.y - widget_rect.size.y / 2.0
};
// Stores the event_reaction_list index together with the tooltip area and tooltip text into tooltip state
// The index will be used later to reset the tooltip state if the mouse leaves this particular reaction button
// Stores the event_reaction_list index together with the tooltip area and tooltip text into tooltip state.
// The index will be used later to reset the tooltip state if the mouse leaves this particular reaction
// button.
self.tooltip_state = Some((id.0, RoomScreenTooltipActions::HoverIn {
tooltip_pos,
tooltip_text: reaction_data.tooltip_text.clone(),
Expand All @@ -188,12 +181,13 @@ impl Widget for ReactionList {
}
} else {
let mut reset_tooltip_state = false;
if let Some((ref index, hover_in_data)) = &self.tooltip_state {
if let Some((ref index, tooltip_actions)) = &self.tooltip_state {
self.children
.iter()
.for_each(|(id, widget_ref)| {
// Search for the children with the same index as the tooltip state and check if the mouse leaves this particular reaction button
// If so, post a HoverOut action to make the tooltip disable
// Search for the children with the same index as the tooltip state
// and check if the mouse leaves this particular reaction button.
// If so, post a HoverOut action to make the tooltip disappear.
if id.0 != *index {
return;
}
Expand All @@ -204,9 +198,9 @@ impl Widget for ReactionList {
}
}
});
// If the mouse does not leave this particular reaction button, post a HoverIn action
// If the mouse does not leave this particular reaction button, propagate tooltip actions.
if !reset_tooltip_state {
cx.widget_action(uid, &scope.path, hover_in_data.clone());
cx.widget_action(uid, &scope.path, tooltip_actions.clone());
}
}
if reset_tooltip_state {
Expand All @@ -219,7 +213,7 @@ impl Widget for ReactionList {
.iter()
.for_each(|(_id, widget_ref)| {
if widget_ref.clicked(actions) {
let text = widget_ref.text().clone();
let text = widget_ref.text();
let reaction_string = text.rsplit_once(' ')
.map(|(prefix, _)| prefix)
.unwrap_or(&text);
Expand Down
8 changes: 4 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ pub struct RoomScreen {
#[rust] tl_state: Option<TimelineUiState>,
/// 5 secs timer when scroll ends
#[rust] fully_read_timer: Timer,

}

impl Drop for RoomScreen {
fn drop(&mut self) {
// This ensures that the `TimelineUiState` instance owned by this room is *always* returned
Expand Down Expand Up @@ -2251,15 +2251,15 @@ impl RoomScreenRef {
}
}

/// Actions for the room screen's tooltip
/// 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
/// Mouse over event when the mouse is over the reaction button.
HoverIn {
tooltip_pos: DVec2,
tooltip_text: String,
tooltip_width: f64,
/// Calculated Y offset required such that the pointed arrow is pointed towards the center of the hovered widget
/// Calculated Y offset required such that the pointed arrow is pointed towards the center of the hovered widget.
callout_y_offset: f64,
},
HoverOut,
Expand Down

0 comments on commit 84d5e51

Please sign in to comment.