Add component instance with general methods. New component constructor

This commit is contained in:
Insality
2020-01-30 01:46:02 +03:00
parent 0542ec4e69
commit ae47bcee8f
22 changed files with 156 additions and 114 deletions

View File

@@ -3,12 +3,9 @@
local const = require("druid.const")
local helper = require("druid.helper")
local component = require("druid.system.component")
local M = {}
M.interest = {
const.ON_UPDATE,
}
local M = component.new("progress", { const.ON_UPDATE })
--- Component init function
@@ -23,7 +20,7 @@ function M.init(self, node, key, init_value)
self.prop = hash("scale."..key)
self.key = key
self.style = helper.get_style(self, "PROGRESS")
self.style = self:get_style()
self.node = helper.get_node(node)
self.scale = gui.get_scale(self.node)
self.size = gui.get_size(self.node)
@@ -52,10 +49,10 @@ local function check_steps(self, from, to, exactly)
end
if v1 < step and step < v2 then
self.step_callback(self.context, step)
self.step_callback(self:get_context(), step)
end
if exactly and exactly == step then
self.step_callback(self.context, step)
self.step_callback(self:get_context(), step)
end
end
end
@@ -139,7 +136,7 @@ function M.to(self, to, callback)
self.target_callback = callback
else
if callback then
callback(self.context, to)
callback(self:get_context(), to)
end
end
end
@@ -156,7 +153,7 @@ function M.update(self, dt)
check_steps(self, prev_value, self.target, self.target)
if self.target_callback then
self.target_callback(self.context, self.target)
self.target_callback(self:get_context(), self.target)
end
self.target = nil