Prevent tooltips from clipping outside window boundaries

This commit is contained in:
Noah 2020-03-09 22:24:04 -07:00
parent 911585ea4d
commit 49f108f302

View File

@ -121,6 +121,22 @@ func (w *Tooltip) Compute(e render.Engine) {
moveTo.X = tPoint.X + (tSize.W / 2) - (size.W / 2)
}
// Adjust to keep the tooltip from clipping outside the window boundaries.
{
width, height := e.WindowSize()
if moveTo.X < 0 {
moveTo.X = 0
} else if moveTo.X+size.W > width {
moveTo.X = width - size.W
}
if moveTo.Y < 0 {
moveTo.Y = 0
} else if moveTo.Y+size.H > height {
moveTo.Y = height - size.H
}
}
w.MoveTo(moveTo)
}