diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 13:03:18 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 13:03:18 +0200 |
| commit | ad40e5c153fa2ccd9162bc970eabd5a11db11a32 (patch) | |
| tree | c6b2c57ea1deab1f2eae373a95004cdcba67c90e /lib | |
| parent | adecc8de0e90b3856c8807e1c3610c70879545ad (diff) | |
| download | conky-theme-udt-ad40e5c153fa2ccd9162bc970eabd5a11db11a32.tar.gz conky-theme-udt-ad40e5c153fa2ccd9162bc970eabd5a11db11a32.zip | |
feat: fluid type for the gpu and cache cards
The big value moves to the right of the heading, on the same baseline,
so the card's width carries it instead of leaving the right half empty.
Type now scales to fill the cell: card.fit_unit measures the rows and
returns the largest size that fits the width, and the widget takes the
smaller of that and its height budget, shrinking only where a row would
collide.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/card.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/card.lua b/lib/card.lua index 185703c..c83e6bc 100644 --- a/lib/card.lua +++ b/lib/card.lua @@ -205,6 +205,34 @@ function M.ring(cr, cx, cy, r, frac, colour, colors, width) cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT) end +-- The largest base size S at which every row of pieces still fits max_w, +-- measured at a reference size and scaled. +-- +-- `groups` is a list of rows; each row is a list of { text, font, factor } +-- pieces drawn at factor*S on that row. A widget uses this to derive one +-- fluid size for the whole card: the cell's height decides how large the +-- content grows, and this pulls S back down only where a row would overrun +-- the width, so type fills the card instead of leaving empty space and never +-- collides. Returns math.huge when there is nothing to measure, leaving the +-- caller's height budget in charge. +function M.fit_unit(cr, max_w, groups, ref) + if not (max_w and max_w > 0) then return math.huge end + ref = ref or 100 + local S = math.huge + for _, row in ipairs(groups) do + local w = 0 + for _, piece in ipairs(row) do + M.font(cr, piece[2], ref * piece[3], false) + w = w + (M.measure(cr, piece[1])) + end + if w > 0 then + local fit = ref * max_w / w + if fit < S then S = fit end + end + end + return S +end + -- Bytes to a short human string: 1181116006 -> '1.1G'. -- The card formats its own numbers because the samplers pass raw bytes. function M.human(bytes) |
