diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index a07cecb12..1acbdc069 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -88,7 +88,7 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font) int lineHeight = font.getLineHeight(); WidgetArray wid; VariantList items; - int tabID = myTab->addTab("Emulation"); + int tabID = myTab->addTab(" Emulation ", TabWidget::AUTO_WIDTH); // settings set mySettingsGroupEmulation = new RadioButtonGroup(); @@ -188,7 +188,7 @@ void DeveloperDialog::addTiaTab(const GUI::Font& font) int pwidth = font.getStringWidth("Faulty Cosmic Ark stars"); WidgetArray wid; VariantList items; - int tabID = myTab->addTab("TIA"); + int tabID = myTab->addTab(" TIA ", TabWidget::AUTO_WIDTH); wid.clear(); @@ -222,15 +222,15 @@ void DeveloperDialog::addTiaTab(const GUI::Font& font) ypos += lineHeight + VGAP * 1; myPlInvPhaseWidget = new CheckboxWidget(myTab, font, HBORDER + INDENT * 3, ypos + 1, - "players"); + "Players"); wid.push_back(myPlInvPhaseWidget); myMsInvPhaseWidget = new CheckboxWidget(myTab, font, myPlInvPhaseWidget->getRight() + 20, ypos + 1, - "missiles"); + "Missiles"); wid.push_back(myMsInvPhaseWidget); myBlInvPhaseWidget = new CheckboxWidget(myTab, font, myMsInvPhaseWidget->getRight() + 20, ypos + 1, - "ball"); + "Ball"); wid.push_back(myBlInvPhaseWidget); ypos += lineHeight + VGAP * 1; @@ -239,11 +239,11 @@ void DeveloperDialog::addTiaTab(const GUI::Font& font) wid.push_back(myPlayfieldLabel); ypos += lineHeight + VGAP * 1; - myPFBitsWidget = new CheckboxWidget(myTab, font, HBORDER + INDENT * 3, ypos + 1, "bits"); + myPFBitsWidget = new CheckboxWidget(myTab, font, HBORDER + INDENT * 3, ypos + 1, "Bits"); wid.push_back(myPFBitsWidget); //ypos += lineHeight + VGAP * 1; - myPFColorWidget = new CheckboxWidget(myTab, font, myPFBitsWidget->getRight() + 20, ypos + 1, "color"); + myPFColorWidget = new CheckboxWidget(myTab, font, myPFBitsWidget->getRight() + 20, ypos + 1, "Color"); wid.push_back(myPFColorWidget); ypos += lineHeight + VGAP * 1; @@ -252,10 +252,10 @@ void DeveloperDialog::addTiaTab(const GUI::Font& font) wid.push_back(mySwapLabel); ypos += lineHeight + VGAP * 1; - myPlSwapWidget = new CheckboxWidget(myTab, font, HBORDER + INDENT * 3, ypos + 1, "players"); + myPlSwapWidget = new CheckboxWidget(myTab, font, HBORDER + INDENT * 3, ypos + 1, "Players"); wid.push_back(myPlSwapWidget); - myBlSwapWidget = new CheckboxWidget(myTab, font, myPlSwapWidget->getRight() + 20, ypos + 1, "ball"); + myBlSwapWidget = new CheckboxWidget(myTab, font, myPlSwapWidget->getRight() + 20, ypos + 1, "Ball"); wid.push_back(myBlSwapWidget); // Add items for tab 2 @@ -276,7 +276,7 @@ void DeveloperDialog::addVideoTab(const GUI::Font& font) int pwidth = font.getMaxCharWidth() * 6; WidgetArray wid; VariantList items; - int tabID = myTab->addTab("Video"); + int tabID = myTab->addTab(" Video ", TabWidget::AUTO_WIDTH); wid.clear(); @@ -411,7 +411,7 @@ void DeveloperDialog::addTimeMachineTab(const GUI::Font& font) lwidth = fontWidth * 11; WidgetArray wid; VariantList items; - int tabID = myTab->addTab("Time Mach."); + int tabID = myTab->addTab(" Time Machine ", TabWidget::AUTO_WIDTH); // settings set mySettingsGroupTM = new RadioButtonGroup(); @@ -475,7 +475,7 @@ void DeveloperDialog::addTimeMachineTab(const GUI::Font& font) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::addDebuggerTab(const GUI::Font& font) { - int tabID = myTab->addTab("Debugger"); + int tabID = myTab->addTab(" Debugger ", TabWidget::AUTO_WIDTH); WidgetArray wid; #ifdef DEBUGGER_SUPPORT diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index 460cec818..108678ac4 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -63,20 +63,38 @@ int TabWidget::getChildY() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int TabWidget::addTab(const string& title) +int TabWidget::addTab(const string& title, int tabWidth) { // Add a new tab page - _tabs.push_back(Tab(title)); + int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; + + if(tabWidth == AUTO_WIDTH) + _tabs.push_back(Tab(title, newWidth)); + else + _tabs.push_back(Tab(title, tabWidth)); int numTabs = int(_tabs.size()); // Determine the new tab width - int newWidth = _font.getStringWidth(title) + 2 * kTabPadding; - if (_tabWidth < newWidth) - _tabWidth = newWidth; + int fixedWidth = 0, fixedTabs = 0; + for(int i = 0; i < int(_tabs.size()); ++i) + { + if(_tabs[i].tabWidth != NO_WIDTH) + { + fixedWidth += _tabs[i].tabWidth; + fixedTabs++; + } + } - int maxWidth = (_w - kTabLeftOffset) / numTabs - kTabLeftOffset; - if (_tabWidth > maxWidth) - _tabWidth = maxWidth; + if(tabWidth == NO_WIDTH) + if(_tabWidth < newWidth) + _tabWidth = newWidth; + + if(numTabs - fixedTabs) + { + int maxWidth = (_w - kTabLeftOffset - fixedWidth) / (numTabs - fixedTabs) - kTabLeftOffset; + if(_tabWidth > maxWidth) + _tabWidth = maxWidth; + } // Activate the new tab setActiveTab(numTabs - 1); @@ -178,11 +196,16 @@ void TabWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) // Determine which tab was clicked int tabID = -1; x -= kTabLeftOffset; - if (x >= 0 && x % (_tabWidth + kTabSpacing) < _tabWidth) + + for(int i = 0; i < int(_tabs.size()); ++i) { - tabID = x / (_tabWidth + kTabSpacing); - if (tabID >= int(_tabs.size())) - tabID = -1; + int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; + if(x >= 0 && x < tabWidth) + { + tabID = i; + break; + } + x -= (tabWidth + kTabSpacing); } // If a tab was clicked, switch to that pane @@ -264,24 +287,25 @@ void TabWidget::drawWidget(bool hilite) int i, x = _x + kTabLeftOffset; for (i = 0; i < int(_tabs.size()); ++i) { + int tabWidth = _tabs[i].tabWidth ? _tabs[i].tabWidth : _tabWidth; ColorId fontcolor = _tabs[i].enabled && onTop? kTextColor : kColor; int yOffset = (i == _activeTab) ? 0 : 1; - s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1, + s.fillRect(x, _y + 1, tabWidth, _tabHeight - 1, (i == _activeTab) ? onTop ? kDlgColor : kBGColorLo : onTop ? kBGColorHi : kDlgColor); // ? kWidColor : kDlgColor s.drawString(_font, _tabs[i].title, x + kTabPadding + yOffset, _y + yOffset + (_tabHeight - _fontHeight - 1), - _tabWidth - 2 * kTabPadding, fontcolor, TextAlign::Center); + tabWidth - 2 * kTabPadding, fontcolor, TextAlign::Center); if(i == _activeTab) { - s.hLine(x, _y, x + _tabWidth - 1, onTop ? kWidColor : kDlgColor); - s.vLine(x + _tabWidth, _y + 1, _y + _tabHeight - 1, onTop ? kBGColorLo : kColor); + s.hLine(x, _y, x + tabWidth - 1, onTop ? kWidColor : kDlgColor); + s.vLine(x + tabWidth, _y + 1, _y + _tabHeight - 1, onTop ? kBGColorLo : kColor); } else - s.hLine(x, _y + _tabHeight, x + _tabWidth, onTop ? kWidColor : kDlgColor); + s.hLine(x, _y + _tabHeight, x + tabWidth, onTop ? kWidColor : kDlgColor); - x += _tabWidth + kTabSpacing; + x += tabWidth + kTabSpacing; } // fill empty right space diff --git a/src/gui/TabWidget.hxx b/src/gui/TabWidget.hxx index ce58af48b..5b5664b89 100644 --- a/src/gui/TabWidget.hxx +++ b/src/gui/TabWidget.hxx @@ -26,6 +26,9 @@ class TabWidget : public Widget, public CommandSender { public: + static const int NO_WIDTH = 0; + static const int AUTO_WIDTH = -1; + enum { kTabChangedCmd = 'TBCH' }; @@ -40,7 +43,7 @@ class TabWidget : public Widget, public CommandSender // 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 - int addTab(const string& title); + int addTab(const string& title, int tabWidth = NO_WIDTH); // Maybe we need to remove tabs again? Hm //void removeTab(int tabID); // Setting the active tab: @@ -76,10 +79,11 @@ class TabWidget : public Widget, public CommandSender Widget* firstWidget; Widget* parentWidget; bool enabled; + int tabWidth; - Tab(const string& t = "", Widget* first = nullptr, Widget* parent = nullptr, - bool e = true) - : title(t), firstWidget(first), parentWidget(parent), enabled(e) { } + Tab(const string& t, int tw = NO_WIDTH, + Widget* first = nullptr, Widget* parent = nullptr, bool e = true) + : title(t), firstWidget(first), parentWidget(parent), enabled(e), tabWidth(tw) { } }; using TabList = vector;