From 7967bd4385849c1a3d26bb01321f252fa27a2878 Mon Sep 17 00:00:00 2001
From: diath <diath@zodiaclabs.org>
Date: Wed, 28 Feb 2018 21:44:49 +0100
Subject: [PATCH] Fix vertical tooltip clamping (#942)

---
 modules/corelib/ui/tooltip.lua | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/modules/corelib/ui/tooltip.lua b/modules/corelib/ui/tooltip.lua
index b1fecc15..d5c61159 100644
--- a/modules/corelib/ui/tooltip.lua
+++ b/modules/corelib/ui/tooltip.lua
@@ -10,13 +10,24 @@ local function moveToolTip(first)
   if not first and (not toolTipLabel:isVisible() or toolTipLabel:getOpacity() < 0.1) then return end
 
   local pos = g_window.getMousePosition()
+  local windowSize = g_window.getSize()
+  local labelSize = toolTipLabel:getSize()
+
+  pos.x = pos.x + 1
   pos.y = pos.y + 1
-  local xdif = g_window.getSize().width - (pos.x + toolTipLabel:getWidth())
-  if xdif < 10 then
-    pos.x = pos.x - toolTipLabel:getWidth() - 3
+
+  if windowSize.width - (pos.x + labelSize.width) < 10 then
+    pos.x = pos.x - labelSize.width - 3
   else
     pos.x = pos.x + 10
   end
+
+  if windowSize.height - (pos.y + labelSize.height) < 10 then
+    pos.y = pos.y - labelSize.height - 3
+  else
+    pos.y = pos.y + 10
+  end
+
   toolTipLabel:setPosition(pos)
 end