mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Documentation experiments
This commit is contained in:
@@ -2,15 +2,27 @@
|
||||
-- @module druid.button
|
||||
|
||||
--- Component events
|
||||
-- @tfield druid_event on_click
|
||||
-- @tfield druid_event on_hold_click
|
||||
-- @tfield druid_event on_long_click
|
||||
-- @tfield druid_event on_double_click
|
||||
-- @table events
|
||||
-- @table Events
|
||||
-- @tfield druid_event on_click On release button callback
|
||||
-- @tfield druid_event on_repeated_click On repeated action button callback
|
||||
-- @tfield druid_event on_long_click On long tap button callback
|
||||
-- @tfield druid_event on_double_click On double tap button callback
|
||||
|
||||
--- Component fields
|
||||
-- @tfield node Main node
|
||||
-- @table fields
|
||||
-- @table Fields
|
||||
-- @tfield node node Trigger node
|
||||
-- @tfield[opt=node] node anim_node Animation node
|
||||
-- @tfield vector3 scale_from Initial scale of anim_node
|
||||
-- @tfield vector3 pos Initial pos of anim_node
|
||||
-- @tfield any params Params to click callbacks
|
||||
-- @tfield boolean hover_anim Is hover anim enabled
|
||||
-- @tfield druid.hover hover Druid hover logic component
|
||||
-- @tfield[opt] node click_zone Restriction zone
|
||||
|
||||
--- Component style params
|
||||
-- @table Style
|
||||
-- @tfield function on_click (self, node)
|
||||
-- @tfield function on_hover (self, node, hover_state)
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
@@ -36,7 +48,7 @@ local function on_button_release(self)
|
||||
if self.style.on_click then
|
||||
self.style.on_click(self, self.anim_node)
|
||||
end
|
||||
self.callback(self:get_context(), self.params, self)
|
||||
self.on_click:trigger(self:get_context(), self.params, self)
|
||||
end
|
||||
return true
|
||||
else
|
||||
@@ -66,19 +78,21 @@ function M.init(self, node, callback, params, anim_node, event)
|
||||
self.anim_node = anim_node and helper:get_node(anim_node) or self.node
|
||||
-- TODO: rename to start_scale
|
||||
self.scale_from = gui.get_scale(self.anim_node)
|
||||
self.pos = gui.get_position(self.anim_node)
|
||||
self.callback = callback
|
||||
self.params = params
|
||||
self.hover_anim = self.style.IS_HOVER
|
||||
self.hover = self.druid:new_hover(node, self, on_button_hover)
|
||||
self.click_zone = nil
|
||||
|
||||
-- Event stubs
|
||||
self.on_click = Event()
|
||||
self.on_hold_click = Event()
|
||||
self.on_repeated_click = Event()
|
||||
self.on_long_click = Event()
|
||||
self.on_double_click = Event()
|
||||
|
||||
self.click_zone = nil
|
||||
if callback then
|
||||
self.on_click:subscribe(callback)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -166,28 +180,4 @@ function M.get_key_trigger(self)
|
||||
end
|
||||
|
||||
|
||||
--- Set usual button callback
|
||||
function M.set_callback(self, callback)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Repeat callback always, while holding button
|
||||
function M.set_hold_callback(self, callback)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Get doubletap callback on this button
|
||||
function M.set_double_tap_callback(self, callback)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Single callbacka after long_tap. No usual callback invoked
|
||||
function M.set_long_tap_callback(self, callback)
|
||||
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
|
@@ -9,26 +9,6 @@ local class = require("druid.system.middleclass")
|
||||
local Component = class("druid.component")
|
||||
|
||||
|
||||
--- Setup component context and his style table
|
||||
-- @function component:setup_component
|
||||
-- @tparam context table Druid context. Usually it is self of script
|
||||
-- @tparam style table Druid style module
|
||||
-- @treturn Component Component itself
|
||||
function Component.setup_component(self, context, style)
|
||||
self._meta = {
|
||||
template = nil,
|
||||
context = nil,
|
||||
nodes = nil,
|
||||
style = nil,
|
||||
}
|
||||
|
||||
self:set_context(context)
|
||||
self:set_style(style)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Get current component style table
|
||||
-- @function component:get_style
|
||||
-- @treturn table Component style table
|
||||
@@ -136,6 +116,26 @@ function Component.get_druid(self)
|
||||
end
|
||||
|
||||
|
||||
--- Setup component context and his style table
|
||||
-- @function component:setup_component
|
||||
-- @tparam context table Druid context. Usually it is self of script
|
||||
-- @tparam style table Druid style module
|
||||
-- @treturn Component Component itself
|
||||
function Component.setup_component(self, context, style)
|
||||
self._meta = {
|
||||
template = nil,
|
||||
context = nil,
|
||||
nodes = nil,
|
||||
style = nil,
|
||||
}
|
||||
|
||||
self:set_context(context)
|
||||
self:set_style(style)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Basic constructor of component. It will call automaticaly
|
||||
-- by `Component.static.create`
|
||||
-- @function component:initialize
|
||||
|
@@ -12,13 +12,20 @@ function M.initialize(self)
|
||||
end
|
||||
|
||||
|
||||
--- Subscribe callback on event
|
||||
-- @function event:subscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.subscribe(self, callback)
|
||||
assert(type(self) == "table", "You should subscribe to event with : syntax")
|
||||
assert(type(callback) == "function", "Callback should be function")
|
||||
|
||||
table.insert(self._callbacks, callback)
|
||||
end
|
||||
|
||||
|
||||
--- Unsubscribe callback on event
|
||||
-- @function event:unsubscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.unsubscribe(self, callback)
|
||||
for i = 1, #self._callbacks do
|
||||
if self._callbacks[i] == callback then
|
||||
@@ -29,6 +36,9 @@ function M.unsubscribe(self, callback)
|
||||
end
|
||||
|
||||
|
||||
--- Trigger the event and call all subscribed callbacks
|
||||
-- @function event:trigger
|
||||
-- @param ... All event params
|
||||
function M.trigger(self, ...)
|
||||
for i = 1, #self._callbacks do
|
||||
self._callbacks[i](...)
|
||||
|
Reference in New Issue
Block a user