FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::MenuPopup Class Reference

#include <menupopup.hpp>

Inheritance diagram for fcn::MenuPopup:
fcn::Container fcn::MouseListener fcn::KeyListener fcn::FocusListener fcn::ActionListener fcn::Widget

Public Member Functions

void addItem (Widget *item)
void addSeparator ()
void draw (Graphics *graphics) override
MenuPopupgetParentMenu () const
WidgetgetParentMenuItem () const
void hide ()
bool isVisible () const
 MenuPopup ()
 MenuPopup (MenuPopup &&)=delete
 MenuPopup (MenuPopup const &)=delete
MenuPopupoperator= (MenuPopup &&)=delete
MenuPopupoperator= (MenuPopup const &)=delete
void setParentMenu (MenuPopup *parent)
void setParentMenuItem (Widget *parent)
void show (int x, int y)
Public Member Functions inherited from fcn::Container
virtual void add (Widget *widget)
virtual void add (Widget *widget, int x, int y)
void addContainerListener (ContainerListener *containerListener)
virtual void addWidget (std::unique_ptr< Widget > widget)
virtual void addWidget (std::unique_ptr< Widget > widget, int x, int y)
void adjustSize () override
 Container ()
 Container (Container &&)=delete
 Container (Container const &)=delete
void expandContent ()
void expandContent (bool recursion) override
WidgetfindWidgetById (std::string const &id) override
WidgetgetBackgroundWidget ()
WidgetgetChild (unsigned int index) const
Rectangle getChildrenArea () override
virtual unsigned int getHorizontalSpacing () const
virtual LayoutPolicy getLayout () const
virtual unsigned int getVerticalSpacing () const
bool isLayouted () override
virtual bool isOpaque () const
virtual bool isUniformSize () const
Containeroperator= (Container &&)=delete
Containeroperator= (Container const &)=delete
void remove (Widget *widget) override
void removeAllChildren () override
void removeContainerListener (ContainerListener *containerListener)
void resizeToContent (bool recursion=true) override
void setBackgroundWidget (Widget *widget)
virtual void setHorizontalSpacing (unsigned int spacing)
virtual void setLayout (LayoutPolicy policy)
virtual void setOpacity (float opacity)
virtual void setOpaque (bool opaque)
virtual void setUniformSize (bool uniform)
virtual void setVerticalSpacing (unsigned int spacing)
Public Member Functions inherited from fcn::Widget
virtual void _draw (Graphics *graphics)
virtual FocusHandler_getFocusHandler ()
virtual std::list< FocusListener * > const & _getFocusListeners ()
virtual FocusHandler_getInternalFocusHandler ()
virtual std::list< KeyListener * > const & _getKeyListeners ()
virtual std::list< MouseListener * > const & _getMouseListeners ()
virtual void _logic ()
virtual void _setFocusHandler (FocusHandler *focusHandler)
virtual void _setParent (Widget *parent)
void adaptLayout ()
virtual void adaptLayout (bool top)
void addActionListener (ActionListener *actionListener)
void addDeathListener (DeathListener *deathListener)
void addDropTargetListener (DropTargetListener *listener)
void addFocusListener (FocusListener *focusListener)
void addKeyListener (KeyListener *keyListener)
void addMouseListener (MouseListener *mouseListener)
void addWidgetListener (WidgetListener *widgetListener)
bool captureMouse ()
bool contains (int x, int y) const
virtual void drawBorder (Graphics *graphics)
void drawBorder (Graphics *graphics, unsigned int sides)
virtual void drawOutline (Graphics *graphics)
virtual void drawSelectionFrame (Graphics *graphics)
void expandContent ()
virtual void focusNext ()
virtual void focusPrevious ()
virtual void fontChanged ()
virtual void getAbsolutePosition (int &x, int &y) const
std::string const & getActionEventId () const
Color const & getBackgroundColor () const
Color const & getBaseColor () const
Color const & getBorderColor () const
unsigned int getBorderSides () const
unsigned int getBorderSize () const
unsigned int getBorderStyle () const
unsigned int getChildrenCount () const
Rectangle const & getDimension () const
Size const & getFixedSize () const
FontgetFont () const
Color const & getForegroundColor () const
int getHeight () const
std::string const & getId () const
void getLastPosition (int &x, int &y) const
int getMarginBottom () const
int getMarginLeft () const
int getMarginRight () const
int getMarginTop () const
Size const & getMaxSize () const
Size const & getMinSize () const
Color const & getOutlineColor () const
unsigned int getOutlineSize () const
unsigned int getPaddingBottom () const
unsigned int getPaddingLeft () const
unsigned int getPaddingRight () const
unsigned int getPaddingTop () const
virtual WidgetgetParent () const
Color const & getSelectionColor () const
SelectionMode getSelectionMode () const
virtual WidgetgetTop () const
unsigned int getVisibleChildrenCount () const
WidgetgetWidgetAt (int x, int y)
virtual WidgetgetWidgetAt (int x, int y, Widget *exclude)
std::list< Widget * > getWidgetsIn (Rectangle const &area)
virtual std::list< Widget * > getWidgetsIn (Rectangle const &area, Widget *ignore)
int getWidth () const
int getX () const
int getY () const
bool hasMouseCapture () const
bool isDescendantOf (Widget const *ancestor) const noexcept
bool isEnabled () const
bool isFixedSize () const
bool isFocusable () const
virtual bool isFocused () const
bool isHorizontalExpand () const
bool isInsideActiveMouseModal () const noexcept
bool isLastPositionSet () const
virtual bool isModalFocusable () const
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocusable () const
bool isMouseInside (MouseEvent const &mouseEvent) const
bool isSetVisible () const
bool isTabInEnabled () const
bool isTabOutEnabled () const
virtual bool isUnderMouseModal () const
bool isVerticalExpand () const
bool isVisible () const
virtual void logic ()
virtual void moveToBottom (Widget *widget)
virtual void moveToTop (Widget *widget)
virtual void onFocusChanged ()
virtual void onFocusGained ()
virtual void onFocusLost ()
Widgetoperator= (Widget &&)=delete
Widgetoperator= (Widget const &)=delete
void releaseMouse ()
void removeActionListener (ActionListener *actionListener)
void removeDeathListener (DeathListener *deathListener)
void removeDropTargetListener (DropTargetListener *listener)
void removeFocusListener (FocusListener *focusListener)
void removeKeyListener (KeyListener *keyListener)
void removeMouseListener (MouseListener *mouseListener)
void removeWidgetListener (WidgetListener *widgetListener)
virtual void requestFocus ()
virtual void requestMoveToBottom ()
virtual void requestMoveToTop ()
void setActionEventId (std::string const &actionEventId)
virtual void setBackgroundColor (Color const &color)
virtual void setBaseColor (Color const &color)
void setBorderBottom (unsigned int size, unsigned int style)
virtual void setBorderColor (Color const &color)
void setBorderSides (unsigned int sides)
void setBorderSize (unsigned int size)
void setBorderStyle (unsigned int style)
void setBorderTop (unsigned int size, unsigned int style)
virtual void setDimension (Rectangle const &dimension)
void setEnabled (bool enabled)
void setFixedSize (Size const &size)
void setFocusable (bool focusable)
virtual void setFocused (bool focused)
virtual void setFont (Font *font)
virtual void setForegroundColor (Color const &color)
virtual void setHeight (int height)
void setHorizontalExpand (bool expand)
void setId (std::string const &id)
void setInternalFocusHandler (FocusHandler *internalFocusHandler)
void setLastPosition (int x, int y)
void setMargin (int margin)
void setMarginBottom (int margin)
void setMarginLeft (int margin)
void setMarginRight (int margin)
void setMarginTop (int margin)
void setMaxSize (Size const &size)
void setMinSize (Size const &size)
virtual void setOutlineColor (Color const &color)
void setOutlineSize (unsigned int size)
void setPadding (unsigned int padding)
void setPaddingBottom (unsigned int padding)
void setPaddingLeft (unsigned int padding)
void setPaddingRight (unsigned int padding)
void setPaddingTop (unsigned int padding)
void setPosition (int x, int y)
virtual void setSelectionColor (Color const &color)
virtual void setSelectionMode (SelectionMode mode)
virtual void setSize (int width, int height)
void setTabInEnabled (bool enabled)
void setTabOutEnabled (bool enabled)
void setVerticalExpand (bool expand)
void setVisible (bool visible)
virtual void setWidth (int width)
void setX (int x)
void setY (int y)
virtual void showPart (Rectangle rectangle)
virtual void showWidgetPart (Widget *widget, Rectangle area)
 Widget ()
 Widget (Widget &&)=delete
 Widget (Widget const &)=delete
Public Member Functions inherited from fcn::MouseListener
virtual void mouseClicked (MouseEvent &mouseEvent)
virtual void mouseDragged (MouseEvent &mouseEvent)
 MouseListener (MouseListener &&)=default
 MouseListener (MouseListener const &)=default
virtual void mouseMoved (MouseEvent &mouseEvent)
virtual void mouseWheelMovedDown (MouseEvent &mouseEvent)
virtual void mouseWheelMovedLeft (MouseEvent &mouseEvent)
virtual void mouseWheelMovedRight (MouseEvent &mouseEvent)
virtual void mouseWheelMovedUp (MouseEvent &mouseEvent)
MouseListeneroperator= (MouseListener &&)=default
MouseListeneroperator= (MouseListener const &)=default
Public Member Functions inherited from fcn::KeyListener
 KeyListener (KeyListener &&)=default
 KeyListener (KeyListener const &)=default
KeyListeneroperator= (KeyListener &&)=default
KeyListeneroperator= (KeyListener const &)=default
Public Member Functions inherited from fcn::FocusListener
virtual void focusGained (Event const &event)
 FocusListener (FocusListener &&)=delete
 FocusListener (FocusListener const &)=delete
FocusListener & operator= (FocusListener &&)=delete
FocusListener & operator= (FocusListener const &)=delete
Public Member Functions inherited from fcn::ActionListener
 ActionListener (ActionListener &&)=delete
 ActionListener (ActionListener const &)=delete
ActionListener & operator= (ActionListener &&)=delete
ActionListener & operator= (ActionListener const &)=delete

Protected Member Functions

void action (ActionEvent const &actionEvent) override
void focusLost (Event const &event) override
void keyPressed (KeyEvent &event) override
void keyReleased (KeyEvent &event) override
void mouseEntered (MouseEvent &event) override
void mouseExited (MouseEvent &event) override
void mousePressed (MouseEvent &event) override
void mouseReleased (MouseEvent &event) override
Protected Member Functions inherited from fcn::Container
void distributeWidgetAddedEvent (Widget *source)
void distributeWidgetRemovedEvent (Widget *source)
Protected Member Functions inherited from fcn::Widget
void add (Widget *widget)
void calculateSize ()
void distributeActionEvent ()
void distributeAncestorHiddenEvent (Widget *ancestor)
void distributeAncestorMovedEvent (Widget *ancestor)
void distributeAncestorShownEvent (Widget *ancestor)
void distributeDragDrop (DragEvent &event)
bool distributeDragEnter (DragEvent &event)
void distributeDragHover (DragEvent &event)
void distributeDragLeave (DragEvent &event)
void distributeHiddenEvent ()
void distributeMovedEvent ()
void distributeResizedEvent ()
void distributeShownEvent ()
std::list< Widget * > const & getChildren () const
void resizeToChildren ()
Protected Member Functions inherited from fcn::MouseListener
 MouseListener ()=default
Protected Member Functions inherited from fcn::KeyListener
 KeyListener ()=default
Protected Member Functions inherited from fcn::FocusListener
 FocusListener ()=default
Protected Member Functions inherited from fcn::ActionListener
 ActionListener ()=default

Additional Inherited Members

Public Types inherited from fcn::Container
enum class  LayoutPolicy : uint8_t {
  Absolute = 0 , AutoSize , Vertical , Horizontal ,
  Circular
}
Public Types inherited from fcn::Widget
enum  BorderSide : uint8_t {
  BORDER_NONE = 0 , BORDER_LEFT = 1 << 0 , BORDER_TOP = 1 << 1 , BORDER_RIGHT = 1 << 2 ,
  BORDER_BOTTOM = 1 << 3 , BORDER_ALL = BORDER_LEFT | BORDER_TOP | BORDER_RIGHT | BORDER_BOTTOM
}
enum  BorderStyle : uint8_t { BORDER_STYLE_BEVEL = 0 , BORDER_STYLE_FLAT = 1 }
enum class  SelectionMode : uint8_t { None = 0 , Border = 1 , Background = 2 }
Static Public Member Functions inherited from fcn::Widget
static DeathListener_getGuiDeathListener ()
static VisibilityEventHandler_getVisibilityEventHandler ()
static void _setGuiDeathListener (DeathListener *deathListener)
static void _setVisibilityEventHandler (VisibilityEventHandler *visibilityEventHandler)
static WidgetgetMouseCapture ()
static void resetGlobalFont ()
static void setGlobalFont (Font *font)
static bool widgetExists (Widget const *widget)
Protected Types inherited from fcn::Container
using ContainerListenerIterator = ContainerListenerList::iterator
using ContainerListenerList = std::list<ContainerListener*>
Protected Attributes inherited from fcn::Container
WidgetmBackgroundWidget {nullptr}
ContainerListenerList mContainerListeners
unsigned int mHorizontalSpacing {2}
LayoutPolicy mLayout {LayoutPolicy::Absolute}
float mOpacity {1.0F}
bool mOpaque {true}
bool mUniform {false}
unsigned int mVerticalSpacing {2}
Protected Attributes inherited from fcn::Widget
std::string mActionEventId
std::list< ActionListener * > mActionListeners
Color mBackgroundColor {0xf9fafb}
Color mBaseColor {0xe5e7eb}
Color mBorderColor {0xd1d5db}
unsigned int mBorderSides {BORDER_ALL}
unsigned int mBorderSize {0}
unsigned int mBorderStyle {BORDER_STYLE_FLAT}
std::list< Widget * > mChildren
FontmCurrentFont {nullptr}
std::list< DeathListener * > mDeathListeners
Rectangle mDimension
std::list< DropTargetListener * > mDropTargetListeners
bool mEnabled {true}
Size mFixedSize {-1, -1}
bool mFixedSizeUsed {false}
bool mFocusable {false}
bool mFocused {false}
FocusHandlermFocusHandler {nullptr}
std::list< FocusListener * > mFocusListeners
Color mForegroundColor {0x1f2933}
bool mHExpand {false}
std::string mId
FocusHandlermInternalFocusHandler {nullptr}
std::list< KeyListener * > mKeyListeners
int mLastX {0}
int mLastY {0}
int mMarginBottom {0}
int mMarginLeft {0}
int mMarginRight {0}
int mMarginTop {0}
Size mMaxSize {std::numeric_limits<int>::max(), std::numeric_limits<int>::max()}
Size mMinSize {0, 0}
std::list< MouseListener * > mMouseListeners
Rectangle mOffsetRect
Color mOutlineColor {0x9ca3af}
unsigned int mOutlineSize {0}
unsigned int mPaddingBottom {0}
unsigned int mPaddingLeft {0}
unsigned int mPaddingRight {0}
unsigned int mPaddingTop {0}
WidgetmParent {nullptr}
Color mSelectionColor {0x3b82f6}
SelectionMode mSelectionMode {SelectionMode::None}
bool mTabIn {true}
bool mTabOut {true}
bool mVExpand {false}
bool mVisible {true}
std::list< WidgetListener * > mWidgetListeners
Static Protected Attributes inherited from fcn::Widget
static DefaultFont mDefaultFont
static FontmGlobalFont = nullptr
static DeathListenermGuiDeathListener = nullptr
static VisibilityEventHandlermVisibilityEventHandler = nullptr
static std::list< Widget * > mWidgetInstances
static WidgetsMouseCapture = nullptr

Detailed Description

A menu popup widget that displays a dropdown menu.

MenuPopup is a modal overlay that appears below or above a menu item. It handles keyboard navigation, hover-to-open for submenus, and click-outside dismissal.

Definition at line 32 of file menupopup.hpp.

Constructor & Destructor Documentation

◆ MenuPopup()

Member Function Documentation

◆ action()

void fcn::MenuPopup::action ( ActionEvent const & actionEvent)
overrideprotectedvirtual

Handles an action event emitted by a widget.

Invoked when a widget triggers an action, providing details about the event via the ActionEvent object.

Parameters
actionEventThe action event data.

Implements fcn::ActionListener.

Definition at line 554 of file menupopup.cpp.

References getParentMenu(), hide(), and MenuPopup().

◆ addItem()

void fcn::MenuPopup::addItem ( Widget * item)

Adds a menu item to the popup.

Parameters
itemThe menu item to add.

Definition at line 300 of file menupopup.cpp.

References fcn::Container::add(), fcn::Widget::adjustSize(), and fcn::Container::resizeToContent().

◆ addSeparator()

void fcn::MenuPopup::addSeparator ( )

Adds a separator to the popup.

Definition at line 328 of file menupopup.cpp.

References fcn::Container::add(), and fcn::Container::resizeToContent().

◆ draw()

void fcn::MenuPopup::draw ( Graphics * graphics)
overridevirtual

Draws the widget.

The call to draw is initiated by the widget's parent. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension. If a widget has children, the parent's draw function will always be called before the children's draw functions are called.

Note
A widget with children won't draw its children unless the children area given by Widget::getChildrenArea returns a none empty rectangle inside the widgets dimension. The children area is considered relative to the widget's position.
Parameters
graphicsA graphics object to draw with.
See also
getChildrenArea, drawOutline, drawBorder

Reimplemented from fcn::Container.

Definition at line 344 of file menupopup.cpp.

References fcn::Container::draw(), fcn::Graphics::fillRectangle(), fcn::Widget::getHeight(), fcn::Widget::getWidth(), and fcn::Graphics::setColor().

◆ focusLost()

void fcn::MenuPopup::focusLost ( Event const & event)
overrideprotectedvirtual

Called when a widget loses focus.

Parameters
eventDescribes the event.

Reimplemented from fcn::FocusListener.

Definition at line 546 of file menupopup.cpp.

References hide(), and isVisible().

◆ getParentMenu()

MenuPopup * fcn::MenuPopup::getParentMenu ( ) const

Gets the parent MenuPopup (for nested menus).

Returns
The parent MenuPopup, or nullptr.

Definition at line 290 of file menupopup.cpp.

References MenuPopup().

Referenced by action().

◆ getParentMenuItem()

Widget * fcn::MenuPopup::getParentMenuItem ( ) const

Gets the parent menu item.

Returns
The parent MenuItem, or nullptr.
See also
setParentMenuItem

Definition at line 285 of file menupopup.cpp.

◆ hide()

void fcn::MenuPopup::hide ( )

Hides the popup.

Definition at line 241 of file menupopup.cpp.

References fcn::Container::Container(), and fcn::Widget::setVisible().

Referenced by fcn::MenuBar::action(), action(), focusLost(), keyPressed(), and mousePressed().

◆ isVisible()

bool fcn::MenuPopup::isVisible ( ) const

Checks if the popup is visible.

Returns
True if visible.

Definition at line 275 of file menupopup.cpp.

Referenced by focusLost().

◆ keyPressed()

void fcn::MenuPopup::keyPressed ( KeyEvent & keyEvent)
overrideprotectedvirtual

Called if a key is pressed when the widget has keyboard focus.

If a key is held down the widget will generate multiple key presses.

Parameters
keyEventDescribes the event.

Reimplemented from fcn::KeyListener.

Definition at line 462 of file menupopup.cpp.

References fcn::Widget::getChildren(), fcn::Key::getValue(), hide(), MenuPopup(), setParentMenu(), setParentMenuItem(), and show().

◆ keyReleased()

void fcn::MenuPopup::keyReleased ( KeyEvent & keyEvent)
overrideprotectedvirtual

Called if a key is released when the widget has keyboard focus.

Parameters
keyEventDescribes the event.

Reimplemented from fcn::KeyListener.

Definition at line 542 of file menupopup.cpp.

◆ mouseEntered()

void fcn::MenuPopup::mouseEntered ( MouseEvent & mouseEvent)
overrideprotectedvirtual

Called when the mouse has entered into the widget area.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 417 of file menupopup.cpp.

References fcn::Widget::getChildren(), MenuPopup(), setParentMenu(), setParentMenuItem(), and show().

◆ mouseExited()

void fcn::MenuPopup::mouseExited ( MouseEvent & mouseEvent)
overrideprotectedvirtual

Called when the mouse has exited the widget area.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 458 of file menupopup.cpp.

◆ mousePressed()

void fcn::MenuPopup::mousePressed ( MouseEvent & mouseEvent)
overrideprotectedvirtual

Called when a mouse button has been pressed down on the widget area.

Note
A mouse press is NOT equal to a mouse click. Use mouseClicked() for "pressed AND released" (full click) on a widget.
See also
mouseClicked
Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 362 of file menupopup.cpp.

References fcn::Container::Container(), fcn::Widget::contains(), fcn::Widget::getAbsolutePosition(), fcn::Container::getChild(), fcn::Widget::getChildrenCount(), fcn::Widget::getHeight(), fcn::Widget::getTop(), fcn::Widget::getWidth(), and hide().

◆ mouseReleased()

void fcn::MenuPopup::mouseReleased ( MouseEvent & mouseEvent)
overrideprotectedvirtual

Called when a mouse button has been released on the widget area.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 413 of file menupopup.cpp.

◆ setParentMenu()

void fcn::MenuPopup::setParentMenu ( MenuPopup * parent)

Sets the parent MenuPopup (for nested menus).

Parameters
parentThe parent popup.

Definition at line 295 of file menupopup.cpp.

References MenuPopup().

Referenced by keyPressed(), and mouseEntered().

◆ setParentMenuItem()

void fcn::MenuPopup::setParentMenuItem ( Widget * parent)

Sets the parent menu item that opened this popup.

Parameters
parentThe parent MenuItem.
See also
getParentMenuItem

Definition at line 280 of file menupopup.cpp.

Referenced by fcn::MenuBar::addMenu(), keyPressed(), and mouseEntered().

◆ show()


The documentation for this class was generated from the following files: