3
0
mirror of https://github.com/britzl/monarch.git synced 2025-06-27 10:27:49 +02:00

Added monarch.is_loaded()

This commit is contained in:
Björn Ritzl 2023-10-26 11:43:19 +02:00
parent c473aa053c
commit 84944f3f22
2 changed files with 24 additions and 2 deletions

View File

@ -228,6 +228,17 @@ function M.is_visible(id)
end end
--- Check if a screen is loaded
-- @param id (string|hash)
-- @return true if the screen is loaded
function M.is_loaded(id)
assert(id, "You must provide a screen id")
id = tohash(id)
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
return screens[id].loaded
end
--- Check if a screen is a popup --- Check if a screen is a popup
-- @param id Screen id -- @param id Screen id
-- @return true if the screen is a popup -- @return true if the screen is a popup

View File

@ -155,6 +155,17 @@ return function()
assert(wait_until_visible(POPUP1)) assert(wait_until_visible(POPUP1))
end) end)
it("should be able to tell if a screen is loaded or not", function()
assert(not monarch.is_loaded(SCREEN1))
monarch.show(SCREEN1)
assert(wait_until_visible(SCREEN1))
assert(monarch.is_loaded(SCREEN1))
monarch.hide(SCREEN1)
assert(wait_until_hidden(SCREEN1))
assert(not monarch.is_loaded(SCREEN1))
end)
it("should be able to show a screen without adding it to the stack", function() it("should be able to show a screen without adding it to the stack", function()
monarch.show(BACKGROUND, { no_stack = true }) monarch.show(BACKGROUND, { no_stack = true })
assert(wait_until_visible(BACKGROUND), "Background was never shown") assert(wait_until_visible(BACKGROUND), "Background was never shown")