Add more item styles, inspired by Android Holo and Neon themes

This commit is contained in:
Emmanuel Lepage Vallee 2014-11-02 23:27:52 -05:00
parent 1a7630e437
commit e72323441d
4 changed files with 280 additions and 0 deletions

84
item/style/holo.lua Normal file
View File

@ -0,0 +1,84 @@
local setmetatable = setmetatable
local math = math
local base = require( "radical.base" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local print = print
local module = {
margins = {
TOP = 2,
BOTTOM = 6,
RIGHT = 4,
LEFT = 4
}
}
local state_cache = {}
local function gen(width,height,bg_color,border_color)
local img = cairo.ImageSurface(cairo.Format.ARGB32, width,height)
local cr = cairo.Context(img)
local rad = corner_radius or 3
cr:set_source(color(bg_color))
cr:rectangle(0,height -4, width , 4)
cr:fill()
return cairo.Pattern.create_for_surface(img)
end
local function widget_draw(self, w, cr, width, height)
local state = self._item.state or {}
local current_state = state._current_key or ""
if not state_cache[current_state] then
state_cache[current_state] = {}
end
local cache = state_cache[current_state]
local hash = width+1234*height
local cached = cache[hash]
--Generate the pixmap
if not cached then
local state_name = current_state == "" and "bg" or "bg_"..(base.colors_by_id[current_state] or "")
cached = gen(width,height,self._item[state_name],bc)
cache[hash] = cached
end
if current_state ~= self._last_state then
self:set_bg(cached)
self._last_state = current_state
end
self:_drawrounded(w, cr, width, height)
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end
local function draw(item,args)
local args = args or {}
if not item.widget._overlay_init then
item.widget._drawrounded = item.widget.draw
item.widget.draw = widget_draw
item.widget._overlay_init = true
item.widget._item = item
end
local state = item.state or {}
local current_state = state._current_key or nil
local state_name = base.colors_by_id[current_state]
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
item.widget:set_fg(item["fg_focus"])
elseif state_name then
item.widget:set_fg( item["fg_"..state_name])
else
item.widget:set_fg(item["fg_normal"])
end
end
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -1,8 +1,11 @@
return {
basic = require("radical.item.style.basic" ),
classic = require("radical.item.style.classic" ),
subtle = require("radical.item.style.subtle" ),
rounded = require("radical.item.style.rounded" ),
holo = require("radical.item.style.holo" ),
arrow_alt = require("radical.item.style.arrow_alt" ),
arrow_prefix = require("radical.item.style.arrow_prefix" ),
arrow_single = require("radical.item.style.arrow_single" ),
slice_prefix = require("radical.item.style.slice_prefix" ),
}

View File

@ -0,0 +1,96 @@
local setmetatable = setmetatable
local base = require( "radical.base" )
local beautiful = require("beautiful" )
local color = require("gears.color" )
local cairo = require("lgi" ).cairo
local wibox = require("wibox" )
local arrow_alt = require("radical.item.style.arrow_alt")
local module = {
margins = {
TOP = 0,
BOTTOM = 0,
RIGHT = 0,
LEFT = 0
}
}
local function prefix_draw(self, w, cr, width, height)
cr:save()
-- This item style require negative padding, this is a little dangerous to
-- do as it can corrupt area outside of the widget
local col = self._item.bg_prefix or beautiful.icon_grad or beautiful.fg_normal
cr:set_source(color(col))
cr:move_to(0,0)
cr:line_to(width,0)
cr:line_to(width-height/2-height/4,height)
cr:line_to(-height/2-height/4,height)
cr:close_path()
cr:reset_clip()
cr:fill()
cr:restore()
self._draw(self, w, cr, width, height)
end
local function prefix_fit(box,w,h)
local width,height = box._fit(box,w,h)
return width + h/2,height
end
local function suffix_fit(box,w,h)
local width,height = box._fit(box,w,h)
return width + h/2 + h/6,height
end
local function widget_draw(self, w, cr, width, height)
self:_drawprefix(w, cr, width, height)
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end
local function draw(item,args)
local args = args or {}
if not item.widget._overlay_init then
item.widget._drawprefix = item.widget.draw
item.widget.draw = widget_draw
item.widget._overlay_init = true
end
if not item._internal.align._setup then
item._internal.align._setup = true
-- Replace prefix function
item._internal.align.first._item = item
item._internal.align.first._fit = item._internal.align.first.fit
item._internal.align.first._draw = item._internal.align.first.draw
item._internal.align.first.fit = prefix_fit
item._internal.align.first.draw = prefix_draw
-- Replace suffix function
item._internal.align.third._item = item
item._internal.align.third._fit = item._internal.align.third.fit
item._internal.align.third.fit = suffix_fit
end
local state = item.state or {}
local current_state = state._current_key or nil
local state_name = base.colors_by_id[current_state]
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
item.widget:set_bg(args.color or item.bg_focus)
item.widget:set_fg(item["fg_focus"])
elseif state_name then
item.widget:set_bg(args.color or item["bg_"..state_name])
item.widget:set_fg( item["fg_"..state_name])
else
item.widget:set_bg(args.color or nil)
item.widget:set_fg(item["fg"])
end
end
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;

97
item/style/subtle.lua Normal file
View File

@ -0,0 +1,97 @@
local setmetatable = setmetatable
local math = math
local base = require( "radical.base" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local print = print
local module = {
margins = {
TOP = 4,
BOTTOM = 4,
RIGHT = 4,
LEFT = 4
}
}
local state_cache = {}
local function gen(w,h,bg_color,border_color)
cr:save()
local img = cairo.ImageSurface(cairo.Format.ARGB32, w,h)
local cr = cairo.Context(img)
local rad = corner_radius or 3
cr:set_source(color(bg_color))
local radius = 3
cr:arc(radius,radius,radius,math.pi,3*(math.pi/2))
cr:arc(w-radius,radius,radius,3*(math.pi/2),math.pi*2)
cr:line_to(w,h)
cr:arc(radius,h-radius,radius,math.pi/2,math.pi)
cr:close_path()
cr:clip()
cr:paint_with_alpha(0.3)
cr:reset_clip()
cr:move_to(w,h-6)
cr:line_to(w,h)
cr:line_to(w-6,h)
cr:fill()
cr:restore()
return cairo.Pattern.create_for_surface(img)
end
local function widget_draw(self, w, cr, width, height)
local state = self._item.state or {}
local current_state = state._current_key or ""
if not state_cache[current_state] then
state_cache[current_state] = {}
end
local cache = state_cache[current_state]
local hash = width+1234*height
local cached = cache[hash]
--Generate the pixmap
if not cached then
local state_name = current_state == "" and "bg" or "bg_"..(base.colors_by_id[current_state] or "")
cached = gen(width,height,self._item[state_name],bc)
cache[hash] = cached
end
if current_state ~= self._last_state then
self:set_bg(cached)
self._last_state = current_state
end
self:_drawrounded(w, cr, width, height)
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end
local function draw(item,args)
local args = args or {}
if not item.widget._overlay_init then
item.widget._drawrounded = item.widget.draw
item.widget.draw = widget_draw
item.widget._overlay_init = true
item.widget._item = item
end
local state = item.state or {}
local current_state = state._current_key or nil
local state_name = base.colors_by_id[current_state]
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
item.widget:set_fg(item["fg_focus"])
elseif state_name then
item.widget:set_fg( item["fg_"..state_name])
else
item.widget:set_fg(item["fg_normal"])
end
end
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;