GUI: Tab cycling handles multiple themes.

First visible tab moves up when a theme's width cannot fit another tab.
This commit is contained in:
Zerophase 2014-04-06 19:56:55 -05:00
parent 5df3c14eba
commit 5c12e09ed1
2 changed files with 14 additions and 10 deletions

View File

@ -183,6 +183,7 @@ void TabWidget::setActiveTab(int tabID) {
}
_activeTab = tabID;
_firstWidget = _tabs[tabID].firstWidget;
_boss->draw();
}
}
@ -227,28 +228,29 @@ void TabWidget::handleMouseDown(int x, int y, int button, int clickCount) {
bool TabWidget::handleKeyDown(Common::KeyState state) {
if (state.hasFlags(Common::KBD_SHIFT) && state.keycode == Common::KEYCODE_TAB)
adjustTabs(-kAheadTab);
adjustTabs(kTabBackwards);
else if (state.keycode == Common::KEYCODE_TAB)
adjustTabs(kAheadTab);
adjustTabs(kTabForwards);
return Widget::handleKeyDown(state);
}
void TabWidget::adjustTabs(int value) {
// determine which tab is next
// Determine which tab is next
int tabID = _activeTab + value;
if (tabID >= (int)_tabs.size())
tabID = 0;
else if (tabID < 0)
tabID = ((int)_tabs.size() - 1);
// slides _firstVisibleTab forward to the correct tab
while (_firstVisibleTab < tabID - kMaxTabs)
// Slides _firstVisibleTab forward to the correct tab
int maxTabsOnScreen = (_w / _tabWidth);
if (tabID >= maxTabsOnScreen && (_firstVisibleTab + maxTabsOnScreen) < (int)_tabs.size())
_firstVisibleTab++;
// slide _firstVisibleTab backwards to the correct tab
// Slides _firstVisibleTab backwards to the correct tab
while (tabID < _firstVisibleTab)
_firstVisibleTab--;
_firstVisibleTab--;
setActiveTab(tabID);
}

View File

@ -28,6 +28,11 @@
#include "common/array.h"
namespace GUI {
enum {
kTabForwards = 1,
kTabBackwards = -1
};
class TabWidget : public Widget {
typedef Common::String String;
@ -38,9 +43,6 @@ class TabWidget : public Widget {
typedef Common::Array<Tab> TabList;
protected:
const int kMaxTabs = 5;
const int kAheadTab = 1;
int _activeTab;
int _firstVisibleTab;
TabList _tabs;