From a36ba5ab1c316096230df51ebc814220e3823ea1 Mon Sep 17 00:00:00 2001 From: Insality Date: Mon, 28 Sep 2020 02:58:43 +0300 Subject: [PATCH] Add more available pivots for dynamic grid --- docs_md/changelog.md | 2 +- druid/base/dynamic_grid.lua | 12 ++++++++++-- druid/const.lua | 2 +- druid/helper.lua | 10 ++++++++++ example/gui/main/main.gui | 10 +++++----- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/docs_md/changelog.md b/docs_md/changelog.md index f4c73ba..1b48160 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -106,7 +106,7 @@ Druid 0.5.0: - Have dynamic element size. So have no ability to precalculate stuff like _static_grid_ - This grid can't have gaps between elements. You will get the error, if spawn element far away from other elements - The grid can spawn elements only in row or in collumn - - The grid node should have __West__ or __North__ pivot (vertical or horizontal element placement) + - The grid node should have __West__, __East__, __South__ or __North__ pivot (vertical or horizontal element placement) - Able to shift nodes left or right on _grid:add_/_grid:remove_ functions - Scroll update: - Add _scroll:set_vertical_scroll_ and _scroll:set_horizontal_scroll_ for disable scroll sides diff --git a/druid/base/dynamic_grid.lua b/druid/base/dynamic_grid.lua index 4d05a56..cefd9b3 100644 --- a/druid/base/dynamic_grid.lua +++ b/druid/base/dynamic_grid.lua @@ -32,6 +32,13 @@ local SIDE_VECTORS = { BOT = vmath.vector3(0, 1, 0), } +local AVAILABLE_PIVOTS = { + gui.PIVOT_N, + gui.PIVOT_S, + gui.PIVOT_W, + gui.PIVOT_E, +} + --- Component init function -- @function dynamic_grid:init @@ -42,8 +49,9 @@ function DynamicGrid:init(parent, side) local parent_pivot = gui.get_pivot(self.parent) self.pivot = helper.get_pivot_offset(parent_pivot) - assert(parent_pivot == gui.PIVOT_W or parent_pivot == gui.PIVOT_N, const.ERRORS.GRID_DYNAMIC_ANCHOR) - self.side = (parent_pivot == gui.PIVOT_W and const.SIDE.X or const.SIDE.Y) + assert(helper.contains(AVAILABLE_PIVOTS, parent_pivot), const.ERRORS.GRID_DYNAMIC_ANCHOR) + self.side = ((parent_pivot == gui.PIVOT_W or parent_pivot == gui.PIVOT_E) + and const.SIDE.X or const.SIDE.Y) self.nodes = {} self.border = vmath.vector4(0) -- Current grid content size diff --git a/druid/const.lua b/druid/const.lua index 151b62b..3437fe4 100644 --- a/druid/const.lua +++ b/druid/const.lua @@ -103,7 +103,7 @@ M.SWIPE = { M.ERRORS = { - GRID_DYNAMIC_ANCHOR = "The pivot of dynamic grid node should be West or North" + GRID_DYNAMIC_ANCHOR = "The pivot of dynamic grid node should be West, East, South or North" } diff --git a/druid/helper.lua b/druid/helper.lua index 3b6792a..c4c0041 100644 --- a/druid/helper.lua +++ b/druid/helper.lua @@ -131,6 +131,16 @@ function M.lerp(a, b, t) end +function M.contains(t, value) + for i = 1, #t do + if t[i] == value then + return i + end + end + return false +end + + --- Check if node is enabled in gui hierarchy. -- Return false, if node or any his parent is disabled -- @function helper.is_enabled diff --git a/example/gui/main/main.gui b/example/gui/main/main.gui index 79d53f6..0497466 100644 --- a/example/gui/main/main.gui +++ b/example/gui/main/main.gui @@ -10297,7 +10297,7 @@ nodes { nodes { position { x: 0.0 - y: -814.0 + y: -1320.0 z: 0.0 w: 1.0 } @@ -10331,7 +10331,7 @@ nodes { id: "grid_dynamic_view" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_N + pivot: PIVOT_S adjust_mode: ADJUST_MODE_FIT parent: "grid_page_content" layer: "" @@ -10386,7 +10386,7 @@ nodes { id: "grid_dynamic_nodes" xanchor: XANCHOR_NONE yanchor: YANCHOR_NONE - pivot: PIVOT_N + pivot: PIVOT_S adjust_mode: ADJUST_MODE_FIT parent: "grid_dynamic_view" layer: "" @@ -10461,7 +10461,7 @@ nodes { } nodes { position { - x: -250.0 + x: 250.0 y: -1464.0 z: 0.0 w: 1.0 @@ -10479,7 +10479,7 @@ nodes { w: 1.0 } size { - x: 500.0 + x: -500.0 y: 100.0 z: 0.0 w: 1.0