radical/bar.lua

78 lines
2.8 KiB
Lua
Raw Normal View History

local setmetatable = setmetatable
local base = require( "radical.base" )
local wibox = require( "wibox" )
2014-02-23 05:59:03 +01:00
local item_style = require( "radical.item.style.arrow_single" )
local item_layout= require( "radical.item.layout.horizontal" )
local common = require( "radical.common" )
local shape = require( "gears.shape" )
2014-01-04 06:49:20 +01:00
local module = {}
2014-01-04 06:49:20 +01:00
local function setup_drawable(data)
local internal = data._internal
2014-01-04 06:49:20 +01:00
-- Use a background to make the border work
internal.widget = wibox.widget.base.make_widget_declarative {
{
{
id = "main_layout" ,
spacing = data.spacing or nil,
_data = data ,
layout = internal.layout_func or wibox.layout.fixed.horizontal
},
id = "main_margin" ,
layout = wibox.container.margin,
},
shape = data.shape or shape.rectangle or nil,
shape_border_width = data.border_width ,
shape_border_color = data.border_color ,
widget = wibox.container.background ,
}
internal.layout = internal.widget:get_children_by_id("main_layout")[1]
internal.margin = internal.widget:get_children_by_id("main_margin")[1]
2014-01-05 23:35:23 +01:00
--Getters
data.get_visible = function() return true end
data.get_margins = common.get_margins
function data.get_widget()
return internal.widget
end
data:get_margins()
2014-01-05 23:35:23 +01:00
if data.style then
data.style(data)
end
2014-01-05 23:35:23 +01:00
common.setup_item_move_events(data)
2014-01-05 23:35:23 +01:00
end
2014-01-04 06:49:20 +01:00
local function new(args)
args = args or {}
args.border_width = args.border_width or 0
args.internal = args.internal or {}
2014-01-04 06:49:20 +01:00
args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable
args.internal.setup_item = args.internal.setup_item or common.setup_item
args.item_style = args.item_style or item_style
args.item_layout = args.item_layout or item_layout
args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1
2014-01-04 06:49:20 +01:00
local ret = base(args)
2014-03-12 05:31:50 +01:00
return ret,ret._internal.widget
2014-01-04 06:49:20 +01:00
end
function module.flex(args)
args = args or {}
args.internal = args.internal or {}
args.internal.layout_func = wibox.layout.flex.horizontal()
local data = new(args)
return data,data._internal.margin
end
2014-01-04 06:49:20 +01:00
return setmetatable(module, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 4; replace-tabs on;