5#include "fifechan/widgets/menubar.hpp"
11#include "fifechan/graphics.hpp"
12#include "fifechan/widgets/menuitem.hpp"
13#include "fifechan/widgets/menupopup.hpp"
30 item->setType(MenuItem::Type::Submenu);
34 item->addActionListener(
this);
36 if (popup !=
nullptr) {
37 item->setSubmenu(popup);
43 if (popup !=
nullptr) {
46 topContainer =
dynamic_cast<Container*
>(p);
48 if (topContainer !=
nullptr) {
52 topContainer->
add(popup, 0, 0);
62 if (mOpenMenu !=
nullptr) {
70 return mOpenMenu !=
nullptr;
81 auto* source =
dynamic_cast<MenuItem*
>(
event.getSource());
83 if (source ==
nullptr) {
87 if (source->getSubmenu() !=
nullptr) {
90 if (mOpenMenu == popup) {
98 if (mOpenMenu !=
nullptr) {
107 int ax = source->getX();
108 int ay = source->getY();
112 while (parent !=
nullptr) {
113 ax += parent->
getX();
114 ay += parent->
getY();
120 popup->
show(ax, ay + source->getHeight());
129 Key const key =
event.getKey();
132 if (key.
getValue() == Key::Escape) {
133 if (mOpenMenu !=
nullptr) {
146 if (childCount == 0) {
151 mSelectedIndex = (mSelectedIndex - 1 +
static_cast<int>(childCount)) %
static_cast<int>(childCount);
153 mSelectedIndex = (mSelectedIndex + 1) %
static_cast<int>(childCount);
158 if (child !=
nullptr) {
167 if (mSelectedIndex >= 0 && mSelectedIndex <
static_cast<int>(
getChildrenCount())) {
169 if (
auto const * menuItem =
dynamic_cast<MenuItem*
>(child)) {
170 if (menuItem->getSubmenu() !=
nullptr) {
197 if (mOpenMenu !=
nullptr) {
199 if (
auto const * mi =
dynamic_cast<MenuItem*
>(target)) {
200 if (mi->getSubmenu() == mOpenMenu) {
Represents an action trigger (e.g., button click).
A composite widget capable of holding and managing child widgets.
void draw(Graphics *graphics) override
Draws the widget.
virtual bool isOpaque() const
Checks if the container is opaque or not.
virtual void add(Widget *widget)
Adds a widget to the container.
Widget * getChild(unsigned int index) const
Gets child by index.
virtual void setOpaque(bool opaque)
Sets the container to be opaque or not.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
void setFixedHeight(unsigned int height)
Sets the default height of the bar.
Represents a keyboard key or character code.
int getValue() const
Gets the value of the key.
Represents a mouse event.
int getX() const
Gets the x coordinate of the mouse event.
int getY() const
Gets the y coordinate of the mouse event.
Represents a rectangular area (X, Y, Width, Height).
Used replacement tokens by configure_file():