From 7c1b542fe82defbd87aa7109aef445a674277463 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 24 Aug 2021 17:27:26 +0300 Subject: [PATCH] add show_table --- README.md | 3 ++- README_ru.md | 3 ++- main/uptimerobot-widget.lua | 2 +- ru/calendar-ru-widget.lua | 2 +- samples/apps-sample.lua | 2 +- samples/table-sample.lua | 9 ++++----- samples/table-sample2.lua | 10 ++++++++++ 7 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 samples/table-sample2.lua diff --git a/README.md b/README.md index 4805865..399ab8e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ For most network scripts `on_alarm()` should be used. * `ui:show_text(string, [no_html])` - displays plain text in widget, repeated call will erase previous text, if second argument is true HTML formatting will be disabled; * `ui:show_lines(table, [table])` - displays a list of lines with the sender (in the manner of a mail widget), the second argument (optional) - the corresponding senders (formatting in the style of a mail widget); -* `ui:show_table(table, column_count, [centering], [folded_string])` - analogue of `show_lines` for displaying rows as a table, the first argument is a table of values, the second is the number of columns in the table, the third is a boolean value indicating whether it is necessary to center the table cells, the fourth is the row that will be shown in collapsed mode; +* `ui:show_grid(table, column_count, [centering], [folded_string])` - analogue of `show_lines` for displaying rows as a grid, the first argument is a table of values, the second is the number of columns in the table, the third is a boolean value indicating whether it is necessary to center the table cells, the fourth is the row that will be shown in collapsed mode; +* `ui:show_table(table, [main_column], [centering], [folded_string]) - displays table, first argument: table of tables, second argument: main column, it will be stretched, occupying main table space, other arguments same as `show_grid`; * `ui:show_buttons(names, [colors])` - displays a list of buttons, the first argument is a table of strings, the second is an optional argument, a table of colors in the format #XXXXXX; * `ui:show_progress_bar(text, current_value, max_value, [color])` - shows the progress bar; * `ui:show_chart(points, [format], [title], [show_grid], [folded_string], [copyright])` - shows the chart, points - table of coordinate tables, format - data format (see below), title - chart name, show\_grid - grid display flag, folded\_string - string for the folded state (otherwise the name will be shown), copyright - string displayed in the lower right corner; diff --git a/README_ru.md b/README_ru.md index 0047dc2..adf018a 100644 --- a/README_ru.md +++ b/README_ru.md @@ -18,7 +18,8 @@ * `ui:show_text(string, [no_html])` - выводит в виджет обычный текст, повторный вызов стирает предыдущий текст, если второй аргумент true форматирование HTML будет отключено; * `ui:show_lines(table, [table])` - выводит список строк с отправителем (на манер почтового виджета), второй аргумент (необязательный) - соответствующие им отправители (форматирование в стиле почтового виджета); -* `ui:show_table(table, column_count, [centering], [folded_string])` - аналог `show_lines` для вывода строк в виде таблицы, первый аргумент - таблица значений, второй - количество столбцов в таблице, третий - булево значение, указывающее, нужно ли центрировать ячейки таблицы, четвертый - строка, которая будет показана в свернутом режиме; +* `ui:show_grid(table, column_count, [centering], [folded_string])` - аналог `show_lines` для вывода строк в виде сетки, первый аргумент - таблица значений, второй - количество столбцов в сетке, третий - булево значение, указывающее, нужно ли центрировать ячейки таблицы, четвертый - строка, которая будет показана в свернутом режиме; +* `ui:show_table(table, [main_column], [centering], [folded_string]) - выводит таблицу, первый аргумент: таблица таблиц, второй аргумент - основная колонка, она будет растягиваться, занимая основное пространство таблицы, остальные аргументы такие же как у `show_grid`; * `ui:show_buttons(names, [colors])` - выводит список кнопок, первый аргумент - таблица строк, второй опциональный аргумент, таблица цветов в формате #XXXXXX; * `ui:show_progress_bar(text, current_value, max_value, [color])` - показывает прогресс бар; * `ui:show_chart(points, [format], [title], [show_grid], [folded_string], [copyright])` - показывает график, points - таблица таблиц координат, format - формат данных (см. ниже), title - название графика, show\_grid - флага показа сетки, folded\_string - строка для свернутого состояния (иначе будет показано название), copyright - строка, отображаемая в правом нижнем углу; diff --git a/main/uptimerobot-widget.lua b/main/uptimerobot-widget.lua index ade55ed..3fb81eb 100644 --- a/main/uptimerobot-widget.lua +++ b/main/uptimerobot-widget.lua @@ -48,7 +48,7 @@ function on_network_result(result) strings_tab[k] = v.friendly_name..": "..format_status(v.status) end - ui:show_table(strings_tab, 2) + ui:show_grid(strings_tab, 2) end -- utils diff --git a/ru/calendar-ru-widget.lua b/ru/calendar-ru-widget.lua index 4d58802..e92b877 100644 --- a/ru/calendar-ru-widget.lua +++ b/ru/calendar-ru-widget.lua @@ -26,7 +26,7 @@ end function on_network_result(result) days = result:split("-") tab = get_cal(year,month) - ui:show_table(tab,8, true) + ui:show_grid(tab, 8, true) ui:set_title(ui:get_default_title().." ("..string.format("%02d.%04d",month,year)..")") end diff --git a/samples/apps-sample.lua b/samples/apps-sample.lua index 629afc3..b3023f6 100644 --- a/samples/apps-sample.lua +++ b/samples/apps-sample.lua @@ -14,7 +14,7 @@ function on_resume() apps_names[k] = get_formatted_name(v) end - ui:show_table(slice(apps_names, 1, 9), 3) + ui:show_grid(slice(apps_names, 1, 9), 3) end function on_click(idx) diff --git a/samples/table-sample.lua b/samples/table-sample.lua index b02ef7f..378e1b3 100644 --- a/samples/table-sample.lua +++ b/samples/table-sample.lua @@ -1,12 +1,11 @@ function on_resume() local table = { - "12345678", "", "", - "1", "2", "3", - "4", "5", "6", - "7", "8", "9", + { "<", "1 USD = 74.023 RUB -0.01%", ">" }, + { "<", "1 USD = 74.023 RUB -0.01%", ">" }, + { "<", "1 USD = 74.023 RUB -0.01%", ">" }, } - ui:show_table(table, 3, true, false, "Nothing there") + ui:show_table(table, 2) end function on_click(idx) diff --git a/samples/table-sample2.lua b/samples/table-sample2.lua new file mode 100644 index 0000000..915ac2d --- /dev/null +++ b/samples/table-sample2.lua @@ -0,0 +1,10 @@ +function on_resume() + local tab = { + { "1234567890" }, + { "1", "2", "3" }, + { "4", "5", "6" }, + { "7", "8", "9" }, + } + + ui:show_table(tab) +end