diff options
Diffstat (limited to 'widgets/details.lua')
| -rw-r--r-- | widgets/details.lua | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/widgets/details.lua b/widgets/details.lua index 45f2f3d..36ce016 100644 --- a/widgets/details.lua +++ b/widgets/details.lua @@ -1,4 +1,5 @@ --- Details: wind, humidity, UV and air quality, over a wind compass. +-- Details: wind, humidity, UV and air quality, with a wind compass as the +-- big value. -- -- Adapted from the Conky-Mirage theme's details tiles by alexsson-xexpanderx -- (see lib/weather.lua). UV and AQI are the measured quantities here, so they @@ -10,17 +11,18 @@ local weather = require 'lib.weather' local M = {} -local function draw_compass(cr, x, y, w, h, colors, deg, S) - local r = math.min(w, h) / 2 - S * 0.1 - if r < 24 then return end - local cx, cy = x + w / 2, y + h / 2 +-- The compass fills the big value's slot: `size` square, its right edge at +-- `right`, its top at `top`. +local function draw_compass(cr, right, top, size, colors, deg) + local r = size / 2 + local cx, cy = right - r, top + r card.rgba(cr, colors.rule, 0.8) cairo_set_line_width(cr, 1) cairo_new_path(cr) cairo_arc(cr, cx, cy, r, 0, math.pi * 2) cairo_stroke(cr) - local size = math.min(r * 0.2, S * 0.32) + local size = r * 0.28 card.font(cr, card.FONT_MONO, size, false) card.rgba(cr, colors.label) for i, p in ipairs({ 'N', 'E', 'S', 'W' }) do @@ -32,7 +34,7 @@ local function draw_compass(cr, x, y, w, h, colors, deg, S) if type(deg) ~= 'number' then return end -- Open-Meteo gives where the wind comes FROM; the needle points where it goes. local a = math.rad(deg + 180) - local tip = r - size * 2 + local tip = r - size * 1.6 local sa, ca = math.sin(a), math.cos(a) -- A filled arrowhead at the tip, so the needle reads one way only. The shaft -- stops at the head's base: a stroke run to the apex would blunt it. @@ -74,10 +76,13 @@ function M.draw(cr, rect, colors) colors[weather.uv_role(uv)] }, { 'AIR (EAQI)', weather.num(aqi), colors[weather.aqi_role(aqi)] }, } - local y, S = card.standard(cr, inner, colors, { - icon = card.ICON.details, title = 'DETAILS', rows = rows, share = 0.8, + card.standard(cr, inner, colors, { + icon = card.ICON.details, title = 'DETAILS', rows = rows, + big = function(cr, right, top, size) + -- 1.2x the slot: the first row starts lower than the big text ends. + draw_compass(cr, right, top, size * 1.2, colors, c.wind_deg) + end, }) - draw_compass(cr, inner.x, y, inner.w, inner.y + inner.h - y, colors, c.wind_deg, S) end return M |
