mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Separate style progrese
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
-- Repeated tap
|
||||
|
||||
local const = require("druid.const")
|
||||
local settings = require("druid.settings")
|
||||
local b_settings = settings.button
|
||||
local helper = require("druid.helper")
|
||||
|
||||
local M = {}
|
||||
@@ -26,16 +24,16 @@ M.interest = {
|
||||
-- @tparam[opt] string event Button react event, const.ACTION_TOUCH by default
|
||||
function M.init(self, node, callback, params, anim_node, event)
|
||||
assert(callback, "Button should have callback. To block input on zone use blocker component")
|
||||
self.style = self.druid_style.BUTTON or {}
|
||||
|
||||
self.style = helper.get_style(self, "BUTTON")
|
||||
self.node = helper.node(node)
|
||||
|
||||
self.event = const.ACTION_TOUCH
|
||||
self.anim_node = anim_node and helper.node(anim_node) or self.node
|
||||
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 = b_settings.IS_HOVER
|
||||
self.hover_anim = self.style.IS_HOVER
|
||||
self.click_zone = nil
|
||||
end
|
||||
|
||||
|
@@ -3,8 +3,6 @@
|
||||
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local settings = require("druid.settings")
|
||||
local p_settings = settings.progress
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -20,14 +18,12 @@ M.interest = {
|
||||
-- @tparam string key Progress bar direction (x or y)
|
||||
-- @tparam number init_value Initial value of progress bar
|
||||
function M.init(self, node, key, init_value)
|
||||
if key ~= const.SIDE.X and key ~= const.SIDE.Y then
|
||||
settings.log("progress component: key must be 'x' or 'y'. Passed:", key)
|
||||
key = const.SIDE.X
|
||||
end
|
||||
assert(key == const.SIDE.X or const.SIDE.Y, "Progress bar key should be 'x' or 'y'")
|
||||
|
||||
self.prop = hash("scale."..key)
|
||||
self.key = key
|
||||
|
||||
self.style = helper.get_style(self, "PROGRESS")
|
||||
self.node = helper.node(node)
|
||||
self.scale = gui.get_scale(self.node)
|
||||
self.size = gui.get_size(self.node)
|
||||
@@ -152,8 +148,8 @@ end
|
||||
function M.update(self, dt)
|
||||
if self.target then
|
||||
local prev_value = self.last_value
|
||||
local step = math.abs(self.last_value - self.target) * (p_settings.SPEED*dt)
|
||||
step = math.max(step, p_settings.MIN_DELTA)
|
||||
local step = math.abs(self.last_value - self.target) * (self.style.SPEED*dt)
|
||||
step = math.max(step, self.style.MIN_DELTA)
|
||||
self:set_to(helper.step(self.last_value, self.target, step))
|
||||
|
||||
if self.last_value == self.target then
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
local helper = require("druid.helper")
|
||||
local const = require("druid.const")
|
||||
local settings = require("druid.settings").scroll
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -18,10 +17,12 @@ M.current_scroll = nil
|
||||
|
||||
|
||||
function M.init(self, scroll_parent, input_zone, border)
|
||||
self.style = helper.get_style(self, "SCROLL")
|
||||
self.node = helper.node(scroll_parent)
|
||||
self.input_zone = helper.node(input_zone)
|
||||
|
||||
self.zone_size = gui.get_size(self.input_zone)
|
||||
self.soft_size = settings.SOFT_ZONE_SIZE
|
||||
self.soft_size = self.style.SOFT_ZONE_SIZE
|
||||
|
||||
-- Distance from node to node's center
|
||||
local offset = helper.get_pivot_offset(gui.get_pivot(self.input_zone))
|
||||
@@ -61,16 +62,16 @@ local function check_soft_target(self)
|
||||
local b = self.border
|
||||
|
||||
if t.y < b.y then
|
||||
t.y = helper.step(t.y, b.y, math.abs(t.y - b.y) * settings.BACK_SPEED)
|
||||
t.y = helper.step(t.y, b.y, math.abs(t.y - b.y) * self.style.BACK_SPEED)
|
||||
end
|
||||
if t.x < b.x then
|
||||
t.x = helper.step(t.x, b.x, math.abs(t.x - b.x) * settings.BACK_SPEED)
|
||||
t.x = helper.step(t.x, b.x, math.abs(t.x - b.x) * self.style.BACK_SPEED)
|
||||
end
|
||||
if t.y > b.w then
|
||||
t.y = helper.step(t.y, b.w, math.abs(t.y - b.w) * settings.BACK_SPEED)
|
||||
t.y = helper.step(t.y, b.w, math.abs(t.y - b.w) * self.style.BACK_SPEED)
|
||||
end
|
||||
if t.x > b.z then
|
||||
t.x = helper.step(t.x, b.z, math.abs(t.x - b.z) * settings.BACK_SPEED)
|
||||
t.x = helper.step(t.x, b.z, math.abs(t.x - b.z) * self.style.BACK_SPEED)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,8 +95,8 @@ local function update_hand_scroll(self, dt)
|
||||
inert.x = math.abs(inert.x) * helper.sign(delta_x)
|
||||
inert.y = math.abs(inert.y) * helper.sign(delta_y)
|
||||
|
||||
inert.x = inert.x * settings.FRICT_HOLD
|
||||
inert.y = inert.y * settings.FRICT_HOLD
|
||||
inert.x = inert.x * self.style.FRICT_HOLD
|
||||
inert.y = inert.y * self.style.FRICT_HOLD
|
||||
|
||||
set_pos(self, self.target)
|
||||
end
|
||||
@@ -116,11 +117,11 @@ local function check_points(self)
|
||||
|
||||
local inert = self.inert
|
||||
if not self.is_inert then
|
||||
if math.abs(inert.x) > settings.DEADZONE then
|
||||
if math.abs(inert.x) > self.style.DEADZONE then
|
||||
self:scroll_to_index(self.selected - helper.sign(inert.x))
|
||||
return
|
||||
end
|
||||
if math.abs(inert.y) > settings.DEADZONE then
|
||||
if math.abs(inert.y) > self.style.DEADZONE then
|
||||
self:scroll_to_index(self.selected + helper.sign(inert.y))
|
||||
return
|
||||
end
|
||||
@@ -154,13 +155,14 @@ local function check_points(self)
|
||||
temp_dist_on_inert = dist
|
||||
end
|
||||
end
|
||||
|
||||
self:scroll_to_index(index_on_inert or index)
|
||||
end
|
||||
|
||||
|
||||
local function check_threshold(self)
|
||||
local inert = self.inert
|
||||
if not self.is_inert or vmath.length(inert) < settings.INERT_THRESHOLD then
|
||||
if not self.is_inert or vmath.length(inert) < self.style.INERT_THRESHOLD then
|
||||
check_points(self)
|
||||
inert.x = 0
|
||||
inert.y = 0
|
||||
@@ -171,11 +173,11 @@ end
|
||||
local function update_free_inert(self, dt)
|
||||
local inert = self.inert
|
||||
if inert.x ~= 0 or inert.y ~= 0 then
|
||||
self.target.x = self.pos.x + (inert.x * dt * settings.INERT_SPEED)
|
||||
self.target.y = self.pos.y + (inert.y * dt * settings.INERT_SPEED)
|
||||
self.target.x = self.pos.x + (inert.x * dt * self.style.INERT_SPEED)
|
||||
self.target.y = self.pos.y + (inert.y * dt * self.style.INERT_SPEED)
|
||||
|
||||
inert.x = inert.x * settings.FRICT
|
||||
inert.y = inert.y * settings.FRICT
|
||||
inert.x = inert.x * self.style.FRICT
|
||||
inert.y = inert.y * self.style.FRICT
|
||||
|
||||
-- Stop, when low inert speed and go to points
|
||||
check_threshold(self)
|
||||
@@ -275,7 +277,7 @@ function M.on_input(self, action_id, action)
|
||||
self.target.y = self.pos.y
|
||||
else
|
||||
local dist = helper.distance(action.x, action.y, inp.start_x, inp.start_y)
|
||||
if not M.current_scroll and dist >= settings.DEADZONE then
|
||||
if not M.current_scroll and dist >= self.style.DEADZONE then
|
||||
local dx = math.abs(inp.start_x - action.x)
|
||||
local dy = math.abs(inp.start_y - action.y)
|
||||
inp.side = (dx > dy) and const.SIDE.X or const.SIDE.Y
|
||||
@@ -331,7 +333,7 @@ function M.scroll_to(self, point, is_instant)
|
||||
self.target = target
|
||||
set_pos(self, target)
|
||||
else
|
||||
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
|
||||
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, self.style.ANIM_SPEED, 0, function()
|
||||
self.animate = false
|
||||
self.target = target
|
||||
set_pos(self, target)
|
||||
|
Reference in New Issue
Block a user