diff options
Diffstat (limited to 'gui/widgets/tab.cpp')
-rw-r--r-- | gui/widgets/tab.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/gui/widgets/tab.cpp b/gui/widgets/tab.cpp index 756781a04b..cf9dd5d962 100644 --- a/gui/widgets/tab.cpp +++ b/gui/widgets/tab.cpp @@ -70,6 +70,12 @@ void TabWidget::init() { } TabWidget::~TabWidget() { + // If widgets were added or removed in the current tab, without tabs + // having been switched using setActiveTab() afterward, then the + // firstWidget in the _tabs list for the active tab may not be up to + // date. So update it now. + if (_activeTab != -1) + _tabs[_activeTab].firstWidget = _firstWidget; _firstWidget = 0; for (uint i = 0; i < _tabs.size(); ++i) { delete _tabs[i].firstWidget; @@ -80,9 +86,19 @@ TabWidget::~TabWidget() { } int16 TabWidget::getChildY() const { + // NOTE: if you change that, make sure to do the same + // changes in the ThemeLayoutTabWidget (gui/ThemeLayout.cpp) return getAbsY() + _tabHeight; } +uint16 TabWidget::getHeight() const { + // NOTE: if you change that, make sure to do the same + // changes in the ThemeLayoutTabWidget (gui/ThemeLayout.cpp) + // NOTE: this height is used for clipping, so it *includes* + // tabs, because it starts from getAbsY(), not getChildY() + return _h + _tabHeight; +} + int TabWidget::addTab(const String &title) { // Add a new tab page Tab newTab; @@ -183,6 +199,12 @@ void TabWidget::setActiveTab(int tabID) { } _activeTab = tabID; _firstWidget = _tabs[tabID].firstWidget; + + // Also ensure the tab is visible in the tab bar + if (_firstVisibleTab > tabID) + _firstVisibleTab = tabID; + else if (_firstVisibleTab + _w / _tabWidth <= tabID) + _firstVisibleTab = tabID - _w / _tabWidth + 1; _boss->draw(); } @@ -258,6 +280,19 @@ void TabWidget::adjustTabs(int value) { void TabWidget::reflowLayout() { Widget::reflowLayout(); + // NOTE: if you change that, make sure to do the same + // changes in the ThemeLayoutTabWidget (gui/ThemeLayout.cpp) + _tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height"); + _tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width"); + _titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top"); + + // If widgets were added or removed in the current tab, without tabs + // having been switched using setActiveTab() afterward, then the + // firstWidget in the _tabs list for the active tab may not be up to + // date. So update it now. + if (_activeTab != -1) + _tabs[_activeTab].firstWidget = _firstWidget; + for (uint i = 0; i < _tabs.size(); ++i) { Widget *w = _tabs[i].firstWidget; while (w) { @@ -266,10 +301,6 @@ void TabWidget::reflowLayout() { } } - _tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height"); - _tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width"); - _titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top"); - if (_tabWidth == 0) { _tabWidth = 40; #ifdef __DS__ @@ -304,9 +335,9 @@ void TabWidget::drawWidget() { for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) { tabs.push_back(_tabs[i].title); } - g_gui.theme()->drawDialogBackground(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP), _bodyBackgroundType); + g_gui.theme()->drawDialogBackgroundClip(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP+_tabHeight), getBossClipRect(), _bodyBackgroundType); - g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); + g_gui.theme()->drawTabClip(Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); } void TabWidget::draw() { |