mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
update checkbox_group component
This commit is contained in:
parent
39b5f1c555
commit
ae9c580c7a
@ -1,11 +1,12 @@
|
||||
--- Checkboux group module
|
||||
-- @module base.checkbox_group
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
local function on_checkbox_click(self, index)
|
||||
if self.is_radio_mode then
|
||||
for i = 1, #self.checkboxes do
|
||||
self.checkboxes[i]:set_state(i == index, true)
|
||||
end
|
||||
if self.callback then
|
||||
self.callback(self.parent.parent, index)
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,15 +31,16 @@ function M.get_state(self)
|
||||
end
|
||||
|
||||
|
||||
function M.init(self, nodes, callback, is_radio_mode, anim_nodes)
|
||||
self.is_radio_mode = is_radio_mode
|
||||
function M.init(self, nodes, callback, click_nodes)
|
||||
self.checkboxes = {}
|
||||
self.callback = callback
|
||||
|
||||
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()
|
||||
on_checkbox_click(self, i)
|
||||
end, anim_node)
|
||||
end, click_node)
|
||||
|
||||
table.insert(self.checkboxes, checkbox)
|
||||
end
|
||||
end
|
||||
|
@ -77,13 +77,13 @@ local function setup_checkbox(self)
|
||||
nil, true,
|
||||
{"radio1/back", "radio2/back", "radio3/back"})
|
||||
|
||||
local group2 = self.druid:new_checkbox_group(
|
||||
local checkbox_group = self.druid:new_checkbox_group(
|
||||
{"checkbox1/check", "checkbox2/check", "checkbox3/check"},
|
||||
nil, false,
|
||||
nil,
|
||||
{"checkbox1/back", "checkbox2/back", "checkbox3/back"})
|
||||
|
||||
group1:set_state({false, false, true})
|
||||
group2:set_state({true, false, true})
|
||||
checkbox_group:set_state({true, false, true})
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user