@@ -300,7 +300,12 @@ function TooltipClass:CalculateColumns(ttY, ttX, ttH, ttW, viewPort)
300300
301301 return columns , maxColumnHeight , drawStack
302302end
303-
303+ --- Draws tooltip to screen
304+ --- @param x number x-coordinate to draw the tooltip at
305+ --- @param y number y-coordinate to draw the tooltip at
306+ --- @param w number | nil optional width of the UI element being hovered over. Tooltip will position itself outside this box (if possible )
307+ --- @param h number | nil optional height of the UI element being hovered over. Needs to be provided alongside ` w`
308+ --- @param viewPort table A table ` {x, y, width, height}` contains active screen boundaries
304309function TooltipClass :Draw (x , y , w , h , viewPort )
305310 if # self .lines == 0 then
306311 return
@@ -355,7 +360,8 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
355360 end
356361 local ttX = x
357362 local ttY = y
358- if w and h then
363+ local isHoverToolTip = w and h -- `w` and `h` typically only provided for hover tooltips
364+ if isHoverToolTip then
359365 ttX = ttX + w + 5
360366 if ttX + ttW > viewPort .x + viewPort .width then
361367 ttX = m_max (viewPort .x , x - 5 - ttW )
@@ -370,11 +376,22 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
370376 -- Initial column calculation
371377 local columns , maxColumnHeight , drawStack = self :CalculateColumns (ttY , ttX , ttH , ttW , viewPort )
372378
373- -- If extra columns don't fit, shift to left and recalculate drawStack
374- if columns > 1 and ttW * columns + ttX >= viewPort .x + viewPort .width then
375- ttX = m_max (viewPort .x , viewPort .x + viewPort .width - ttW * columns )
376- columns , maxColumnHeight , drawStack = self :CalculateColumns (ttY , ttX , ttH , ttW , viewPort )
377- end
379+ -- If hover tooltip and extra columns don't fit, shift to left and adjust drawStack (because hover tooltips can't scroll)
380+ if columns > 1 and isHoverToolTip and ttW * columns + ttX >= viewPort .x + viewPort .width then
381+ local newX = m_max (viewPort .x , viewPort .x + viewPort .width - ttW * columns )
382+ local offsetX = newX - ttX
383+ ttX = newX
384+
385+ for _ , line in ipairs (drawStack ) do
386+ if # line < 6 then
387+ -- Text element entries have 6 entries and `x` at `[2]`
388+ line [2 ] = line [2 ] + offsetX
389+ else
390+ -- Image, Separators, etc. have 5 entries and `x` at `[1]`
391+ line [1 ] = line [1 ] + offsetX
392+ end
393+ end
394+ end
378395
379396 -- background shading currently must be drawn before text lines. API change will allow something like the commented lines below
380397 SetDrawColor (0 , 0 , 0 , .85 )
0 commit comments