Cursor doesn't move yet in response, but I'd like it to stay on screen.
TZ3ZNGRMZ3DG33VVEZI74W5W5T73JYMEIYQ3SO6Y4A6FN3OUZIKQC
if chord == 'up' then
Display_settings.y = math.max(Display_settings.y - Pan_step, 0)
elseif chord == 'down' then
local visible_column_max_y = most(column_height, visible_columns())
if visible_column_max_y - Display_settings.y > App.screen.height/2 then
Display_settings.y = Display_settings.y + Pan_step
end
elseif chord == 'left' then
Display_settings.x = math.max(Display_settings.x - Pan_step, 0)
elseif chord == 'right' then
if Display_settings.x < (#Surface-1) * (Display_settings.column_width + Padding_horizontal) then
Display_settings.x = Display_settings.x + Pan_step
end
elseif chord == 'pageup' or chord == 'S-up' then
Display_settings.y = math.max(Display_settings.y - App.screen.height + Line_height*2, 0)
elseif chord == 'pagedown' or chord == 'S-down' then
local visible_column_max_y = most(column_height, visible_columns())
if visible_column_max_y - Display_settings.y > App.screen.height then
Display_settings.y = Display_settings.y + App.screen.height - Line_height*2
end
elseif chord == 'S-left' then
Display_settings.x = math.max(Display_settings.x - Display_settings.column_width - Padding_horizontal, 0)
elseif chord == 'S-right' then
if Display_settings.x < (#Surface-1) * (Display_settings.column_width + Padding_horizontal) then
Display_settings.x = Display_settings.x + Display_settings.column_width + Padding_horizontal
end
end
end
end
function visible_columns()
local result = {}
local col = col(Display_settings.x)
local x = left_edge_sx(col) - Display_settings.x
while col <= #Surface do
x = x + Padding_horizontal
table.insert(result, col)
x = x + Display_settings.column_width + Padding_horizontal
if x > App.screen.width then
break
end
col = col+1
-- convert x surface pixel coordinate into column index
function col(x)
return 1 + math.floor(x / (Padding_horizontal + Display_settings.column_width))
end
-- col is 1-indexed
-- returns x surface pixel coordinate of left edge of column col
function left_edge_sx(col)
return Margin_right + (col-1)*(Padding_horizontal + Display_settings.column_width)
end
function column_height(col)
local result = Margin_top
for pane_index, pane in ipairs(Surface[col]) do
result = result + Margin_above + Cache[pane.id].height + Margin_below + Padding_vertical
end
return result
end
function most(f, arr)
local result = nil
for _,x in ipairs(arr) do
local curr = f(x)
if result == nil or result < curr then
result = curr
end
end
return result
end