#219 properly close out GUI on error on pocket and coordinator

This commit is contained in:
Mikayla
2023-04-21 18:53:28 +00:00
parent 706fb5ea74
commit e1da8b59d3
12 changed files with 89 additions and 112 deletions

View File

@@ -2,20 +2,22 @@
-- Graphics Rendering Control
--
local main_view = require("pocket.ui.main")
local style = require("pocket.ui.style")
local main_view = require("pocket.ui.main")
local style = require("pocket.ui.style")
local flasher = require("graphics.flasher")
local flasher = require("graphics.flasher")
local DisplayBox = require("graphics.elements.displaybox")
local renderer = {}
local ui = {
view = nil
display = nil
}
-- start the pocket GUI
function renderer.start_ui()
if ui.view == nil then
if ui.display == nil then
-- reset screen
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
@@ -27,11 +29,12 @@ function renderer.start_ui()
term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
end
-- init front panel view
ui.display = DisplayBox{window=term.current(),fg_bg=style.root}
main_view(ui.display)
-- start flasher callback task
flasher.run()
-- init front panel view
ui.view = main_view(term.current())
end
end
@@ -40,13 +43,13 @@ function renderer.close_ui()
-- stop blinking indicators
flasher.clear()
if ui.view ~= nil then
if ui.display ~= nil then
-- hide to stop animation callbacks
ui.view.hide()
ui.display.hide()
end
-- clear root UI elements
ui.view = nil
ui.display = nil
-- restore colors
for i = 1, #style.colors do
@@ -64,12 +67,14 @@ end
-- is the UI ready?
---@nodiscard
---@return boolean ready
function renderer.ui_ready() return ui.view ~= nil end
function renderer.ui_ready() return ui.display ~= nil end
-- handle a mouse event
---@param event mouse_interaction
function renderer.handle_mouse(event)
ui.view.handle_mouse(event)
if ui.display ~= nil then
ui.display.handle_mouse(event)
end
end
return renderer