Working with the default group and root kinda sucks if you have to do it from lua!custom
parent
b7f37f6426
commit
effac1917a
@ -1,37 +0,0 @@ |
||||
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 |
@ -1,3 +1,4 @@ |
||||
local backstack = require("backstack") |
||||
local main_menu = require("main_menu"):Create(backstack.root) |
||||
backstack:Push(main_menu) |
||||
local main_menu = require("main_menu") |
||||
|
||||
backstack.push(main_menu) |
||||
|
@ -0,0 +1,13 @@ |
||||
--- Module for adding and removing screens from the system's backstack. |
||||
-- @module backstack |
||||
|
||||
local backstack = {} |
||||
|
||||
--- Pushes a new screen onto the backstack. |
||||
-- @tparam function constructor Called to create the UI for the new screen. A new default root object and group will be set before calling this function. The function provided should return a table holding any bindings used by this screen; the returned value is retained so long as this screen is present in the backstack. |
||||
function backstack.push(constructor) end |
||||
|
||||
--- Removes the currently active screen, and instead shows the screen underneath it on the backstack. Does nothing if this is the only existing screen. |
||||
function backstack.pop() end |
||||
|
||||
return backstack |
Loading…
Reference in new issue