mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Rename Infinity list to Data list
This commit is contained in:
parent
03a00fe3d2
commit
72efdc13bf
@ -4,10 +4,10 @@ local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
|
||||
local M = component.create("infinity_list")
|
||||
local DataList = component.create("data_list")
|
||||
|
||||
|
||||
function M:init(data_list, 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()
|
||||
@ -28,23 +28,23 @@ function M:init(data_list, scroll, grid, create_function)
|
||||
|
||||
self.scroll.on_scroll:subscribe(self._check_elements, self)
|
||||
|
||||
self:set_data(data_list)
|
||||
self:set_data(data)
|
||||
end
|
||||
|
||||
|
||||
function M:on_remove()
|
||||
function DataList.on_remove(self)
|
||||
self.scroll.on_scroll:unsubscribe(self._check_elements, self)
|
||||
end
|
||||
|
||||
|
||||
function M:set_data(data_list)
|
||||
self._data = data_list
|
||||
function DataList.set_data(self, data)
|
||||
self._data = data
|
||||
self:_update_data_info()
|
||||
self:_refresh()
|
||||
end
|
||||
|
||||
|
||||
function M:add(data, index, shift_policy)
|
||||
function DataList.add(self, data, index, shift_policy)
|
||||
index = index or self._data_last_index + 1
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
|
||||
@ -66,13 +66,13 @@ function M:add(data, index, shift_policy)
|
||||
end
|
||||
|
||||
|
||||
function M:remove(index, shift_policy)
|
||||
function DataList.remove(self, index, shift_policy)
|
||||
table.remove(self._data, index)
|
||||
self:_refresh()
|
||||
end
|
||||
|
||||
|
||||
function M:remove_by_data(data, shift_policy)
|
||||
function DataList.remove_by_data(self, data, shift_policy)
|
||||
local index = helper.contains(self._data, data)
|
||||
if index then
|
||||
table.remove(self._data, index)
|
||||
@ -81,28 +81,28 @@ function M:remove_by_data(data, shift_policy)
|
||||
end
|
||||
|
||||
|
||||
function M:clear()
|
||||
function DataList.clear(self)
|
||||
self._data = {}
|
||||
self:_refresh()
|
||||
end
|
||||
|
||||
|
||||
function M:get_first_index()
|
||||
function DataList.get_first_index(self)
|
||||
return self._data_first_index
|
||||
end
|
||||
|
||||
|
||||
function M:get_last_index()
|
||||
function DataList.get_last_index(self)
|
||||
return self._data_last_index
|
||||
end
|
||||
|
||||
|
||||
function M:get_length()
|
||||
function DataList.get_length(self)
|
||||
return self._data_length
|
||||
end
|
||||
|
||||
|
||||
function M:get_index(data)
|
||||
function DataList.get_index(self, data)
|
||||
for index, value in pairs(self._data) do
|
||||
if value == data then
|
||||
return index
|
||||
@ -113,14 +113,14 @@ function M:get_index(data)
|
||||
end
|
||||
|
||||
|
||||
function M:scroll_to_index(index)
|
||||
function DataList.scroll_to_index(self, index)
|
||||
self.top_index = helper.clamp(index, 1, #self._data)
|
||||
self:_refresh()
|
||||
self.scroll.on_scroll:trigger(self:get_context(), self)
|
||||
end
|
||||
|
||||
|
||||
function M:_add_at(index)
|
||||
function DataList._add_at(self, index)
|
||||
if self._data_visual[index] then
|
||||
self:_remove_at(index)
|
||||
end
|
||||
@ -134,7 +134,7 @@ function M:_add_at(index)
|
||||
end
|
||||
|
||||
|
||||
function M:_remove_at(index)
|
||||
function DataList._remove_at(self, index)
|
||||
self.grid:remove(index, const.SHIFT.NO_SHIFT)
|
||||
|
||||
local node = self._data_visual[index].node
|
||||
@ -147,7 +147,7 @@ function M:_remove_at(index)
|
||||
end
|
||||
|
||||
|
||||
function M:_refresh()
|
||||
function DataList._refresh(self)
|
||||
for index, _ in pairs(self._data_visual) do
|
||||
self:_remove_at(index)
|
||||
end
|
||||
@ -155,7 +155,7 @@ function M:_refresh()
|
||||
end
|
||||
|
||||
|
||||
function M:_check_elements()
|
||||
function DataList._check_elements(self)
|
||||
for index, data in pairs(self._data_visual) do
|
||||
if self.scroll:is_node_in_view(data.node) then
|
||||
self.top_index = index
|
||||
@ -173,7 +173,7 @@ function M:_check_elements()
|
||||
end
|
||||
|
||||
|
||||
function M:_check_elements_from(index, step)
|
||||
function DataList._check_elements_from(self, index, step)
|
||||
local is_outside = false
|
||||
while not is_outside do
|
||||
if not self._data[index] then
|
||||
@ -202,7 +202,7 @@ function M:_check_elements_from(index, step)
|
||||
end
|
||||
|
||||
|
||||
function M:_update_data_info()
|
||||
function DataList._update_data_info(self)
|
||||
self._data_first_index = false
|
||||
self._data_last_index = false
|
||||
self._data_length = 0
|
||||
@ -220,4 +220,4 @@ function M:_update_data_info()
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return DataList
|
@ -53,7 +53,7 @@ local progress = require("druid.extended.progress")
|
||||
local radio_group = require("druid.extended.radio_group")
|
||||
local slider = require("druid.extended.slider")
|
||||
local timer = require("druid.extended.timer")
|
||||
local infinity_list = require("druid.extended.infinity_list")
|
||||
local data_list = require("druid.extended.data_list")
|
||||
|
||||
|
||||
local DruidInstance = class("druid.druid_instance")
|
||||
@ -542,12 +542,12 @@ function DruidInstance.new_checkbox_group(self, nodes, callback, click_nodes)
|
||||
end
|
||||
|
||||
|
||||
--- Create infinity list basic component
|
||||
-- @function druid:new_infinity_list
|
||||
--- Create data list basic component
|
||||
-- @function druid:new_data_list
|
||||
-- @tparam args ... drag init args
|
||||
-- @treturn Component infinity list component
|
||||
function DruidInstance.new_infinity_list(self, ...)
|
||||
return DruidInstance.create(self, infinity_list, ...)
|
||||
-- @treturn Component data list component
|
||||
function DruidInstance.new_data_list(self, ...)
|
||||
return DruidInstance.create(self, data_list, ...)
|
||||
end
|
||||
|
||||
|
||||
|
@ -86,14 +86,14 @@ local function setup_infinity_list(self)
|
||||
table.insert(data, i)
|
||||
end
|
||||
|
||||
self.infinity_list = self.druid:new_infinity_list(data, self.infinity_scroll, self.infinity_grid, function(record, index)
|
||||
self.infinity_list = self.druid:new_data_list(data, self.infinity_scroll, self.infinity_grid, function(record, index)
|
||||
-- function should return gui_node, [druid_component]
|
||||
local root, button = create_infinity_instance(self, record, index)
|
||||
button:set_click_zone(self.infinity_scroll.view_node)
|
||||
return root, button
|
||||
end)
|
||||
|
||||
self.infinity_list_hor = self.druid:new_infinity_list(data, self.infinity_scroll_hor, self.infinity_grid_hor, function(record, index)
|
||||
self.infinity_list_hor = self.druid:new_data_list(data, self.infinity_scroll_hor, self.infinity_grid_hor, function(record, index)
|
||||
-- function should return gui_node, [druid_component]
|
||||
local root, button = create_infinity_instance_hor(self, record, index)
|
||||
button:set_click_zone(self.infinity_scroll_hor.view_node)
|
||||
@ -108,12 +108,12 @@ local function setup_infinity_list(self)
|
||||
end)
|
||||
|
||||
|
||||
self.infinity_list_small = self.druid:new_infinity_list(data, self.infinity_scroll_3, self.infinity_grid_3, function(record, index)
|
||||
self.infinity_list_small = self.druid:new_data_list(data, self.infinity_scroll_3, self.infinity_grid_3, function(record, index)
|
||||
-- function should return gui_node, [druid_component]
|
||||
return create_infinity_instance_small(self, record, index)
|
||||
end)
|
||||
|
||||
self.infinity_list_dynamic = self.druid:new_infinity_list(data, self.infinity_scroll_dynamic, self.infinity_grid_dynamic, function(record, index)
|
||||
self.infinity_list_dynamic = self.druid:new_data_list(data, self.infinity_scroll_dynamic, self.infinity_grid_dynamic, function(record, index)
|
||||
-- function should return gui_node, [druid_component]
|
||||
return create_infinity_instance_dynamic(self, record, index)
|
||||
end)
|
||||
@ -122,7 +122,7 @@ local function setup_infinity_list(self)
|
||||
self.infinity_list_dynamic:scroll_to_index(25)
|
||||
end)
|
||||
|
||||
self.infinity_list_dynamic_hor = self.druid:new_infinity_list(data, self.infinity_scroll_dynamic_hor, self.infinity_grid_dynamic_hor, function(record, index)
|
||||
self.infinity_list_dynamic_hor = self.druid:new_data_list(data, self.infinity_scroll_dynamic_hor, self.infinity_grid_dynamic_hor, function(record, index)
|
||||
-- function should return gui_node, [druid_component]
|
||||
return create_infinity_instance_dynamic_hor(self, record, index)
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user