Fix scroll events while animating

Fix slider issue with negative distance
Add bunch of new functions to grid
More accurate progress bar scaling with 9-slice images
This commit is contained in:
Insality
2024-09-10 21:46:29 +03:00
parent 986a4695f6
commit d533e5ee2d
6 changed files with 131 additions and 17 deletions

View File

@@ -201,9 +201,9 @@ function Hover:_set_cursor(priority, cursor)
local priority = nil
local cursor_to_set = nil
for _, stack in pairs(cursor_stack) do
for priority, _ in pairs(stack) do
if priority > (priority or 0) then
priority = priority
for pr, _ in pairs(stack) do
if pr > (priority or 0) then
priority = pr
cursor_to_set = stack[priority]
end
end

View File

@@ -54,7 +54,7 @@
-- @tfield node content_node
--- Flag, if scroll now moving by inertion
-- @tfield bool _is_inert
-- @tfield boolean _is_inert
--- Current inert speed
-- @tfield vector3 inertion
@@ -704,6 +704,10 @@ end
function Scroll._update_free_scroll(self, dt)
if self.is_animate then
return
end
local target = self.target_position
if self._is_inert and (self.inertion.x ~= 0 or self.inertion.y ~= 0) then
@@ -725,6 +729,10 @@ end
function Scroll._update_hand_scroll(self, dt)
if self.is_animate then
self:_cancel_animate()
end
local dx = self.target_position.x - self.position.x
local dy = self.target_position.y - self.position.y

View File

@@ -240,6 +240,23 @@ function StaticGrid.add(self, item, index, shift_policy, is_instant)
end
--- Set new items to the grid. All previous items will be removed
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam node[] nodes The new grid nodes
-- @tparam[opt=false] boolean is_instant If true, update node positions instantly
function StaticGrid.set_items(self, nodes, is_instant)
self.nodes = nodes
for index = 1, #nodes do
local item = nodes[index]
gui.set_parent(item, self.parent)
end
self:_update(is_instant)
self.on_change_items:trigger(self:get_context())
end
--- Remove the item from the grid. Note that gui node will be not deleted
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam number index The grid node index to remove
@@ -382,6 +399,35 @@ function StaticGrid.set_in_row(self, in_row)
end
--- Set new node size for grid
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam[opt] number width The new node width
-- @tparam[opt] number height The new node height
-- @treturn druid.static_grid Current grid instance
function StaticGrid.set_item_size(self, width, height)
if width then
self.node_size.x = width
end
if height then
self.node_size.y = height
end
self:_update()
self.on_change_items:trigger(self:get_context())
return self
end
--- Sort grid nodes by custom comparator function
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam function comparator The comparator function. (a, b) -> boolean
-- @treturn druid.static_grid Current grid instance
function StaticGrid.sort_nodes(self, comparator)
table.sort(self.nodes, comparator)
self:_update(true)
end
--- Update grid inner state
-- @tparam StaticGrid self @{StaticGrid}
-- @tparam boolean|nil is_instant If true, node position update instantly, otherwise with set_position_function callback