Skip to content

Commit

Permalink
#51 Get default grid anchor from node
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Apr 20, 2020
1 parent e18d150 commit 6f8190f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 5 additions & 1 deletion druid/base/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
-- @tfield vector3 border_offer The border offset for correct anchor calculations

local Event = require("druid.event")
local const = require("druid.const")
local component = require("druid.component")

local M = component.create("grid")
Expand All @@ -35,7 +36,10 @@ function M.init(self, parent, element, in_row)
self.nodes = {}

self.offset = vmath.vector3(0)
self.anchor = vmath.vector3(0.5, 0, 0)

local pivot = const.PIVOTS[gui.get_pivot(self.parent)]
self.anchor = vmath.vector3(0.5 + pivot.x, 0.5 - pivot.y, 0)

self.in_row = in_row or 1
self.node_size = gui.get_size(self:get_node(element))
self.border = vmath.vector4(0)
Expand Down
1 change: 0 additions & 1 deletion example/page/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local function init_grid(self)

local grid_scroll = self.druid:new_scroll("grid_content", "scroll_with_grid_size")
local grid = self.druid:new_grid("grid_content", "grid_prefab", 20)
grid:set_anchor(vmath.vector3(0, 0.5, 0))

for i = 1, 40 do
local clone_prefab = gui.clone_tree(prefab)
Expand Down

0 comments on commit 6f8190f

Please sign in to comment.