some chat functionality

This commit is contained in:
Eduardo Bart
2012-01-13 23:37:15 -02:00
parent aae784468b
commit 61aa710d1c
27 changed files with 345 additions and 146 deletions

View File

@@ -1,14 +1,14 @@
UITabBar = extends(UIWidget)
-- private functions
local function onTabClick(tabButton)
tabButton.tabBar:selectTab(tabButton)
local function onTabClick(tab)
tab.tabBar:selectTab(tab)
end
local function tabBlink(tabButton)
if not tabButton.blinking then return end
tabButton:setOn(not tabButton:isOn())
scheduleEvent(function() tabBlink(tabButton) end, 500)
local function tabBlink(tab)
if not tab.blinking then return end
tab:setOn(not tab:isOn())
scheduleEvent(function() tabBlink(tab) end, 500)
end
-- public functions
@@ -31,44 +31,52 @@ function UITabBar:addTab(text, panel)
panel = createWidget(self:getStyleName() .. 'Panel')
end
local tabButton = createWidget(self:getStyleName() .. 'Button', self)
tabButton.tabPanel = panel
tabButton.tabBar = self
tabButton:setText(text)
tabButton:setWidth(tabButton:getTextSize().width + tabButton:getPaddingLeft() + tabButton:getPaddingRight())
connect(tabButton, { onClick = onTabClick })
local tab = createWidget(self:getStyleName() .. 'Button', self)
tab.tabPanel = panel
tab.tabBar = self
tab:setText(text)
tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
connect(tab, { onClick = onTabClick })
table.insert(self.tabs, tabButton)
table.insert(self.tabs, tab)
if #self.tabs == 1 then
self:selectTab(tabButton)
self:selectTab(tab)
end
return tabButton
return tab
end
function UITabBar:selectTab(tabButton)
if self.currentTabButton == tabButton then return end
function UITabBar:getTab(text)
for k,tab in pairs(self.tabs) do
if tab:getText() == text then
return tab
end
end
end
function UITabBar:selectTab(tab)
if self.currentTab == tab then return end
if self.contentWidget then
local selectedWidget = self.contentWidget:getFirstChild()
if selectedWidget then
self.contentWidget:removeChild(selectedWidget)
end
self.contentWidget:addChild(tabButton.tabPanel)
tabButton.tabPanel:fill('parent')
self.contentWidget:addChild(tab.tabPanel)
tab.tabPanel:fill('parent')
end
if self.currentTabButton then
self.currentTabButton:setChecked(false)
if self.currentTab then
self.currentTab:setChecked(false)
end
self.currentTabButton = tabButton
tabButton:setChecked(true)
tabButton:setOn(false)
tabButton.blinking = false
self.currentTab = tab
tab:setChecked(true)
tab:setOn(false)
tab.blinking = false
end
function UITabBar:selectNextTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTab)
if index == nil then return end
local nextTab = self.tabs[index + 1] or self.tabs[1]
if not nextTab then return end
@@ -76,26 +84,30 @@ function UITabBar:selectNextTab()
end
function UITabBar:selectPrevTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTab)
if index == nil then return end
local prevTab = self.tabs[index - 1] or self.tabs[#self.tabs]
if not prevTab then return end
self:selectTab(prevTab)
end
function UITabBar:blinkTab(tabButton)
if tabButton:isChecked() or tabButton.blinking then return end
tabButton.blinking = true
tabBlink(tabButton)
function UITabBar:blinkTab(tab)
if tab:isChecked() or tab.blinking then return end
tab.blinking = true
tabBlink(tab)
end
function UITabBar:getTabPanel(tabButton)
return tabButton.tabPanel
function UITabBar:getTabPanel(tab)
return tab.tabPanel
end
function UITabBar:getCurrentTabPanel()
if self.currentTabButton then
return self.currentTabButton.tabPanel
if self.currentTab then
return self.currentTab.tabPanel
end
end
function UITabBar:getCurrentTab()
return self.currentTab
end