mirror of
https://github.com/Insality/druid
synced 2025-09-28 02:22:19 +02:00
Add druid events in components
This commit is contained in:
@@ -1,18 +1,12 @@
|
||||
--- Checkboux group module
|
||||
-- @module druid.checkbox_group
|
||||
|
||||
local Event = require("druid.event")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("checkbox_group")
|
||||
|
||||
|
||||
local function on_checkbox_click(self, index)
|
||||
if self.callback then
|
||||
self.callback(self:get_context(), index)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.set_state(self, indexes)
|
||||
for i = 1, #indexes do
|
||||
if self.checkboxes[i] then
|
||||
@@ -36,12 +30,13 @@ end
|
||||
function M.init(self, nodes, callback, click_nodes)
|
||||
self.druid = self:get_druid()
|
||||
self.checkboxes = {}
|
||||
self.callback = callback
|
||||
|
||||
self.on_checkbox_click = Event(callback)
|
||||
|
||||
for i = 1, #nodes do
|
||||
local click_node = click_nodes and click_nodes[i] or nil
|
||||
local checkbox = self.druid:new_checkbox(nodes[i], function()
|
||||
on_checkbox_click(self, i)
|
||||
self.on_checkbox_click:trigger(self:get_context(), i)
|
||||
end, click_node)
|
||||
|
||||
table.insert(self.checkboxes, checkbox)
|
||||
|
Reference in New Issue
Block a user