add show_checkbox_dialog
This commit is contained in:
@@ -51,7 +51,7 @@ First line<br/>Second line
|
||||
|
||||
* `ui:show_dialog(title, text, [button1_text], [button2_text])` - показать диалог; первый аргумент - заголовок, второй - текст, button1\_text - имя первой кнопки, button2\_text - имя второй кнопки;
|
||||
* `ui:show_edit_dialog(title, [text], [default_value])` - показать диалог с полем ввода: title - заголовок, text - подпись, default\_value - стандартное значения поля ввода;
|
||||
* `ui:show_checkbox_dialog(title, lines, [index])` - показать диалог с выбором: title - заголовок, lines - таблица строк, index - индекс дефолтового значения;
|
||||
* `ui:show_radio_dialog(title, lines, [index])` - показать диалог с выбором: title - заголовок, lines - таблица строк, index - индекс дефолтового значения;
|
||||
|
||||
Нажатия на кнопки диалога должны обрабатываться в колбеке `on_dialog_action(number)`, где 1 - это первая кнопка, 2 - вторая, а -1 - нажатие кнопки "закрыть", если никакие кнопки не были указаны. `ui:show_edit_dialog()` возвращает текст в колбек `on_dialog_action(text)`.
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ function on_click(idx)
|
||||
ui:show_edit_dialog("Введите количество", "", amount)
|
||||
elseif idx == 3 then
|
||||
dialog_id = "cur"
|
||||
ui:show_checkbox_dialog("Выберите валюту", curs_n, cur_idx)
|
||||
ui:show_radio_dialog("Выберите валюту", curs_n, cur_idx)
|
||||
elseif idx == 6 then
|
||||
dialog_id = "base_cur"
|
||||
ui:show_checkbox_dialog("Выберите базовую валюту", base_curs_n, base_cur_idx)
|
||||
ui:show_radio_dialog("Выберите базовую валюту", base_curs_n, base_cur_idx)
|
||||
elseif idx == 8 then
|
||||
date = next_date(date)
|
||||
get_rates(date)
|
||||
|
||||
@@ -7,10 +7,20 @@ function on_click()
|
||||
ui:show_checkbox_dialog("Title", dialog_items, 2)
|
||||
end
|
||||
|
||||
function on_dialog_action(idx)
|
||||
if idx == -1 then
|
||||
function on_dialog_action(tab)
|
||||
if tab == -1 then
|
||||
ui:show_toast("Dialog cancelled")
|
||||
else
|
||||
ui:show_toast("Checked: "..dialog_items[idx])
|
||||
ui:show_toast("Checked: "..table_to_string(tab))
|
||||
end
|
||||
end
|
||||
|
||||
function table_to_string(tab)
|
||||
local s = ""
|
||||
|
||||
for k, v in ipairs(tab) do
|
||||
s = s..v.." "
|
||||
end
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
16
samples/radio-dialog.sample.lua
Normal file
16
samples/radio-dialog.sample.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
function on_resume()
|
||||
ui:show_text("Open dialog")
|
||||
end
|
||||
|
||||
function on_click()
|
||||
dialog_items = { "One", "Two", "Three" }
|
||||
ui:show_radio_dialog("Title", dialog_items, 2)
|
||||
end
|
||||
|
||||
function on_dialog_action(idx)
|
||||
if idx == -1 then
|
||||
ui:show_toast("Dialog cancelled")
|
||||
else
|
||||
ui:show_toast("Choosen: "..dialog_items[idx])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user