Skip to content

Commit ddec577

Browse files
committed
fix wrapping of buff/debuff info text in compared Calcs tab
1 parent 457fb26 commit ddec577

1 file changed

Lines changed: 57 additions & 11 deletions

File tree

src/Classes/CompareTab.lua

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ local configVisibility = LoadModule("Modules/ConfigVisibility")
1919
-- Node IDs below this value are normal passive tree nodes; IDs at or above are cluster jewel nodes
2020
local CLUSTER_NODE_OFFSET = 65536
2121

22+
-- Wrap a string into lines for a given pixel width at font height 14 ("VAR").
23+
-- Breaks BEFORE a word that would exceed the width, so rendered lines never
24+
-- overshoot into the next column.
25+
local function wrapInfoLine(str, width)
26+
local lines = {}
27+
if not str or str == "" or width <= 0 then
28+
return lines
29+
end
30+
local lineStart = 1
31+
local pos = 1
32+
while pos <= #str do
33+
local ws, we = str:find("%s+", pos)
34+
local wordEnd = ws and (ws - 1) or #str
35+
if lineStart < pos and DrawStringWidth(14, "VAR", str:sub(lineStart, wordEnd)) > width then
36+
local committed = (str:sub(lineStart, pos - 1):gsub("%s+$", ""))
37+
t_insert(lines, committed)
38+
lineStart = pos
39+
end
40+
if not ws then
41+
t_insert(lines, str:sub(lineStart))
42+
break
43+
end
44+
pos = we + 1
45+
end
46+
return lines
47+
end
48+
2249
-- Layout constants (shared across Draw, DrawConfig, DrawItems, DrawCalcs, etc.)
2350
local LAYOUT = {
2451
-- Main tab control bar
@@ -2144,12 +2171,21 @@ function CompareTabClass:LayoutCalcsSkillControls(vp, compareEntry)
21442171
local pOutput = primaryEnv and primaryEnv.player and primaryEnv.player.output
21452172
local cOutput = compareEnv and compareEnv.player and compareEnv.player.output
21462173
if pOutput or cOutput then
2174+
local wrapWidth = colWidth - 8
2175+
local infoLabels = {
2176+
BuffList = "Aura/Buff Skills",
2177+
CombatList = "Combat Buffs",
2178+
CurseList = "Curses/Debuffs",
2179+
}
21472180
local infoKeys = { "BuffList", "CombatList", "CurseList" }
21482181
for _, key in ipairs(infoKeys) do
21492182
local pVal = pOutput and pOutput[key]
21502183
local cVal = cOutput and cOutput[key]
21512184
if (pVal and pVal ~= "") or (cVal and cVal ~= "") then
2152-
textLinesHeight = textLinesHeight + 18
2185+
local label = infoLabels[key]
2186+
local pLines = (pVal and pVal ~= "") and #wrapInfoLine(label .. ": " .. pVal, wrapWidth) or 0
2187+
local cLines = (cVal and cVal ~= "") and #wrapInfoLine(label .. ": " .. cVal, wrapWidth) or 0
2188+
textLinesHeight = textLinesHeight + m_max(pLines, cLines, 1) * 18
21532189
end
21542190
end
21552191
end
@@ -4087,6 +4123,7 @@ function CompareTabClass:DrawCalcsSkillHeader(vp, compareEntry, headerHeight, pr
40874123
self.calcsSkillHeaderHover = nil -- Reset hover state
40884124
if pOutput or cOutput then
40894125
local cursorX, cursorY = GetCursorPos()
4126+
local wrapWidth = colWidth - 8
40904127
local infoLines = {
40914128
{ label = "Aura/Buff Skills", key = "BuffList", breakdown = "SkillBuffs" },
40924129
{ label = "Combat Buffs", key = "CombatList" },
@@ -4096,33 +4133,42 @@ function CompareTabClass:DrawCalcsSkillHeader(vp, compareEntry, headerHeight, pr
40964133
local pVal = pOutput and pOutput[info.key]
40974134
local cVal = cOutput and cOutput[info.key]
40984135
if (pVal and pVal ~= "") or (cVal and cVal ~= "") then
4136+
local pLines = (pVal and pVal ~= "") and wrapInfoLine(info.label .. ": " .. pVal, wrapWidth) or {}
4137+
local cLines = (cVal and cVal ~= "") and wrapInfoLine(info.label .. ": " .. cVal, wrapWidth) or {}
4138+
local pH = #pLines * 18
4139+
local cH = #cLines * 18
4140+
local rowH = m_max(pH, cH, 18)
40994141
-- Check hover per-side for lines that have breakdown data
4100-
if info.breakdown and cursorY >= textY and cursorY < textY + 18 then
4101-
local onLeft = cursorX >= leftX and cursorX < rightX
4102-
local onRight = cursorX >= rightX and cursorX < vp.x + vp.width
4142+
if info.breakdown and cursorY >= textY and cursorY < textY + rowH then
4143+
local onLeft = cursorX >= leftX and cursorX < rightX and pH > 0 and cursorY < textY + pH
4144+
local onRight = cursorX >= rightX and cursorX < vp.x + vp.width and cH > 0 and cursorY < textY + cH
41034145
if onLeft then
41044146
SetDrawColor(0.15, 0.25, 0.15)
4105-
DrawImage(nil, leftX, textY, colWidth, 18)
4147+
DrawImage(nil, leftX, textY, colWidth, pH)
41064148
self.calcsSkillHeaderHover = {
41074149
breakdown = info.breakdown,
41084150
label = info.label,
41094151
build = self.primaryBuild,
4110-
x = leftX, y = textY, w = colWidth, h = 18,
4152+
x = leftX, y = textY, w = colWidth, h = pH,
41114153
}
41124154
elseif onRight then
41134155
SetDrawColor(0.15, 0.25, 0.15)
4114-
DrawImage(nil, rightX, textY, colWidth, 18)
4156+
DrawImage(nil, rightX, textY, colWidth, cH)
41154157
self.calcsSkillHeaderHover = {
41164158
breakdown = info.breakdown,
41174159
label = info.label,
41184160
build = compareEntry,
4119-
x = rightX, y = textY, w = colWidth, h = 18,
4161+
x = rightX, y = textY, w = colWidth, h = cH,
41204162
}
41214163
end
41224164
end
4123-
DrawString(leftX, textY + 1, "LEFT", 14, "VAR", "^7" .. info.label .. ": " .. (pVal or ""))
4124-
DrawString(rightX, textY + 1, "LEFT", 14, "VAR", "^7" .. info.label .. ": " .. (cVal or ""))
4125-
textY = textY + 18
4165+
for i, line in ipairs(pLines) do
4166+
DrawString(leftX, textY + 1 + (i - 1) * 18, "LEFT", 14, "VAR", "^7" .. line)
4167+
end
4168+
for i, line in ipairs(cLines) do
4169+
DrawString(rightX, textY + 1 + (i - 1) * 18, "LEFT", 14, "VAR", "^7" .. line)
4170+
end
4171+
textY = textY + rowH
41264172
end
41274173
end
41284174
end

0 commit comments

Comments
 (0)