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

Compare commits

...

4 Commits
2.7.0 ... 2.8.0

Author SHA1 Message Date
Björn Ritzl
4231b0b89c Prevent show/back operations while busy
Fixes #22
2018-06-10 16:17:41 +02:00
Alexey Gulev
c2239d67e5 Finish transition when layout changes (#21)
* If layout changes when transaction in progress we have to finish current transaction
2018-06-10 14:31:46 +02:00
Björn Ritzl
9765daa2a9 Updated changelog (again) 2018-06-08 07:48:33 +02:00
Björn Ritzl
7b2b269c72 Update changelog 2018-06-08 07:42:17 +02:00
5 changed files with 126 additions and 11 deletions

56
CHANGELOG.md Normal file
View File

@@ -0,0 +1,56 @@
## Monarch 2.7.0 [britzl released 2018-06-04]
NEW: Added monarch.top([offset]) and monarch.bottom([offset]) to get screen id of top and bottom screens (w. optional offset)
NEW: Transition messages now contain `next_screen` or `previous_screen`
## Monarch 2.6.1 [britzl released 2018-06-04]
FIX: Check if screen has already been preloaded before trying to preload it again (the callback will still be invoked).
## Monarch 2.6.0 [britzl released 2018-06-03]
NEW: monarch.preload() to load but not show a screen. Useful for content heavy screens that you wish to show without delay.
## Monarch 2.5.0 [britzl released 2018-06-01]
NEW: Transitions will send a `transition_done` message to the creator of the transition to notify that the transition has finished. The `message` will contain which transition that was finished.
## Monarch 2.4.0 [britzl released 2018-05-26]
NEW: Screen transitions are remembered so that they can be replayed when the screen layout changes.
## Monarch 2.3.0 [britzl released 2018-03-24]
CHANGE: The functions in monarch.lua that previously only accepted a hash as screen id now also accepts strings (and does the conversion internally)
## Monarch 2.2.0 [britzl released 2018-03-19]
NEW: Transitions now handle layout changes (via `layout_changed` message)
NEW: Transitions can now be notified of changes in window size using transition.window_resize(width, height)
## Monarch 2.1 [britzl released 2017-12-27]
NEW: Added Popup on Popup flag that allows a popup to be shown on top of another popup
## Monarch 2.0 [britzl released 2017-12-08]
BREAKING CHANGE: If you are using custom screen transitions (ie your own transition functions) you need to make a change to the function. The previous function signature was ```(node, to, easing, duration, delay, url)``` where ```url``` was the URL to where the ```transition_done``` message was supposed to be posted. The new function signature for a transition function is: ```(node, to, easing, duration, delay, cb)``` where ```cb``` is a function that should be invoked when the transition is completed.
FIX: Fixed issues related to screen transitions.
FIX: Code cleanup to reduce code duplication.
FIX: Improved documentation regarding transitions.
## Monarch 1.4 [britzl released 2017-12-06]
FIX: Several bugfixes for specific corner cases.
## Monarch 1.3 [britzl released 2017-12-01]
FIX: monarch.back(data, cb) set the data on the previous screen not the new current screen.
NEW: monarch.is_top(id)
NEW: monarch.get_stack()
NEW: monarch.in_stack(id)
## Monarch 1.2 [britzl released 2017-11-28]
NEW: Message id constants exposed from the Monarch module
NEW: Focus lost/gained contains id of next/previous screen
## Monarch 1.1 [britzl released 2017-11-22]
FIX: Bugfixes for transitions and state under certain circumstances
NEW: Added 'reload' option to show() command.
## Monarch 1.0 [britzl released 2017-09-28]
First public stable release
## Monarch 0.9 [britzl released 2017-09-17]

View File

@@ -245,6 +245,10 @@ 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.
* ```reload``` (boolean) - If the reload flag is set Monarch will reload the collection proxy if it's already loaded (this can happen if the previous screen was a popup).
**RETURN**
* ```success``` (boolean) - True if the process of showing the screen was started successfully. False if already busy showing/hiding a screen.
### monarch.back([data], [callback])
Go back to a previous Monarch screen
@@ -252,6 +256,9 @@ Go back to a previous Monarch screen
* ```data``` (table) - Optional data to associate with the screen you are going back to. Retrieve using ```monarch.data()```.
* ```callback``` (function) - Optional function to call when the previous screen is visible.
**RETURN**
* ```success``` (boolean) - True if the process of going back to a previous screen was started successfully. False if already busy showing/hiding a screen.
### monarch.preload(screen_id, [callback])
Preload a Monarch screen. This will load but not enable the screen. This is useful for content heavy screens that you wish to be able to show without having to wait for it load.

View File

@@ -1,9 +1,5 @@
local M = {}
local screens = {}
local stack = {}
local CONTEXT = hash("monarch_context")
local PROXY_LOADED = hash("proxy_loaded")
local PROXY_UNLOADED = hash("proxy_unloaded")
@@ -25,6 +21,15 @@ M.FOCUS = {}
M.FOCUS.GAINED = hash("monarch_focus_gained")
M.FOCUS.LOST = hash("monarch_focus_lost")
-- all registered screens
local screens = {}
-- the current stack of screens
local stack = {}
-- true while busy showing/hiding something
local busy = false
local function log(...) end
@@ -225,6 +230,7 @@ local function show_out(screen, next_screen, cb)
log("show_out()", screen.id)
local co
co = coroutine.create(function()
busy = true
screen.co = co
change_context(screen)
release_input(screen)
@@ -238,6 +244,7 @@ local function show_out(screen, next_screen, cb)
unload(screen)
end
screen.co = nil
busy = false
if cb then cb() end
end)
coroutine.resume(co)
@@ -247,6 +254,7 @@ local function show_in(screen, previous_screen, reload, cb)
log("show_in()", screen.id)
local co
co = coroutine.create(function()
busy = true
screen.co = co
change_context(screen)
if reload and screen.loaded then
@@ -271,6 +279,7 @@ local function show_in(screen, previous_screen, reload, cb)
acquire_input(screen)
focus_gained(screen, previous_screen)
screen.co = nil
busy = false
if cb then cb() end
end)
coroutine.resume(co)
@@ -280,6 +289,7 @@ local function back_in(screen, previous_screen, cb)
log("back_in()", screen.id)
local co
co = coroutine.create(function()
busy = true
screen.co = co
change_context(screen)
if screen.preloaded then
@@ -297,6 +307,7 @@ local function back_in(screen, previous_screen, cb)
acquire_input(screen)
focus_gained(screen, previous_screen)
screen.co = nil
busy = false
if cb then cb() end
end)
coroutine.resume(co)
@@ -306,6 +317,7 @@ local function back_out(screen, next_screen, cb)
log("back_out()", screen.id)
local co
co = coroutine.create(function()
busy = true
screen.co = co
change_context(screen)
release_input(screen)
@@ -313,6 +325,7 @@ local function back_out(screen, next_screen, cb)
transition(screen, M.TRANSITION.BACK_OUT, { next_screen = next_screen and next_screen.id })
unload(screen)
screen.co = nil
busy = false
if cb then cb() end
end)
coroutine.resume(co)
@@ -346,8 +359,13 @@ end
-- This would be the case if doing a show() from a popup on the screen just below the popup.
-- @param data (*) - Optional data to set on the screen. Can be retrieved by the data() function
-- @param cb (function) - Optional callback to invoke when screen is shown
-- @return success True if screen is successfully shown, false if busy performing another operation
function M.show(id, options, data, cb)
assert(id, "You must provide a screen id")
if busy then
return false
end
id = tohash(id)
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
@@ -392,13 +410,20 @@ function M.show(id, options, data, cb)
-- show screen
show_in(screen, top, options and options.reload, cb)
return true
end
-- Go back to the previous screen in the stack
-- @param data (*) - Optional data to set for the previous screen
-- @param cb (function) - Optional callback to invoke when the previous screen is visible again
-- @return true if successfully going back, false if busy performing another operation
function M.back(data, cb)
if busy then
return false
end
local screen = table.remove(stack)
if screen then
log("back()", screen.id)
@@ -424,6 +449,7 @@ function M.back(data, cb)
elseif cb then
cb()
end
return true
end
--- Preload a screen. This will load but not enable and show a screen. Useful for "heavier" screens

View File

@@ -110,22 +110,28 @@ function M.create(node)
delay = delay,
in_progress = false,
urls = {},
id = nil
}
end
local function finish_transition(transition)
transition.in_progress = false
local message = { transition = transition.id }
while #transition.urls > 0 do
local url = table.remove(transition.urls)
msg.post(url, monarch.TRANSITION.DONE, message)
end
end
local function start_transition(transition, transition_id, url)
table.insert(transition.urls, url)
if not transition.in_progress then
table.insert(transition.urls, msg.url())
current_transition = transition
transition.in_progress = true
transition.id = transition_id
current_transition = transition
transition.fn(node, initial_data, transition.easing, transition.duration, transition.delay or 0, function()
transition.in_progress = false
local message = { transition = transition_id }
while #transition.urls > 0 do
local url = table.remove(transition.urls)
msg.post(url, monarch.TRANSITION.DONE, message)
end
finish_transition(transition)
end)
end
end
@@ -139,6 +145,9 @@ function M.create(node)
-- were transitioned out
if current_transition then
current_transition.fn(node, initial_data, current_transition.easing, 0, 0)
if current_transition.in_progress then
finish_transition(current_transition)
end
end
else
local transition = transitions[message_id]

View File

@@ -148,6 +148,23 @@ return function()
end)
it("should prevent further operations while hiding/showing a screen", function()
assert(monarch.show(SCREEN1) == true)
assert(monarch.show(SCREEN2) == false)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")
assert_stack({ SCREEN1 })
assert(monarch.show(SCREEN2) == true)
assert(wait_until_shown(SCREEN2), "Screen1 was never shown")
assert_stack({ SCREEN1, SCREEN2 })
assert(monarch.back() == true)
assert(monarch.back() == false)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")
assert_stack({ SCREEN1 })
end)
it("should close any open popups when showing a popup without the Popup On Popup flag", function()
monarch.show(SCREEN1)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")