mirror of
https://github.com/britzl/monarch.git
synced 2025-09-27 18:12:22 +02:00
Improved examples. Added transitions
This commit is contained in:
@@ -100,6 +100,7 @@ local function back_out(screen)
|
||||
local co
|
||||
co = coroutine.create(function()
|
||||
screen.co = co
|
||||
msg.post(screen.script, "release_input_focus")
|
||||
msg.post(screen.script, "monarch_context")
|
||||
coroutine.yield()
|
||||
msg.post(screen.transitions.back_out, "transition_back_out")
|
||||
|
@@ -1,32 +0,0 @@
|
||||
local monarch = require "monarch.monarch"
|
||||
|
||||
|
||||
function init(self)
|
||||
-- Add initialization code here
|
||||
-- Remove this function if not needed
|
||||
end
|
||||
|
||||
function final(self)
|
||||
-- Add finalization code here
|
||||
-- Remove this function if not needed
|
||||
end
|
||||
|
||||
function update(self, dt)
|
||||
-- Add update code here
|
||||
-- Remove this function if not needed
|
||||
end
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
-- Add message-handling code here
|
||||
-- Remove this function if not needed
|
||||
end
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
-- Add input-handling code here
|
||||
-- Remove this function if not needed
|
||||
end
|
||||
|
||||
function on_reload(self)
|
||||
-- Add reload-handling code here
|
||||
-- Remove this function if not needed
|
||||
end
|
@@ -10,7 +10,6 @@ go.property("transition_back_out", msg.url())
|
||||
|
||||
|
||||
function init(self)
|
||||
print("screen init", self.proxy)
|
||||
monarch.register(self.screen_id, self.screen_proxy, self.popup, {
|
||||
show_in = self.transition_show_in,
|
||||
show_out = self.transition_show_out,
|
||||
@@ -20,25 +19,20 @@ function init(self)
|
||||
end
|
||||
|
||||
function final(self)
|
||||
print("screen final", self.proxy)
|
||||
monarch.unregister(self.screen_id)
|
||||
end
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
print("screen on_message", message_id, sender)
|
||||
if message_id == hash("show") then
|
||||
monarch.show(self.screen_id, message.clear)
|
||||
elseif message_id == hash("hide") then
|
||||
monarch.hide(self.screen_id)
|
||||
elseif message_id == hash("back") then
|
||||
monarch.hide(self.screen_id)
|
||||
elseif message_id == hash("transition_show_in") then
|
||||
msg.post(sender, "transition_done")
|
||||
elseif message_id == hash("transition_show_out") then
|
||||
msg.post(sender, "transition_done")
|
||||
elseif message_id == hash("transition_back_in") then
|
||||
msg.post(sender, "transition_done")
|
||||
elseif message_id == hash("transition_back_out") then
|
||||
elseif message_id == hash("transition_show_in")
|
||||
or message_id == hash("transition_show_out")
|
||||
or message_id == hash("transition_back_in")
|
||||
or message_id == hash("transition_back_out") then
|
||||
msg.post(sender, "transition_done")
|
||||
else
|
||||
monarch.on_message(message_id, message, sender)
|
||||
|
132
monarch/transitions/gui.lua
Normal file
132
monarch/transitions/gui.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
local M = {}
|
||||
|
||||
local WIDTH = tonumber(sys.get_config("display.width"))
|
||||
local HEIGHT = tonumber(sys.get_config("display.height"))
|
||||
|
||||
local LEFT = vmath.vector3(-WIDTH * 2, 0, 0)
|
||||
local RIGHT = vmath.vector3(WIDTH * 2, 0, 0)
|
||||
local TOP = vmath.vector3(0, HEIGHT * 2, 0)
|
||||
local BOTTOM = vmath.vector3(0, -HEIGHT * 2, 0)
|
||||
|
||||
function M.instant(node, to, easing, duration, delay, url)
|
||||
msg.post(url, "transition_done")
|
||||
end
|
||||
|
||||
local function slide_in(direction, node, to, easing, duration, delay, url)
|
||||
local from = to + direction
|
||||
gui.set_position(node, from)
|
||||
gui.animate(node, gui.PROP_POSITION, to, easing, duration, delay, function()
|
||||
msg.post(url, "transition_done")
|
||||
end)
|
||||
end
|
||||
|
||||
function M.slide_in_left(node, to, easing, duration, delay, url)
|
||||
return slide_in(LEFT, node, to, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_in_right(node, to, easing, duration, delay, url)
|
||||
slide_in(RIGHT, node, to, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_in_top(node, to, easing, duration, delay, url)
|
||||
slide_in(TOP, node, to, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_in_bottom(node, to, easing, duration, delay, url)
|
||||
slide_in(BOTTOM, node, to, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
|
||||
local function slide_out(direction, node, from, easing, duration, delay, url)
|
||||
local to = from + direction
|
||||
gui.set_position(node, from)
|
||||
gui.animate(node, gui.PROP_POSITION, to, easing, duration, delay, function()
|
||||
msg.post(url, "transition_done")
|
||||
end)
|
||||
end
|
||||
|
||||
function M.slide_out_left(node, from, easing, duration, delay, url)
|
||||
slide_out(LEFT, node, from, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_out_right(node, from, easing, duration, delay, url)
|
||||
slide_out(RIGHT, node, from, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_out_top(node, from, easing, duration, delay, url)
|
||||
slide_out(TOP, node, from, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
function M.slide_out_bottom(node, from, easing, duration, delay, url)
|
||||
slide_out(BOTTOM, node, from, easing, duration, delay, url)
|
||||
end
|
||||
|
||||
--- Create a transition for a node
|
||||
-- @return Transition instance
|
||||
function M.create(node)
|
||||
assert(node, "You must provide a node")
|
||||
|
||||
local instance = {}
|
||||
|
||||
local transitions = {
|
||||
[hash("transition_show_in")] = M.instant,
|
||||
[hash("transition_show_out")] = M.instant,
|
||||
[hash("transition_back_in")] = M.instant,
|
||||
[hash("transition_back_out")] = M.instant,
|
||||
}
|
||||
|
||||
local initial_position = gui.get_position(node)
|
||||
|
||||
-- Forward on_message calls here
|
||||
function instance.handle(message_id, message, sender)
|
||||
transitions[message_id](sender)
|
||||
end
|
||||
|
||||
-- Specify the transition function when this node is transitioned
|
||||
-- to
|
||||
-- @param fn Transition function (see slide_in_left and other above)
|
||||
-- @param easing Easing function to use
|
||||
-- @param duration Transition duration
|
||||
-- @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)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
-- Specify the transition function when this node is transitioned
|
||||
-- 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)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
--- Specify the transition function when this node is transitioned
|
||||
-- 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)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
--- Specify the transition function when this node is transitioned
|
||||
-- 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)
|
||||
end
|
||||
return instance
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
return M
|
Reference in New Issue
Block a user