Improve tabs move in console chat, looks nice now

This commit is contained in:
Eduardo Bart 2013-01-16 15:41:12 -02:00
parent 2e75380218
commit a80e758e32
7 changed files with 45 additions and 34 deletions

View File

@ -4,7 +4,7 @@ compiler:
before_script: before_script:
- sudo apt-add-repository ppa:28msec/boost -y - sudo apt-add-repository ppa:28msec/boost -y
- sudo apt-get update -y - sudo apt-get update -y
- sudo apt-get install libboost1.50 libphysfs-dev libssl-dev liblua5.1-dev libglew1.6-dev libvorbis-dev libopenal-dev libz-dev -y - sudo apt-get install libboost-all-dev libphysfs-dev libssl-dev liblua5.1-dev libglew1.6-dev libvorbis-dev libopenal-dev libz-dev -y
script: | script: |
cmake . -DCMAKE_BUILD_TYPE=Release cmake . -DCMAKE_BUILD_TYPE=Release
make make

View File

@ -10,8 +10,8 @@ TabBarButton < UIButton
icon-color: white icon-color: white
color: #aaaaaa color: #aaaaaa
anchors.top: parent.top anchors.top: parent.top
padding: 5
anchors.left: parent.left anchors.left: parent.left
padding: 5
$hover !checked: $hover !checked:
image-clip: 0 20 20 20 image-clip: 0 20 20 20

View File

@ -6,31 +6,49 @@ local function onTabClick(tab)
tab.tabBar:selectTab(tab) tab.tabBar:selectTab(tab)
end end
local function updateMargins(tabBar) local function updateMargins(tabBar, ignored)
if #tabBar.tabs == 0 then return end if #tabBar.tabs == 0 then return end
local currentMargin = 0 local currentMargin = 0
for i = 1, #tabBar.tabs do for i = 1, #tabBar.tabs do
if tabBar.tabs[i] ~= ignored then
if i == 1 then if i == 1 then
tabBar.tabs[i]:setMarginLeft(0) tabBar.tabs[i]:setMarginLeft(0)
else else
tabBar.tabs[i]:setMarginLeft(tabBar.tabSpacing * (i - 1) + currentMargin) tabBar.tabs[i]:setMarginLeft(tabBar.tabSpacing * (i - 1) + currentMargin)
end end
end
currentMargin = currentMargin + tabBar.tabs[i]:getWidth() currentMargin = currentMargin + tabBar.tabs[i]:getWidth()
end end
end end
local function onTabMousePress(tab, mousePos, mouseButton) local function onTabMousePress(tab, mousePos, mouseButton)
if mouseButton == MouseLeftButton and tab.tabBar.tabsMoveable then if mouseButton == MouseRightButton then
tab.tabBar.selected = tab
elseif mouseButton == MouseRightButton then
if tab.menuCallback then tab.menuCallback(tab, mousePos, mouseButton) end if tab.menuCallback then tab.menuCallback(tab, mousePos, mouseButton) end
return true
end end
end end
local function onTabMouseRelease(tab, mousePos, mouseButton) local function onTabDragEnter(tab)
tab:raise()
tab.tabBar.selected = tab
return true
end
local function onTabDragLeave(tab)
updateMargins(tab.tabBar)
tab.tabBar.selected = nil
return true
end
local function onTabDragMove(tab, mousePos, mouseMoved)
if tab == tab.tabBar.selected then
local newMargin = tab:getMarginLeft() + mouseMoved.x
if newMargin >= -tab.tabBar.tabSpacing and newMargin < tab.tabBar:getWidth() - tab:getWidth() then
tab:setMarginLeft(newMargin)
end
local tabs = tab.tabBar.tabs local tabs = tab.tabBar.tabs
if tab.tabBar.selected then
local lastMargin = -tab.tabBar.tabSpacing local lastMargin = -tab.tabBar.tabSpacing
for i = 1, #tabs do for i = 1, #tabs do
local nextMargin = tabs[i + 1] and (tabs[i + 1] == tab and (tabs[i]:getMarginLeft() + tabs[i]:getWidth() + tab.tabBar.tabSpacing) or tabs[i + 1]:getMarginLeft()) or tab.tabBar:getWidth() local nextMargin = tabs[i + 1] and (tabs[i + 1] == tab and (tabs[i]:getMarginLeft() + tabs[i]:getWidth() + tab.tabBar.tabSpacing) or tabs[i + 1]:getMarginLeft()) or tab.tabBar:getWidth()
@ -39,27 +57,16 @@ local function onTabMouseRelease(tab, mousePos, mouseButton)
local newIndex = table.find(tab.tabBar.tabs, tab.tabBar.tabs[i]) local newIndex = table.find(tab.tabBar.tabs, tab.tabBar.tabs[i])
table.remove(tab.tabBar.tabs, table.find(tab.tabBar.tabs, tab)) table.remove(tab.tabBar.tabs, table.find(tab.tabBar.tabs, tab))
table.insert(tab.tabBar.tabs, newIndex, tab) table.insert(tab.tabBar.tabs, newIndex, tab)
updateMargins(tab.tabBar) updateMargins(tab.tabBar, tab)
break break
else else
updateMargins(tab.tabBar) updateMargins(tab.tabBar, tab)
break break
end end
end end
lastMargin = tab.tabBar.tabs[i]:getMarginLeft() == 0 and -tab.tabBar.tabSpacing or tab.tabBar.tabs[i]:getMarginLeft() lastMargin = tab.tabBar.tabs[i]:getMarginLeft() == 0 and -tab.tabBar.tabSpacing or tab.tabBar.tabs[i]:getMarginLeft()
end end
end end
tab.tabBar.selected = nil
end
local function onTabMouseMove(tab, mousePos, mouseMoved)
if tab == tab.tabBar.selected then
local newMargin = tab:getMarginLeft() + mouseMoved.x
if newMargin >= -tab.tabBar.tabSpacing and newMargin < tab.tabBar:getWidth() - tab:getWidth() then
tab:setMarginLeft(newMargin)
end
end
end end
local function tabBlink(tab) local function tabBlink(tab)
@ -75,7 +82,7 @@ function UITabBar.create()
tabbar.tabs = {} tabbar.tabs = {}
tabbar.selected = nil -- dragged tab tabbar.selected = nil -- dragged tab
tabbar.tabSpacing = 5 tabbar.tabSpacing = 5
tabsMoveable = false tabbar.tabsMoveable = false
return tabbar return tabbar
end end
@ -102,13 +109,15 @@ function UITabBar:addTab(text, panel, menuCallback)
tab.tabPanel = panel tab.tabPanel = panel
tab.tabBar = self tab.tabBar = self
tab:setId('tab') tab:setId('tab')
tab:setDraggable(self.tabsMoveable)
tab:setText(text) tab:setText(text)
tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight()) tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
tab.menuCallback = menuCallback or nil tab.menuCallback = menuCallback or nil
tab.onClick = onTabClick tab.onClick = onTabClick
tab.onMousePress = onTabMousePress tab.onMousePress = onTabMousePress
tab.onMouseRelease = onTabMouseRelease tab.onDragEnter = onTabDragEnter
tab.onMouseMove = onTabMouseMove tab.onDragLeave = onTabDragLeave
tab.onDragMove = onTabDragMove
tab.onDestroy = function() tab.tabPanel:destroy() end tab.onDestroy = function() tab.tabPanel:destroy() end
table.insert(self.tabs, tab) table.insert(self.tabs, tab)

View File

@ -238,6 +238,8 @@ function toboolean(v)
if v == 1 then if v == 1 then
return true return true
end end
elseif type(v) == 'boolean' then
return v
end end
return false return false
end end

View File

@ -64,7 +64,7 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
if not writeable then if not writeable then
textWindow:setText(tr('Show Text')) textWindow:setText(tr('Show Text'))
--textEdit:wrapText() textEdit:wrapText()
cancelButton:hide() cancelButton:hide()
cancelButton:setWidth(0) cancelButton:setWidth(0)
okButton:setMarginRight(0) okButton:setMarginRight(0)

View File

@ -122,7 +122,7 @@ void UIManager::inputEvent(const InputEvent& event)
} }
if(m_pressedWidget && event.mouseButton == Fw::MouseLeftButton) if(m_pressedWidget && event.mouseButton == Fw::MouseLeftButton)
updatePressedWidget(nullptr, event.mousePos); updatePressedWidget(nullptr, event.mousePos, !accepted);
break; break;
} }
case Fw::MouseMoveInputEvent: { case Fw::MouseMoveInputEvent: {
@ -161,13 +161,13 @@ void UIManager::inputEvent(const InputEvent& event)
}; };
} }
void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos) void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos, bool fireClicks)
{ {
UIWidgetPtr oldPressedWidget = m_pressedWidget; UIWidgetPtr oldPressedWidget = m_pressedWidget;
m_pressedWidget = newPressedWidget; m_pressedWidget = newPressedWidget;
// when releasing mouse inside pressed widget area send onClick event // when releasing mouse inside pressed widget area send onClick event
if(oldPressedWidget && oldPressedWidget->isEnabled() && oldPressedWidget->containsPoint(clickedPos)) if(fireClicks && oldPressedWidget && oldPressedWidget->isEnabled() && oldPressedWidget->containsPoint(clickedPos))
oldPressedWidget->onClick(clickedPos); oldPressedWidget->onClick(clickedPos);
if(newPressedWidget) if(newPressedWidget)

View File

@ -39,7 +39,7 @@ public:
void resize(const Size& size); void resize(const Size& size);
void inputEvent(const InputEvent& event); void inputEvent(const InputEvent& event);
void updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point()); void updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point(), bool fireClicks = true);
bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point()); bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
void updateHoveredWidget(bool now = false); void updateHoveredWidget(bool now = false);