Use C functions for the backstack, instead of a lua module
Working with the default group and root kinda sucks if you have to do it from lua!
This commit is contained in:
@@ -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
|
||||
+3
-2
@@ -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)
|
||||
|
||||
+2
-6
@@ -3,11 +3,9 @@ local widgets = require("widgets")
|
||||
local legacy_ui = require("legacy_ui")
|
||||
local database = require("database")
|
||||
|
||||
local main_menu = {}
|
||||
|
||||
function main_menu:Create(parent)
|
||||
return function()
|
||||
local menu = {}
|
||||
menu.root = lvgl.Object(parent, {
|
||||
menu.root = lvgl.Object(nil, {
|
||||
flex = {
|
||||
flex_direction = "column",
|
||||
flex_wrap = "wrap",
|
||||
@@ -46,5 +44,3 @@ function main_menu:Create(parent)
|
||||
|
||||
return menu
|
||||
end
|
||||
|
||||
return main_menu
|
||||
|
||||
Reference in New Issue
Block a user