Dismiss tooltips on click

This commit is contained in:
Conrad Irwin 2023-11-16 10:26:09 -07:00
parent 4540f04dbe
commit d782426491

View file

@ -960,11 +960,11 @@ where
cx.background_executor().timer(TOOLTIP_DELAY).await;
view.update(&mut cx, move |view_state, cx| {
active_tooltip.borrow_mut().replace(ActiveTooltip {
waiting: None,
tooltip: Some(AnyTooltip {
view: tooltip_builder(view_state, cx),
cursor_offset: cx.mouse_position(),
}),
_task: None,
});
cx.notify();
})
@ -972,12 +972,17 @@ where
}
});
active_tooltip.borrow_mut().replace(ActiveTooltip {
waiting: Some(task),
tooltip: None,
_task: Some(task),
});
}
});
let active_tooltip = element_state.active_tooltip.clone();
cx.on_mouse_event(move |_, _: &MouseDownEvent, _, _| {
active_tooltip.borrow_mut().take();
});
if let Some(active_tooltip) = element_state.active_tooltip.borrow().as_ref() {
if active_tooltip.tooltip.is_some() {
cx.active_tooltip = active_tooltip.tooltip.clone()
@ -1207,9 +1212,8 @@ pub struct InteractiveElementState {
}
pub struct ActiveTooltip {
#[allow(unused)] // used to drop the task
waiting: Option<Task<()>>,
tooltip: Option<AnyTooltip>,
_task: Option<Task<()>>,
}
/// Whether or not the element or a group that contains it is clicked by the mouse.