mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
add create as _factory method
This commit is contained in:
parent
cb82acd5da
commit
d5c3aae745
@ -1,11 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
--- input handler
|
|
||||||
-- @param action_id - input action id
|
|
||||||
-- @param action - input action
|
|
||||||
function M.on_input(instance, action_id, action)
|
|
||||||
instance.callback(instance.parent.parent)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
@ -10,7 +10,7 @@ local _factory = {}
|
|||||||
local STRING = "string"
|
local STRING = "string"
|
||||||
|
|
||||||
--- New druid era, registering components
|
--- New druid era, registering components
|
||||||
local components = {
|
M.comps = {
|
||||||
-- basic
|
-- basic
|
||||||
button = require("druid.base.button"),
|
button = require("druid.base.button"),
|
||||||
android_back = require("druid.base.android_back"),
|
android_back = require("druid.base.android_back"),
|
||||||
@ -20,7 +20,7 @@ local components = {
|
|||||||
|
|
||||||
|
|
||||||
local function register_basic_components()
|
local function register_basic_components()
|
||||||
for k, v in pairs(components) do
|
for k, v in pairs(M.comps) do
|
||||||
M.register(k, v)
|
M.register(k, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -28,8 +28,8 @@ end
|
|||||||
|
|
||||||
function M.register(name, module)
|
function M.register(name, module)
|
||||||
-- TODO: Find better solution to creating elements?
|
-- TODO: Find better solution to creating elements?
|
||||||
_factory["new_" .. name] = function(factory, node_name, ...)
|
_factory["new_" .. name] = function(factory, node_or_name, ...)
|
||||||
M.create(factory, module, node_name, ...)
|
_factory.create(factory, module, node_or_name, ...)
|
||||||
end
|
end
|
||||||
log("Register component", name)
|
log("Register component", name)
|
||||||
end
|
end
|
||||||
@ -82,16 +82,14 @@ local function create(module, factory, name, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.create(factory, module, name, ...)
|
function _factory.create(factory, module, node_or_name, ...)
|
||||||
local instance = create(module, factory, name)
|
local instance = create(module, factory, node_or_name)
|
||||||
|
|
||||||
if instance.init then
|
if instance.init then
|
||||||
instance:init(...)
|
instance:init(...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
register_basic_components()
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--- Called on_message
|
--- Called on_message
|
||||||
function _factory.on_message(factory, message_id, message, sender)
|
function _factory.on_message(factory, message_id, message, sender)
|
||||||
@ -151,4 +149,6 @@ function _factory.update(factory, dt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
register_basic_components()
|
||||||
|
|
||||||
return M
|
return M
|
@ -24,14 +24,18 @@ function init(self)
|
|||||||
self.druid:new_button("button_1", function()
|
self.druid:new_button("button_1", function()
|
||||||
print("On button 1")
|
print("On button 1")
|
||||||
end)
|
end)
|
||||||
self.druid:new_button("button_2", function()
|
|
||||||
|
--alternative way of component registration
|
||||||
|
self.druid:create(druid.comps.button, "button_2", function()
|
||||||
print("On button 2")
|
print("On button 2")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
self.druid:new_button("button_3", function()
|
self.druid:new_button("button_3", function()
|
||||||
print("On button 3")
|
print("On button 3")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
druid.register("my_custom_component", {})
|
||||||
|
|
||||||
self.druid:new_android_back(function(self, params)
|
self.druid:new_android_back(function(self, params)
|
||||||
print("On android back", params)
|
print("On android back", params)
|
||||||
end, 2)
|
end, 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user