Introduce a new Tooltip element and a with_tooltip helper

This commit is contained in:
Antonio Scandurra 2022-06-01 09:55:25 +02:00
parent 94fc28b29d
commit 982de971fa
5 changed files with 112 additions and 31 deletions

View file

@ -311,7 +311,7 @@ impl Presenter {
if let Some(region_id) = region.id() {
if !self.hovered_region_ids.contains(&region_id) {
invalidated_views.push(region.view_id);
hovered_regions.push(region.clone());
hovered_regions.push((region.clone(), position));
self.hovered_region_ids.insert(region_id);
}
}
@ -319,7 +319,7 @@ impl Presenter {
if let Some(region_id) = region.id() {
if self.hovered_region_ids.contains(&region_id) {
invalidated_views.push(region.view_id);
unhovered_regions.push(region.clone());
unhovered_regions.push((region.clone(), position));
self.hovered_region_ids.remove(&region_id);
}
}
@ -348,20 +348,20 @@ impl Presenter {
let mut event_cx = self.build_event_context(cx);
let mut handled = false;
for unhovered_region in unhovered_regions {
for (unhovered_region, position) in unhovered_regions {
handled = true;
if let Some(hover_callback) = unhovered_region.hover {
event_cx.with_current_view(unhovered_region.view_id, |event_cx| {
hover_callback(false, event_cx);
hover_callback(position, false, event_cx);
})
}
}
for hovered_region in hovered_regions {
for (hovered_region, position) in hovered_regions {
handled = true;
if let Some(hover_callback) = hovered_region.hover {
event_cx.with_current_view(hovered_region.view_id, |event_cx| {
hover_callback(true, event_cx);
hover_callback(position, true, event_cx);
})
}
}
@ -449,6 +449,7 @@ impl Presenter {
view_stack: Default::default(),
invalidated_views: Default::default(),
notify_count: 0,
window_id: self.window_id,
app: cx,
}
}
@ -626,6 +627,7 @@ pub struct EventContext<'a> {
pub font_cache: &'a FontCache,
pub text_layout_cache: &'a TextLayoutCache,
pub app: &'a mut MutableAppContext,
pub window_id: usize,
pub notify_count: usize,
view_stack: Vec<usize>,
invalidated_views: HashSet<usize>,
@ -653,6 +655,14 @@ impl<'a> EventContext<'a> {
result
}
pub fn window_id(&self) -> usize {
self.window_id
}
pub fn view_id(&self) -> Option<usize> {
self.view_stack.last().copied()
}
pub fn dispatch_any_action(&mut self, action: Box<dyn Action>) {
self.dispatched_actions.push(DispatchDirective {
dispatcher_view_id: self.view_stack.last().copied(),