move settings node from factory to component (#8)

This commit is contained in:
Maxim Tuprikov 2019-03-29 00:51:37 +03:00 committed by GitHub
parent 12f5f22b69
commit 7395f029e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 23 deletions

View File

@ -1,6 +1,7 @@
local data = require("druid.data")
local ui_animate = require "druid.helper.druid_animate"
local ui_animate = require("druid.helper.druid_animate")
local settings = require("druid.settings")
local helper = require("druid.helper.helper")
local b_settings = settings.button
local M = {}
@ -14,7 +15,8 @@ M.DEFAULT_ACTIVATE_SCALE = vmath.vector3(1, 1, 1)
M.DEFAUL_ACTIVATION_TIME = 0.2
function M.init(instance, callback, params, anim_node)
function M.init(instance, node, callback, params, anim_node, event)
instance.node = helper.get_node(node)
instance.event = data.A_TOUCH
instance.anim_node = anim_node and gui.get_node(anim_node) or instance.node
instance.scale_from = gui.get_scale(instance.anim_node)

View File

@ -1,5 +1,6 @@
local data = require("druid.data")
local settings = require("druid.settings")
local helper = require("druid.helper.helper")
local M = {}
M.interest = {
@ -8,7 +9,8 @@ M.interest = {
}
function M.init(instance, value, is_locale)
function M.init(instance, node, value, is_locale)
instance.node = helper.get_node(node)
instance.last_color = gui.get_color(instance.node)
if is_locale then
instance.text_id = value

View File

@ -1,6 +1,6 @@
local data = require("druid.data")
local formats = require("druid.helper.formats")
local helper = require("druid.helper.ui_helper")
local helper = require("druid.helper.helper")
local M = {}
M.interest = {
@ -10,7 +10,8 @@ M.interest = {
local empty = function() end
function M.init(instance, seconds_from, seconds_to, callback)
function M.init(instance, node, seconds_from, seconds_to, callback)
instance.node = helper.get_node(node)
seconds_from = math.max(seconds_from, 0)
seconds_to = math.max(seconds_to or 0, 0)
callback = callback or empty

View File

@ -7,8 +7,6 @@ local M = {}
local log = settings.log
local _factory = {}
local STRING = "string"
M.comps = {
button = require("druid.base.button"),
android_back = require("druid.base.android_back"),
@ -26,8 +24,8 @@ end
function M.register(name, module)
-- TODO: Find better solution to creating elements?
_factory["new_" .. name] = function(factory, node_or_name, ...)
return _factory.new(factory, module, node_or_name, ...)
_factory["new_" .. name] = function(factory, ...)
return _factory.new(factory, module, ...)
end
log("Register component", name)
end
@ -54,19 +52,9 @@ local function input_init(factory)
end
local function create(module, factory, name)
local function create(module, factory)
local instance = setmetatable({}, {__index = module})
instance.parent = factory
if name then
if type(name) == STRING then
instance.name = name
instance.node = gui.get_node(name)
else
--name already is node
instance.name = nil
instance.node = name
end
end
factory[#factory + 1] = instance
local register_to = module.interest or {}
@ -84,8 +72,8 @@ local function create(module, factory, name)
end
function _factory.new(factory, module, node_or_name, ...)
local instance = create(module, factory, node_or_name)
function _factory.new(factory, module, ...)
local instance = create(module, factory)
if instance.init then
instance:init(...)

View File

@ -18,6 +18,15 @@ function M.centrate_text_with_icon(text_node, icon_node, offset_x)
end
local STRING = "string"
function M.get_node(node_or_name)
if type(node_or_name) == STRING then
return gui.get_node(node_or_name)
end
return node_or_name
end
function M.step(current, target, step)
if current < target then
return math.min(current + step, target)

View File

@ -46,7 +46,7 @@ function init(self)
self.druid:new_text("text_2", "Simple text")
self.druid:new_text("text_3", "locale_text", true)
self.druid:new_timer("text_1", 0.5, 0, function()
self.druid:new_timer("text_1", 5, 0, function()
print("On timer end")
end)