2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
local function left(data)
|
2016-07-04 08:50:15 +02:00
|
|
|
data.next_item.selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function right(data)
|
2016-07-04 08:50:15 +02:00
|
|
|
data.previous_item.selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function up(data)
|
2016-07-04 08:50:15 +02:00
|
|
|
local idx,rc,col = data.current_index,data.rowcount,data.column
|
|
|
|
idx = idx-col
|
|
|
|
if idx <= 0 then
|
|
|
|
idx = rc + idx + 1
|
|
|
|
end
|
|
|
|
data.items[idx].selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function down(data)
|
2016-07-04 08:50:15 +02:00
|
|
|
local idx,rc,col = data.current_index,data.rowcount,data.column
|
|
|
|
idx = idx+col
|
|
|
|
if idx > rc then
|
|
|
|
idx = idx - rc - 1
|
|
|
|
end
|
|
|
|
data.items[idx].selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
2016-07-04 08:50:15 +02:00
|
|
|
function module.setup_key_hooks(data)
|
|
|
|
data:add_key_hook({}, "Up" , "press", up )
|
|
|
|
data:add_key_hook({}, "Down" , "press", down )
|
|
|
|
data:add_key_hook({}, "Left" , "press", left )
|
|
|
|
data:add_key_hook({}, "Right" , "press", right )
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--Get preferred item geometry
|
|
|
|
local function item_fit(data,item,...)
|
2016-07-04 08:50:15 +02:00
|
|
|
return data.item_height, data.item_height
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function new(data)
|
2016-07-04 08:50:15 +02:00
|
|
|
return wibox.layout {
|
|
|
|
column_count = data.column,
|
|
|
|
row_count = data.row or (not data.column and 2 or nil),
|
|
|
|
item_fit = item_fit,
|
|
|
|
setup_key_hooks = module.setup_key_hooks,
|
|
|
|
layout = wibox.layout.grid --FIXME this is monkeypatched
|
|
|
|
}
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2016-07-04 08:50:15 +02:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|