FifeGUI 0.2.0
A C++ GUI library designed for games.
menupopup.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2026 Fifengine contributors
3
4#ifndef INCLUDE_FIFECHAN_WIDGETS_MENUPOPUP_HPP_
5#define INCLUDE_FIFECHAN_WIDGETS_MENUPOPUP_HPP_
6
7// Standard library includes
8#include <memory>
9
10// Platform config include
11#include "fifechan/platform.hpp"
12
13// Project headers (subdirs before local)
14#include "fifechan/focushandler.hpp"
15#include "fifechan/listeners/actionlistener.hpp"
16#include "fifechan/listeners/focuslistener.hpp"
17#include "fifechan/listeners/keylistener.hpp"
18#include "fifechan/listeners/mouselistener.hpp"
19#include "fifechan/widgets/container.hpp"
20
21namespace fcn
22{
23 class ModalBackdrop;
32 class FIFEGUI_API MenuPopup :
33 public Container,
34 public MouseListener,
35 public KeyListener,
36 public FocusListener,
37 public ActionListener
38 {
39 public:
43 MenuPopup();
44
45 ~MenuPopup() override = default;
46
47 MenuPopup(MenuPopup const &) = delete;
48 MenuPopup& operator=(MenuPopup const &) = delete;
49 MenuPopup(MenuPopup&&) = delete;
50 MenuPopup& operator=(MenuPopup&&) = delete;
51
58 void show(int x, int y);
59
63 void hide();
64
70 // cppcheck-suppress duplInheritedMember
71 bool isVisible() const;
72
79 void setParentMenuItem(Widget* parent);
80
88
94 MenuPopup* getParentMenu() const;
95
101 void setParentMenu(MenuPopup* parent);
102
108 void addItem(Widget* item);
109
113 void addSeparator();
114
115 // Inherited from Widget
116
117 void draw(Graphics* graphics) override;
118
119 protected:
120 // Inherited from MouseListener
121
122 void mousePressed(MouseEvent& event) override;
123 void mouseReleased(MouseEvent& event) override;
124 void mouseEntered(MouseEvent& event) override;
125 void mouseExited(MouseEvent& event) override;
126
127 // Inherited from KeyListener
128
129 void keyPressed(KeyEvent& event) override;
130 void keyReleased(KeyEvent& event) override;
131
132 // Inherited from FocusListener
133
134 void focusLost(Event const & event) override;
135
136 // Inherited from ActionListener
137
138 void action(ActionEvent const & actionEvent) override;
139
140 private:
146 void layoutItems();
147
151 // cppcheck-suppress duplInheritedMember
152 bool mVisible{false};
153
157 Widget* mParentMenuItem{nullptr};
158
162 MenuPopup* mParentMenu{nullptr};
163
167 MenuPopup* mOpenChild{nullptr};
168
173 ModalBackdrop* mBackdrop{nullptr};
174
178 int mHoverIndex{-1};
179
183 std::unique_ptr<FocusHandler::ModalScope> mModalScope;
184 };
185} // namespace fcn
186
187#endif // INCLUDE_FIFECHAN_WIDGETS_MENUPOPUP_HPP_
Represents an action trigger (e.g., button click).
Container()
Constructor.
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.
void setParentMenuItem(Widget *parent)
Sets the parent menu item that opened this popup.
Widget * getParentMenuItem() const
Gets the parent menu item.
void setParentMenu(MenuPopup *parent)
Sets the parent MenuPopup (for nested menus).
void hide()
Hides the popup.
void addItem(Widget *item)
Adds a menu item to the popup.
void mouseEntered(MouseEvent &event) override
Called when the mouse has entered into the widget area.
void action(ActionEvent const &actionEvent) override
Handles an action event emitted by a widget.
void mousePressed(MouseEvent &event) override
Called when a mouse button has been pressed down on the widget area.
void keyPressed(KeyEvent &event) override
Called if a key is pressed when the widget has keyboard focus.
bool isVisible() const
Checks if the popup is visible.
MenuPopup * getParentMenu() const
Gets the parent MenuPopup (for nested menus).
void focusLost(Event const &event) override
Called when a widget loses focus.
void mouseExited(MouseEvent &event) override
Called when the mouse has exited the widget area.
void mouseReleased(MouseEvent &event) override
Called when a mouse button has been released on the widget area.
void draw(Graphics *graphics) override
Draws the widget.
MenuPopup()
Constructor.
void show(int x, int y)
Shows the popup at a specific position.
void addSeparator()
Adds a separator to the popup.
void keyReleased(KeyEvent &event) override
Called if a key is released when the widget has keyboard focus.
A Transparent fullscreen backdrop.
Represents a mouse event.
MouseListener(MouseListener const &)=default
Copy constructor.
Abstract base class defining the common behavior, properties, and lifecycle of all GUI elements.
Definition widget.hpp:55
Used replacement tokens by configure_file():