mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Add druid with context, get component druid as helper.get_druid(context)
This commit is contained in:
@@ -26,7 +26,7 @@ end
|
||||
-- @tparam table action on_input action
|
||||
function M.on_input(self, action_id, action)
|
||||
if action[const.RELEASED] then
|
||||
self.callback(self.parent.parent, self.params)
|
||||
self.callback(self.context, self.params)
|
||||
end
|
||||
|
||||
return true
|
||||
|
@@ -74,7 +74,7 @@ local function on_button_release(self)
|
||||
if self.tap_anim then
|
||||
self.tap_anim(self)
|
||||
end
|
||||
self.callback(self.parent.parent, self.params, self)
|
||||
self.callback(self.context, self.params, self)
|
||||
settings.play_sound(self.sound)
|
||||
else
|
||||
set_hover(self, false)
|
||||
@@ -151,7 +151,7 @@ function M.deactivate(self, is_animate, callback)
|
||||
-- callback call three times in gui.animation
|
||||
local clbk = helper.after(3, function()
|
||||
if callback then
|
||||
callback(self.parent.parent)
|
||||
callback(self.context)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -167,7 +167,7 @@ function M.deactivate(self, is_animate, callback)
|
||||
gui.set_color(self.node, M.DEFAULT_DEACTIVATE_COLOR)
|
||||
gui.set_scale(self.node, M.DEFAULT_DEACTIVATE_SCALE)
|
||||
if callback then
|
||||
callback(self.parent.parent)
|
||||
callback(self.context)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -179,7 +179,7 @@ function M.activate(self, is_animate, callback)
|
||||
local clbk = helper.after(3, function()
|
||||
self.disabled = false
|
||||
if callback then
|
||||
callback(self.parent.parent)
|
||||
callback(self.context)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -196,7 +196,7 @@ function M.activate(self, is_animate, callback)
|
||||
gui.set_scale(self.node, M.DEFAULT_ACTIVATE_SCALE)
|
||||
self.disabled = false
|
||||
if callback then
|
||||
callback(self.parent.parent)
|
||||
callback(self.context)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -21,7 +21,7 @@ function M.set_state(self, state, is_silence)
|
||||
state_animate(self.node, state)
|
||||
|
||||
if not is_silence and self.callback then
|
||||
self.callback(self.parent.parent, state)
|
||||
self.callback(self.context, state)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,17 +32,18 @@ end
|
||||
|
||||
|
||||
-- TODO: pass self as first parameter
|
||||
local function on_click(context, self)
|
||||
local function on_click(self)
|
||||
M.set_state(self, not self.state)
|
||||
end
|
||||
|
||||
|
||||
function M.init(self, node, callback, click_node)
|
||||
self.druid = helper.get_druid(self)
|
||||
self.node = helper.node(node)
|
||||
self.click_node = helper.node(click_node)
|
||||
self.callback = callback
|
||||
|
||||
self.button = self.parent:new_button(self.click_node or self.node, on_click, self)
|
||||
self.button = self.druid:new_button(self.click_node or self.node, on_click)
|
||||
M.set_state(self, false, true)
|
||||
end
|
||||
|
||||
|
@@ -1,12 +1,14 @@
|
||||
--- Checkboux group module
|
||||
-- @module base.checkbox_group
|
||||
|
||||
local helper = require("druid.helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
local function on_checkbox_click(self, index)
|
||||
if self.callback then
|
||||
self.callback(self.parent.parent, index)
|
||||
self.callback(self.context, index)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,12 +34,13 @@ end
|
||||
|
||||
|
||||
function M.init(self, nodes, callback, click_nodes)
|
||||
self.druid = helper.get_druid(self)
|
||||
self.checkboxes = {}
|
||||
self.callback = callback
|
||||
|
||||
for i = 1, #nodes do
|
||||
local click_node = click_nodes and click_nodes[i] or nil
|
||||
local checkbox = self.parent:new_checkbox(nodes[i], function()
|
||||
local checkbox = self.druid:new_checkbox(nodes[i], function()
|
||||
on_checkbox_click(self, i)
|
||||
end, click_node)
|
||||
|
||||
|
@@ -56,10 +56,10 @@ local function check_steps(self, from, to, exactly)
|
||||
end
|
||||
|
||||
if v1 < step and step < v2 then
|
||||
self.step_callback(self.parent.parent, step)
|
||||
self.step_callback(self.context, step)
|
||||
end
|
||||
if exactly and exactly == step then
|
||||
self.step_callback(self.parent.parent, step)
|
||||
self.step_callback(self.context, step)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -143,7 +143,7 @@ function M.to(self, to, callback)
|
||||
self.target_callback = callback
|
||||
else
|
||||
if callback then
|
||||
callback(self.parent.parent, to)
|
||||
callback(self.context, to)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -160,7 +160,7 @@ function M.update(self, dt)
|
||||
check_steps(self, prev_value, self.target, self.target)
|
||||
|
||||
if self.target_callback then
|
||||
self.target_callback(self.parent.parent, self.target)
|
||||
self.target_callback(self.context, self.target)
|
||||
end
|
||||
|
||||
self.target = nil
|
||||
|
@@ -1,6 +1,8 @@
|
||||
--- Radio group module
|
||||
-- @module base.checkbox_group
|
||||
|
||||
local helper = require("druid.helper")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@@ -10,7 +12,7 @@ local function on_checkbox_click(self, index)
|
||||
end
|
||||
|
||||
if self.callback then
|
||||
self.callback(self.parent.parent, index)
|
||||
self.callback(self.context, index)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,12 +37,13 @@ end
|
||||
|
||||
|
||||
function M.init(self, nodes, callback, click_nodes)
|
||||
self.druid = helper.get_druid(self)
|
||||
self.checkboxes = {}
|
||||
self.callback = callback
|
||||
|
||||
for i = 1, #nodes do
|
||||
local click_node = click_nodes and click_nodes[i] or nil
|
||||
local checkbox = self.parent:new_checkbox(nodes[i], function()
|
||||
local checkbox = self.druid:new_checkbox(nodes[i], function()
|
||||
on_checkbox_click(self, i)
|
||||
end, click_node)
|
||||
|
||||
|
@@ -352,7 +352,7 @@ function M.scroll_to_index(self, index, skip_cb)
|
||||
self.selected = index
|
||||
|
||||
if not skip_cb and self.on_point_callback then
|
||||
self.on_point_callback(self.parent.parent, index, self.points[index])
|
||||
self.on_point_callback(self.context, index, self.points[index])
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -12,7 +12,7 @@ M.interest = {
|
||||
|
||||
local function on_change_value(self)
|
||||
if self.callback then
|
||||
self.callback(self.parent.parent, self.value)
|
||||
self.callback(self.context, self.value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -25,7 +25,7 @@ function M.init(self, node, seconds_from, seconds_to, callback)
|
||||
|
||||
if seconds_to - seconds_from == 0 then
|
||||
self:set_state(false)
|
||||
self.callback(self.parent.parent, self)
|
||||
self.callback(self.context, self)
|
||||
end
|
||||
return self
|
||||
end
|
||||
@@ -76,7 +76,7 @@ function M.update(self, dt)
|
||||
M.set_to(self, self.value)
|
||||
if self.value == self.target then
|
||||
self:set_state(false)
|
||||
self.callback(self.parent.parent, self)
|
||||
self.callback(self.context, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user