aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/gpu.lua
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/gpu.lua')
-rw-r--r--widgets/gpu.lua48
1 files changed, 35 insertions, 13 deletions
diff --git a/widgets/gpu.lua b/widgets/gpu.lua
index 87e22f3..7933e3b 100644
--- a/widgets/gpu.lua
+++ b/widgets/gpu.lua
@@ -24,26 +24,48 @@ function M.draw(cr, rect, colors)
local inner = card.card(cr, rect, colors)
local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end
- local label_size = clamp(inner.w * 0.030, 11, 18)
- local big_size = clamp(inner.w * 0.085, 26, 56)
- local row_size = clamp(inner.w * 0.030, 11, 17)
+ local pkg = data.sensor('xe', 'temp2_input')
+ local big_txt = pkg and string.format('%d\u{00B0}', pkg) or '--'
+
+ -- Fluid type. One base size S drives every element. The cell's height sets
+ -- how large the content grows; the measured width fit pulls S back down
+ -- only where the header or a row would overrun the card. So a tall cell
+ -- gets larger type instead of empty space, and nothing ever collides.
+ local LABEL_F, ROW_F = 0.32, 0.34
+ local row_n = #TEMPS + 1 -- VRAM + FAN
+ local S_h = inner.h * 0.94 / (2.088 + row_n * 0.646)
+ local groups = {
+ { { 'GPU', card.FONT_MONO, LABEL_F }, { big_txt, card.FONT_HEAVY, 1.0 } },
+ { { 'ARC B580', card.FONT_MONO, LABEL_F } },
+ }
+ for _, t in ipairs(TEMPS) do
+ groups[#groups + 1] = { { t[3], card.FONT_MONO, ROW_F },
+ { '888\u{00B0}', card.FONT_MONO, ROW_F } }
+ end
+ groups[#groups + 1] = { { 'FAN', card.FONT_MONO, ROW_F },
+ { '8888 RPM', card.FONT_MONO, ROW_F } }
+ local S = clamp(math.min(S_h, card.fit_unit(cr, inner.w * 0.96, groups, 100)), 10, 72)
+ local label_size = S * LABEL_F
+ local row_size = S * ROW_F
local y = inner.y
+ -- The package temperature is the headline, since there is no load to show.
+ -- It shares the header line with the label, set on the same baseline and
+ -- right-aligned, so the card's width carries the number rather than leaving
+ -- the right half empty under a left-set value.
+ card.font(cr, card.FONT_HEAVY, S, false)
+ card.rgba(cr, pkg and card.threshold(pkg, 75, 85, colors) or colors.label)
+ card.text_right(cr, inner.x + inner.w, y + S, big_txt)
+
card.font(cr, card.FONT_MONO, label_size, false)
card.rgba(cr, colors.label)
- card.text(cr, inner.x, y + label_size, 'GPU')
- card.rgba(cr, colors.value)
- card.text_right(cr, inner.x + inner.w, y + label_size, 'ARC B580')
+ card.text(cr, inner.x, y + S, 'GPU')
- -- The package temperature is the headline, since there is no load to show.
- local pkg = data.sensor('xe', 'temp2_input')
- card.font(cr, card.FONT_HEAVY, big_size, false)
- card.rgba(cr, pkg and card.threshold(pkg, 75, 85, colors) or colors.label)
- card.text(cr, inner.x, y + label_size + big_size,
- pkg and string.format('%d\u{00B0}', pkg) or '--')
+ card.rgba(cr, colors.value)
+ card.text(cr, inner.x, y + S + label_size * 1.7, 'ARC B580')
- local ey = y + label_size + big_size + 18
+ local ey = y + S + label_size * 3.4
local step = row_size * 1.9
card.font(cr, card.FONT_MONO, row_size, false)