Refactor drawing helpers to utilize shared UI module functions

This commit is contained in:
MayaTheShy
2026-03-22 01:56:15 -04:00
parent 50fa771ca4
commit 338af14b6b

View File

@@ -679,47 +679,21 @@ local function smelterHitTest(x, y)
end end
------------------------------------------------- -------------------------------------------------
-- Drawing helpers (write to draw target) -- Drawing helpers (delegated to shared ui module)
------------------------------------------------- -------------------------------------------------
local draw = nil local draw = nil -- set to window target before each draw cycle
local function monWrite(x, y, text, fg, bg) local function setDrawTarget(target)
draw.setCursorPos(x, y) draw = target
if fg then draw.setTextColor(fg) end ui.draw = target
if bg then draw.setBackgroundColor(bg) end
draw.write(text)
end end
local function monFill(y, color) local function monWrite(x, y, text, fg, bg) ui.monWrite(x, y, text, fg, bg) end
local w, _ = draw.getSize() local function monFill(y, color) ui.monFill(y, color) end
draw.setCursorPos(1, y) local function monCenter(y, text, fg, bg) ui.monCenter(y, text, fg, bg) end
draw.setBackgroundColor(color) local function monBar(x, y, w, r, bc, bgc) ui.monBar(x, y, w, r, bc, bgc) end
draw.write(string.rep(" ", w)) local function drawButton(x, y, t, fg, bg, pl, pr) return ui.drawButton(x, y, t, fg, bg, pl, pr) end
end
local function monCenter(y, text, fg, bg)
local w, _ = draw.getSize()
local x = math.floor((w - #text) / 2) + 1
monWrite(x, y, text, fg, bg)
end
local function monBar(x, y, width, ratio, barColor, bgColor)
local filled = math.floor(ratio * width)
draw.setCursorPos(x, y)
draw.setBackgroundColor(barColor)
draw.write(string.rep(" ", filled))
draw.setBackgroundColor(bgColor)
draw.write(string.rep(" ", width - filled))
end
local function drawButton(x, y, text, fg, bg, padLeft, padRight)
padLeft = padLeft or 1
padRight = padRight or 1
local full = string.rep(" ", padLeft) .. text .. string.rep(" ", padRight)
monWrite(x, y, full, fg, bg)
return x, y, x + #full - 1, y
end
------------------------------------------------- -------------------------------------------------
-- Dashboard (reads ONLY from cache — no peripheral calls — instant) -- Dashboard (reads ONLY from cache — no peripheral calls — instant)