partition manager + tab/wizard rework

This commit is contained in:
kepler155c@gmail.com
2020-04-26 19:39:58 -06:00
parent b0d2ce0199
commit ef9f0e09b6
35 changed files with 588 additions and 334 deletions

View File

@@ -14,11 +14,11 @@ end
function UI.Tabs:add(children)
local buttons = { }
for _,child in pairs(children) do
if type(child) == 'table' and child.UIElement and child.tabTitle then
if type(child) == 'table' and child.UIElement and child.UIElement == 'Tab' then
child.y = 2
table.insert(buttons, {
index = child.index,
text = child.tabTitle,
text = child.title,
event = 'tab_select',
tabUid = child.uid,
})
@@ -34,7 +34,12 @@ function UI.Tabs:add(children)
end
if self.parent then
local enabled = self.enabled
-- don't enable children upon add
self.enabled = nil
UI.Window.add(self, children)
self.enabled = enabled
end
end
@@ -43,7 +48,15 @@ Make to the passed tab active.]]
function UI.Tabs:selectTab(tab)
local menuItem = Util.find(self.tabBar.children, 'tabUid', tab.uid)
if menuItem then
self.tabBar:emit({ type = 'tab_select', button = { uid = menuItem.uid } })
if self.enabled then
self.tabBar:emit({ type = 'tab_select', button = { uid = menuItem.uid } })
else
local previous = Util.find(self.tabBar.children, 'selected', true)
if previous then
previous.selected = false
end
menuItem.selected = true
end
end
end
@@ -59,14 +72,20 @@ function UI.Tabs:enable()
self.tabBar:enable()
local menuItem = Util.find(self.tabBar.children, 'selected', true)
self:enableTab(menuItem.tabUid)
end
function UI.Tabs:enableTab(tabUid, hint)
for child in self:eachChild() do
child.transitionHint = nil
if child.uid == menuItem.tabUid then
child:enable()
self:emit({ type = 'tab_activate', activated = child })
elseif child.tabTitle then
child:disable()
child.transitionHint = hint
if child.uid == tabUid then
if not child.enabled then
child:enable()
end
elseif child.UIElement == 'Tab' then
if child.enabled then
child:disable()
end
end
end
end
@@ -76,15 +95,7 @@ function UI.Tabs:eventHandler(event)
local tab = self:find(event.tab.tabUid)
local hint = event.current > event.last and 'slideLeft' or 'slideRight'
for child in self:eachChild() do
if child.uid == event.tab.tabUid then
child.transitionHint = hint
child:enable()
elseif child.tabTitle then
child:disable()
end
end
self:emit({ type = 'tab_activate', activated = tab })
self:enableTab(event.tab.tabUid, hint)
tab:draw()
return true
end
@@ -94,28 +105,28 @@ function UI.Tabs.example()
return UI.Tabs {
tab1 = UI.Tab {
index = 1,
tabTitle = 'tab1',
title = 'tab1',
entry = UI.TextEntry { y = 3, shadowText = 'text' },
},
tab2 = UI.Tab {
index = 2,
tabTitle = 'tab2',
title = 'tab2',
subtabs = UI.Tabs {
x = 3, y = 2, ex = -3, ey = -2,
tab1 = UI.Tab {
index = 1,
tabTitle = 'tab4',
title = 'tab4',
entry = UI.TextEntry { y = 3, shadowText = 'text' },
},
tab3 = UI.Tab {
index = 2,
tabTitle = 'tab5',
title = 'tab5',
},
},
},
tab3 = UI.Tab {
index = 3,
tabTitle = 'tab3',
title = 'tab3',
},
enable = function(self)
UI.Tabs.enable(self)