mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Add outside scroll vector, add correct check for is in view zone
This commit is contained in:
parent
2b5c5bf6fa
commit
7ac6c9b02b
@ -155,6 +155,7 @@ function Scroll.init(self, view_node, content_node)
|
|||||||
self._is_vertical_scroll = true
|
self._is_vertical_scroll = true
|
||||||
self._grid_on_change = nil
|
self._grid_on_change = nil
|
||||||
self._grid_on_change_callback = nil
|
self._grid_on_change_callback = nil
|
||||||
|
self._outside_offset_vector = vmath.vector3(0)
|
||||||
|
|
||||||
self:_update_size()
|
self:_update_size()
|
||||||
end
|
end
|
||||||
@ -166,6 +167,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function Scroll.update(self, dt)
|
function Scroll.update(self, dt)
|
||||||
|
self:_update_params(dt)
|
||||||
if self.drag.is_drag then
|
if self.drag.is_drag then
|
||||||
self:_update_hand_scroll(dt)
|
self:_update_hand_scroll(dt)
|
||||||
else
|
else
|
||||||
@ -362,13 +364,14 @@ function Scroll.set_vertical_scroll(self, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Check node if it visible now on scroll
|
--- Check node if it visible now on scroll.
|
||||||
|
-- Extra border is not affected. Return true for elements in extra scroll zone
|
||||||
-- @tparam Scroll self
|
-- @tparam Scroll self
|
||||||
-- @tparma node node The node to check
|
-- @tparma node node The node to check
|
||||||
-- @treturn boolean True, if node in visible scroll area
|
-- @treturn boolean True, if node in visible scroll area
|
||||||
function Scroll.is_node_in_view(self, node)
|
function Scroll.is_node_in_view(self, node)
|
||||||
local node_border = helper.get_border(node, gui.get_position(node))
|
local node_border = helper.get_border(node, gui.get_position(node))
|
||||||
local view_border = helper.get_border(self.view_node, -self.position)
|
local view_border = helper.get_border(self.view_node, -(self.position - self._outside_offset_vector))
|
||||||
|
|
||||||
-- Check is vertical outside (Left or Right):
|
-- Check is vertical outside (Left or Right):
|
||||||
if node_border.z < view_border.x or node_border.x > view_border.z then
|
if node_border.z < view_border.x or node_border.x > view_border.z then
|
||||||
@ -666,4 +669,30 @@ function Scroll._update_size(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function Scroll._update_params(self, dt)
|
||||||
|
local t = self.target_position
|
||||||
|
local b = self.available_pos
|
||||||
|
|
||||||
|
self._outside_offset_vector.x = 0
|
||||||
|
self._outside_offset_vector.y = 0
|
||||||
|
|
||||||
|
-- Right border (minimum x)
|
||||||
|
if t.x < b.x then
|
||||||
|
self._outside_offset_vector.x = t.x - b.x
|
||||||
|
end
|
||||||
|
-- Left border (maximum x)
|
||||||
|
if t.x > b.z then
|
||||||
|
self._outside_offset_vector.x = t.x - b.z
|
||||||
|
end
|
||||||
|
-- Top border (minimum y)
|
||||||
|
if t.y < b.y then
|
||||||
|
self._outside_offset_vector.y = t.y - b.y
|
||||||
|
end
|
||||||
|
-- Bot border (maximum y)
|
||||||
|
if t.y > b.w then
|
||||||
|
self._outside_offset_vector.y = t.y - b.w
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return Scroll
|
return Scroll
|
||||||
|
@ -189,6 +189,8 @@ function M:_check_elements_from(index, step)
|
|||||||
is_outside = true
|
is_outside = true
|
||||||
|
|
||||||
-- remove nexts:
|
-- remove nexts:
|
||||||
|
-- We add one more element, which is not in view to
|
||||||
|
-- check what it's always outside to stop spawning
|
||||||
local remove_index = index + step
|
local remove_index = index + step
|
||||||
while self._data_visual[remove_index] do
|
while self._data_visual[remove_index] do
|
||||||
self:_remove_at(remove_index)
|
self:_remove_at(remove_index)
|
||||||
|
@ -11,7 +11,7 @@ local function create_infinity_instance(self, record, index)
|
|||||||
self.infinity_list:add(self.infinity_list:get_length() + 1)
|
self.infinity_list:add(self.infinity_list:get_length() + 1)
|
||||||
end)
|
end)
|
||||||
button.on_long_click:subscribe(function()
|
button.on_long_click:subscribe(function()
|
||||||
self.infinity_list:remove_by_data(record)
|
-- self.infinity_list:remove_by_data(record)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return instance["infinity_prefab"], button
|
return instance["infinity_prefab"], button
|
||||||
@ -25,7 +25,7 @@ local function create_infinity_instance_hor(self, record, index)
|
|||||||
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab"], function()
|
local button = self.druid:new_button(instance["infinity_prefab"], function()
|
||||||
print("Infinity click on", record)
|
print("Infinity click on", record)
|
||||||
self.infinity_list_hor:remove_by_data(record)
|
-- self.infinity_list_hor:remove_by_data(record)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return instance["infinity_prefab"], button
|
return instance["infinity_prefab"], button
|
||||||
@ -40,7 +40,7 @@ local function create_infinity_instance_small(self, record, index)
|
|||||||
|
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_small"], function()
|
local button = self.druid:new_button(instance["infinity_prefab_small"], function()
|
||||||
print("Infinity click on", record)
|
print("Infinity click on", record)
|
||||||
self.infinity_list_small:remove_by_data(record)
|
-- self.infinity_list_small:remove_by_data(record)
|
||||||
end)
|
end)
|
||||||
button:set_click_zone(self.infinity_scroll_3.view_node)
|
button:set_click_zone(self.infinity_scroll_3.view_node)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ local function create_infinity_instance_dynamic(self, record, index)
|
|||||||
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(200, 60 + index * 3, 0))
|
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(200, 60 + index * 3, 0))
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
||||||
print("Dynamic click on", record)
|
print("Dynamic click on", record)
|
||||||
self.infinity_list_dynamic:remove_by_data(record)
|
-- self.infinity_list_dynamic:remove_by_data(record)
|
||||||
end)
|
end)
|
||||||
button:set_click_zone(self.infinity_scroll_dynamic.view_node)
|
button:set_click_zone(self.infinity_scroll_dynamic.view_node)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ local function create_infinity_instance_dynamic_hor(self, record, index)
|
|||||||
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(150 + 2 * index, 60, 0))
|
gui.set_size(instance["infinity_prefab_dynamic"], vmath.vector3(150 + 2 * index, 60, 0))
|
||||||
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
local button = self.druid:new_button(instance["infinity_prefab_dynamic"], function()
|
||||||
print("Dynamic click on", record)
|
print("Dynamic click on", record)
|
||||||
self.infinity_list_dynamic_hor:remove_by_data(record)
|
-- self.infinity_list_dynamic_hor:remove_by_data(record)
|
||||||
end)
|
end)
|
||||||
button:set_click_zone(self.infinity_scroll_dynamic_hor.view_node)
|
button:set_click_zone(self.infinity_scroll_dynamic_hor.view_node)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user