5#include "fifechan/widgets/menubar.hpp"
14#include "fifechan/graphics.hpp"
15#include "fifechan/widgets/menuitem.hpp"
16#include "fifechan/widgets/menupopup.hpp"
31 auto item = std::make_unique<MenuItem>(text);
33 item->setType(MenuItem::Type::Submenu);
37 item->addActionListener(
this);
39 if (popup !=
nullptr) {
40 item->setSubmenu(popup);
46 if (popup !=
nullptr) {
49 topContainer =
dynamic_cast<Container*
>(p);
51 if (topContainer !=
nullptr) {
55 topContainer->
add(popup, 0, 0);
60 return item.release();
65 if (mOpenMenu !=
nullptr) {
73 return mOpenMenu !=
nullptr;
84 auto* source =
dynamic_cast<MenuItem*
>(
event.getSource());
86 if (source ==
nullptr) {
90 if (source->getSubmenu() !=
nullptr) {
93 if (mOpenMenu == popup) {
101 if (mOpenMenu !=
nullptr) {
110 int ax = source->getX();
111 int ay = source->getY();
115 while (parent !=
nullptr) {
116 ax += parent->
getX();
117 ay += parent->
getY();
123 popup->
show(ax, ay + source->getHeight());
132 Key
const key =
event.getKey();
135 if (key.getValue() == fcn::Key::ESCAPE) {
136 if (mOpenMenu !=
nullptr) {
147 if (key.getValue() == fcn::Key::LEFT || key.getValue() == fcn::Key::RIGHT) {
149 if (childCount == 0) {
153 if (key.getValue() == fcn::Key::LEFT) {
154 mSelectedIndex = (mSelectedIndex - 1 +
static_cast<int>(childCount)) %
static_cast<int>(childCount);
156 mSelectedIndex = (mSelectedIndex + 1) %
static_cast<int>(childCount);
161 if (child !=
nullptr) {
169 if (key.getValue() == fcn::Key::KEY_RETURN || key.getValue() == fcn::Key::DOWN) {
170 if (mSelectedIndex >= 0 && std::cmp_less(mSelectedIndex,
getChildrenCount())) {
172 if (
auto const * menuItem =
dynamic_cast<MenuItem*
>(child)) {
173 if (menuItem->getSubmenu() !=
nullptr) {
200 if (mOpenMenu !=
nullptr) {
202 if (
auto const * mi =
dynamic_cast<MenuItem*
>(target)) {
203 if (mi->getSubmenu() == mOpenMenu) {
225 assert(
"graphics must not be null" && graphics !=
nullptr);
Represents an action trigger (e.g., button click).
A composite widget capable of holding and managing child widgets.
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 draw(Graphics *graphics) override
Draws the widget.
void setFixedHeight(unsigned int height)
Sets the default height of the bar.
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():