Skip to content

ContextMenu

Overlays · interactive

A menu, and the same menu at a point rather than under a control.

Import

cpp
#include "gbui/widgets/contextMenu.hpp"

Example

ContextMenu

contextMenu · Overlays · interactive

Nothing is downloaded until you press it.

cpp
MenuResult contextMenu(Ui& ui, const Interaction& input, std::string_view id, Vec2 at, const std::vector<MenuEntry>& entries, MenuState& state, const MenuOptions& options = {});

The same menu, at a point. at is where the pointer was when the reader asked for it — keep it, because a menu that re-reads the live pointer position walks away from itself as the reader moves towards it. if (input.rightClicked("row")) { menuAt = input.pointer(); menuOpen = true; } if (menuOpen)

menu · Overlays · interactive

Nothing is downloaded until you press it.

cpp
MenuResult menu(Ui& ui, const Interaction& input, std::string_view id, std::string_view anchorId, const std::vector<MenuEntry>& entries, MenuState& state, const MenuOptions& options = {});

A menu hanging off anchorId. Draw it while the caller's own flag says it is open, exactly as popover is drawn — this holds no open state of its own.

API

OptionTypeDefaultWhat it does
namestd::string_viewWhat the menu is, announced before its first row.
widthfloat0.0fHow wide it is. Zero sizes it to its widest row, which is what a menu should do — a fixed width either truncates a command or leaves a gap.
maxVisiblestd::size_t14How many rows before it scrolls.
OptionTypeDefaultWhat it does
namestd::string_viewWhat the menu is, announced before its first row.
widthfloat0.0fHow wide it is. Zero sizes it to its widest row, which is what a menu should do — a fixed width either truncates a command or leaves a gap.
maxVisiblestd::size_t14How many rows before it scrolls.

Released under the LGPL-3.0-or-later licence.