cherry-pick update checkbox_group

This commit is contained in:
Insality 2019-09-26 08:45:58 +03:00
parent 2d3ef5f6c3
commit 05dd08b149

View File

@ -1,11 +1,12 @@
--- Checkboux group module
-- @module base.checkbox_group
local M = {} local M = {}
local function on_checkbox_click(self, index) local function on_checkbox_click(self, index)
if self.is_radio_mode then if self.callback then
for i = 1, #self.checkboxes do self.callback(self.parent.parent, index)
self.checkboxes[i]:set_state(i == index, true)
end
end end
end end
@ -30,15 +31,16 @@ function M.get_state(self)
end end
function M.init(self, nodes, callback, is_radio_mode, anim_nodes) function M.init(self, nodes, callback, click_nodes)
self.is_radio_mode = is_radio_mode
self.checkboxes = {} self.checkboxes = {}
self.callback = callback
for i = 1, #nodes do for i = 1, #nodes do
local anim_node = anim_nodes and anim_nodes[i] or nil local click_node = click_nodes and click_nodes[i] or nil
local checkbox = self.parent:new_checkbox(nodes[i], function() local checkbox = self.parent:new_checkbox(nodes[i], function()
on_checkbox_click(self, i) on_checkbox_click(self, i)
end, anim_node) end, click_node)
table.insert(self.checkboxes, checkbox) table.insert(self.checkboxes, checkbox)
end end
end end