mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
update scroll and helper
This commit is contained in:
parent
4ce8e85d15
commit
099eaa1e10
@ -99,10 +99,7 @@ end
|
||||
|
||||
|
||||
local function get_zone_center(self)
|
||||
local pos = vmath.vector3(self.pos)
|
||||
pos.x = pos.x + self.center_offset.x
|
||||
pos.y = pos.y + self.center_offset.y
|
||||
return pos
|
||||
return self.pos + self.center_offset
|
||||
end
|
||||
|
||||
|
||||
@ -257,7 +254,7 @@ end
|
||||
|
||||
|
||||
function M.on_input(self, action_id, action)
|
||||
if action_id ~= data.A_TOUCH then
|
||||
if action_id ~= data.ACTION_TOUCH then
|
||||
return false
|
||||
end
|
||||
local inp = self.input
|
||||
@ -289,18 +286,21 @@ function M.on_input(self, action_id, action)
|
||||
M.current_scroll = self
|
||||
end
|
||||
end
|
||||
if M.current_scroll == self then
|
||||
add_delta(self, action.dx, action.dy)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if inp.touch and not action.pressed then
|
||||
if M.current_scroll == self then
|
||||
add_delta(self, action.dx, action.dy)
|
||||
result = true
|
||||
end
|
||||
end
|
||||
|
||||
if action.released then
|
||||
inp.touch = false
|
||||
inp.side = false
|
||||
if M.current_scroll == self then
|
||||
M.current_scroll = nil
|
||||
inp.touch = false
|
||||
inp.side = false
|
||||
result = true
|
||||
end
|
||||
check_threshold(self)
|
||||
@ -311,7 +311,7 @@ end
|
||||
|
||||
|
||||
--- Start scroll to point (x, y, z)
|
||||
function M.scroll_to(self, point)
|
||||
function M.scroll_to(self, point, is_instant)
|
||||
local b = self.border
|
||||
local target = vmath.vector3(point)
|
||||
target.x = helper.clamp(point.x - self.center_offset.x, b.x, b.z)
|
||||
@ -319,12 +319,18 @@ function M.scroll_to(self, point)
|
||||
|
||||
cancel_animate(self)
|
||||
|
||||
self.animate = true
|
||||
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
|
||||
self.animate = false
|
||||
self.animate = not is_instant
|
||||
|
||||
if is_instant then
|
||||
self.target = target
|
||||
set_pos(self, target)
|
||||
end)
|
||||
else
|
||||
gui.animate(self.node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, settings.ANIM_SPEED, 0, function()
|
||||
self.animate = false
|
||||
self.target = target
|
||||
set_pos(self, target)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
-- actions
|
||||
|
||||
-- Actions
|
||||
M.A_TOUCH = hash("touch")
|
||||
M.A_TEXT = hash("text")
|
||||
M.A_BACKSPACE = hash("backspace")
|
||||
@ -11,21 +10,20 @@ M.A_ANDR_BACK = hash("back")
|
||||
M.RELEASED = "released"
|
||||
M.PRESSED = "pressed"
|
||||
|
||||
--- interests
|
||||
|
||||
--- Interests
|
||||
M.ON_MESSAGE = hash("on_message")
|
||||
M.ON_UPDATE = hash("on_update")
|
||||
|
||||
-- input
|
||||
-- Input
|
||||
M.ON_SWIPE = hash("on_swipe")
|
||||
M.ON_INPUT = hash("on_input")
|
||||
|
||||
M.ui_input = {
|
||||
[M.ON_SWIPE] = true,
|
||||
[M.ON_INPUT] = true
|
||||
|
||||
}
|
||||
-- ui messages
|
||||
|
||||
-- UI messages
|
||||
M.ON_CHANGE_LANGUAGE = hash("on_change_language")
|
||||
M.ON_LAYOUT_CHANGED = hash("on_layout_changed")
|
||||
|
||||
|
@ -1,23 +1,70 @@
|
||||
local M = {}
|
||||
|
||||
function M.centrate_text_with_icon(text_node, icon_node, offset_x)
|
||||
offset_x = offset_x or 0
|
||||
local metr = gui.get_text_metrics_from_node(text_node)
|
||||
local scl = gui.get_scale(text_node).x
|
||||
local pos = gui.get_position(text_node)
|
||||
local scl_i = gui.get_scale(icon_node).x
|
||||
local pos_i = gui.get_position(icon_node)
|
||||
local w = metr.width * scl -- text width
|
||||
local icon_w = gui.get_size(icon_node).x * scl_i -- icon width
|
||||
local width = w + icon_w
|
||||
--- Text node or icon node can be nil
|
||||
local function get_text_width(text_node)
|
||||
if text_node then
|
||||
local text_metrics = gui.get_text_metrics_from_node(text_node)
|
||||
local text_scale = gui.get_scale(text_node).x
|
||||
return text_metrics.width * text_scale
|
||||
end
|
||||
|
||||
pos.x = -width/2 + w + offset_x
|
||||
gui.set_position(text_node, pos)
|
||||
pos_i.x = width/2 - icon_w + offset_x
|
||||
gui.set_position(icon_node, pos_i)
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
local function get_icon_width(icon_node)
|
||||
if icon_node then
|
||||
local icon_scale_x = gui.get_scale(icon_node).x
|
||||
return gui.get_size(icon_node).x * icon_scale_x -- icon width
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
--- Text node or icon node can be nil
|
||||
function M.centrate_text_with_icon(text_node, icon_node, margin)
|
||||
margin = margin or 0
|
||||
local text_width = get_text_width(text_node)
|
||||
local icon_width = get_icon_width(icon_node)
|
||||
local width = text_width + icon_width
|
||||
|
||||
if text_node then
|
||||
local pos = gui.get_position(text_node)
|
||||
pos.x = -width/2 + text_width - margin/2
|
||||
gui.set_position(text_node, pos)
|
||||
end
|
||||
|
||||
if icon_node then
|
||||
local icon_pos = gui.get_position(icon_node)
|
||||
icon_pos.x = width/2 - icon_width + margin/2
|
||||
gui.set_position(icon_node, icon_pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Icon node or text node can be nil
|
||||
function M.centrate_icon_with_text(icon_node, text_node, margin)
|
||||
margin = margin or 0
|
||||
local icon_width = get_icon_width(icon_node)
|
||||
local text_width = get_text_width(text_node)
|
||||
local width = text_width + icon_width
|
||||
|
||||
if text_node then
|
||||
local pos = gui.get_position(text_node)
|
||||
pos.x = width/2 - text_width + margin/2
|
||||
gui.set_position(text_node, pos)
|
||||
end
|
||||
|
||||
if icon_node then
|
||||
local icon_pos = gui.get_position(icon_node)
|
||||
icon_pos.x = -width/2 + icon_width - margin/2
|
||||
gui.set_position(icon_node, icon_pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local STRING = "string"
|
||||
function M.get_node(node_or_name)
|
||||
if type(node_or_name) == STRING then
|
||||
@ -96,4 +143,5 @@ function M.get_pivot_offset(pivot)
|
||||
return pivots[pivot]
|
||||
end
|
||||
|
||||
|
||||
return M
|
Loading…
x
Reference in New Issue
Block a user