Improve tabs move in console chat, looks nice now
This commit is contained in:
parent
2e75380218
commit
a80e758e32
|
@ -4,7 +4,7 @@ compiler:
|
|||
before_script:
|
||||
- sudo apt-add-repository ppa:28msec/boost -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: |
|
||||
cmake . -DCMAKE_BUILD_TYPE=Release
|
||||
make
|
||||
|
|
|
@ -10,8 +10,8 @@ TabBarButton < UIButton
|
|||
icon-color: white
|
||||
color: #aaaaaa
|
||||
anchors.top: parent.top
|
||||
padding: 5
|
||||
anchors.left: parent.left
|
||||
padding: 5
|
||||
|
||||
$hover !checked:
|
||||
image-clip: 0 20 20 20
|
||||
|
|
|
@ -6,31 +6,49 @@ local function onTabClick(tab)
|
|||
tab.tabBar:selectTab(tab)
|
||||
end
|
||||
|
||||
local function updateMargins(tabBar)
|
||||
local function updateMargins(tabBar, ignored)
|
||||
if #tabBar.tabs == 0 then return end
|
||||
|
||||
local currentMargin = 0
|
||||
for i = 1, #tabBar.tabs do
|
||||
if i == 1 then
|
||||
tabBar.tabs[i]:setMarginLeft(0)
|
||||
else
|
||||
tabBar.tabs[i]:setMarginLeft(tabBar.tabSpacing * (i - 1) + currentMargin)
|
||||
if tabBar.tabs[i] ~= ignored then
|
||||
if i == 1 then
|
||||
tabBar.tabs[i]:setMarginLeft(0)
|
||||
else
|
||||
tabBar.tabs[i]:setMarginLeft(tabBar.tabSpacing * (i - 1) + currentMargin)
|
||||
end
|
||||
end
|
||||
currentMargin = currentMargin + tabBar.tabs[i]:getWidth()
|
||||
end
|
||||
end
|
||||
|
||||
local function onTabMousePress(tab, mousePos, mouseButton)
|
||||
if mouseButton == MouseLeftButton and tab.tabBar.tabsMoveable then
|
||||
tab.tabBar.selected = tab
|
||||
elseif mouseButton == MouseRightButton then
|
||||
if mouseButton == MouseRightButton then
|
||||
if tab.menuCallback then tab.menuCallback(tab, mousePos, mouseButton) end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function onTabMouseRelease(tab, mousePos, mouseButton)
|
||||
local tabs = tab.tabBar.tabs
|
||||
if tab.tabBar.selected then
|
||||
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 lastMargin = -tab.tabBar.tabSpacing
|
||||
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()
|
||||
|
@ -39,27 +57,16 @@ local function onTabMouseRelease(tab, mousePos, mouseButton)
|
|||
local newIndex = table.find(tab.tabBar.tabs, tab.tabBar.tabs[i])
|
||||
table.remove(tab.tabBar.tabs, table.find(tab.tabBar.tabs, tab))
|
||||
table.insert(tab.tabBar.tabs, newIndex, tab)
|
||||
updateMargins(tab.tabBar)
|
||||
updateMargins(tab.tabBar, tab)
|
||||
break
|
||||
else
|
||||
updateMargins(tab.tabBar)
|
||||
updateMargins(tab.tabBar, tab)
|
||||
break
|
||||
end
|
||||
end
|
||||
lastMargin = tab.tabBar.tabs[i]:getMarginLeft() == 0 and -tab.tabBar.tabSpacing or tab.tabBar.tabs[i]:getMarginLeft()
|
||||
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
|
||||
|
||||
local function tabBlink(tab)
|
||||
|
@ -75,7 +82,7 @@ function UITabBar.create()
|
|||
tabbar.tabs = {}
|
||||
tabbar.selected = nil -- dragged tab
|
||||
tabbar.tabSpacing = 5
|
||||
tabsMoveable = false
|
||||
tabbar.tabsMoveable = false
|
||||
return tabbar
|
||||
end
|
||||
|
||||
|
@ -102,13 +109,15 @@ function UITabBar:addTab(text, panel, menuCallback)
|
|||
tab.tabPanel = panel
|
||||
tab.tabBar = self
|
||||
tab:setId('tab')
|
||||
tab:setDraggable(self.tabsMoveable)
|
||||
tab:setText(text)
|
||||
tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
|
||||
tab.menuCallback = menuCallback or nil
|
||||
tab.onClick = onTabClick
|
||||
tab.onMousePress = onTabMousePress
|
||||
tab.onMouseRelease = onTabMouseRelease
|
||||
tab.onMouseMove = onTabMouseMove
|
||||
tab.onDragEnter = onTabDragEnter
|
||||
tab.onDragLeave = onTabDragLeave
|
||||
tab.onDragMove = onTabDragMove
|
||||
tab.onDestroy = function() tab.tabPanel:destroy() end
|
||||
|
||||
table.insert(self.tabs, tab)
|
||||
|
|
|
@ -238,6 +238,8 @@ function toboolean(v)
|
|||
if v == 1 then
|
||||
return true
|
||||
end
|
||||
elseif type(v) == 'boolean' then
|
||||
return v
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
|
|||
|
||||
if not writeable then
|
||||
textWindow:setText(tr('Show Text'))
|
||||
--textEdit:wrapText()
|
||||
textEdit:wrapText()
|
||||
cancelButton:hide()
|
||||
cancelButton:setWidth(0)
|
||||
okButton:setMarginRight(0)
|
||||
|
|
|
@ -122,7 +122,7 @@ void UIManager::inputEvent(const InputEvent& event)
|
|||
}
|
||||
|
||||
if(m_pressedWidget && event.mouseButton == Fw::MouseLeftButton)
|
||||
updatePressedWidget(nullptr, event.mousePos);
|
||||
updatePressedWidget(nullptr, event.mousePos, !accepted);
|
||||
break;
|
||||
}
|
||||
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;
|
||||
m_pressedWidget = newPressedWidget;
|
||||
|
||||
// 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);
|
||||
|
||||
if(newPressedWidget)
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
void resize(const Size& size);
|
||||
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());
|
||||
void updateHoveredWidget(bool now = false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue