mirror of
https://github.com/Insality/druid.git
synced 2025-09-28 18:42:19 +02:00
Add new examples
This commit is contained in:
39
example/examples/basic/checkbox_group/checkbox_group.lua
Normal file
39
example/examples/basic/checkbox_group/checkbox_group.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
local event = require("druid.event")
|
||||
local component = require("druid.component")
|
||||
|
||||
-- Require checkbox component from checkbox example
|
||||
local checkbox = require("example.examples.basic.checkbox.checkbox")
|
||||
|
||||
---@class checkbox_group: druid.base_component
|
||||
---@field druid druid_instance
|
||||
---@field button druid.button
|
||||
local M = component.create("checkbox_group")
|
||||
|
||||
|
||||
---@param template string
|
||||
---@param nodes table<hash, node>
|
||||
function M:init(template, nodes)
|
||||
self.druid = self:get_druid(template, nodes)
|
||||
|
||||
self.checkbox_1 = self.druid:new(checkbox, "checkbox_1")
|
||||
self.checkbox_2 = self.druid:new(checkbox, "checkbox_2")
|
||||
self.checkbox_3 = self.druid:new(checkbox, "checkbox_3")
|
||||
|
||||
self.checkbox_1.on_state_changed:subscribe(self.on_checkbox_click, self)
|
||||
self.checkbox_2.on_state_changed:subscribe(self.on_checkbox_click, self)
|
||||
self.checkbox_3.on_state_changed:subscribe(self.on_checkbox_click, self)
|
||||
|
||||
self.on_state_changed = event.create()
|
||||
end
|
||||
|
||||
|
||||
function M:on_checkbox_click()
|
||||
print("Checkbox 1: ", self.checkbox_1:get_state())
|
||||
print("Checkbox 2: ", self.checkbox_2:get_state())
|
||||
print("Checkbox 3: ", self.checkbox_3:get_state())
|
||||
|
||||
self.on_state_changed:trigger(self.checkbox_1:get_state(), self.checkbox_2:get_state(), self.checkbox_3:get_state())
|
||||
end
|
||||
|
||||
|
||||
return M
|
Reference in New Issue
Block a user