28#include <guichan/widgets/container.hpp>
32 mWidgetContainer->setOpaque(
false);
33 addWidgetListener(
this);
35 mArrowButton[0] = std::make_unique<Button>(std::string(),
"shift_left",
this);
36 mArrowButton[1] = std::make_unique<Button>(std::string(),
"shift_right",
this);
53 for (
const auto &[tab,
_] : mTabs)
55 if (tab->getCaption() == name)
56 return static_cast<Tab*
>(tab);
76 for (
const auto &[tab, widget] : mTabs)
78 if (tab->getCaption() == name)
87 if (gcn::Tab *tab = getSelectedTab())
95 gcn::TabbedArea::addTab(tab, widget);
97 int frameSize = widget->getFrameSize();
98 widget->setPosition(frameSize, frameSize);
99 widget->setSize(mWidgetContainer->getWidth() - frameSize * 2,
100 mWidgetContainer->getHeight() - frameSize * 2);
110 mTabsToDelete.push_back(tab);
117 if (tab == mSelectedTab)
122 mSelectedTab =
nullptr;
125 for (
auto iter = mTabs.begin(); iter != mTabs.end(); iter++)
127 if (iter->first == tab)
129 mTabContainer->remove(tab);
135 for (
auto iter = mTabsToDelete.begin(); iter != mTabsToDelete.end(); iter++)
139 mTabsToDelete.erase(iter);
157 if (mouseEvent.isConsumed())
160 if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
162 gcn::Widget *widget = mTabContainer->getWidgetAt(mouseEvent.getX(),
165 if (
auto *tab =
dynamic_cast<gcn::Tab*
>(widget))
175 gcn::TabbedArea::setSelectedTab(tab);
177 if (
Tab *newTab =
dynamic_cast<Tab*
>(tab))
178 newTab->setCurrent();
189 int frameSize = w->getFrameSize();
190 w->setSize(mWidgetContainer->getWidth() - frameSize * 2,
191 mWidgetContainer->getHeight() - frameSize * 2);
195 int innerWidth = getWidth() - 4 -
mArrowButton[0]->getWidth()
201 if (newWidth < innerWidth)
215 for (
const auto &[tab,
_] : mTabs)
230 int maxTabHeight = 0;
231 for (
auto &tab : mTabs)
233 if (tab.first->getHeight() > maxTabHeight)
235 maxTabHeight = tab.first->getHeight();
242 gcn::Tab* tab = mTabs[i].first;
243 tab->setPosition(x, maxTabHeight - tab->getHeight());
244 x += tab->getWidth();
253 gcn::Tab* tab = mTabs[i].first;
254 x -= tab->getWidth();
255 tab->setPosition(x, maxTabHeight - tab->getHeight());
262 Widget *source = actionEvent.getSource();
264 if (
Tab *tab =
dynamic_cast<Tab*
>(source))
270 if (actionEvent.getId() ==
"shift_left")
275 else if (actionEvent.getId() ==
"shift_right")
290 const bool arrowButtonsVisible =
mTabsWidth > getWidth() - 2;
294 if (!arrowButtonsVisible)
300 const int availableWidth = getWidth() - 2 -
mArrowButton[0]->getWidth()
A central point of control for graphics.
void pushClipRect(const gcn::Rectangle &rect)
A tab, the same as the Guichan tab in 0.8, but extended to allow transparency.
void setCaption(const std::string &caption)
Sets the caption of the tab.
void draw(gcn::Graphics *graphics) override
Draw the tabbed area.
void updateVisibleTabsWidth()
Update the overall width of visible tab.
int mVisibleTabsWidth
The overall width of visible tab.
void action(const gcn::ActionEvent &actionEvent) override
void logic() override
Override the logic function since it's broken in guichan 0.8.
void widgetResized(const gcn::Event &event) override
void addTab(gcn::Tab *tab, gcn::Widget *widget) override
Add a tab.
int mTabsWidth
The overall width of all tab.
void mousePressed(gcn::MouseEvent &mouseEvent) override
gcn::Widget * getCurrentWidget()
Returns the widget for the current tab.
void removeTab(gcn::Tab *tab) override
Override the remove tab function as it's broken in guichan 0.8.
void updateTabsWidth()
Update the overall width of all tab.
void setSelectedTab(unsigned int index) override
Tab * getTab(const std::string &name) const
Return tab with specified name as caption.
void adjustTabPositions()
int getNumberOfTabs() const
Return how many tabs have been created.
gcn::Widget * getWidget(const std::string &name) const
Returns the widget with the tab that has specified caption.
void updateArrowEnableState()
Check whether the arrow should be clickable.
std::unique_ptr< Button > mArrowButton[2]
The tab arrows.
unsigned mTabScrollIndex
The tab scroll index.