Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/Classes/Tooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,26 @@ end

function TooltipClass:GetDynamicSize(viewPort)
local staticttW, staticttH = self:GetSize()
local columns, ttH = self:CalculateColumns(0, 0, staticttH, staticttW, viewPort)
local ttW = columns * staticttW
local columns, ttH, _, extraColumnWidth = self:CalculateColumns(0, 0, staticttH, staticttW, viewPort)

-- ensure extra column width has sensible value
extraColumnWidth = (columns > 1 and extraColumnWidth > 0) and extraColumnWidth or staticttW
local ttW = staticttW + (m_max(columns - 1, 0) * extraColumnWidth)

return ttW + H_PAD, ttH + V_PAD
end

--- Calculates the column breaks, layout heights, and individual rendering instructions for tooltip lines.
--- By default, items exceeding window height will wrap to a new column.
---@param ttY number Base y-coordinate for the tooltip content
---@param ttX number Base x-coordinate for the tooltip content
---@param ttH number The total estimated height of the tooltip content, used to determine column breakpoints
---@param ttW number The pixel width of the primary (first) tooltip column
---@param viewPort table A table `{x, y, width, height}` containing active screen boundaries
---@return number columns The total number of layout columns generated
---@return number maxColumnHeight The maximum pixel height reached across all formatted columns
---@return table drawStack An array of sequential rendering instructions (texts, images, separators, and their coordinates)
---@return number extraColumnWidth The required dynamic pixel width calculated for any additional columns beyond the first
function TooltipClass:CalculateColumns(ttY, ttX, ttH, ttW, viewPort)
local y = ttY + 2 * BORDER_WIDTH
if self.titleYOffset then
Expand All @@ -176,6 +190,7 @@ function TooltipClass:CalculateColumns(ttY, ttX, ttH, ttW, viewPort)
local x = ttX
local columns = 1 -- reset to count columns by block heights
local currentBlock = 1
local extraColumnWidth = 0
local maxColumnHeight = 0
local drawStack = {}
local font
Expand Down Expand Up @@ -211,7 +226,7 @@ function TooltipClass:CalculateColumns(ttY, ttX, ttH, ttW, viewPort)
local curX = ttX + ttW / 2 - totalWidth / 2
-- Draw title
t_insert(drawStack, {curX, y + (titleSize - titleSize)/2, "LEFT", titleSize, font, title.text})
curX = curX + DrawStringWidth(titleSize, font, title.text) + 6
curX = curX + DrawStringWidth(titleSize, font, title.text) + (H_PAD / 2)

-- Draw oils
local maxOilHeight = 0
Expand Down Expand Up @@ -321,7 +336,8 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
end
local ttX = x
local ttY = y
if w and h then
local isHoverToolTip = w and h -- `w` and `h` typically only provided for hover tooltips
if isHoverToolTip then
ttX = ttX + w + 5
if ttX + ttW > viewPort.x + viewPort.width then
ttX = m_max(viewPort.x, x - 5 - ttW)
Expand All @@ -341,7 +357,7 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
-- background shading currently must be drawn before text lines. API change will allow something like the commented lines below
SetDrawColor(0, 0, 0, .85)
--SetDrawLayer(nil, GetDrawLayer() - 5)
DrawImage(nil, ttX, ttY + BORDER_WIDTH, ttW * columns - BORDER_WIDTH, maxColumnHeight - 2 * BORDER_WIDTH)
DrawImage(nil, ttX, ttY + BORDER_WIDTH, totalDrawWidth - BORDER_WIDTH, maxColumnHeight - 2 * BORDER_WIDTH)
--SetDrawLayer(nil, GetDrawLayer())
SetDrawColor(1, 1, 1)

Expand Down Expand Up @@ -498,11 +514,16 @@ function TooltipClass:Draw(x, y, w, h, viewPort)
else
SetDrawColor(unpack(self.color))
end

-- draw vertical borders, accounting for separate extra column width
for i = 0, columns do
DrawImage(nil, ttX + ttW * i - BORDER_WIDTH * math.ceil(i^2 / (i^2 + 1)), ttY, BORDER_WIDTH, maxColumnHeight)
local extraColXOffset = i > 0 and ttW + ((i - 1) * extraColumnWidth) or 0
local currentX = ttX + extraColXOffset
DrawImage(nil, currentX - BORDER_WIDTH * math.ceil(i^2 / (i^2 + 1)), ttY, BORDER_WIDTH, maxColumnHeight)
end
DrawImage(nil, ttX, ttY, ttW * columns, BORDER_WIDTH) -- top border
DrawImage(nil, ttX, ttY + maxColumnHeight - BORDER_WIDTH, ttW * columns, BORDER_WIDTH) -- bottom border
-- draw horizontal borders
DrawImage(nil, ttX, ttY, totalDrawWidth, BORDER_WIDTH) -- top
DrawImage(nil, ttX, ttY + maxColumnHeight - BORDER_WIDTH, totalDrawWidth, BORDER_WIDTH) -- bottom

return ttW, ttH
end
112 changes: 112 additions & 0 deletions src/Classes/Tooltip.lua.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
diff a/src/Classes/Tooltip.lua b/src/Classes/Tooltip.lua (rejected hunks)
@@ -319,41 +319,41 @@ function TooltipClass:CalculateColumns(ttY, ttX, ttH, ttW, viewPort)
end

-- Resizing/Shrinking drawStack elements in extra columns
- -- NOTE: this logic depends on the current structure of `drawStack` --> needs adjustment if lengths or coordinates logic changes
- if columns > 1 and extraColumnWidth > 0 then
- for _, line in ipairs(drawStack) do
- local isText = #line >= 6 -- Text elements have 6 props, images/separators have 5
- local xIdx = isText and 1 or 2 -- `x` value at index 1 for text, 2 otherwise
- local origX = line[xIdx]
-
- -- calculate column index (origX is at least x * original widths from start)
- local colIndex = m_floor((origX - ttX) / ttW) + 1
-
- if colIndex > 1 then
- local oldBaseX = ttX + ttW * (colIndex - 1)
- local newBaseX = ttX + ttW + extraColumnWidth * (colIndex - 2) -- `- 2` because first column is unchanged
-
- -- Update x coordinates
- if isText and line[3] == "CENTER_X" then
+ -- NOTE: this logic depends on the current structure of `drawStack` --> needs adjustment if lengths or coordinates logic changes
+ if columns > 1 and extraColumnWidth > 0 then
+ for _, line in ipairs(drawStack) do
+ local isText = #line >= 6 -- Text elements have 6 props, images/separators have 5
+ local xIdx = isText and 1 or 2 -- `x` value at index 1 for text, 2 otherwise
+ local origX = line[xIdx]
+
+ -- calculate column index (origX is at least x * original widths from start)
+ local colIndex = m_floor((origX - ttX) / ttW) + 1
+
+ if colIndex > 1 then
+ local oldBaseX = ttX + ttW * (colIndex - 1)
+ local newBaseX = ttX + ttW + extraColumnWidth * (colIndex - 2) -- `- 2` because first column is unchanged
+
+ -- Update x coordinates
+ if isText and line[3] == "CENTER_X" then
-- centered texts
- line[xIdx] = newBaseX + extraColumnWidth / 2
- else
+ line[xIdx] = newBaseX + extraColumnWidth / 2
+ else
-- "LEFT" aligned text and images (NOTE: "RIGHT" aligned does not seem to exist)
- line[xIdx] = origX - oldBaseX + newBaseX
- end
+ line[xIdx] = origX - oldBaseX + newBaseX
+ end

- -- Resize separators/dividers (technically unlikely to appear in extra columns, but just in case)
- if not isText then
+ -- Resize separators/dividers (technically unlikely to appear in extra columns, but just in case)
+ if not isText then
-- separator images have `width` value at index 4
- if line[1] and type(line[1]) == "table" and line[1].isSeparator then
- line[4] = extraColumnWidth - H_PAD -- "fancy" separators get extra padding
- else
- line[4] = extraColumnWidth - BORDER_WIDTH
- end
- end
- end
- end
- end
+ if line[1] and type(line[1]) == "table" and line[1].isSeparator then
+ line[4] = extraColumnWidth - H_PAD -- "fancy" separators get extra padding
+ else
+ line[4] = extraColumnWidth - BORDER_WIDTH
+ end
+ end
+ end
+ end
+ end

return columns, maxColumnHeight, drawStack, extraColumnWidth
end
@@ -435,24 +435,24 @@ function TooltipClass:Draw(x, y, w, h, viewPort)

-- ensure extraColumnWidth has sensible value and calculate new total width (original width + extraColumns)
extraColumnWidth = (columns > 1 and extraColumnWidth > 0) and extraColumnWidth or ttW
- local totalDrawWidth = ttW + (m_max(columns - 1, 0) * extraColumnWidth)
+ local totalDrawWidth = ttW + (m_max(columns - 1, 0) * extraColumnWidth)

-- If hover tooltip and extra columns don't fit, shift to left and adjust drawStack (because hover tooltips can't scroll)
if columns > 1 and isHoverToolTip and totalDrawWidth + ttX >= viewPort.x + viewPort.width then
- local newX = m_max(viewPort.x, viewPort.x + viewPort.width - totalDrawWidth)
- local offsetX = newX - ttX
- ttX = newX
-
- for _, line in ipairs(drawStack) do
- if #line < 6 then
+ local newX = m_max(viewPort.x, viewPort.x + viewPort.width - totalDrawWidth)
+ local offsetX = newX - ttX
+ ttX = newX
+
+ for _, line in ipairs(drawStack) do
+ if #line < 6 then
-- Text element entries have 6 entries and `x` at `[2]`
- line[2] = line[2] + offsetX
- else
+ line[2] = line[2] + offsetX
+ else
-- Image, Separators, etc. have 5 entries and `x` at `[1]`
- line[1] = line[1] + offsetX
- end
- end
- end
+ line[1] = line[1] + offsetX
+ end
+ end
+ end

-- background shading currently must be drawn before text lines. API change will allow something like the commented lines below
SetDrawColor(0, 0, 0, .85)