diff options
Diffstat (limited to 'lua/backstack.lua')
| -rw-r--r-- | lua/backstack.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lua/backstack.lua b/lua/backstack.lua new file mode 100644 index 00000000..c54fbac4 --- /dev/null +++ b/lua/backstack.lua @@ -0,0 +1,37 @@ +local lvgl = require("lvgl") + +local backstack = { + root = lvgl.Object(nil, { + w = lvgl.HOR_RES(), + h = lvgl.VER_RES(), + }), + stack = {}, +} + +function backstack:Top() + return self.stack[#self.stack] +end + +function backstack:SetTopParent(parent) + local top = self:Top() + if top and top.root then + top.root:set_parent(parent) + end +end + +function backstack:Push(screen) + self:SetTopParent(nil) + table.insert(self.stack, screen) + self:SetTopParent(self.root) +end + +function backstack:Pop(num) + num = num or 1 + for _ = 1, num do + local removed = table.remove(self.stack) + removed.root:delete() + end + self:SetTopParent(self.root) +end + +return backstack |
