FifeGUI 0.3.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// Standard library includes
9#include <map>
10#include <memory>
11#include <string>
12#include <utility>
13#include <vector>
14
15// Platform config include
16#include "fifechan/platform.hpp"
17
18// Project headers (subdirs before local)
19#include "fifechan/listeners/actionlistener.hpp"
20#include "fifechan/listeners/keylistener.hpp"
21#include "fifechan/listeners/mouselistener.hpp"
22#include "fifechan/widget.hpp"
23#include "fifechan/widgets/container.hpp"
24
25namespace fcn
26{
27 class Tab;
28
36 class FIFEGUI_API TabbedArea : public ActionListener, public KeyListener, public MouseListener, public Widget
37 {
38 friend class Tab;
39
40 public:
41 TabbedArea();
42
43 ~TabbedArea() override;
44
45 TabbedArea(TabbedArea const &) = delete;
46 TabbedArea& operator=(TabbedArea const &) = delete;
47 TabbedArea(TabbedArea&&) = delete;
48 TabbedArea& operator=(TabbedArea&&) = delete;
49
65 void setOpaque(bool opaque);
66
73 bool isOpaque() const;
74
84 virtual void addTab(Tab* tab, Widget* widget);
85
92 virtual void removeTabWithIndex(unsigned int index);
93
100 virtual void removeTab(Tab* tab);
101
106 int getNumberOfTabs() const;
107
115 virtual bool isTabSelected(unsigned int index) const;
116
124 virtual bool isTabSelected(Tab* tab) const;
125
132 virtual void setSelectedTab(unsigned int index);
133
140 virtual void setSelectedTab(Tab* tab);
141
149 virtual int getSelectedTabIndex() const;
150
157 Tab* getSelectedTab() const;
158
159 // Inherited from Widget
160
163
164 void resizeToContent(bool recursion = true) override;
165
166 void expandContent(bool recursion) override;
167
171 void adjustSize() override;
172
173 Rectangle getChildrenArea() override;
174
175 void draw(Graphics* graphics) override;
176
178 void setWidth(int width) override;
179
181 void setHeight(int height) override;
182
184 void setSize(int width, int height) override;
185
187 void setDimension(Rectangle const & dimension) override;
188
190 void setBaseColor(Color const & color) override;
191
193 void setBackgroundWidget(Widget* widget);
194
197
205
213
224 virtual void setUniformSize(bool uniform);
225
233 virtual bool isUniformSize() const;
234
241 virtual void setVerticalSpacing(unsigned int spacing);
242
249 virtual unsigned int getVerticalSpacing() const;
250
257 virtual void setHorizontalSpacing(unsigned int spacing);
258
265 virtual unsigned int getHorizontalSpacing() const;
266
267 // Inherited from ActionListener
268
269 void action(ActionEvent const & actionEvent) override;
270
271 // Inherited from DeathListener
272
274 virtual void death(Event const & event);
275
276 // Inherited from KeyListener
277
278 void keyPressed(KeyEvent& keyEvent) override;
279
280 // Inherited from MouseListener
281
282 void mousePressed(MouseEvent& mouseEvent) override;
283
284 protected:
288 void adjustTabPositions();
289
293 Tab* mSelectedTab{nullptr};
294
299
304
311 std::vector<std::unique_ptr<Tab>> mTabsToDelete;
312
316 std::vector<std::pair<Tab*, Widget*>> mTabs;
317
321 bool mOpaque{false};
322 };
323} // namespace fcn
324
325#endif // INCLUDE_FIFECHAN_WIDGETS_TABBEDAREA_HPP_
Represents an action trigger (e.g., button click).
Color.
Definition color.hpp:58
A composite widget capable of holding and managing child widgets.
Definition container.hpp:36
LayoutPolicy
The layout policy of the container.
Definition container.hpp:50
Base class for all GUI event objects.
Definition event.hpp:25
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Represents a key event.
Definition keyevent.hpp:26
KeyListener(KeyListener const &)=default
Copy constructor.
Represents a mouse event.
MouseListener(MouseListener const &)=default
Copy constructor.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
A single tab label used within a TabbedArea.
Definition tab.hpp:31
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.
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 mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed down on the widget area.
virtual void setUniformSize(bool uniform)
Enables or disables uniform sizing of child elements.
void setSize(int width, int height) override
Set the size (width and height) of the tabbed area in pixels.
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.
void setDimension(Rectangle const &dimension) override
Set the area dimension for the tabbed area.
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
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
Handles an action event emitted by a widget.
void adjustTabPositions()
Adjusts the positions of the tabs.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
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
Stores tabs owned by this instance for automatic destruction.
void setWidth(int width) override
Set the width of the tabbed area in pixels.
Container::LayoutPolicy getLayout() const
Gets the layout of the tabbedarea.
std::vector< std::pair< Tab *, Widget * > > mTabs
Associates each tab with the widget displayed when it 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.
void setHeight(int height) override
Set the height of the tabbed area in pixels.
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:52
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1597
virtual void resizeToContent(bool recursion=true)
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1580
Used replacement tokens by configure_file():