aboutsummaryrefslogtreecommitdiffhomepage
path: root/init.lua
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-07-08 19:11:59 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-07-08 19:11:59 -0400
commit0c5db0948dabfb31aefc8f21bd58084cb0e1dbf6 (patch)
treeb674b7996ea401428e18c0459626cd6af20a991f /init.lua
parent0a7df04bb862e3b2901b28d62ec1a004c84e56f4 (diff)
Auto-convert '#RRGGBB' format theme colors to 0xBBGGRR number format.
This allows for use of colors directly in view functions.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua6
1 files changed, 5 insertions, 1 deletions
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)