al_popup_menu(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_popup_menu β€” Allegro 5 API πŸ’–

okay bestie, sit down, hydrate, and let's talk about popping up a lil menu right next to your cursor ✨ This one lives in the Allegro 5 API (section 3alleg5 if you're keeping score), and it's giving right-click energy in the best way.


✨ SYNOPSIS ✨

#include <allegro5/allegro_native_dialog.h>

bool al_popup_menu(ALLEGRO_MENU *popup, ALLEGRO_DISPLAY *display)

🌸 DESCRIPTION 🌸

So the way that this works is: it displays a context menu next to the mouse cursor. That's it. That's the whole vibe. πŸ–±οΈβœ¨

Heads up though β€” the menu has to have been created with al_create_popup_menu(3alleg5) first. You can't just roll up with any old menu, she needs to be born a popup menu, iykyk.

Once it's up, it generates events just like a regular display menu does β€” same event flow, same energy, no special treatment. πŸ‘‘

And lowkey important: it is possible that the menu will be canceled without any selection being made. Like, user clicks away, hits escape, changes their mind β€” no selection, no problem, that's a valid outcome fr fr.

Now, the display parameter β€” this one trips people up so listen closely 🫢. It indicates which window the menu is associated with (specifically when you process the menu click event). But β€” and this is the part everyone gets wrong β€” it does not actually affect where the menu is located on the screen. It's an association thing, not a positioning thing. The menu goes where the cursor is, periodt. πŸ’…

Returns true if the context menu was displayed.

⚠️ Linux besties, this one's for you: on Linux this function will fail if any of the mouse keys are held down. I.e. it will only reliably work if you handle it in ALLEGRO_MOUSE_BUTTON_UP events β€” and even then, only if that event corresponds to the final mouse button that was pressed. Not me finding this out the hard way 😭 Handle your button-up events properly, okay?

πŸŽ€ SINCE πŸŽ€

5.1.0 β€” she's been iconic since day one, no cap. 🌈


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page!! this came to you straight from the Allegro reference manual, al_popup_menu(3alleg5), section 3alleg5 β€” go forth and pop up some menus, you absolute main character πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from