mirror of
https://github.com/kepler155c/opus
synced 2024-06-13 17:06:54 +00:00
redo tabs + wizard
This commit is contained in:
parent
f6d1cfc7ee
commit
fb0f3e567a
305
sys/apis/ui.lua
305
sys/apis/ui.lua
|
@ -864,6 +864,18 @@ function UI.Window:focusFirst()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Window:refocus()
|
||||||
|
local el = self
|
||||||
|
while el do
|
||||||
|
local focusables = el:getFocusables()
|
||||||
|
if focusables[1] then
|
||||||
|
self:setFocus(focusables[1])
|
||||||
|
break
|
||||||
|
end
|
||||||
|
el = el.parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UI.Window:scrollIntoView()
|
function UI.Window:scrollIntoView()
|
||||||
local parent = self.parent
|
local parent = self.parent
|
||||||
|
|
||||||
|
@ -925,6 +937,12 @@ function UI.Window:emit(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Window:find(uid)
|
||||||
|
if self.children then
|
||||||
|
return Util.find(self.children, 'uid', uid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UI.Window:eventHandler(event)
|
function UI.Window:eventHandler(event)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -1165,13 +1183,12 @@ end
|
||||||
function UI.Page:focusPrevious()
|
function UI.Page:focusPrevious()
|
||||||
local function getPreviousFocus(focused)
|
local function getPreviousFocus(focused)
|
||||||
local focusables = self:getFocusables()
|
local focusables = self:getFocusables()
|
||||||
for k, v in ipairs(focusables) do
|
local k = Util.contains(focusables, focused)
|
||||||
if v == focused then
|
if k then
|
||||||
if k > 1 then
|
if k > 1 then
|
||||||
return focusables[k - 1]
|
return focusables[k - 1]
|
||||||
end
|
|
||||||
return focusables[#focusables]
|
|
||||||
end
|
end
|
||||||
|
return focusables[#focusables]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1184,13 +1201,12 @@ end
|
||||||
function UI.Page:focusNext()
|
function UI.Page:focusNext()
|
||||||
local function getNextFocus(focused)
|
local function getNextFocus(focused)
|
||||||
local focusables = self:getFocusables()
|
local focusables = self:getFocusables()
|
||||||
for k, v in ipairs(focusables) do
|
local k = Util.contains(focusables, focused)
|
||||||
if v == focused then
|
if k then
|
||||||
if k < #focusables then
|
if k < #focusables then
|
||||||
return focusables[k + 1]
|
return focusables[k + 1]
|
||||||
end
|
|
||||||
return focusables[1]
|
|
||||||
end
|
end
|
||||||
|
return focusables[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1230,7 +1246,6 @@ function UI.Page:eventHandler(event)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Grid --]]--
|
--[[-- Grid --]]--
|
||||||
|
@ -2076,7 +2091,7 @@ function UI.DropMenu:show(x, y)
|
||||||
self.canvas:setVisible(true)
|
self.canvas:setVisible(true)
|
||||||
|
|
||||||
self.enabled = true
|
self.enabled = true
|
||||||
for _,child in ipairs(self.children) do
|
for _,child in pairs(self.children) do
|
||||||
child:enable()
|
child:enable()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2093,50 +2108,76 @@ end
|
||||||
|
|
||||||
function UI.DropMenu:eventHandler(event)
|
function UI.DropMenu:eventHandler(event)
|
||||||
if event.type == 'focus_lost' and self.enabled then
|
if event.type == 'focus_lost' and self.enabled then
|
||||||
for _,child in ipairs(self.children) do
|
if not Util.contains(self.children, event.focused) then
|
||||||
if child == event.focused then
|
self:hide()
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
self:hide()
|
|
||||||
--self.parent:focusFirst()
|
|
||||||
elseif event.type == 'mouse_out' and self.enabled then
|
elseif event.type == 'mouse_out' and self.enabled then
|
||||||
self:hide()
|
self:hide()
|
||||||
self:setFocus(self.parent)
|
self:refocus()
|
||||||
else
|
else
|
||||||
return UI.MenuBar.eventHandler(self, event)
|
return UI.MenuBar.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[-- TabBarMenuItem --]]--
|
||||||
|
UI.TabBarMenuItem = class(UI.Button)
|
||||||
|
UI.TabBarMenuItem.defaults = {
|
||||||
|
UIElement = 'TabBarMenuItem',
|
||||||
|
event = 'tab_select',
|
||||||
|
textColor = colors.black,
|
||||||
|
selectedBackgroundColor = colors.cyan,
|
||||||
|
unselectedBackgroundColor = colors.lightGray,
|
||||||
|
backgroundColor = colors.lightGray,
|
||||||
|
}
|
||||||
|
function UI.TabBarMenuItem:draw()
|
||||||
|
if self.selected then
|
||||||
|
self.backgroundColor = self.selectedBackgroundColor
|
||||||
|
self.backgroundFocusColor = self.selectedBackgroundColor
|
||||||
|
else
|
||||||
|
self.backgroundColor = self.unselectedBackgroundColor
|
||||||
|
self.backgroundFocusColor = self.unselectedBackgroundColor
|
||||||
|
end
|
||||||
|
UI.Button.draw(self)
|
||||||
|
end
|
||||||
|
|
||||||
--[[-- TabBar --]]--
|
--[[-- TabBar --]]--
|
||||||
UI.TabBar = class(UI.MenuBar)
|
UI.TabBar = class(UI.MenuBar)
|
||||||
UI.TabBar.defaults = {
|
UI.TabBar.defaults = {
|
||||||
UIElement = 'TabBar',
|
UIElement = 'TabBar',
|
||||||
|
buttonClass = 'TabBarMenuItem',
|
||||||
selectedBackgroundColor = colors.cyan,
|
selectedBackgroundColor = colors.cyan,
|
||||||
focusBackgroundColor = colors.green,
|
|
||||||
}
|
}
|
||||||
function UI.TabBar:selectTab(text)
|
function UI.TabBar:enable()
|
||||||
local selected, lastSelected
|
UI.MenuBar.enable(self)
|
||||||
|
if not Util.find(self.children, 'selected', true) then
|
||||||
|
local menuItem = self:getFocusables()[1]
|
||||||
|
if menuItem then
|
||||||
|
menuItem.selected = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for k,child in pairs(self:getFocusables()) do
|
function UI.TabBar:eventHandler(event)
|
||||||
if child.selected then
|
if event.type == 'tab_select' then
|
||||||
lastSelected = k
|
local selected, si = Util.find(self:getFocusables(), 'uid', event.button.uid)
|
||||||
end
|
local previous, pi = Util.find(self:getFocusables(), 'selected', true)
|
||||||
child.selected = child.text == text
|
|
||||||
if child.selected then
|
if si ~= pi then
|
||||||
selected = k
|
selected.selected = true
|
||||||
child.backgroundColor = self.selectedBackgroundColor
|
previous.selected = false
|
||||||
child.backgroundFocusColor = self.selectedBackgroundColor
|
self:emit({ type = 'tab_change', current = si, last = pi, tab = selected })
|
||||||
else
|
|
||||||
child.backgroundColor = self.backgroundColor
|
|
||||||
child.backgroundFocusColor = self.backgroundColor
|
|
||||||
end
|
end
|
||||||
|
UI.MenuBar.draw(self)
|
||||||
end
|
end
|
||||||
if selected and lastSelected and selected ~= lastSelected then
|
return UI.MenuBar.eventHandler(self, event)
|
||||||
self:emit({ type = 'tab_change', current = selected, last = lastSelected })
|
end
|
||||||
|
|
||||||
|
function UI.TabBar:selectTab(text)
|
||||||
|
local menuItem = Util.find(self.children, 'text', text)
|
||||||
|
if menuItem then
|
||||||
|
menuItem.selected = true
|
||||||
end
|
end
|
||||||
UI.MenuBar.draw(self)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Tabs --]]--
|
--[[-- Tabs --]]--
|
||||||
|
@ -2178,88 +2219,128 @@ function UI.Tabs:enable()
|
||||||
self.enabled = true
|
self.enabled = true
|
||||||
self.tabBar:enable()
|
self.tabBar:enable()
|
||||||
|
|
||||||
-- focus first tab
|
local menuItem = Util.find(self.tabBar.children, 'selected', true)
|
||||||
local menuItem = self.tabBar:getFocusables()[1]
|
|
||||||
if menuItem then
|
|
||||||
self:activateTab(menuItem.tabUid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Tabs:activateTab(uid)
|
for _,child in pairs(self.children) do
|
||||||
local tab = Util.find(self.children, 'uid', uid)
|
if child.uid == menuItem.tabUid then
|
||||||
if tab then
|
child:enable()
|
||||||
for _,child in pairs(self.children) do
|
self:emit({ type = 'tab_activate', activated = child })
|
||||||
if child.uid ~= uid and child.tabTitle then
|
elseif child.tabTitle then
|
||||||
child:disable()
|
child:disable()
|
||||||
end
|
|
||||||
end
|
|
||||||
if not tab.enabled then
|
|
||||||
self.tabBar:selectTab(tab.tabTitle)
|
|
||||||
tab:enable()
|
|
||||||
tab:draw()
|
|
||||||
self:emit({ type = 'tab_activate', activated = tab, element = self })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.Tabs:eventHandler(event)
|
function UI.Tabs:eventHandler(event)
|
||||||
if event.type == 'tab_select' then
|
if event.type == 'tab_change' then
|
||||||
self:activateTab(event.button.tabUid)
|
local tab = self:find(event.tab.tabUid)
|
||||||
elseif event.type == 'tab_change' then
|
if event.current > event.last then
|
||||||
for _,tab in ipairs(self.children) do
|
tab:addTransition('slideLeft')
|
||||||
if tab ~= self.tabBar then
|
else
|
||||||
if event.current > event.last then
|
tab:addTransition('slideRight')
|
||||||
tab:addTransition('slideLeft')
|
|
||||||
else
|
|
||||||
tab:addTransition('slideRight')
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[-- WindowScroller --]]--
|
for _,child in pairs(self.children) do
|
||||||
UI.WindowScroller = class(UI.Window)
|
if child.uid == event.tab.tabUid then
|
||||||
UI.WindowScroller.defaults = {
|
|
||||||
UIElement = 'WindowScroller',
|
|
||||||
children = { },
|
|
||||||
}
|
|
||||||
function UI.WindowScroller:enable()
|
|
||||||
self.enabled = true
|
|
||||||
if #self.children > 0 then
|
|
||||||
for k,child in ipairs(self.children) do
|
|
||||||
if k == 1 then
|
|
||||||
child:enable()
|
child:enable()
|
||||||
else
|
elseif child.tabTitle then
|
||||||
child:disable()
|
child:disable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self:emit({ type = 'tab_activate', activated = tab })
|
||||||
|
tab:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.WindowScroller:nextChild()
|
--[[-- Wizard --]]--
|
||||||
for i = 1, #self.children do
|
UI.Wizard = class(UI.Window)
|
||||||
if self.children[i].enabled then
|
UI.Wizard.defaults = {
|
||||||
if i < #self.children then
|
UIElement = 'Wizard',
|
||||||
self:addTransition('slideLeft')
|
pages = { },
|
||||||
self.children[i]:disable()
|
}
|
||||||
self.children[i + 1]:enable()
|
function UI.Wizard:postInit()
|
||||||
end
|
self.cancelButton = UI.Button {
|
||||||
break
|
x = 2, y = -1,
|
||||||
|
text = 'Cancel',
|
||||||
|
event = 'cancel',
|
||||||
|
}
|
||||||
|
self.previousButton = UI.Button {
|
||||||
|
x = -18, y = -1,
|
||||||
|
text = '< Back',
|
||||||
|
event = 'previousView',
|
||||||
|
}
|
||||||
|
self.nextButton = UI.Button {
|
||||||
|
x = -9, y = -1,
|
||||||
|
text = 'Next >',
|
||||||
|
event = 'nextView',
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.merge(self, self.pages)
|
||||||
|
for _, child in pairs(self.pages) do
|
||||||
|
child.ey = -2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Wizard:enable()
|
||||||
|
self.enabled = true
|
||||||
|
for _,child in ipairs(self.children) do
|
||||||
|
if not child.index then
|
||||||
|
child:enable()
|
||||||
|
elseif child.index == 1 then
|
||||||
|
child:enable()
|
||||||
|
else
|
||||||
|
child:disable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self:emit({ type = 'enable_view', view = Util.find(self.pages, 'index', 1) })
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.WindowScroller:prevChild()
|
function UI.Wizard:nextView()
|
||||||
for i = 1, #self.children do
|
local currentView = Util.find(self.pages, 'enabled', true)
|
||||||
if self.children[i].enabled then
|
local nextView = Util.find(self.pages, 'index', currentView.index + 1)
|
||||||
if i - 1 > 0 then
|
|
||||||
self:addTransition('slideRight')
|
if nextView then
|
||||||
self.children[i]:disable()
|
self:addTransition('slideLeft')
|
||||||
self.children[i - 1]:enable()
|
currentView:disable()
|
||||||
end
|
nextView:enable()
|
||||||
break
|
self:emit({ type = 'enable_view', view = nextView })
|
||||||
|
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:addTransition('slideRight')
|
||||||
|
currentView:disable()
|
||||||
|
nextView:enable()
|
||||||
|
self:emit({ type = 'enable_view', view = nextView })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function UI.Wizard:eventHandler(event)
|
||||||
|
if event.type == 'nextView' then
|
||||||
|
self:nextView()
|
||||||
|
self:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'previousView' then
|
||||||
|
self:prevView()
|
||||||
|
self:draw()
|
||||||
|
|
||||||
|
elseif event.type == 'enable_view' then
|
||||||
|
if Util.find(self.pages, 'index', event.view.index - 1) then
|
||||||
|
self.previousButton:enable()
|
||||||
|
else
|
||||||
|
self.previousButton:disable()
|
||||||
|
end
|
||||||
|
|
||||||
|
if Util.find(self.pages, 'index', event.view.index + 1) then
|
||||||
|
self.nextButton.text = 'Next >'
|
||||||
|
self.nextButton.event = 'nextView'
|
||||||
|
else
|
||||||
|
self.nextButton.text = 'Accept'
|
||||||
|
self.nextButton.event = 'accept'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2454,19 +2535,14 @@ function UI.StatusBar:timedStatus(status, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.StatusBar:getColumnWidth(name)
|
function UI.StatusBar:getColumnWidth(name)
|
||||||
for _,c in pairs(self.columns) do
|
local c = Util.find(self.columns, 'key', name)
|
||||||
if c.key == name then
|
return c and c.cw
|
||||||
return c.cw
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.StatusBar:setColumnWidth(name, width)
|
function UI.StatusBar:setColumnWidth(name, width)
|
||||||
for _,c in pairs(self.columns) do
|
local c = Util.find(self.columns, 'key', name)
|
||||||
if c.key == name then
|
if c then
|
||||||
c.cw = width
|
c.cw = width
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2561,8 +2637,6 @@ function UI.TextEntry:updateScroll()
|
||||||
elseif self.pos < self.scroll then
|
elseif self.pos < self.scroll then
|
||||||
self.scroll = self.pos
|
self.scroll = self.pos
|
||||||
end
|
end
|
||||||
|
|
||||||
--debug('p:%d s:%d w:%d l:%d', self.pos, self.scroll, self.width, self.limit)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.TextEntry:draw()
|
function UI.TextEntry:draw()
|
||||||
|
@ -2886,7 +2960,8 @@ end
|
||||||
|
|
||||||
function UI.TextArea:draw()
|
function UI.TextArea:draw()
|
||||||
self:clear()
|
self:clear()
|
||||||
self:setCursorPos(1, 1)
|
-- self:setCursorPos(1, 1)
|
||||||
|
self.cursorX, self.cursorY = 1, 1
|
||||||
self:print(self.value)
|
self:print(self.value)
|
||||||
self.ymax = self.cursorY + 1
|
self.ymax = self.cursorY + 1
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,14 @@ function Util.transpose(t)
|
||||||
return tt
|
return tt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Util.contains(t, value)
|
||||||
|
for k,v in pairs(t) do
|
||||||
|
if v == value then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Util.find(t, name, value)
|
function Util.find(t, name, value)
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
if v[name] == value then
|
if v[name] == value then
|
||||||
|
|
|
@ -90,11 +90,11 @@ local categories = { }
|
||||||
for _,f in pairs(applications) do
|
for _,f in pairs(applications) do
|
||||||
if not categories[f.category] then
|
if not categories[f.category] then
|
||||||
categories[f.category] = true
|
categories[f.category] = true
|
||||||
table.insert(buttons, { text = f.category, event = 'category' })
|
table.insert(buttons, { text = f.category })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(buttons, function(a, b) return a.text < b.text end)
|
table.sort(buttons, function(a, b) return a.text < b.text end)
|
||||||
table.insert(buttons, 1, { text = 'Recent', event = 'category' })
|
table.insert(buttons, 1, { text = 'Recent' })
|
||||||
table.insert(buttons, { text = '+', event = 'new' })
|
table.insert(buttons, { text = '+', event = 'new' })
|
||||||
|
|
||||||
local function parseIcon(iconText)
|
local function parseIcon(iconText)
|
||||||
|
@ -329,8 +329,7 @@ end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'category' then
|
if event.type == 'tab_select' then
|
||||||
self.tabBar:selectTab(event.button.text)
|
|
||||||
self.container:setCategory(event.button.text, true)
|
self.container:setCategory(event.button.text, true)
|
||||||
self.container:draw()
|
self.container:draw()
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ local systemPage = UI.Page {
|
||||||
info = UI.TextArea {
|
info = UI.TextArea {
|
||||||
x = 2, ex = -2,
|
x = 2, ex = -2,
|
||||||
y = 7,
|
y = 7,
|
||||||
|
inactive = true,
|
||||||
value = 'Add a password to enable other computers to connect to this one.',
|
value = 'Add a password to enable other computers to connect to this one.',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -150,7 +151,7 @@ if settings then
|
||||||
end
|
end
|
||||||
|
|
||||||
systemPage.tabs:add({
|
systemPage.tabs:add({
|
||||||
systemTab = UI.Window {
|
settingsTab = UI.Window {
|
||||||
tabTitle = 'Settings',
|
tabTitle = 'Settings',
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
y = 1,
|
y = 1,
|
||||||
|
@ -166,7 +167,7 @@ if settings then
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
function systemPage.tabs.systemTab:eventHandler(event)
|
function systemPage.tabs.settingsTab:eventHandler(event)
|
||||||
if event.type == 'grid_select' then
|
if event.type == 'grid_select' then
|
||||||
event.selected.value = not event.selected.value
|
event.selected.value = not event.selected.value
|
||||||
settings.set(event.selected.name, event.selected.value)
|
settings.set(event.selected.name, event.selected.value)
|
||||||
|
@ -187,7 +188,6 @@ function systemPage.tabs.pathTab.grid:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function systemPage.tabs.pathTab:eventHandler(event)
|
function systemPage.tabs.pathTab:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'update_path' then
|
if event.type == 'update_path' then
|
||||||
env.path = self.entry.value
|
env.path = self.entry.value
|
||||||
self.grid:setIndex(self.grid:getIndex())
|
self.grid:setIndex(self.grid:getIndex())
|
||||||
|
@ -208,7 +208,6 @@ function systemPage.tabs.aliasTab.grid:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function systemPage.tabs.aliasTab:eventHandler(event)
|
function systemPage.tabs.aliasTab:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'delete_alias' then
|
if event.type == 'delete_alias' then
|
||||||
env.aliases[self.grid:getSelected().alias] = nil
|
env.aliases[self.grid:getSelected().alias] = nil
|
||||||
self.grid:setIndex(self.grid:getIndex())
|
self.grid:setIndex(self.grid:getIndex())
|
||||||
|
@ -254,7 +253,6 @@ function systemPage.tabs.infoTab:eventHandler(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
function systemPage:eventHandler(event)
|
function systemPage:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:exitPullEvents()
|
UI:exitPullEvents()
|
||||||
elseif event.type == 'tab_activate' then
|
elseif event.type == 'tab_activate' then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user