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

Added a note on letting the init fucntion of the screen.script finish first

This commit is contained in:
Björn Ritzl 2017-12-25 00:24:25 +01:00
parent 995843ff20
commit 1467b136d8

View File

@ -42,6 +42,16 @@ You show a screen in one of two ways:
Showing a screen will push it to the top of the stack and trigger an optional transition. The previous screen will be hidden (with an optional transition) unless the screen to be shown is a [popup](#popups). Showing a screen will push it to the top of the stack and trigger an optional transition. The previous screen will be hidden (with an optional transition) unless the screen to be shown is a [popup](#popups).
NOTE: You must ensure that the ```init()``` function of the ```screen.script``` has run. The ```init()``` function is responsible for registering the screen and it's not possible to show it until this has happened. A good practice is to delay the first call by posting a message to a controller script or similar before calling ```monarch.show()``` the first time:
function init(self)
msg.post("#", "show_first_screen")
end
function on_message(self, message_id, message, sender)
monarch.show("first_screen")
end
#### Preventing duplicates in the stack #### Preventing duplicates in the stack
You can pass an optional ```clear``` flag when showing a screen (either as a key value pair in the options table when calling ```monarch.show()``` or in the message). If the clear flag is set Monarch will search the stack for the screen in question. If the screen already exists in the stack and the ```clear``` flag is set Monarch will remove all screens between the current top and the screen in question. Example: You can pass an optional ```clear``` flag when showing a screen (either as a key value pair in the options table when calling ```monarch.show()``` or in the message). If the clear flag is set Monarch will search the stack for the screen in question. If the screen already exists in the stack and the ```clear``` flag is set Monarch will remove all screens between the current top and the screen in question. Example:
@ -150,7 +160,7 @@ Both the ```monarch.show()``` and ```monarch.back()``` functions take an optiona
## Monarch API ## Monarch API
### monarch.show(screen_id, [options], [data], [callback]) ### monarch.show(screen_id, [options], [data], [callback])
Show a Monarch screen Show a Monarch screen. Note that the screen must be registered before it can be shown. The ```init()``` function of the ```screen.script``` takes care of registration.
**PARAMETERS** **PARAMETERS**
* ```screen_id``` (hash) - Id of the screen to show. * ```screen_id``` (hash) - Id of the screen to show.