diff options
Diffstat (limited to 'apps/plugins/lua/include_lua')
-rw-r--r-- | apps/plugins/lua/include_lua/print.lua | 165 | ||||
-rw-r--r-- | apps/plugins/lua/include_lua/printmenus.lua | 249 | ||||
-rw-r--r-- | apps/plugins/lua/include_lua/printtable.lua | 63 |
3 files changed, 419 insertions, 58 deletions
diff --git a/apps/plugins/lua/include_lua/print.lua b/apps/plugins/lua/include_lua/print.lua index 3fb19bef1f..3b4c389848 100644 --- a/apps/plugins/lua/include_lua/print.lua +++ b/apps/plugins/lua/include_lua/print.lua | |||
@@ -123,6 +123,49 @@ local _print = {} do | |||
123 | return w, h, msg | 123 | return w, h, msg |
124 | end | 124 | end |
125 | -------------------------------------------------------------------------------- | 125 | -------------------------------------------------------------------------------- |
126 | local function set_linedesc(t_linedesc, opts) | ||
127 | local o = opts or _print.opt.get(true) | ||
128 | --local out = function() local t = {} for k, v in pairs(o) do t[#t + 1] = tostring(k) t[#t + 1] = tostring(v) end return table.concat(t, "\n") end | ||
129 | --rb.splash_scroller(1000, out()) | ||
130 | local linedesc ={ | ||
131 | --These are the defaults - changes will be made below if you supplied t_linedesc | ||
132 | indent = 0, -- internal indent text | ||
133 | line = 0, -- line index within group | ||
134 | nlines = 1, -- selection grouping | ||
135 | offset = 0, -- internal item offset | ||
136 | scroll = true, | ||
137 | selected = false, --internal | ||
138 | separator_height = 0, | ||
139 | line_separator = false, | ||
140 | show_cursor = false, | ||
141 | show_icons = false, | ||
142 | icon = -1, | ||
143 | icon_fn = function() return -1 end, | ||
144 | style = rb.STYLE_COLORBAR, | ||
145 | text_color = o.fg_pattern or WHITE, | ||
146 | line_color = o.bg_pattern or BLACK, | ||
147 | line_end_color= o.bg_pattern or BLACK, | ||
148 | } | ||
149 | if type(t_linedesc) == "table" then | ||
150 | |||
151 | if not o.linedesc then | ||
152 | o.linedesc = {} | ||
153 | for k, v in pairs(linedesc) do | ||
154 | o.linedesc[k] = v | ||
155 | end | ||
156 | end | ||
157 | |||
158 | for k, v in pairs(t_linedesc) do | ||
159 | o.linedesc[k] = v | ||
160 | end | ||
161 | if o.linedesc.separator_height > 0 then | ||
162 | o.linedesc.line_separator = true | ||
163 | end | ||
164 | return | ||
165 | end | ||
166 | o.linedesc = linedesc | ||
167 | return o.linedesc | ||
168 | end | ||
126 | 169 | ||
127 | -- set defaults for print view | 170 | -- set defaults for print view |
128 | local function set_defaults() | 171 | local function set_defaults() |
@@ -138,11 +181,13 @@ local _print = {} do | |||
138 | line = 1, | 181 | line = 1, |
139 | max_line = _NIL, | 182 | max_line = _NIL, |
140 | col = 0, | 183 | col = 0, |
141 | ovfl = "auto", | 184 | header = false, --Internal use - treats first entry as header |
142 | justify = "left", | 185 | ovfl = "auto", -- auto, manual, none |
143 | autoupdate = true, | 186 | justify = "left", --left, center, right |
144 | drawsep = false, | 187 | autoupdate = true, --updates screen as items are added |
188 | drawsep = false, -- separator between items | ||
145 | } | 189 | } |
190 | set_linedesc(nil, _p_opts) -- default line display | ||
146 | _p_opts.max_line = max_lines(_p_opts) | 191 | _p_opts.max_line = max_lines(_p_opts) |
147 | 192 | ||
148 | s_lines, col_buf = {}, {} | 193 | s_lines, col_buf = {}, {} |
@@ -187,29 +232,16 @@ local _print = {} do | |||
187 | 232 | ||
188 | -- helper function sets up colors/marker for selected items | 233 | -- helper function sets up colors/marker for selected items |
189 | local function show_selected(iLine, msg) | 234 | local function show_selected(iLine, msg) |
190 | local o = get_settings() -- using a copy of opts so changes revert | ||
191 | |||
192 | if s_lines[iLine] == true then | ||
193 | if not rb.lcd_set_background then | ||
194 | o.drawmode = bit.bxor(o.drawmode, 4) | ||
195 | else | ||
196 | o.fg_pattern = o.bg_pattern | ||
197 | o.bg_pattern = o.sel_pattern | ||
198 | end | ||
199 | -- alternative selection method | ||
200 | --msg = "> " .. msg | ||
201 | end | ||
202 | |||
203 | if not o then rb.set_viewport() return end | ||
204 | |||
205 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | 235 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens |
236 | local o = get_settings() -- using a copy of opts so changes revert | ||
237 | if not o then rb.set_viewport() return end | ||
206 | o.fg_pattern = 3 - o.fg_pattern | 238 | o.fg_pattern = 3 - o.fg_pattern |
207 | o.bg_pattern = 3 - o.bg_pattern | 239 | o.bg_pattern = 3 - o.bg_pattern |
240 | rb.set_viewport(o) | ||
241 | o = _NIL | ||
242 | else | ||
243 | show_selected = function() end -- no need to check again | ||
208 | end | 244 | end |
209 | |||
210 | rb.set_viewport(o) | ||
211 | |||
212 | o = _NIL | ||
213 | end | 245 | end |
214 | 246 | ||
215 | -- sets line explicitly or increments line if line is _NIL | 247 | -- sets line explicitly or increments line if line is _NIL |
@@ -274,31 +306,82 @@ local _print = {} do | |||
274 | s_lines[iLine] = true | 306 | s_lines[iLine] = true |
275 | end | 307 | end |
276 | 308 | ||
277 | -- Internal print function | 309 | -- Internal print function |
278 | local function print_internal(t_opts, x, w, h, msg) | 310 | local function print_internal(t_opts, x, w, h, msg) |
279 | 311 | ||
312 | local linedesc | ||
313 | local line_separator = false | ||
280 | local o = t_opts | 314 | local o = t_opts |
281 | if o.justify == "center" then | 315 | local ld = o.linedesc or set_linedesc() |
282 | x = x + (o.width - w) / 2 | 316 | local show_cursor = ld.show_cursor or 0 |
283 | elseif o.justify == "right" then | 317 | local line_indent = 0 |
284 | x = x + (o.width - w) | 318 | |
319 | local linestyle = ld.style or rb.STYLE_COLORBAR | ||
320 | |||
321 | if o.justify ~= "left" then | ||
322 | line_indent = (o.width - w) --"right" | ||
323 | if o.justify == "center" then | ||
324 | line_indent = line_indent / 2 | ||
325 | end | ||
285 | end | 326 | end |
286 | 327 | ||
287 | local line = o.line - 1 -- rb is 0-based lua is 1-based | 328 | local line = o.line - 1 -- rb is 0-based lua is 1-based |
288 | if(o.ovfl == "auto" and w >= o.width) then -- -o.x | 329 | |
289 | rb.lcd_puts_scroll(0, line, msg) | 330 | if o.ovfl == "manual" then --save msg for later side scroll |
331 | col_buf_insert(msg, o.line, o) | ||
332 | end | ||
333 | |||
334 | -- bit of a pain to set the fields this way but its much more efficient than iterating a table to set them | ||
335 | local function set_desc(tld, scroll, separator_height, selected, style, indent, text_color, line_color, line_end_color) | ||
336 | tld.scroll = scroll | ||
337 | tld.separator_height = separator_height | ||
338 | tld.selected = selected | ||
339 | tld.style = style | ||
340 | tld.indent = indent | ||
341 | tld.text_color = text_color | ||
342 | tld.line_color = line_color | ||
343 | tld.line_end_color = line_end_color | ||
344 | end | ||
345 | |||
346 | line_separator = ld.line_separator | ||
347 | |||
348 | if o.line == 1 and o.header then | ||
349 | --rb scroller doesn't like negative offset! | ||
350 | local indent = line_indent < 0 and 0 or line_indent | ||
351 | set_desc(ld, true, 1, false, rb.STYLE_DEFAULT, | ||
352 | indent, o.fg_pattern, o.bg_pattern, o.bg_pattern) | ||
353 | ld.show_cursor = false | ||
354 | elseif s_lines[o.line] then | ||
355 | --/* Display line selector */ | ||
356 | local style = show_cursor == true and rb.STYLE_DEFAULT or linestyle | ||
357 | |||
358 | local indent = line_indent < 0 and 0 or line_indent | ||
359 | --rb scroller doesn't like negative offset! | ||
360 | local ovfl = (o.ovfl == "auto" and w >= o.width and x == 0) | ||
361 | set_desc(ld, ovfl, 0, true, style, indent, | ||
362 | o.bg_pattern, o.sel_pattern, o.sel_pattern) | ||
290 | else | 363 | else |
291 | rb.lcd_putsxy(x, line * h, msg) | 364 | set_desc(ld, false, 0, false, rb.STYLE_DEFAULT,line_indent, |
292 | if o.ovfl == "manual" then --save msg for later side scroll | 365 | o.fg_pattern, o.bg_pattern, o.bg_pattern) |
293 | col_buf_insert(msg, o.line, o) | ||
294 | end | ||
295 | end | 366 | end |
296 | if o.drawsep == true then | 367 | |
297 | if s_lines[o.line] == true then | 368 | if ld.show_icons then |
298 | rb.set_viewport(o) --nned to revert drawmode if selected | 369 | ld.icon = ld.icon_fn(line, ld.icon or -1) |
370 | end | ||
371 | |||
372 | rb.lcd_put_line(x, line *h, msg, ld) | ||
373 | |||
374 | ld.show_cursor = show_cursor | ||
375 | ld.style = linestyle | ||
376 | if line_separator then | ||
377 | if ld.selected == true then | ||
378 | rb.set_viewport(o) -- revert drawmode if selected | ||
299 | end | 379 | end |
300 | rb.lcd_drawline(0, line * h, o.width, line * h) | 380 | rb.lcd_drawline(0, line * h, o.width, line * h) |
381 | rb.lcd_drawline(0, line * h + h, o.width, line * h + h) --only to add the last line | ||
382 | -- but we don't have an idea which line is the last line here so every line is the last line! | ||
301 | end | 383 | end |
384 | |||
302 | --only update the line we changed | 385 | --only update the line we changed |
303 | update_line(o.autoupdate, o, line, h) | 386 | update_line(o.autoupdate, o, line, h) |
304 | 387 | ||
@@ -308,7 +391,7 @@ local _print = {} do | |||
308 | -- Helper function that acts mostly like a normal printf() would | 391 | -- Helper function that acts mostly like a normal printf() would |
309 | local function printf(fmt, v1, ...) | 392 | local function printf(fmt, v1, ...) |
310 | local o = get_settings(true) | 393 | local o = get_settings(true) |
311 | local w, h, msg | 394 | local w, h, msg, rep |
312 | local line = o.line - 1 -- rb is 0-based lua is 1-based | 395 | local line = o.line - 1 -- rb is 0-based lua is 1-based |
313 | 396 | ||
314 | if not (fmt) or (fmt) == "\n" then -- handles blank line / single '\n' | 397 | if not (fmt) or (fmt) == "\n" then -- handles blank line / single '\n' |
@@ -322,6 +405,9 @@ local _print = {} do | |||
322 | return o.line, o.max_line, o.width, h | 405 | return o.line, o.max_line, o.width, h |
323 | end | 406 | end |
324 | 407 | ||
408 | fmt, rep = fmt.gsub(fmt or "", "%%h", "%%s") | ||
409 | o.header = (rep == 1) | ||
410 | |||
325 | msg = string.format(fmt, v1, ...) | 411 | msg = string.format(fmt, v1, ...) |
326 | 412 | ||
327 | show_selected(o.line, msg) | 413 | show_selected(o.line, msg) |
@@ -337,6 +423,8 @@ local _print = {} do | |||
337 | local function set_column(x) | 423 | local function set_column(x) |
338 | local o = get_settings() | 424 | local o = get_settings() |
339 | if o.ovfl ~= "manual" then return end -- no buffer stored to scroll | 425 | if o.ovfl ~= "manual" then return end -- no buffer stored to scroll |
426 | rb.lcd_scroll_stop() | ||
427 | |||
340 | local res, w, h, str, line | 428 | local res, w, h, str, line |
341 | 429 | ||
342 | for key, value in pairs(col_buf) do | 430 | for key, value in pairs(col_buf) do |
@@ -367,6 +455,7 @@ local _print = {} do | |||
367 | _print.opt.justify = set_justify | 455 | _print.opt.justify = set_justify |
368 | _print.opt.sel_line = select_line | 456 | _print.opt.sel_line = select_line |
369 | _print.opt.line = set_line | 457 | _print.opt.line = set_line |
458 | _print.opt.linedesc = set_linedesc | ||
370 | _print.opt.autoupdate = set_update | 459 | _print.opt.autoupdate = set_update |
371 | _print.clear = clear | 460 | _print.clear = clear |
372 | _print.f = printf | 461 | _print.f = printf |
diff --git a/apps/plugins/lua/include_lua/printmenus.lua b/apps/plugins/lua/include_lua/printmenus.lua new file mode 100644 index 0000000000..3e8f870104 --- /dev/null +++ b/apps/plugins/lua/include_lua/printmenus.lua | |||
@@ -0,0 +1,249 @@ | |||
1 | --[[ | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2017 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end | ||
24 | |||
25 | require("printtable") | ||
26 | |||
27 | local _clr = require("color") | ||
28 | |||
29 | local _LCD = rb.lcd_framebuffer() | ||
30 | |||
31 | --[[ -- dpad requires: | ||
32 | require("actions") -- Contains rb.actions & rb.contexts | ||
33 | local _timer = require("timer") | ||
34 | -- Button definitions -- | ||
35 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL | ||
36 | local DOWN_BUTTON = rb.actions.PLA_DOWN | ||
37 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT | ||
38 | local EXIT_BUTTON = rb.actions.PLA_EXIT | ||
39 | local LEFT_BUTTON = rb.actions.PLA_LEFT | ||
40 | local LEFTR_BUTTON = rb.actions.PLA_LEFT_REPEAT | ||
41 | local RIGHT_BUTTON = rb.actions.PLA_RIGHT | ||
42 | local RIGHTR_BUTTON = rb.actions.PLA_RIGHT_REPEAT | ||
43 | local SEL_BUTTON = rb.actions.PLA_SELECT | ||
44 | local SELREL_BUTTON = rb.actions.PLA_SELECT_REL | ||
45 | local SELR_BUTTON = rb.actions.PLA_SELECT_REPEAT | ||
46 | local UP_BUTTON = rb.actions.PLA_UP | ||
47 | local UPR_BUTTON = rb.actions.PLA_UP_REPEAT | ||
48 | ]] | ||
49 | -------------------------------------------------------------------------------- | ||
50 | local function get_core_settings() | ||
51 | if rb.core_color_table ~= nil and rb.core_talk_table ~= nil and | ||
52 | rb.core_list_settings_table ~= nil then return end | ||
53 | |||
54 | local rbs_is_loaded = (package.loaded.rbsettings ~= nil) | ||
55 | local s_is_loaded = (package.loaded.settings ~= nil) | ||
56 | |||
57 | require("rbsettings") | ||
58 | require("settings") | ||
59 | rb.metadata = nil -- remove track metadata settings | ||
60 | |||
61 | local rb_settings = rb.settings.dump('global_settings', "system") | ||
62 | local color_table = {} | ||
63 | local talk_table = {} | ||
64 | local list_settings_table = {} | ||
65 | local list_settings = "cursor_style|show_icons|statusbar|scrollbar|scrollbar_width|list_separator_height|backdrop_file|" | ||
66 | for key, value in pairs(rb_settings) do | ||
67 | key = key or "" | ||
68 | if (key:find("color")) then | ||
69 | color_table[key]=value | ||
70 | elseif (key:find("talk")) then | ||
71 | talk_table[key]=value | ||
72 | elseif (list_settings:find(key)) then | ||
73 | list_settings_table[key]=value | ||
74 | end | ||
75 | end | ||
76 | |||
77 | if not s_is_loaded then | ||
78 | rb.settings = nil | ||
79 | package.loaded.settings = nil | ||
80 | end | ||
81 | |||
82 | if not rbs_is_loaded then | ||
83 | rb.system = nil | ||
84 | rb.metadata = nil | ||
85 | package.loaded.rbsettings = nil | ||
86 | end | ||
87 | |||
88 | rb.core_color_table = color_table | ||
89 | rb.core_talk_table = talk_table | ||
90 | rb.core_list_settings_table = list_settings_table | ||
91 | collectgarbage("collect") | ||
92 | end | ||
93 | |||
94 | --[[ cursor style button routine | ||
95 | -- left / right are x, xi is increment xir is increment when repeat | ||
96 | -- up / down are y, yi is increment yir is increment when repeat | ||
97 | -- cancel is returned as 0,1 | ||
98 | -- select as 0, 1, 2, 3 (none, pressed, repeat, relesed) | ||
99 | -- x_chg and y_chg are the amount x or y changed | ||
100 | -- timeout == nil or -1 loop waits indefinitely till button is pressed | ||
101 | -- time since last button press is returned in ticks.. | ||
102 | -- make xi, xir, yi, yir negative to flip direction... | ||
103 | ]] | ||
104 | --[[ | ||
105 | local function dpad(x, xi, xir, y, yi, yir, timeout, overflow) | ||
106 | local scroll_is_fixed = overflow ~= "manual" | ||
107 | _timer("dpad") -- start a persistant timer; keeps time between button events | ||
108 | if timeout == nil then timeout = -1 end | ||
109 | local cancel, select = 0, 0 | ||
110 | local x_chg, y_chg = 0, 0 | ||
111 | local button | ||
112 | while true do | ||
113 | button = rb.get_plugin_action(timeout) | ||
114 | |||
115 | if button == CANCEL_BUTTON then | ||
116 | cancel = 1 | ||
117 | break; | ||
118 | elseif button == EXIT_BUTTON then | ||
119 | cancel = 1 | ||
120 | break; | ||
121 | elseif button == SEL_BUTTON then | ||
122 | select = 1 | ||
123 | timeout = timeout + 1 | ||
124 | elseif button == SELR_BUTTON then | ||
125 | select = 2 | ||
126 | timeout = timeout + 1 | ||
127 | elseif button == SELREL_BUTTON then | ||
128 | select = -1 | ||
129 | timeout = timeout + 1 | ||
130 | elseif button == LEFT_BUTTON then | ||
131 | x_chg = x_chg - xi | ||
132 | if scroll_is_fixed then | ||
133 | cancel = 1 | ||
134 | break; | ||
135 | end | ||
136 | elseif button == LEFTR_BUTTON then | ||
137 | x_chg = x_chg - xir | ||
138 | elseif button == RIGHT_BUTTON then | ||
139 | x_chg = x_chg + xi | ||
140 | if scroll_is_fixed then | ||
141 | select = 1 | ||
142 | timeout = timeout + 1 | ||
143 | end | ||
144 | elseif button == RIGHTR_BUTTON then | ||
145 | x_chg = x_chg + xir | ||
146 | elseif button == UP_BUTTON then | ||
147 | y_chg = y_chg + yi | ||
148 | elseif button == UPR_BUTTON then | ||
149 | y_chg = y_chg + yir | ||
150 | elseif button == DOWN_BUTTON then | ||
151 | y_chg = y_chg - yi | ||
152 | elseif button == DOWNR_BUTTON then | ||
153 | y_chg = y_chg - yir | ||
154 | elseif timeout >= 0 then--and rb.button_queue_count() < 1 then | ||
155 | break; | ||
156 | end | ||
157 | |||
158 | if x_chg ~= 0 or y_chg ~= 0 then | ||
159 | timeout = timeout + 1 | ||
160 | end | ||
161 | end | ||
162 | |||
163 | x = x + x_chg | ||
164 | y = y + y_chg | ||
165 | |||
166 | return cancel, select, x_chg, x, y_chg, y, _timer.check("dpad", true) | ||
167 | end -- dpad | ||
168 | ]] | ||
169 | -------------------------------------------------------------------------------- | ||
170 | -- displays text in menu_t calls function in same indice of func_t when selected | ||
171 | function print_menu(menu_t, func_t, selected, settings, copy_screen) | ||
172 | |||
173 | local i, start, vcur, screen_img | ||
174 | |||
175 | if selected then vcur = selected + 1 end | ||
176 | if vcur and vcur <= 1 then vcur = 2 end | ||
177 | |||
178 | get_core_settings() | ||
179 | local c_table = rb.core_color_table or {} | ||
180 | |||
181 | if not settings then | ||
182 | settings = {} | ||
183 | settings.default = true | ||
184 | end | ||
185 | |||
186 | settings.justify = settings.justify or "center" | ||
187 | settings.wrap = settings.wrap or true | ||
188 | settings.hfgc = settings.hfgc or c_table.lst_color or _clr.set( 0, 000, 000, 000) | ||
189 | settings.hbgc = settings.hbgc or c_table.bg_color or _clr.set(-1, 255, 255, 255) | ||
190 | settings.ifgc = settings.ifgc or c_table.fg_color or _clr.set(-1, 000, 255, 060) | ||
191 | settings.ibgc = settings.ibgc or c_table.bg_color or _clr.set( 0, 000, 000, 000) | ||
192 | settings.iselc = settings.iselc or c_table.lss_color or _clr.set( 1, 000, 200, 100) | ||
193 | |||
194 | if not settings.linedesc or rb.core_list_settings_table then | ||
195 | settings.linedesc = settings.linedesc or {} | ||
196 | local t_l = rb.core_list_settings_table | ||
197 | local linedesc = { | ||
198 | separator_height = t_l.list_separator_height or 0, | ||
199 | show_cursor = (t_l.cursor_style or 0) == 0, | ||
200 | style = t_l.cursor_style or 0xFFFF, --just a random non used index | ||
201 | show_icons = t_l.show_icons or false, | ||
202 | text_color = c_table.fg_color or _clr.set(-1, 000, 255, 060), | ||
203 | line_color = c_table.bg_color or _clr.set( 0, 000, 000, 000), | ||
204 | line_end_color= c_table.bg_color or _clr.set( 0, 000, 000, 000), | ||
205 | } | ||
206 | local styles = {rb.STYLE_NONE, rb.STYLE_INVERT, rb.STYLE_GRADIENT, rb.STYLE_COLORBAR, rb.STYLE_DEFAULT} | ||
207 | linedesc.style = styles[linedesc.style + 1] or rb.STYLE_COLORBAR | ||
208 | |||
209 | for k, v in pairs(linedesc) do | ||
210 | --dont overwrite supplied settings | ||
211 | settings.linedesc[k] = settings.linedesc[k] or v | ||
212 | end | ||
213 | end | ||
214 | |||
215 | settings.hasheader = true | ||
216 | settings.co_routine = nil | ||
217 | settings.msel = false | ||
218 | settings.start = start | ||
219 | settings.curpos = vcur | ||
220 | --settings.dpad_fn = dpad | ||
221 | |||
222 | while not i or i > 0 do | ||
223 | if copy_screen == true then | ||
224 | --make a copy of screen for restoration | ||
225 | screen_img = screen_img or rb.new_image() | ||
226 | screen_img:copy(_LCD) | ||
227 | else | ||
228 | screen_img = nil | ||
229 | end | ||
230 | |||
231 | _LCD:clear(settings.ibgc) | ||
232 | |||
233 | settings.start = start | ||
234 | settings.curpos = vcur | ||
235 | |||
236 | i, start, vcur = print_table(menu_t, #menu_t, settings) | ||
237 | --vcur = vcur + 1 | ||
238 | collectgarbage("collect") | ||
239 | if copy_screen == true then _LCD:copy(screen_img) end | ||
240 | |||
241 | if func_t and func_t[i] then | ||
242 | if func_t[i](i, menu_t) == true then break end | ||
243 | else | ||
244 | break | ||
245 | end | ||
246 | end | ||
247 | if settings.default == true then settings = nil end | ||
248 | return screen_img, i | ||
249 | end | ||
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 = {} |