FifeGUI 0.2.0
A C++ GUI library designed for games.
tabbedarea.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_TABBEDAREA_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_TABBEDAREA_HPP_
7
8#include <map>
9#include <memory>
10#include <string>
11#include <utility>
12#include <vector>
13
14#include "fifechan/actionlistener.hpp"
15#include "fifechan/keylistener.hpp"
16#include "fifechan/mouselistener.hpp"
17#include "fifechan/platform.hpp"
18#include "fifechan/widget.hpp"
19#include "fifechan/widgets/container.hpp"
20
21namespace fcn
22{
23 class Tab;
24
32 class FIFEGUI_API TabbedArea : public ActionListener, public KeyListener, public MouseListener, public Widget
33 {
34 friend class Tab;
35
36 public:
37 TabbedArea();
38
39 ~TabbedArea() override;
40
41 TabbedArea(TabbedArea const &) = delete;
42 TabbedArea& operator=(TabbedArea const &) = delete;
43 TabbedArea(TabbedArea&&) = delete;
44 TabbedArea& operator=(TabbedArea&&) = delete;
45
60 void setOpaque(bool opaque);
61
68 bool isOpaque() const;
69
78 virtual void addTab(Tab* tab, Widget* widget);
79
86 virtual void removeTabWithIndex(unsigned int index);
87
94 virtual void removeTab(Tab* tab);
95
100 int getNumberOfTabs() const;
101
109 virtual bool isTabSelected(unsigned int index) const;
110
118 virtual bool isTabSelected(Tab* tab) const;
119
126 virtual void setSelectedTab(unsigned int index);
127
134 virtual void setSelectedTab(Tab* tab);
135
143 virtual int getSelectedTabIndex() const;
144
151 Tab* getSelectedTab() const;
152
153 // Inherited from Widget
154
157
158 void resizeToContent(bool recursion) override;
159
160 void expandContent(bool recursion) override;
161
165 void adjustSize() override;
166
167 Rectangle getChildrenArea() override;
168
169 void draw(Graphics* graphics) override;
170
172 void setWidth(int width);
173
175 void setHeight(int height);
176
178 void setSize(int width, int height);
179
181 void setDimension(Rectangle const & dimension);
182
184 void setBaseColor(Color const & color) override;
185
187 void setBackgroundWidget(Widget* widget);
188
191
200
209
218 virtual void setUniformSize(bool uniform);
219
227 virtual bool isUniformSize() const;
228
235 virtual void setVerticalSpacing(unsigned int spacing);
236
243 virtual unsigned int getVerticalSpacing() const;
244
251 virtual void setHorizontalSpacing(unsigned int spacing);
252
259 virtual unsigned int getHorizontalSpacing() const;
260
261 // Inherited from ActionListener
262
263 void action(ActionEvent const & actionEvent) override;
264
265 // Inherited from DeathListener
266
268 virtual void death(Event const & event);
269
270 // Inherited from KeyListener
271
272 void keyPressed(KeyEvent& keyEvent) override;
273
274 // Inherited from MouseListener
275
276 void mousePressed(MouseEvent& mouseEvent) override;
277
278 protected:
282 void adjustTabPositions();
283
287 Tab* mSelectedTab{nullptr};
288
293
298
304 std::vector<std::unique_ptr<Tab>> mTabsToDelete;
305
310 std::vector<std::pair<Tab*, Widget*>> mTabs;
311
315 bool mOpaque{false};
316 };
317} // namespace fcn
318
319#endif // INCLUDE_FIFECHAN_WIDGETS_TABBEDAREA_HPP_
Represents an action trigger (e.g., button click).
Color.
Definition color.hpp:56
A composite widget capable of holding and managing child widgets.
Definition container.hpp:32
LayoutPolicy
The layout policy of the container.
Definition container.hpp:38
Base class for all GUI event objects.
Definition event.hpp:24
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
Represents a key event.
Definition keyevent.hpp:22
Represents a mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
A single tab label used within a TabbedArea.
Definition tab.hpp:27
Container * mTabContainer
Holds the container for the tabs.
bool mOpaque
True if the tabbed area is opaque, false otherwise.
virtual bool isUniformSize() const
True if the tab container tries to expand the childs to a uniform size.
void resizeToContent(bool recursion) override
Resize this widget to fit its content.
virtual unsigned int getHorizontalSpacing() const
Get the horizontal spacing between rows.
virtual unsigned int getVerticalSpacing() const
Get the vertical spacing between rows.
virtual int getSelectedTabIndex() const
Gets the index of the selected tab.
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
void setHeight(int height)
Set the height of the tabbed area in pixels.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
virtual void setUniformSize(bool uniform)
If enabled, the free space is distributed in a way that the size of the childrens will be equal (if p...
void setDimension(Rectangle const &dimension)
Set the area dimension for the tabbed area.
virtual void death(Event const &event)
DeathListener callback invoked when a child widget dies.
virtual bool isTabSelected(unsigned int index) const
Checks if a tab given an index is selected or not.
virtual void setHorizontalSpacing(unsigned int spacing)
Set the horizontal spacing between columns.
virtual void setSelectedTab(unsigned int index)
Sets a tab given an index to be selected.
void setLayout(Container::LayoutPolicy policy)
Sets the layout of the tabbedarea.
void setBaseColor(Color const &color) override
Set the base/background color used for the tabbed area.
virtual void addTab(Tab *tab, Widget *widget)
Adds a tab to the tabbed area.
void action(ActionEvent const &actionEvent) override
Called when an action is received from a widget.
void adjustTabPositions()
Adjusts the positions of the tabs.
void setSize(int width, int height)
Set the size (width and height) of the tabbed area in pixels.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
void setWidth(int width)
Set the width of the tabbed area in pixels.
Container * mWidgetContainer
Holds the container for the widgets.
Widget * getBackgroundWidget()
Get the background widget, or nullptr if none is set.
void adjustSize() override
Adjusts the size of the tab container and the widget container.
std::vector< std::unique_ptr< Tab > > mTabsToDelete
Holds a vector of tabs to delete in the destructor.
Container::LayoutPolicy getLayout() const
Gets the layout of the tabbedarea.
std::vector< std::pair< Tab *, Widget * > > mTabs
A map between a tab and a widget to display when the tab is selected.
void setBackgroundWidget(Widget *widget)
Set the background widget which is drawn behind tabs.
int getNumberOfTabs() const
Returns the number of tabs in this tabbed area.
virtual void removeTabWithIndex(unsigned int index)
Removes a tab from the tabbed area.
virtual void setVerticalSpacing(unsigned int spacing)
Set the vertical spacing between rows.
void setOpaque(bool opaque)
Sets the tabbed area to be opaque or not.
Tab * getSelectedTab() const
Gets the selected tab.
virtual void removeTab(Tab *tab)
Removes a tab from the tabbed area.
bool isOpaque() const
Checks if the tabbed area is opaque or not.
Tab * mSelectedTab
Holds the selected tab.
void draw(Graphics *graphics) override
Draws the widget.
void expandContent(bool recursion) override
Expands child widgets to fit this widget's size.
Widget()
Constructor.
Definition widget.cpp:36
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1440
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1417