Skip to content

Commit

Permalink
Add some spacing between tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 9, 2022
1 parent cd17145 commit f503561
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
mut avoid_rect: Rect,
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> Option<R> {
let spacing = 4.0;

// if there are multiple tooltips open they should use the same common_id for the `tooltip_size` caching to work.
let mut frame_state =
ctx.frame_state()
Expand All @@ -168,9 +170,9 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
let mut position = if frame_state.rect.is_positive() {
avoid_rect = avoid_rect.union(frame_state.rect);
if above {
frame_state.rect.left_top()
frame_state.rect.left_top() - spacing * Vec2::Y
} else {
frame_state.rect.left_bottom()
frame_state.rect.left_bottom() + spacing * Vec2::Y
}
} else if let Some(position) = suggested_position {
position
Expand Down Expand Up @@ -199,10 +201,10 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
if new_rect.shrink(1.0).intersects(avoid_rect) {
if above {
// place below instead:
position = avoid_rect.left_bottom();
position = avoid_rect.left_bottom() + spacing * Vec2::Y;
} else {
// place above instead:
position = Pos2::new(position.x, avoid_rect.min.y - expected_size.y);
position = Pos2::new(position.x, avoid_rect.min.y - expected_size.y - spacing);
}
}
}
Expand Down

0 comments on commit f503561

Please sign in to comment.