mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
#152 Add instans set_state for Checkbox component
This commit is contained in:
parent
8d0f9e5070
commit
b42d16d999
12
druid/extended/checkbox.lua
Normal file → Executable file
12
druid/extended/checkbox.lua
Normal file → Executable file
@ -49,13 +49,14 @@ end
|
||||
-- @tparam node node Gui node
|
||||
-- @tparam function callback Checkbox callback
|
||||
-- @tparam[opt=node] node click_node Trigger node, by default equals to node
|
||||
function Checkbox.init(self, node, callback, click_node)
|
||||
-- @tparam[opt=false] boolean initial_state The initial state of checkbox, default - false
|
||||
function Checkbox.init(self, node, callback, click_node, initial_state)
|
||||
self.druid = self:get_druid()
|
||||
self.node = self:get_node(node)
|
||||
self.click_node = self:get_node(click_node)
|
||||
|
||||
self.button = self.druid:new_button(self.click_node or self.node, on_click)
|
||||
self:set_state(false, true)
|
||||
self:set_state(initial_state, true, true)
|
||||
|
||||
self.on_change_state = Event(callback)
|
||||
end
|
||||
@ -70,13 +71,16 @@ end
|
||||
-- @tparam Checkbox self
|
||||
-- @tparam bool state Checkbox state
|
||||
-- @tparam bool is_silent Don't trigger on_change_state if true
|
||||
function Checkbox.set_state(self, state, is_silent)
|
||||
-- @tparam bool is_instant If instant checkbox change
|
||||
function Checkbox.set_state(self, state, is_silent, is_instant)
|
||||
self.state = state
|
||||
self.style.on_change_state(self, self.node, state)
|
||||
self.style.on_change_state(self, self.node, state, is_instant)
|
||||
|
||||
if not is_silent then
|
||||
self.on_change_state:trigger(self:get_context(), state)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user