diff options
author | mitchell <70453897+667e-11@users.noreply.github.com> | 2020-07-08 19:11:59 -0400 |
---|---|---|
committer | mitchell <70453897+667e-11@users.noreply.github.com> | 2020-07-08 19:11:59 -0400 |
commit | 0c5db0948dabfb31aefc8f21bd58084cb0e1dbf6 (patch) | |
tree | b674b7996ea401428e18c0459626cd6af20a991f /init.lua | |
parent | 0a7df04bb862e3b2901b28d62ec1a004c84e56f4 (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.lua | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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) |