diff options
Diffstat (limited to 'apps/plugins/lua/include_lua/printtable.lua')
-rw-r--r-- | apps/plugins/lua/include_lua/printtable.lua | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/apps/plugins/lua/include_lua/printtable.lua b/apps/plugins/lua/include_lua/printtable.lua index b289beeb0e..c23d801f83 100644 --- a/apps/plugins/lua/include_lua/printtable.lua +++ b/apps/plugins/lua/include_lua/printtable.lua | |||
@@ -27,9 +27,9 @@ require("actions") -- Contains rb.actions & rb.contexts | |||
27 | local _clr = require("color") | 27 | local _clr = require("color") |
28 | local _print = require("print") | 28 | local _print = require("print") |
29 | local _timer = require("timer") | 29 | local _timer = require("timer") |
30 | local sb_width = 5 | ||
30 | 31 | ||
31 | -- Button definitions -- | 32 | -- Button definitions -- |
32 | local EXIT_BUTTON = rb.PLA_EXIT | ||
33 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL | 33 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL |
34 | local DOWN_BUTTON = rb.actions.PLA_DOWN | 34 | local DOWN_BUTTON = rb.actions.PLA_DOWN |
35 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT | 35 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT |
@@ -71,8 +71,8 @@ end | |||
71 | -- time since last button press is returned in ticks.. | 71 | -- time since last button press is returned in ticks.. |
72 | -- make xi, xir, yi, yir negative to flip direction... | 72 | -- make xi, xir, yi, yir negative to flip direction... |
73 | ]] | 73 | ]] |
74 | 74 | local function dpad(x, xi, xir, y, yi, yir, timeout, overflow) | |
75 | local function dpad(x, xi, xir, y, yi, yir, timeout) | 75 | local scroll_is_fixed = overflow ~= "manual" |
76 | _timer("dpad") -- start a persistant timer; keeps time between button events | 76 | _timer("dpad") -- start a persistant timer; keeps time between button events |
77 | if timeout == nil then timeout = -1 end | 77 | if timeout == nil then timeout = -1 end |
78 | local cancel, select = 0, 0 | 78 | local cancel, select = 0, 0 |
@@ -98,10 +98,18 @@ local function dpad(x, xi, xir, y, yi, yir, timeout) | |||
98 | timeout = timeout + 1 | 98 | timeout = timeout + 1 |
99 | elseif button == LEFT_BUTTON then | 99 | elseif button == LEFT_BUTTON then |
100 | x_chg = x_chg - xi | 100 | x_chg = x_chg - xi |
101 | if scroll_is_fixed then | ||
102 | cancel = 1 | ||
103 | break; | ||
104 | end | ||
101 | elseif button == LEFTR_BUTTON then | 105 | elseif button == LEFTR_BUTTON then |
102 | x_chg = x_chg - xir | 106 | x_chg = x_chg - xir |
103 | elseif button == RIGHT_BUTTON then | 107 | elseif button == RIGHT_BUTTON then |
104 | x_chg = x_chg + xi | 108 | x_chg = x_chg + xi |
109 | if scroll_is_fixed then | ||
110 | select = 1 | ||
111 | timeout = timeout + 1 | ||
112 | end | ||
105 | elseif button == RIGHTR_BUTTON then | 113 | elseif button == RIGHTR_BUTTON then |
106 | x_chg = x_chg + xir | 114 | x_chg = x_chg + xir |
107 | elseif button == UP_BUTTON then | 115 | elseif button == UP_BUTTON then |
@@ -152,19 +160,26 @@ function print_table(t, t_count, settings) | |||
152 | end | 160 | end |
153 | 161 | ||
154 | local wrap, justify, start, curpos, co_routine, hasheader, m_sel | 162 | local wrap, justify, start, curpos, co_routine, hasheader, m_sel |
155 | local header_fgc, header_bgc, item_fgc, item_bgc, item_selc, drawsep | 163 | local header_fgc, header_bgc, item_fgc, item_bgc, item_selc |
164 | local table_linedesc, drawsep, overflow, dpad_fn | ||
156 | do | 165 | do |
157 | local s = settings or _print.get_settings() | 166 | local s = settings or _print.get_settings() |
158 | wrap, justify = s.wrap, s.justify | 167 | wrap, justify = s.wrap, s.justify |
159 | start, curpos = s.start, s.curpos | 168 | start, curpos = s.start, s.curpos |
160 | co_routine = s.co_routine | 169 | co_routine = s.co_routine |
161 | hasheader = s.hasheader | 170 | hasheader = s.hasheader |
162 | drawsep = s.drawsep | 171 | drawsep = s.drawsep |
163 | m_sel = false | 172 | sb_width = s.sb_width or sb_width |
173 | m_sel = false | ||
174 | table_linedesc = s.linedesc | ||
175 | dpad_fn = s.dpad_fn | ||
176 | if type(dpad_fn) ~= "function" then dpad_fn = dpad end | ||
177 | |||
164 | if co_routine == nil then | 178 | if co_routine == nil then |
165 | --no multi select in incremental mode | 179 | --no multi select in incremental mode |
166 | m_sel = s.msel | 180 | m_sel = s.msel |
167 | end | 181 | end |
182 | overflow = s.ovfl or "auto" | ||
168 | header_fgc = s.hfgc or _clr.set( 0, 000, 000, 000) | 183 | header_fgc = s.hfgc or _clr.set( 0, 000, 000, 000) |
169 | header_bgc = s.hbgc or _clr.set(-1, 255, 255, 255) | 184 | header_bgc = s.hbgc or _clr.set(-1, 255, 255, 255) |
170 | item_fgc = s.ifgc or _clr.set(-1, 000, 255, 060) | 185 | item_fgc = s.ifgc or _clr.set(-1, 000, 255, 060) |
@@ -210,16 +225,19 @@ function print_table(t, t_count, settings) | |||
210 | -- displays header text at top | 225 | -- displays header text at top |
211 | local function disp_header(hstr) | 226 | local function disp_header(hstr) |
212 | local header = header or hstr | 227 | local header = header or hstr |
213 | local opts = _print.opt.get() | 228 | local opts = _print.opt.get() -- save to restore settings |
214 | _print.opt.overflow("none") -- don't scroll header; colors change | 229 | _print.opt.overflow("auto") -- don't scroll header; colors change |
215 | _print.opt.color(header_fgc, header_bgc) | 230 | _print.opt.color(header_fgc, header_bgc) |
216 | _print.opt.line(1) | 231 | _print.opt.line(1) |
217 | 232 | ||
233 | rb.set_viewport(_print.opt.get(true)) | ||
218 | _print.f() | 234 | _print.f() |
219 | local line = _print.f(header) | 235 | _print.f("%h", tostring(header)) --hack to signal header |
220 | 236 | ||
221 | _print.opt.set(opts) | 237 | _print.opt.set(opts) -- restore settings |
222 | _print.opt.line(2) | 238 | _print.opt.line(2) |
239 | rb.set_viewport(opts) | ||
240 | opts = nil | ||
223 | return 2 | 241 | return 2 |
224 | end | 242 | end |
225 | 243 | ||
@@ -229,7 +247,7 @@ function print_table(t, t_count, settings) | |||
229 | rb.lcd_update() | 247 | rb.lcd_update() |
230 | 248 | ||
231 | local quit, select, x_chg, xi, y_chg, yi, timeb = | 249 | local quit, select, x_chg, xi, y_chg, yi, timeb = |
232 | dpad(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl) | 250 | dpad_fn(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl, nil, overflow) |
233 | 251 | ||
234 | t_p.vcursor = t_p.vcursor + y_chg | 252 | t_p.vcursor = t_p.vcursor + y_chg |
235 | 253 | ||
@@ -322,6 +340,7 @@ function print_table(t, t_count, settings) | |||
322 | 340 | ||
323 | rb.button_clear_queue() -- keep the button queue from overflowing | 341 | rb.button_clear_queue() -- keep the button queue from overflowing |
324 | end | 342 | end |
343 | rb.lcd_scroll_stop() | ||
325 | return sel | 344 | return sel |
326 | end -- display_table | 345 | end -- display_table |
327 | --============================================================================-- | 346 | --============================================================================-- |
@@ -331,7 +350,7 @@ function print_table(t, t_count, settings) | |||
331 | _print.opt.color(item_fgc, item_bgc, item_selc) | 350 | _print.opt.color(item_fgc, item_bgc, item_selc) |
332 | 351 | ||
333 | table_p = init_position(15, 5) | 352 | table_p = init_position(15, 5) |
334 | line, maxline = _print.opt.area(5, 1, rb.LCD_WIDTH - 10, rb.LCD_HEIGHT - 2) | 353 | line, maxline = _print.opt.area(5, 1, rb.LCD_WIDTH - 10 - sb_width, rb.LCD_HEIGHT - 2) |
335 | maxline = math.min(maxline, t_count) | 354 | maxline = math.min(maxline, t_count) |
336 | 355 | ||
337 | -- allow user to start at a position other than the beginning | 356 | -- allow user to start at a position other than the beginning |
@@ -349,9 +368,11 @@ function print_table(t, t_count, settings) | |||
349 | end | 368 | end |
350 | 369 | ||
351 | _print.opt.sel_line(table_p.vcursor) | 370 | _print.opt.sel_line(table_p.vcursor) |
352 | _print.opt.overflow("manual") | 371 | _print.opt.overflow(overflow) |
353 | _print.opt.justify(justify) | 372 | _print.opt.justify(justify) |
354 | 373 | ||
374 | _print.opt.linedesc(table_linedesc) | ||
375 | |||
355 | local opts = _print.opt.get() | 376 | local opts = _print.opt.get() |
356 | opts.drawsep = drawsep | 377 | opts.drawsep = drawsep |
357 | _print.opt.set(opts) | 378 | _print.opt.set(opts) |
@@ -360,17 +381,19 @@ function print_table(t, t_count, settings) | |||
360 | -- initialize vertical scrollbar | 381 | -- initialize vertical scrollbar |
361 | set_vsb(); do | 382 | set_vsb(); do |
362 | local vsb =_print.opt.get() | 383 | local vsb =_print.opt.get() |
384 | vsb.width = vsb.width + sb_width | ||
385 | |||
363 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | 386 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens |
364 | vsb.fg_pattern = 3 - vsb.fg_pattern | 387 | vsb.fg_pattern = 3 - vsb.fg_pattern |
365 | vsb.bg_pattern = 3 - vsb.bg_pattern | 388 | vsb.bg_pattern = 3 - vsb.bg_pattern |
366 | end | 389 | end |
367 | 390 | ||
368 | set_vsb = function (item) | 391 | set_vsb = function (item) |
369 | if t_count > (maxline or t_count) then | 392 | if sb_width > 0 and t_count > (maxline or t_count) then |
370 | rb.set_viewport(vsb) | 393 | rb.set_viewport(vsb) |
371 | item = item or 0 | 394 | item = item or 0 |
372 | local m = maxline / 2 + 1 | 395 | local m = maxline / 2 + 1 |
373 | rb.gui_scrollbar_draw(vsb.width - 5, vsb.y, 5, vsb.height, | 396 | rb.gui_scrollbar_draw(vsb.width - sb_width, vsb.y, sb_width, vsb.height, |
374 | t_count, math.max(0, item - m), | 397 | t_count, math.max(0, item - m), |
375 | math.min(item + m, t_count), 0) | 398 | math.min(item + m, t_count), 0) |
376 | end | 399 | end |
@@ -378,7 +401,7 @@ function print_table(t, t_count, settings) | |||
378 | end -- set_vsb | 401 | end -- set_vsb |
379 | local selected = display_table(table_p, 0, 1, 0) | 402 | local selected = display_table(table_p, 0, 1, 0) |
380 | 403 | ||
381 | _print.opt.defaults() | 404 | _print.opt.defaults() --restore settings |
382 | 405 | ||
383 | if m_sel == true then -- walk the table to get selected items | 406 | if m_sel == true then -- walk the table to get selected items |
384 | selected = {} | 407 | selected = {} |