From 49f108f3027fb54a308cdaf8fc98b762fc8b53c1 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 9 Mar 2020 22:24:04 -0700 Subject: [PATCH] Prevent tooltips from clipping outside window boundaries --- tooltip.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tooltip.go b/tooltip.go index 5b59fa7..fa5db0d 100644 --- a/tooltip.go +++ b/tooltip.go @@ -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) }