-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,55 @@ | ||
local setmetatable = setmetatable | ||
local ipairs = ipairs | ||
local math = math | ||
local wibox = require( "wibox" ) | ||
|
||
local module = {} | ||
|
||
local function left(data) | ||
data.next_item.selected = true | ||
data.next_item.selected = true | ||
end | ||
|
||
local function right(data) | ||
data.previous_item.selected = true | ||
data.previous_item.selected = true | ||
end | ||
|
||
local function up(data) | ||
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 | ||
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 | ||
end | ||
|
||
local function down(data) | ||
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 | ||
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 | ||
end | ||
|
||
function module:setup_key_hooks(data) | ||
data:add_key_hook({}, "Up" , "press", up ) | ||
data:add_key_hook({}, "&" , "press", up ) | ||
data:add_key_hook({}, "Down" , "press", down ) | ||
data:add_key_hook({}, "KP_Enter", "press", down ) | ||
data:add_key_hook({}, "Left" , "press", left ) | ||
data:add_key_hook({}, "\"" , "press", left ) | ||
data:add_key_hook({}, "Right" , "press", right ) | ||
data:add_key_hook({}, "#" , "press", right ) | ||
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 ) | ||
end | ||
|
||
--Get preferred item geometry | ||
local function item_fit(data,item,...) | ||
return data.item_height, data.item_height | ||
return data.item_height, data.item_height | ||
end | ||
|
||
local function new(data) | ||
local mode = data.column ~= nil | ||
local rows = {} | ||
local l = wibox.layout.fixed[mode and "horizontal" or "vertical"]() | ||
local constraint = mode and data.column or data.row or 2 | ||
for i=1,constraint do | ||
local l2 = wibox.layout.fixed[mode and "vertical" or "horizontal"]() | ||
l:add(l2) | ||
rows[#rows+1] = l2 | ||
end | ||
l.fit = function(a1,a2,a3) | ||
local r1,r2 = data.item_height*math.ceil(data.rowcount/constraint),data.item_height*constraint | ||
return (mode and r2 or r1),(mode and r1 or r2) | ||
end | ||
l.add = function(_, it) | ||
for k,v in ipairs(rows) do | ||
v:reset() | ||
end | ||
local rc = data.rowcount+1 | ||
for i=1,rc do | ||
rows[((i-1)%constraint)+1]:add((rc == i and it.widget or data.items[i].widget)) | ||
end | ||
return true | ||
end | ||
--TODO only load the layouts when draw() is called | ||
l.item_fit = item_fit | ||
return l | ||
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 | ||
} | ||
end | ||
|
||
return setmetatable(module, { __call = function(_, ...) return new(...) end }) | ||
-- kate: space-indent on; indent-width 2; replace-tabs on; | ||
-- kate: space-indent on; indent-width 4; replace-tabs on; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters