mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Update docs
This commit is contained in:
parent
001fc163ea
commit
295aca26a3
@ -157,6 +157,7 @@ Desc
|
|||||||
-- Mouse scroll working when cursor is hover on scroll view node
|
-- Mouse scroll working when cursor is hover on scroll view node
|
||||||
-- Vertical scroll have more priority than horizontal
|
-- Vertical scroll have more priority than horizontal
|
||||||
-- Fix: When Hover component node became disabled, reset hover state (throw on_hover and on_mouse_hover events)
|
-- Fix: When Hover component node became disabled, reset hover state (throw on_hover and on_mouse_hover events)
|
||||||
|
-- By default mouse scroll is disabled
|
||||||
-- This is basic implementation, it is work not perfect
|
-- This is basic implementation, it is work not perfect
|
||||||
- **#43** Add Data List Druid extended component. Component used to manage huge amount of data to make stuff like "infinity" scroll.
|
- **#43** Add Data List Druid extended component. Component used to manage huge amount of data to make stuff like "infinity" scroll.
|
||||||
- Add context argument to Druid Event. You can pass this argument to forward it first in your callbacks (for example - object context)
|
- Add context argument to Druid Event. You can pass this argument to forward it first in your callbacks (for example - object context)
|
||||||
|
@ -103,8 +103,8 @@ end
|
|||||||
-- @tfield[opt=0.2] number ANIM_SPEED Scroll gui.animation speed for scroll_to function
|
-- @tfield[opt=0.2] number ANIM_SPEED Scroll gui.animation speed for scroll_to function
|
||||||
-- @tfield[opt=0] number EXTRA_STRETCH_SIZE extra size in pixels outside of scroll (stretch effect)
|
-- @tfield[opt=0] number EXTRA_STRETCH_SIZE extra size in pixels outside of scroll (stretch effect)
|
||||||
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, content node with size less than view node size can be scrolled
|
||||||
-- @tfield[opt=25] bool WHEEL_SCROLL_SPEED The scroll speed via mouse wheel scroll or touchpad. Set to 0 to disable wheel scrolling
|
-- @tfield[opt=0] bool WHEEL_SCROLL_SPEED The scroll speed via mouse wheel scroll or touchpad. Set to 0 to disable wheel scrolling
|
||||||
-- @tfield[opt=false] bool SMALL_CONTENT_SCROLL If true, invert direction for touchpad and mouse wheel scroll
|
-- @tfield[opt=false] bool WHEEL_SCROLL_INVERTED If true, invert direction for touchpad and mouse wheel scroll
|
||||||
function Scroll.on_style_change(self, style)
|
function Scroll.on_style_change(self, style)
|
||||||
self.style = {}
|
self.style = {}
|
||||||
self.style.EXTRA_STRETCH_SIZE = style.EXTRA_STRETCH_SIZE or 0
|
self.style.EXTRA_STRETCH_SIZE = style.EXTRA_STRETCH_SIZE or 0
|
||||||
@ -118,7 +118,7 @@ function Scroll.on_style_change(self, style)
|
|||||||
self.style.INERT_SPEED = style.INERT_SPEED or 30
|
self.style.INERT_SPEED = style.INERT_SPEED or 30
|
||||||
self.style.POINTS_DEADZONE = style.POINTS_DEADZONE or 20
|
self.style.POINTS_DEADZONE = style.POINTS_DEADZONE or 20
|
||||||
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
|
self.style.SMALL_CONTENT_SCROLL = style.SMALL_CONTENT_SCROLL or false
|
||||||
self.style.WHEEL_SCROLL_SPEED = style.WHEEL_SCROLL_SPEED or 25
|
self.style.WHEEL_SCROLL_SPEED = style.WHEEL_SCROLL_SPEED or 0
|
||||||
self.style.WHEEL_SCROLL_INVERTED = style.WHEEL_SCROLL_INVERTED or false
|
self.style.WHEEL_SCROLL_INVERTED = style.WHEEL_SCROLL_INVERTED or false
|
||||||
|
|
||||||
self._is_inert = not (self.style.FRICT == 0 or
|
self._is_inert = not (self.style.FRICT == 0 or
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
--- Manage data for huge dataset in scroll
|
--- Component to manage data for huge dataset in scroll.
|
||||||
--- It requires basic druid scroll and druid grid components
|
-- It requires Druid Scroll and Druid Grid (Static or Dynamic) components
|
||||||
|
-- @module DataList
|
||||||
|
-- @within BaseComponent
|
||||||
|
-- @alias druid.data_list
|
||||||
|
|
||||||
|
|
||||||
|
--- The Druid scroll component
|
||||||
|
-- @tfield Scroll scroll
|
||||||
|
|
||||||
|
--- The Druid Grid component
|
||||||
|
-- @tfield StaticGrid grid
|
||||||
|
|
||||||
|
--- The current visual top data index
|
||||||
|
-- @tfield number top_index
|
||||||
|
|
||||||
|
--- The current visual last data index
|
||||||
|
-- @tfield number last_index
|
||||||
|
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.component")
|
local component = require("druid.component")
|
||||||
@ -7,9 +25,11 @@ local component = require("druid.component")
|
|||||||
local DataList = component.create("data_list")
|
local DataList = component.create("data_list")
|
||||||
|
|
||||||
|
|
||||||
|
--- Data list constructor
|
||||||
|
-- @tparam Scroll self
|
||||||
|
-- @tparam node view_node GUI view scroll node
|
||||||
|
-- @tparam node content_node GUI content scroll node
|
||||||
function DataList.init(self, data, scroll, grid, create_function)
|
function DataList.init(self, data, scroll, grid, create_function)
|
||||||
self.view_size = gui.get_size(scroll.view_node)
|
|
||||||
self.prefab_size = grid.node_size
|
|
||||||
self.druid = self:get_druid()
|
self.druid = self:get_druid()
|
||||||
self.scroll = scroll
|
self.scroll = scroll
|
||||||
self.grid = grid
|
self.grid = grid
|
||||||
@ -18,8 +38,8 @@ function DataList.init(self, data, scroll, grid, create_function)
|
|||||||
--- Current visual elements indexes
|
--- Current visual elements indexes
|
||||||
self.top_index = 1
|
self.top_index = 1
|
||||||
self.last_index = 1
|
self.last_index = 1
|
||||||
self.create_function = create_function
|
|
||||||
|
|
||||||
|
self._create_function = create_function
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self._data_first_index = false
|
self._data_first_index = false
|
||||||
self._data_last_index = false
|
self._data_last_index = false
|
||||||
@ -32,11 +52,16 @@ function DataList.init(self, data, scroll, grid, create_function)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Druid System on_remove function
|
||||||
|
-- @tparam DataList self
|
||||||
function DataList.on_remove(self)
|
function DataList.on_remove(self)
|
||||||
self.scroll.on_scroll:unsubscribe(self._check_elements, self)
|
self.scroll.on_scroll:unsubscribe(self._check_elements, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set new data set for DataList component
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam table data The new data array
|
||||||
function DataList.set_data(self, data)
|
function DataList.set_data(self, data)
|
||||||
self._data = data
|
self._data = data
|
||||||
self:_update_data_info()
|
self:_update_data_info()
|
||||||
@ -44,6 +69,12 @@ function DataList.set_data(self, data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Add element to DataList. Currenly untested
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam table data
|
||||||
|
-- @tparam number index
|
||||||
|
-- @tparam number shift_policy The constant from const.SHIFT.*
|
||||||
|
-- @local
|
||||||
function DataList.add(self, data, index, shift_policy)
|
function DataList.add(self, data, index, shift_policy)
|
||||||
index = index or self._data_last_index + 1
|
index = index or self._data_last_index + 1
|
||||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||||
@ -66,12 +97,22 @@ function DataList.add(self, data, index, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Remove element from DataList. Currenly untested
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam number index
|
||||||
|
-- @tparam number shift_policy The constant from const.SHIFT.*
|
||||||
|
-- @local
|
||||||
function DataList.remove(self, index, shift_policy)
|
function DataList.remove(self, index, shift_policy)
|
||||||
table.remove(self._data, index)
|
table.remove(self._data, index)
|
||||||
self:_refresh()
|
self:_refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Remove element from DataList by data value. Currenly untested
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam tabe data
|
||||||
|
-- @tparam number shift_policy The constant from const.SHIFT.*
|
||||||
|
-- @local
|
||||||
function DataList.remove_by_data(self, data, shift_policy)
|
function DataList.remove_by_data(self, data, shift_policy)
|
||||||
local index = helper.contains(self._data, data)
|
local index = helper.contains(self._data, data)
|
||||||
if index then
|
if index then
|
||||||
@ -81,27 +122,38 @@ function DataList.remove_by_data(self, data, shift_policy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Clear the DataList and refresh visuals
|
||||||
|
-- @tparam DataList self
|
||||||
function DataList.clear(self)
|
function DataList.clear(self)
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self:_refresh()
|
self:_refresh()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return first index from data. It not always equals to 1
|
||||||
|
-- @tparam DataList self
|
||||||
function DataList.get_first_index(self)
|
function DataList.get_first_index(self)
|
||||||
return self._data_first_index
|
return self._data_first_index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return last index from data
|
||||||
|
-- @tparam DataList self
|
||||||
function DataList.get_last_index(self)
|
function DataList.get_last_index(self)
|
||||||
return self._data_last_index
|
return self._data_last_index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return amount of data
|
||||||
|
-- @tparam DataList self
|
||||||
function DataList.get_length(self)
|
function DataList.get_length(self)
|
||||||
return self._data_length
|
return self._data_length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return index for data value
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam table data
|
||||||
function DataList.get_index(self, data)
|
function DataList.get_index(self, data)
|
||||||
for index, value in pairs(self._data) do
|
for index, value in pairs(self._data) do
|
||||||
if value == data then
|
if value == data then
|
||||||
@ -113,6 +165,9 @@ function DataList.get_index(self, data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Instant scroll to element with passed index
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam number index
|
||||||
function DataList.scroll_to_index(self, index)
|
function DataList.scroll_to_index(self, index)
|
||||||
self.top_index = helper.clamp(index, 1, #self._data)
|
self.top_index = helper.clamp(index, 1, #self._data)
|
||||||
self:_refresh()
|
self:_refresh()
|
||||||
@ -120,12 +175,16 @@ function DataList.scroll_to_index(self, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Add element at passed index
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam number index
|
||||||
|
-- @local
|
||||||
function DataList._add_at(self, index)
|
function DataList._add_at(self, index)
|
||||||
if self._data_visual[index] then
|
if self._data_visual[index] then
|
||||||
self:_remove_at(index)
|
self:_remove_at(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
local node, instance = self.create_function(self._data[index], index)
|
local node, instance = self._create_function(self._data[index], index)
|
||||||
self.grid:add(node, index, const.SHIFT.NO_SHIFT)
|
self.grid:add(node, index, const.SHIFT.NO_SHIFT)
|
||||||
self._data_visual[index] = {
|
self._data_visual[index] = {
|
||||||
node = node,
|
node = node,
|
||||||
@ -134,6 +193,10 @@ function DataList._add_at(self, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Remove element from passed index
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam number index
|
||||||
|
-- @local
|
||||||
function DataList._remove_at(self, index)
|
function DataList._remove_at(self, index)
|
||||||
self.grid:remove(index, const.SHIFT.NO_SHIFT)
|
self.grid:remove(index, const.SHIFT.NO_SHIFT)
|
||||||
|
|
||||||
@ -147,6 +210,9 @@ function DataList._remove_at(self, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Fully refresh all DataList elements
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @local
|
||||||
function DataList._refresh(self)
|
function DataList._refresh(self)
|
||||||
for index, _ in pairs(self._data_visual) do
|
for index, _ in pairs(self._data_visual) do
|
||||||
self:_remove_at(index)
|
self:_remove_at(index)
|
||||||
@ -155,6 +221,9 @@ function DataList._refresh(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check elements which should be created
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @local
|
||||||
function DataList._check_elements(self)
|
function DataList._check_elements(self)
|
||||||
for index, data in pairs(self._data_visual) do
|
for index, data in pairs(self._data_visual) do
|
||||||
if self.scroll:is_node_in_view(data.node) then
|
if self.scroll:is_node_in_view(data.node) then
|
||||||
@ -173,6 +242,12 @@ function DataList._check_elements(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check elements which should be created.
|
||||||
|
-- Start from index with step until element is outside of scroll view
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @tparam number index
|
||||||
|
-- @tparam number step
|
||||||
|
-- @local
|
||||||
function DataList._check_elements_from(self, index, step)
|
function DataList._check_elements_from(self, index, step)
|
||||||
local is_outside = false
|
local is_outside = false
|
||||||
while not is_outside do
|
while not is_outside do
|
||||||
@ -202,6 +277,10 @@ function DataList._check_elements_from(self, index, step)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Update actual data params
|
||||||
|
-- @tparam DataList self
|
||||||
|
-- @local
|
||||||
function DataList._update_data_info(self)
|
function DataList._update_data_info(self)
|
||||||
self._data_first_index = false
|
self._data_first_index = false
|
||||||
self._data_last_index = false
|
self._data_last_index = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user