From 0c5db0948dabfb31aefc8f21bd58084cb0e1dbf6 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 8 Jul 2020 19:11:59 -0400 Subject: Auto-convert '#RRGGBB' format theme colors to 0xBBGGRR number format. This allows for use of colors directly in view functions. --- init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 9a56f2a5..36ba839c 100644 --- a/init.lua +++ b/init.lua @@ -35,7 +35,11 @@ local function set_theme(view, name, options) -- be captured later during init. local property = view.property local colors = setmetatable({}, {__newindex = function(t, name, color) - property['color.' .. name] = color -- TODO: auto-convert '#RRGGBB'? + if type(color) == 'string' then + local r, g, b = color:match('^#(%x%x)(%x%x)(%x%x)$') + color = tonumber(string.format('%s%s%s', b, g, r), 16) or 0 + end + property['color.' .. name] = color rawset(t, name, color) -- cache instead of __index for property[...] end}) local styles = setmetatable({}, {__newindex = function(_, name, props) -- cgit v1.2.3