mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
cherry-pick update checkbox_group
This commit is contained in:
parent
2d3ef5f6c3
commit
05dd08b149
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user