3
0
mirror of https://github.com/britzl/monarch.git synced 2025-11-26 19:00:53 +01:00

Compare commits

..

12 Commits
0.9 ... 1.0

Author SHA1 Message Date
Björn Ritzl
d02cd03d2c Documentation fixes 2017-09-28 08:45:59 +02:00
Björn Ritzl
52ce9929a1 More documentation improvements 2017-09-28 08:34:29 +02:00
Björn Ritzl
240c039d03 controller->focus 2017-09-28 08:23:06 +02:00
Björn Ritzl
e46a703b25 Changed from controller_url to focus_url. Improved docs 2017-09-28 08:22:05 +02:00
Björn Ritzl
e24acb51d8 Fixed wrong message constant 2017-09-26 02:16:44 +02:00
Björn Ritzl
1174de2ba5 Cleanup 2017-09-25 21:55:12 +02:00
Björn Ritzl
95fd994fa0 Simplified message constant. Added focus message 2017-09-25 21:33:28 +02:00
Björn Ritzl
e7edfbe173 Changed how transition urls are defined 2017-09-25 21:21:33 +02:00
Björn Ritzl
592418fef7 Fixed a too high render order value 2017-09-25 21:20:58 +02:00
Björn Ritzl
d397b90dc2 Default to 0 delay 2017-09-25 18:16:04 +02:00
Björn Ritzl
09e2478378 Allow data to be passed when showing or going back 2017-09-25 18:15:55 +02:00
Björn Ritzl
149c50221c Null fix when handling transitions 2017-09-25 18:01:40 +02:00
11 changed files with 230 additions and 142 deletions

113
README.md
View File

@@ -10,70 +10,75 @@ https://github.com/britzl/monarch/archive/master.zip
Using Monarch requires that screens are created in a certain way. Once you have one or more screens created you can start navigating between the screens.
## Creating screens
Monarch screens are created in individual collections and loaded through collection proxies. The recommended setup is to create one game object per screen and per game object attach a collection proxy component and an instance of the ````screen.script```` provided by Monarch. The screen.script will take care of the setup of the screen. All you need to do is to make sure that the script properties on the ````screen.script```` are correct:
Monarch screens are created in individual collections and loaded through collection proxies. The recommended setup is to create one game object per screen and per game object attach a collection proxy component and an instance of the ```screen.script``` provided by Monarch. The screen.script will take care of the setup of the screen. All you need to do is to make sure that the script properties on the ```screen.script``` are correct:
* **Screen Proxy (url)** - The URL to the collection proxy component containing the actual screen. Defaults to ````#collectionproxy````
* **Screen Id (hash)** - A unique id that can be used to reference the screen when navigating your app
* **Popup (boolean)** - Check this if the screen should be treated as a [popup](#popups)
* **Transition Show In (url)** - Optional URL to call when the screen is about to be shown. Use this to trigger a transition (see the section on [transitions](#transitions))
* **Transition Show Out (url)** - Optional URL to call when the screen is about to be hidden. Use this to trigger a transition (see the section on [transitions](#transitions))
* **Transition Back In (url)** - Optional URL to call when the screen is about to be shown when navigating back in the screen hierarchy. Use this to trigger a transition (see the section on [transitions](#transitions))
* **Transition Back Out (url)** - Optional URL to call when the screen is about to be hidden when navigating back in the screen hierarchy. Use this to trigger a transition (see the section on [transitions](#transitions))
* **Screen Proxy (url)** - The URL to the collection proxy component containing the actual screen. Defaults to ```#collectionproxy```.
* **Screen Id (hash)** - A unique id that can be used to reference the screen when navigating your app.
* **Popup (boolean)** - Check this if the screen should be treated as a [popup](#popups).
* **Transition Url (url)** - Optional URL to call when the screen is about to be shown/hidden. Use this to trigger a transition (see the section on [transitions](#transitions)).
* **Focus Url (url)** - Optional URL to call when the screen gains or loses focus (see the section on [screen focus](#screen-focus-gainloss)).
![](docs/setup.png)
## Navigating between screens
The navigation in Monarch is based around a stack of screens. When a screen is shown it is pushed to the top of the stack. When going back to a previous screen the topmost screen on the stack is removed. Example:
* Showing screen A
* Stack is [A]
* Stack is ```[A]```
* Showing screen B
* Stack is [A, B] - (B is on top)
* Stack is ```[A, B]``` - (B is on top)
* Going back
* Stack is [A]
* Stack is ```[A]```
### Showing a new screen
You show a screen in one of two ways:
1. Post a ````show```` message to the ````screen.script````
2. Call ````monarch.show(screen_id, [options], [callback])````
1. Post a ```show``` message to the ```screen.script```
2. Call ```monarch.show()``` (see below)
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).
#### 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:
* Stack is [A, B, C, D] - (D is on top)
* A call to ````monarch.show(B, { clear = true })```` is made
* Stack is [A, B]
* Stack is ```[A, B, C, D]``` - (D is on top)
* A call to ```monarch.show(B, { clear = true })``` is made
* Stack is ```[A, B]```
As opposed to if the ```clear``` flag was not set:
* Stack is ```[A, B, C, D]``` - (D is on top)
* A call to ```monarch.show(B, { clear = false })``` is made
* Stack is ```[A, B, C, D, B]``` - (B is on top)
### Going back to a previous screen
You navigate back in the screen hierarchy in one of two ways:
1. Post a ````back```` message to the ````screen.script````
2. Call ````monarch.back()````
1. Post a ```back``` message to the ```screen.script```
2. Call ```monarch.back()``` (see below)
## Input focus
Monarch will acquire and release input focus on the screens and ensure that only the top-most screen will ever have input focus.
Monarch will acquire and release input focus on the game objects containing the proxies to the screens and ensure that only the top-most screen will ever have input focus.
## Popups
A screen that is flagged as a popup (see list of screen properties above) will be treated slightly differently when it comes to navigation. If a popup is at the top of the stack (ie currently shown) and another screen or popup is shown then the current popup will be removed from the stack. This means that it is not possible to have a popup anywhere in the stack but the top. This also means that you cannot navigate back to a popup since popups can only exist on the top of the stack. Another important difference between normal screens and popups is that when a popup is shown on top of a non-popup the current top screen will not be unloaded and instead remain visible in the background.
* Stack is [A, B]
* A call to ````monarch.show(C)```` is made and C is a popup
* Stack is [A, B, C]
* A call to ````monarch.show(D)````
* Stack is [A, B, D]
* Stack is ```[A, B]```
* A call to ```monarch.show(C)``` is made and C is a popup
* Stack is ```[A, B, C]```
* A call to ```monarch.show(D)```
* Stack is ```[A, B, D]```
## Transitions
You can add optional transitions when navigating between screens. The default behavior is that screen navigation is instant but if you have defined a transition for a screen Monarch will wait until the transition is completed before proceeding. The Transition Show In/Out and Transition Back In/Out properties described above should be URLs to one or more scripts with on_message handlers for the following messages:
You can add optional transitions when navigating between screens. The default behavior is that screen navigation is instant but if you have defined a transition for a screen Monarch will wait until the transition is completed before proceeding. The Transition Url property described above should be the URL to a script with an ```on_message``` handlers for the following messages:
* ````transition_show_in````
* ````transition_show_out````
* ````transition_back_in````
* ````transition_back_out````
* ```transition_show_in```
* ```transition_show_out```
* ```transition_back_in```
* ``transition_back_out```
When a transition is completed it is up to the developer to send a ````transition_done```` message back to the sender to indicate that the transition is completed and that Monarch can continue the navigation sequence. Monarch comes with a system for setting up transitions easily in a gui_script. Example:
When a transition is completed it is up to the developer to send a ```transition_done``` message back to the sender to indicate that the transition is completed and that Monarch can continue the navigation sequence. Monarch comes with a system for setting up transitions easily in a gui_script. Example:
local transitions = require "monarch.transitions.gui"
@@ -92,5 +97,49 @@ When a transition is completed it is up to the developer to send a ````transitio
self.transition.handle(message_id, message, sender)
end
## Screen focus gain/loss
Monarch will send focus gain and focus loss messages if a Focus Url was provided when the screen was created. Example:
local monarch = require "monarch.monarch"
function on_message(self, message_id, message, sender)
if message_id == monarch.FOCUS_GAINED then
print("Focus gained")
elseif message_id == monarch.FOCUS_LOST then
print("Focus lost")
end
end
## Callbacks
Both the ```monarch.show()``` and ```monarch.back()``` functions take an optional callback function that will be invoked when the transition is completed. Note that this will not take into account when custom transitions are completed. The callback will be invoked immediately when the loading and unloading of collections are done and when the internal state of Monarch has completed the navigation.
Both the ```monarch.show()``` and ```monarch.back()``` functions take an optional callback function that will be invoked when the ```transition_show_in``` (or the ```transition_back_in``` in the case of a ```monarch.back()``` call) transition is completed. Tthe transition is considered completed when a ```transition_done``` message has been received (see section on [transitions](#transitions) above).
## Monarch API
### monarch.show(screen_id, [options], [data], [callback])
Show a Monarch screen
**PARAMETERS**
* ```screen_id``` (hash) - Id of the screen to show.
* ```options``` (table) - Options when showing the new screen (see below).
* ```data``` (table) - Optional data to associate with the screen. Retrieve using ```monarch.data()```.
* ```callback``` (function) - Function to call when the new screen is visible.
The options table can contain the following fields:
* ```clear``` (boolean) - If the clear flag is set Monarch will search the stack for the screen that is to be shown. 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.
### monarch.back([data], [callback])
Go back to a previous Monarch screen
**PARAMETERS**
* ```data``` (table) - Optional data to associate with the screen you are going back to. Retrieve using ```monarch.data()```.
* ```callback``` (function) - Function to call when the previous screen is visible.
### monarch.data(screen_id)
Get the data associated with a screen (from a call to ```monarch.show()``` or ```monarch.back()```).
**PARAMETERS**
* ```screen_id``` (hash) - Id of the screen to get data for
**RETURN**
* ```data``` (table) - Data associated with the screen.

BIN
docs/setup.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@@ -181,6 +181,69 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 320.0
y: 1050.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "<text>"
font: "example"
id: "level"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "root"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512

View File

@@ -4,6 +4,9 @@ local transitions = require "monarch.transitions.gui"
function init(self)
msg.post(".", "acquire_input_focus")
local data = monarch.data(hash("game"))
gui.set_text(gui.get_node("level"), tostring(data.level))
self.transition = transitions.create(gui.get_node("root"))
.show_in(transitions.slide_in_right, gui.EASING_OUTQUAD, 0.6, 0)
.show_out(transitions.slide_out_left, gui.EASING_INQUAD, 0.6, 0)
@@ -14,7 +17,7 @@ end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.released then
if gui.pick_node(gui.get_node("win_button"), action.x, action.y) then
monarch.show(hash("menu"), { clear = true }, function()
monarch.show(hash("menu"), { clear = true }, nil, function()
print("showing menu done")
end)
end

View File

@@ -22,22 +22,7 @@ embedded_instances {
" type: PROPERTY_TYPE_HASH\n"
" }\n"
" properties {\n"
" id: \"transition_show_in\"\n"
" value: \"menu:/go#menu\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_show_out\"\n"
" value: \"menu:/go#menu\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_in\"\n"
" value: \"menu:/go#menu\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_out\"\n"
" id: \"transition_url\"\n"
" value: \"menu:/go#menu\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
@@ -96,7 +81,7 @@ embedded_instances {
" }\n"
"}\n"
"components {\n"
" id: \"main1\"\n"
" id: \"gui\"\n"
" component: \"/example/debug.gui\"\n"
" position {\n"
" x: 0.0\n"
@@ -150,22 +135,7 @@ embedded_instances {
" type: PROPERTY_TYPE_HASH\n"
" }\n"
" properties {\n"
" id: \"transition_show_in\"\n"
" value: \"pregame:/go#pregame\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_show_out\"\n"
" value: \"pregame:/go#pregame\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_in\"\n"
" value: \"pregame:/go#pregame\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_out\"\n"
" id: \"transition_url\"\n"
" value: \"pregame:/go#pregame\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
@@ -228,22 +198,7 @@ embedded_instances {
" type: PROPERTY_TYPE_HASH\n"
" }\n"
" properties {\n"
" id: \"transition_show_in\"\n"
" value: \"game:/go#game\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_show_out\"\n"
" value: \"game:/go#game\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_in\"\n"
" value: \"game:/go#game\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_out\"\n"
" id: \"transition_url\"\n"
" value: \"game:/go#game\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
@@ -311,22 +266,7 @@ embedded_instances {
" type: PROPERTY_TYPE_BOOLEAN\n"
" }\n"
" properties {\n"
" id: \"transition_show_in\"\n"
" value: \"popup:/go#popup\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_show_out\"\n"
" value: \"popup:/go#popup\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_in\"\n"
" value: \"popup:/go#popup\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"
" properties {\n"
" id: \"transition_back_out\"\n"
" id: \"transition_url\"\n"
" value: \"popup:/go#popup\"\n"
" type: PROPERTY_TYPE_URL\n"
" }\n"

View File

@@ -14,7 +14,7 @@ end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.released then
if gui.pick_node(gui.get_node("startgame_button"), action.x, action.y) then
monarch.show(hash("popup"), nil, function()
monarch.show(hash("popup"), nil, nil, function()
print("showing popup done")
end)
end

View File

@@ -5,7 +5,7 @@ function init(self)
msg.post(".", "acquire_input_focus")
self.ok = gui.get_node("ok_button")
self.cancel = gui.get_node("cancel_button")
gui.set_render_order(16)
gui.set_render_order(15)
self.transition = transitions.create(gui.get_node("root"))
.show_in(transitions.slide_in_top, gui.EASING_OUTQUAD, 0.6, 0)
@@ -18,7 +18,7 @@ function on_input(self, action_id, action)
if action_id == hash("touch") and action.released then
if gui.pick_node(self.ok, action.x, action.y) then
print("ok")
monarch.show(hash("pregame"), nil, function()
monarch.show(hash("pregame"), nil, nil, function()
print("pregame show done")
end)
elseif gui.pick_node(self.cancel, action.x, action.y) then

View File

@@ -17,7 +17,7 @@ function on_input(self, action_id, action)
if action_id == hash("touch") and action.released then
if gui.pick_node(self.play, action.x, action.y) then
print("play")
monarch.show(hash("game"), nil, function()
monarch.show(hash("game"), nil, { level = 1 }, function()
print("showing game done")
end)
elseif gui.pick_node(self.back, action.x, action.y) then

View File

@@ -4,9 +4,17 @@ local screens = {}
local stack = {}
local CONTEXT = hash("monarch_context")
local PROXY_LOADED = hash("proxy_loaded")
local PROXY_UNLOADED = hash("proxy_unloaded")
M.TRANSITION_DONE = hash("transition_done")
M.FOCUS_GAINED = hash("monarch_focus_gained")
M.FOCUS_LOST = hash("monarch_focus_lost")
local function screen_from_proxy(proxy)
for id,screen in pairs(screens) do
for _,screen in pairs(screens) do
if screen.proxy == proxy then
return screen
end
@@ -15,7 +23,7 @@ end
local function screen_from_script()
local url = msg.url()
for id,screen in pairs(screens) do
for _,screen in pairs(screens) do
if screen.script == url then
return screen
end
@@ -31,9 +39,16 @@ local function in_stack(id)
return false
end
function M.register(id, proxy, popup, transitions)
function M.register(id, proxy, popup, transition_url, focus_url)
assert(not screens[id], ("There is already a screen registered with id %s"):format(tostring(id)))
screens[id] = { id = id, proxy = proxy, script = msg.url(), popup = popup, transitions = transitions }
screens[id] = {
id = id,
proxy = proxy,
script = msg.url(),
popup = popup,
transition_url = transition_url,
focus_url = focus_url,
}
end
function M.unregister(id)
@@ -46,14 +61,17 @@ local function show_out(screen, next_screen, cb)
co = coroutine.create(function()
screen.co = co
msg.post(screen.script, "release_input_focus")
msg.post(screen.script, "monarch_context")
msg.post(screen.script, CONTEXT)
coroutine.yield()
if not next_screen.popup then
msg.post(screen.transitions.show_out, "transition_show_out")
msg.post(screen.transition_url, "transition_show_out")
coroutine.yield()
msg.post(screen.proxy, "unload")
coroutine.yield()
end
if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_LOST)
end
screen.co = nil
if cb then cb() end
end)
@@ -64,15 +82,18 @@ local function show_in(screen, cb)
local co
co = coroutine.create(function()
screen.co = co
msg.post(screen.script, "monarch_context")
msg.post(screen.script, CONTEXT)
coroutine.yield()
msg.post(screen.proxy, "async_load")
coroutine.yield()
msg.post(screen.proxy, "enable")
stack[#stack + 1] = screen
msg.post(screen.transitions.show_in, "transition_show_in")
msg.post(screen.transition_url, "transition_show_in")
coroutine.yield()
msg.post(screen.script, "acquire_input_focus")
if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_GAINED)
end
screen.co = nil
if cb then cb() end
end)
@@ -83,16 +104,19 @@ local function back_in(screen, previous_screen, cb)
local co
co = coroutine.create(function()
screen.co = co
msg.post(screen.script, "monarch_context")
msg.post(screen.script, CONTEXT)
coroutine.yield()
if not previous_screen.popup then
msg.post(screen.proxy, "async_load")
coroutine.yield()
msg.post(screen.proxy, "enable")
msg.post(screen.transitions.back_in, "transition_back_in")
msg.post(screen.transition_url, "transition_back_in")
coroutine.yield()
end
msg.post(screen.script, "acquire_input_focus")
if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_GAINED)
end
screen.co = nil
if cb then cb() end
end)
@@ -104,11 +128,14 @@ local function back_out(screen, cb)
co = coroutine.create(function()
screen.co = co
msg.post(screen.script, "release_input_focus")
msg.post(screen.script, "monarch_context")
msg.post(screen.script, CONTEXT)
coroutine.yield()
msg.post(screen.transitions.back_out, "transition_back_out")
msg.post(screen.transition_url, "transition_back_out")
coroutine.yield()
msg.post(screen.proxy, "unload")
if screen.focus_url then
msg.post(screen.focus_url, M.FOCUS_LOST)
end
screen.co = nil
if cb then cb() end
end)
@@ -116,16 +143,27 @@ local function back_out(screen, cb)
end
--- Get data associated with a screen
-- @param id Id of the screen to get data for
-- @return Data associated with the screen
function M.data(id)
assert(id, "You must provide a screen id")
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
return screens[id].data
end
--- Show a new screen
-- @param id Id of the screen to show
-- @param options Table with options when showing the screen (can be nil). Valid values:
-- * clear - Set to true if the stack should be cleared down to an existing instance of the screen
-- @param data Optional data to set on the screen. Can be retrieved by the data() function
-- @ param cb Optional callback to invoke when screen is shown
function M.show(id, options, cb)
function M.show(id, options, data, cb)
assert(id, "You must provide a screen id")
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
local screen = screens[id]
screen.data = data
-- manipulate the current top
-- close popup if needed
@@ -163,13 +201,17 @@ end
-- Go back to the previous screen in the stack
-- @param data Optional data to set for the previous screen
-- @param cb Optional callback to invoke when the previous screen is visible again
function M.back(cb)
function M.back(data, cb)
local screen = table.remove(stack)
if screen then
back_out(screen, cb)
local top = stack[#stack]
if top then
if data then
screen.data = data
end
back_in(top, screen)
end
elseif cb then
@@ -179,18 +221,18 @@ end
function M.on_message(message_id, message, sender)
if message_id == hash("proxy_loaded") then
if message_id == PROXY_LOADED then
local screen = screen_from_proxy(sender)
assert(screen, "Unable to find screen for loaded proxy")
coroutine.resume(screen.co)
elseif message_id == hash("proxy_unloaded") then
elseif message_id == PROXY_UNLOADED then
local screen = screen_from_proxy(sender)
assert(screen, "Unable to find screen for unloaded proxy")
elseif message_id == hash("monarch_context") then
elseif message_id == CONTEXT then
local screen = screen_from_script()
assert(screen, "Unable to find screen for current script url")
coroutine.resume(screen.co)
elseif message_id == hash("transition_done") then
elseif message_id == M.TRANSITION_DONE then
local screen = screen_from_script()
assert(screen, "Unable to find screen for current script url")
coroutine.resume(screen.co)

View File

@@ -3,19 +3,12 @@ local monarch = require "monarch.monarch"
go.property("screen_proxy", msg.url("#collectionproxy"))
go.property("screen_id", hash(""))
go.property("popup", false)
go.property("transition_show_in", msg.url())
go.property("transition_show_out", msg.url())
go.property("transition_back_in", msg.url())
go.property("transition_back_out", msg.url())
go.property("transition_url", msg.url())
go.property("focus_url", msg.url())
function init(self)
monarch.register(self.screen_id, self.screen_proxy, self.popup, {
show_in = self.transition_show_in,
show_out = self.transition_show_out,
back_in = self.transition_back_in,
back_out = self.transition_back_out,
})
monarch.register(self.screen_id, self.screen_proxy, self.popup, self.transition_url, self.focus_url)
end
function final(self)

View File

@@ -79,7 +79,9 @@ function M.create(node)
-- Forward on_message calls here
function instance.handle(message_id, message, sender)
transitions[message_id](sender)
if transitions[message_id] then
transitions[message_id](sender)
end
end
-- Specify the transition function when this node is transitioned
@@ -90,8 +92,7 @@ function M.create(node)
-- @param delay Transition delay
function instance.show_in(fn, easing, duration, delay)
transitions[hash("transition_show_in")] = function(url)
print("transition_show_in", url, fn)
fn(node, initial_position, easing, duration, delay, url)
fn(node, initial_position, easing, duration, delay or 0, url)
end
return instance
end
@@ -100,8 +101,7 @@ function M.create(node)
-- from when showing another screen
function instance.show_out(fn, easing, duration, delay)
transitions[hash("transition_show_out")] = function(url)
print("transition_show_out")
fn(node, initial_position, easing, duration, delay, url)
fn(node, initial_position, easing, duration, delay or 0, url)
end
return instance
end
@@ -110,8 +110,7 @@ function M.create(node)
-- to when navigating back in the screen stack
function instance.back_in(fn, easing, duration, delay)
transitions[hash("transition_back_in")] = function(url)
print("transition_back_in")
fn(node, initial_position, easing, duration, delay, url)
fn(node, initial_position, easing, duration, delay or 0, url)
end
return instance
end
@@ -120,8 +119,7 @@ function M.create(node)
-- from when navigating back in the screen stack
function instance.back_out(fn, easing, duration, delay)
transitions[hash("transition_back_out")] = function(url)
print("transition_back_out")
fn(node, initial_position, easing, duration, delay, url)
fn(node, initial_position, easing, duration, delay or 0, url)
end
return instance
end