mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
#162 Add static grid last row alignment
This commit is contained in:
parent
97e7631d22
commit
3ac2986171
@ -70,9 +70,11 @@ end
|
||||
-- or create your own style
|
||||
-- @table style
|
||||
-- @tfield[opt=false] bool IS_DYNAMIC_NODE_POSES If true, always center grid content as grid pivot sets
|
||||
-- @tfield[opt=false] bool IS_ALIGN_LAST_ROW If true, always align last row of the grid as grid pivot sets
|
||||
function StaticGrid.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.IS_DYNAMIC_NODE_POSES = style.IS_DYNAMIC_NODE_POSES or false
|
||||
self.style.IS_ALIGN_LAST_ROW = style.IS_ALIGN_LAST_ROW or false
|
||||
end
|
||||
|
||||
|
||||
@ -122,7 +124,9 @@ function StaticGrid.get_pos(self, index)
|
||||
local row = math.ceil(index / self.in_row) - 1
|
||||
local col = (index - row * self.in_row) - 1
|
||||
|
||||
_temp_pos.x = col * self.node_size.x + self._zero_offset.x
|
||||
local zero_offset_x = self:_get_zero_offset_x(row)
|
||||
|
||||
_temp_pos.x = col * self.node_size.x + zero_offset_x
|
||||
_temp_pos.y = -row * self.node_size.y + self._zero_offset.y
|
||||
_temp_pos.z = 0
|
||||
|
||||
@ -437,4 +441,27 @@ function StaticGrid:_get_zero_offset()
|
||||
end
|
||||
|
||||
|
||||
--- Return offset x for last row in grid. Used to align this row accorting to grid's anchor
|
||||
-- @function static:_grid:_get_zero_offset_x
|
||||
-- @treturn number The offset x value
|
||||
-- @local
|
||||
function StaticGrid:_get_zero_offset_x(row_index)
|
||||
if not self.style.IS_DYNAMIC_NODE_POSES or not self.style.IS_ALIGN_LAST_ROW then
|
||||
return self._zero_offset.x
|
||||
end
|
||||
|
||||
local offset_x = self._zero_offset.x
|
||||
local last_row = math.ceil(self.last_index / self.in_row) - 1
|
||||
|
||||
if last_row > 0 and last_row == row_index then
|
||||
local elements_in_row = (self.last_index - (last_row * self.in_row)) - 1
|
||||
local offset = elements_in_row * self.node_size.x * self.anchor.x
|
||||
offset_x = self.node_size.x * self.node_pivot.x - self.node_size.x * self.pivot.x - offset
|
||||
end
|
||||
|
||||
return offset_x
|
||||
end
|
||||
|
||||
|
||||
|
||||
return StaticGrid
|
||||
|
@ -61,6 +61,7 @@ M["drag"] = {
|
||||
|
||||
M["static_grid"] = {
|
||||
IS_DYNAMIC_NODE_POSES = false, -- Always align by content size with node anchor
|
||||
IS_ALIGN_LAST_ROW = true, -- Align the last row of grid
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,6 +39,10 @@ function init(self)
|
||||
grid_e,
|
||||
}
|
||||
|
||||
for i = 1, #grids do
|
||||
grids[i].style.IS_DYNAMIC_NODE_POSES = false
|
||||
end
|
||||
|
||||
|
||||
local animate_grides = function()
|
||||
for _, grid in ipairs(grids) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user