mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
add simple checkbox component
This commit is contained in:
parent
6f37a1ec9a
commit
7917a08f5c
44
druid/base/checkbox.lua
Normal file
44
druid/base/checkbox.lua
Normal file
@ -0,0 +1,44 @@
|
||||
--- Druid checkbox component
|
||||
-- @module base.checkbox
|
||||
|
||||
local helper = require("druid.helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
local function state_animate(node, state)
|
||||
local target = state and 1 or 0
|
||||
gui.animate(node, "color.w", target, gui.EASING_OUTSINE, 0.1)
|
||||
end
|
||||
|
||||
|
||||
function M.set_state(self, state, is_silence)
|
||||
if self.state == state then
|
||||
return
|
||||
end
|
||||
|
||||
self.state = state
|
||||
state_animate(self.node, state)
|
||||
|
||||
if not is_silence and self.callback then
|
||||
self.callback(self.parent.parent, state)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- TODO: pass self as first parameter
|
||||
local function on_click(context, self)
|
||||
M.set_state(self, not self.state)
|
||||
end
|
||||
|
||||
|
||||
function M.init(self, node, callback, click_node)
|
||||
self.node = helper.get_node(node)
|
||||
self.click_node = helper.get_node(click_node)
|
||||
self.callback = callback
|
||||
self.button = self.parent:new_button(self.click_node or self.node, on_click, self)
|
||||
M.set_state(self, false, true)
|
||||
end
|
||||
|
||||
|
||||
return M
|
@ -22,6 +22,7 @@ M.comps = {
|
||||
progress = require("druid.base.progress"),
|
||||
grid = require("druid.base.grid"),
|
||||
scroll = require("druid.base.scroll"),
|
||||
checkbox = require("druid.base.checkbox"),
|
||||
|
||||
progress_rich = require("druid.rich.progress_rich"),
|
||||
}
|
||||
|
@ -62,6 +62,16 @@ local function setup_grid(self)
|
||||
end
|
||||
|
||||
|
||||
local function setup_checkbox(self)
|
||||
self.druid:new_checkbox("radio1/check", nil, "radio1/back")
|
||||
self.druid:new_checkbox("radio2/check", nil, "radio2/back")
|
||||
self.druid:new_checkbox("radio3/check", nil, "radio3/back")
|
||||
self.druid:new_checkbox("checkbox1/check", nil, "checkbox1/back")
|
||||
self.druid:new_checkbox("checkbox2/check", nil, "checkbox2/back")
|
||||
self.druid:new_checkbox("checkbox3/check", nil, "checkbox3/back")
|
||||
end
|
||||
|
||||
|
||||
local function setup_timer(self)
|
||||
self.timer = self.druid:new_timer("timer", 300, 0, empty_callback)
|
||||
end
|
||||
@ -85,6 +95,7 @@ function M.setup_page(self)
|
||||
setup_progress(self)
|
||||
setup_grid(self)
|
||||
setup_timer(self)
|
||||
setup_checkbox(self)
|
||||
setup_scroll(self)
|
||||
setup_back_handler(self)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user