Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/egui/src/containers/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,17 @@ impl Tooltip<'_> {

// Fast early-outs:
if response.enabled() {
if !response.hovered() || !response.ctx.input(|i| i.pointer.has_pointer()) {
// Hover-only container responses (e.g. `ui.horizontal(...).response`) live below
// child widgets. In that case `response.hovered()` can stay false while the pointer
// is still inside the container rect. Allow tooltips for these hover-only responses
// when the pointer is in the interaction rect and on the same layer.
let hovered_or_container_pointer = response.hovered()
|| (response.sense == Sense::hover()
&& response
.ctx
.rect_contains_pointer(response.layer_id, response.interact_rect));

if !hovered_or_container_pointer || !response.ctx.input(|i| i.pointer.has_pointer()) {
return false;
}
} else if !response
Expand Down
23 changes: 23 additions & 0 deletions tests/egui_tests/tests/regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ fn combobox_should_have_value() {
);
}

#[test]
fn horizontal_response_tooltip_should_show_when_hovering_child() {
let mut harness = Harness::builder().with_size((84.0, 64.0)).build_ui(|ui| {
ui.style_mut().interaction.tooltip_delay = 0.0;
ui.style_mut().interaction.show_tooltips_only_when_still = false;

ui.horizontal(|ui| {
_ = ui.button("A");
_ = ui.button("B").on_hover_text("B has a tooltip");
})
.response
.on_hover_text("test");
});

harness.get_by_label("A").hover();
harness.run_steps(5);
harness.snapshot("horizontal_response_tooltip_should_show_when_hovering_child");

harness.get_by_label("B").hover();
harness.run_steps(5);
harness.snapshot("horizontal_response_topmost_tooltip_should_win");
}

/// This test ensures that `ui.response().interact(...)` works correctly.
///
/// This was broken, because there was an optimization in [`egui::Response::interact`]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum - I wanted to test that the tooltip for B pops up, but in this case I think we just hit the logic of "keep the previous tooltip open"? I think this needs to be a separate test then

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading