Fix `on_hover_text_at_pointer` for transformed layers (#5429)
This commit is contained in:
parent
cd0f5859b2
commit
c5ac7d301a
|
|
@ -87,17 +87,22 @@ pub fn show_tooltip_at_pointer<R>(
|
|||
|
||||
// Add a small exclusion zone around the pointer to avoid tooltips
|
||||
// covering what we're hovering over.
|
||||
let mut exclusion_rect = Rect::from_center_size(pointer_pos, Vec2::splat(24.0));
|
||||
let mut pointer_rect = Rect::from_center_size(pointer_pos, Vec2::splat(24.0));
|
||||
|
||||
// Keep the left edge of the tooltip in line with the cursor:
|
||||
exclusion_rect.min.x = pointer_pos.x;
|
||||
pointer_rect.min.x = pointer_pos.x;
|
||||
|
||||
// Transform global coords to layer coords:
|
||||
if let Some(transform) = ctx.memory(|m| m.layer_transforms.get(&parent_layer).copied()) {
|
||||
pointer_rect = transform.inverse() * pointer_rect;
|
||||
}
|
||||
|
||||
show_tooltip_at_dyn(
|
||||
ctx,
|
||||
parent_layer,
|
||||
widget_id,
|
||||
allow_placing_below,
|
||||
&exclusion_rect,
|
||||
&pointer_rect,
|
||||
Box::new(add_contents),
|
||||
)
|
||||
})
|
||||
|
|
@ -155,6 +160,7 @@ fn show_tooltip_at_dyn<'c, R>(
|
|||
widget_rect: &Rect,
|
||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||
) -> R {
|
||||
// Transform layer coords to global coords:
|
||||
let mut widget_rect = *widget_rect;
|
||||
if let Some(transform) = ctx.memory(|m| m.layer_transforms.get(&parent_layer).copied()) {
|
||||
widget_rect = transform * widget_rect;
|
||||
|
|
|
|||
|
|
@ -73,20 +73,29 @@ impl crate::View for PanZoom {
|
|||
for (i, (pos, callback)) in [
|
||||
(
|
||||
egui::Pos2::new(0.0, 0.0),
|
||||
Box::new(|ui: &mut egui::Ui, _: &mut Self| ui.button("top left!"))
|
||||
as Box<dyn Fn(&mut egui::Ui, &mut Self) -> egui::Response>,
|
||||
Box::new(|ui: &mut egui::Ui, _: &mut Self| {
|
||||
ui.button("top left").on_hover_text("Normal tooltip")
|
||||
}) as Box<dyn Fn(&mut egui::Ui, &mut Self) -> egui::Response>,
|
||||
),
|
||||
(
|
||||
egui::Pos2::new(0.0, 120.0),
|
||||
Box::new(|ui: &mut egui::Ui, _| ui.button("bottom left?")),
|
||||
Box::new(|ui: &mut egui::Ui, _| {
|
||||
ui.button("bottom left").on_hover_text("Normal tooltip")
|
||||
}),
|
||||
),
|
||||
(
|
||||
egui::Pos2::new(120.0, 120.0),
|
||||
Box::new(|ui: &mut egui::Ui, _| ui.button("right bottom :D")),
|
||||
Box::new(|ui: &mut egui::Ui, _| {
|
||||
ui.button("right bottom")
|
||||
.on_hover_text_at_pointer("Tooltip at pointer")
|
||||
}),
|
||||
),
|
||||
(
|
||||
egui::Pos2::new(120.0, 0.0),
|
||||
Box::new(|ui: &mut egui::Ui, _| ui.button("right top ):")),
|
||||
Box::new(|ui: &mut egui::Ui, _| {
|
||||
ui.button("right top")
|
||||
.on_hover_text_at_pointer("Tooltip at pointer")
|
||||
}),
|
||||
),
|
||||
(
|
||||
egui::Pos2::new(60.0, 60.0),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:79ce1dbf7627579d4e10de6494e34d8fd9685506d7b35cb3c9148f90f8c01366
|
||||
size 25144
|
||||
oid sha256:ccfda16ef7cdf94f7fbbd2c0f8df6f6de7904969e2a66337920c32608a6f9f05
|
||||
size 25357
|
||||
|
|
|
|||
Loading…
Reference in New Issue