Align tooltip based on the available window space

This commit is contained in:
Antonio Scandurra 2022-06-01 10:03:46 +02:00
parent b3242417b3
commit 238827642a
3 changed files with 14 additions and 4 deletions

View file

@ -101,9 +101,16 @@ impl Element for Tooltip {
self.child.paint(bounds.origin(), visible_bounds, cx);
if let Some(tooltip) = self.tooltip.as_mut() {
let origin = self.state.read(cx).position.get();
let size = tooltip.size();
let mut bounds = RectF::new(origin, tooltip.size());
if bounds.lower_right().x() > cx.window_size.x() {
bounds.set_origin_x(bounds.origin_x() - bounds.width());
}
if bounds.lower_right().y() > cx.window_size.y() {
bounds.set_origin_y(bounds.origin_y() - bounds.height());
}
cx.scene.push_stacking_context(None);
tooltip.paint(origin, RectF::new(origin, size), cx);
tooltip.paint(bounds.origin(), bounds, cx);
cx.scene.pop_stacking_context();
}
}