Make tooltips be shown at different directions if there's not enough space

This commit is contained in:
Michael Alexsander 2022-07-23 14:51:06 -03:00
parent 667cef39b4
commit 46346cfaa5
1 changed files with 12 additions and 2 deletions

View File

@ -1234,13 +1234,23 @@ void Viewport::_gui_show_tooltip() {
Rect2i vr = window->get_usable_parent_rect(); Rect2i vr = window->get_usable_parent_rect();
if (r.size.x + r.position.x > vr.size.x + vr.position.x) { if (r.size.x + r.position.x > vr.size.x + vr.position.x) {
r.position.x = vr.position.x + vr.size.x - r.size.x; // Place it in the opposite direction. If it fails, just hug the border.
r.position.x = gui.tooltip_pos.x - r.size.x - tooltip_offset.x;
if (r.position.x < vr.position.x) {
r.position.x = vr.position.x + vr.size.x - r.size.x;
}
} else if (r.position.x < vr.position.x) { } else if (r.position.x < vr.position.x) {
r.position.x = vr.position.x; r.position.x = vr.position.x;
} }
if (r.size.y + r.position.y > vr.size.y + vr.position.y) { if (r.size.y + r.position.y > vr.size.y + vr.position.y) {
r.position.y = vr.position.y + vr.size.y - r.size.y; // Same as above.
r.position.y = gui.tooltip_pos.y - r.size.y - tooltip_offset.y;
if (r.position.y < vr.position.y) {
r.position.y = vr.position.y + vr.size.y - r.size.y;
}
} else if (r.position.y < vr.position.y) { } else if (r.position.y < vr.position.y) {
r.position.y = vr.position.y; r.position.y = vr.position.y;
} }