mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
* base scroll implementation * add scroll collection example mofidy scrolls, fix callback calls * unhover button if start swipe notify input components on swipe * add node center offset, calc by pivots modify with with node center scroll (to correct scroll to point) * Refactor, add some docs * fix: set_pos on end on scroll * add gui.animate speed in settings
87 lines
2.3 KiB
Plaintext
87 lines
2.3 KiB
Plaintext
local druid = require("druid.druid")
|
|
|
|
|
|
local function init_left_page(self)
|
|
local prefab = gui.get_node("prefab")
|
|
self.left_grid = self.druid:new_grid("page_parent", prefab, 1)
|
|
self.left_grid:set_offset(vmath.vector3(0, 5, 0))
|
|
self.left_grid:set_anchor(vmath.vector3(0.5, 0, 0))
|
|
|
|
for i = 1, 30 do
|
|
local nodes = gui.clone_tree(prefab)
|
|
gui.set_text(nodes["number"], i)
|
|
self.left_grid:add(nodes["prefab"])
|
|
end
|
|
|
|
local size = self.left_grid:get_size()
|
|
local view_size = gui.get_size(gui.get_node("page_parent"))
|
|
|
|
self.left_scroll = self.druid:new_scroll("page_parent", "page_input",
|
|
vmath.vector4(0, view_size.y/2, 0, -size.w - view_size.y/2))
|
|
|
|
self.left_scroll:set_points(self.left_grid:get_all_pos())
|
|
end
|
|
|
|
|
|
local function log(self, index)
|
|
print("Click on", index)
|
|
end
|
|
|
|
|
|
local function init_right_page(self)
|
|
local prefab = gui.get_node("prefab")
|
|
self.right_grid = self.druid:new_grid("right_parent", prefab, 1)
|
|
self.right_grid:set_offset(vmath.vector3(0, 5, 0))
|
|
self.right_grid:set_anchor(vmath.vector3(0.5, 0, 0))
|
|
|
|
for i = 1, 20 do
|
|
local nodes = gui.clone_tree(prefab)
|
|
gui.set_text(nodes["number"], i)
|
|
self.druid:new_button(nodes["prefab"], log, i)
|
|
self.right_grid:add(nodes["prefab"])
|
|
end
|
|
|
|
local size = self.right_grid:get_size()
|
|
local view_size = gui.get_size(gui.get_node("right_parent"))
|
|
|
|
-- TODO: Should we calc scrolle size with parent size?
|
|
-- If yes, we will pass only content size to correct scrolling
|
|
self.right_scroll = self.druid:new_scroll("right_parent", "right_input",
|
|
vmath.vector4(0, 0, 0, -size.w - view_size.y))
|
|
|
|
self.right_scroll:set_points(self.right_grid:get_all_pos())
|
|
|
|
self.right_scroll:on_point_move(function(self, index, pos)
|
|
print("Point to element:", index)
|
|
end)
|
|
end
|
|
|
|
|
|
function init(self)
|
|
self.druid = druid.new(self)
|
|
|
|
-- -600 to 600 - left and right pos.x pages
|
|
-- border is vmath.vector4(left_x, top_y, right_x, bot_y)
|
|
self.main_scroll = self.druid:new_scroll("parent", "input_zone",
|
|
vmath.vector4(-600, 0, 600, 0))
|
|
|
|
self.main_scroll:set_points({
|
|
vmath.vector3(600, 0, 0),
|
|
vmath.vector3(0, 0, 0),
|
|
vmath.vector3(-600, 0, 0),
|
|
})
|
|
-- Disable free inert and we only scroll via points, if exist
|
|
self.main_scroll:set_inert(false)
|
|
|
|
init_left_page(self)
|
|
init_right_page(self)
|
|
end
|
|
|
|
function update(self, dt)
|
|
self.druid:update(dt)
|
|
end
|
|
|
|
function on_input(self, action_id, action)
|
|
self.druid:on_input(action_id, action)
|
|
end
|