aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/TabWidget.cpp32
-rw-r--r--gui/TabWidget.h25
2 files changed, 48 insertions, 9 deletions
diff --git a/gui/TabWidget.cpp b/gui/TabWidget.cpp
index 8159147c83..38ea6229ec 100644
--- a/gui/TabWidget.cpp
+++ b/gui/TabWidget.cpp
@@ -114,6 +114,38 @@ int TabWidget::addTab(const String &title) {
return _activeTab;
}
+void TabWidget::removeTab(int tabID) {
+ assert(0 <= tabID && tabID < (int)_tabs.size());
+
+ // Deactive the tab if it's currently the active one
+ if (tabID == _activeTab) {
+ _tabs[tabID].firstWidget = _firstWidget;
+ releaseFocus();
+ _firstWidget = 0;
+ }
+
+ // Dispose the widgets in that tab and then the tab itself
+ delete _tabs[tabID].firstWidget;
+ _tabs.remove_at(tabID);
+
+ // Adjust _firstVisibleTab if necessary
+ if (_firstVisibleTab >= (int)_tabs.size()) {
+ _firstVisibleTab = MAX(0, (int)_tabs.size() - 1);
+ }
+
+ // The active tab was removed, so select a new active one (if any remains)
+ if (tabID == _activeTab) {
+ _activeTab = -1;
+ if (tabID >= (int)_tabs.size())
+ tabID = _tabs.size() - 1;
+ if (tabID >= 0)
+ setActiveTab(tabID);
+ }
+
+ // Finally trigger a redraw
+ _boss->draw();
+}
+
void TabWidget::setActiveTab(int tabID) {
assert(0 <= tabID && tabID < (int)_tabs.size());
if (_activeTab != tabID) {
diff --git a/gui/TabWidget.h b/gui/TabWidget.h
index bb836e0999..7e4c1d8139 100644
--- a/gui/TabWidget.h
+++ b/gui/TabWidget.h
@@ -62,18 +62,21 @@ public:
void init();
- virtual int16 getChildY() const;
-
- // Problem: how to add items to a tab?
- // First off, widget should allow non-dialog bosses, (i.e. also other widgets)
- // Could add a common base class for Widgets and Dialogs.
- // Then you add tabs using the following method, which returns a unique ID
+ /**
+ * Add a new tab with the given title. Returns a unique ID which can be used
+ * to identify the tab (to remove it / activate it etc.).
+ */
int addTab(const String &title);
- // Maybe we need to remove tabs again? Hm
- //void removeTab(int tabID);
+ /**
+ * Remove the tab with the given tab ID. Disposes all child widgets of that tab.
+ * TODO: This code is *unfinished*. In particular, it changes the
+ * tabIDs, so that they are not unique anymore! This is bad.
+ */
+ void removeTab(int tabID);
- /** Set the active tab by specifying a valid tab ID.
+ /**
+ * Set the active tab by specifying a valid tab ID.
* setActiveTab changes the value of _firstWidget. This means new
* Widgets are always added to the active tab.
*/
@@ -88,6 +91,10 @@ public:
virtual void draw();
protected:
+ // We overload getChildY to make sure child widgets are positioned correctly.
+ // Essentially this compensates for the space taken up by the tab title header.
+ virtual int16 getChildY() const;
+
virtual void drawWidget(bool hilite);
virtual Widget *findWidget(int x, int y);