mirror of
https://github.com/kepler155c/opus
synced 2025-02-03 19:09:08 +00:00
rework wizard page handling
This commit is contained in:
parent
0e3fb88f1d
commit
7d17a21aa4
@ -944,6 +944,7 @@ function UI.Device:postInit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.Device:resize()
|
function UI.Device:resize()
|
||||||
|
self.device.setTextScale(self.textScale)
|
||||||
self.width, self.height = self.device.getSize()
|
self.width, self.height = self.device.getSize()
|
||||||
self.lines = { }
|
self.lines = { }
|
||||||
self.canvas:resize(self.width, self.height)
|
self.canvas:resize(self.width, self.height)
|
||||||
@ -2328,61 +2329,45 @@ function UI.Wizard:add(pages)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Wizard:getPage(index)
|
||||||
|
return Util.find(self.pages, 'index', index)
|
||||||
|
end
|
||||||
|
|
||||||
function UI.Wizard:enable(...)
|
function UI.Wizard:enable(...)
|
||||||
self.enabled = true
|
self.enabled = true
|
||||||
for _,child in ipairs(self.children) do
|
self.index = 1
|
||||||
if not child.index then
|
local initial = self:getPage(1)
|
||||||
child:enable(...)
|
for _,child in pairs(self.children) do
|
||||||
elseif child.index == 1 then
|
if child == initial or not child.index then
|
||||||
child:enable(...)
|
child:enable(...)
|
||||||
else
|
else
|
||||||
child:disable()
|
child:disable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:emit({ type = 'enable_view', next = Util.find(self.pages, 'index', 1) })
|
self:emit({ type = 'enable_view', next = initial })
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Wizard:nextView()
|
|
||||||
local currentView = Util.find(self.pages, 'enabled', true)
|
|
||||||
local nextView = Util.find(self.pages, 'index', currentView.index + 1)
|
|
||||||
|
|
||||||
if nextView then
|
|
||||||
self:emit({ type = 'enable_view', view = nextView })
|
|
||||||
self:addTransition('slideLeft')
|
|
||||||
currentView:disable()
|
|
||||||
nextView:enable()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Wizard:prevView()
|
|
||||||
local currentView = Util.find(self.pages, 'enabled', true)
|
|
||||||
local nextView = Util.find(self.pages, 'index', currentView.index - 1)
|
|
||||||
|
|
||||||
if nextView then
|
|
||||||
self:emit({ type = 'enable_view', view = nextView })
|
|
||||||
self:addTransition('slideRight')
|
|
||||||
currentView:disable()
|
|
||||||
nextView:enable()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Wizard:isViewValid()
|
function UI.Wizard:isViewValid()
|
||||||
local currentView = Util.find(self.pages, 'enabled', true)
|
local currentView = self:getPage(self.index)
|
||||||
return not currentView.validate and true or currentView:validate()
|
return not currentView.validate and true or currentView:validate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Wizard:eventHandler(event)
|
function UI.Wizard:eventHandler(event)
|
||||||
if event.type == 'nextView' then
|
if event.type == 'nextView' then
|
||||||
local currentView = Util.find(self.pages, 'enabled', true)
|
local currentView = self:getPage(self.index)
|
||||||
if self:isViewValid() then
|
if self:isViewValid() then
|
||||||
local nextView = Util.find(self.pages, 'index', currentView.index + 1)
|
self.index = self.index + 1
|
||||||
|
local nextView = self:getPage(self.index)
|
||||||
currentView:emit({ type = 'enable_view', next = nextView, current = currentView })
|
currentView:emit({ type = 'enable_view', next = nextView, current = currentView })
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'previousView' then
|
elseif event.type == 'previousView' then
|
||||||
local currentView = Util.find(self.pages, 'enabled', true)
|
local currentView = self:getPage(self.index)
|
||||||
local nextView = Util.find(self.pages, 'index', currentView.index - 1)
|
local nextView = self:getPage(self.index - 1)
|
||||||
currentView:emit({ type = 'enable_view', prev = nextView, current = currentView })
|
if nextView then
|
||||||
|
self.index = self.index - 1
|
||||||
|
currentView:emit({ type = 'enable_view', prev = nextView, current = currentView })
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
|
|
||||||
elseif event.type == 'wizard_complete' then
|
elseif event.type == 'wizard_complete' then
|
||||||
@ -2403,13 +2388,13 @@ function UI.Wizard:eventHandler(event)
|
|||||||
local current = event.next or event.prev
|
local current = event.next or event.prev
|
||||||
if not current then error('property "index" is required on wizard pages') end
|
if not current then error('property "index" is required on wizard pages') end
|
||||||
|
|
||||||
if Util.find(self.pages, 'index', current.index - 1) then
|
if self:getPage(self.index - 1) then
|
||||||
self.previousButton:enable()
|
self.previousButton:enable()
|
||||||
else
|
else
|
||||||
self.previousButton:disable()
|
self.previousButton:disable()
|
||||||
end
|
end
|
||||||
|
|
||||||
if Util.find(self.pages, 'index', current.index + 1) then
|
if self:getPage(self.index + 1) then
|
||||||
self.nextButton.text = 'Next >'
|
self.nextButton.text = 'Next >'
|
||||||
self.nextButton.event = 'nextView'
|
self.nextButton.event = 'nextView'
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user