Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
popup_menu.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/menu.hpp>
6
7namespace portals {
8struct PopupEntry;
9
10namespace detail {
12std::vector<PopupEntry> emptyPopupEntries();
14} // namespace detail
15
17struct PopupEntry {
19 std::string caption = std::string(0, '\0');
20 std::vector<PopupEntry> children = detail::emptyPopupEntries();
21 std::optional<char32_t> mnemonic;
22 bool submenu{};
23 bool enabled{true};
24 bool visible{true};
25};
26
27namespace detail {
29inline std::vector<PopupEntry> emptyPopupEntries() {
30 // The complete type permits the count constructor, which keeps debug proxy allocation fallible.
31 return std::vector<PopupEntry>(0);
32}
33
35} // namespace detail
36
39 std::size_t maxEntries{256};
40 std::size_t maxDepth{8};
42 std::int32_t panelGap{1};
44};
45
50class PopupMenu final : public Menu {
51public:
63 PopupMenu(GraphemeText empty, const std::vector<PopupEntry> &entries, const std::vector<ui::ActionRef> &leaves,
64 PopupMenuOptions options, Node<Dialog> layer, ControlStyle style = {},
66 ~PopupMenu() override;
67
69 std::expected<CellSize, TreeError> measure(CellSize available) override;
71 std::expected<void, TreeError> arrange(CellRect local) override;
73 std::expected<void, TreeError> paint(PaintContext &context) override;
75 Node<Dialog> dialogRoot() const noexcept;
77 std::size_t panelCount() const noexcept;
79 std::optional<std::size_t> selectedIndex() const noexcept override;
81 std::size_t visibleRowCount() const noexcept override;
83 void resetSelection() noexcept;
84
85private:
86 struct State;
87 std::unique_ptr<State> state_;
88 Node<Dialog> layer_;
89
90 std::expected<void, TreeError> prepare(WidgetTree &, Node<Menu>, WidthPolicy) override;
91 void invalidatePresentation() noexcept override;
92 std::expected<Input, TreeError> input(WidgetTree &, Node<Menu>, const RoutedEvent &, const NodeGeometry &) override;
93};
94} // namespace portals
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
Full-host structural root containing at most one visible opaque panel. This is deliberately not a Siz...
Definition dialog.hpp:102
Owning validated UTF-8 and immutable extended grapheme measurements.
Definition text.hpp:145
Menu(GraphemeText empty, const std::vector< ui::ActionRef > &actions, MenuOptions options={}, ControlStyle style={}, SizePolicy policy=DEFAULT_MENU_POLICY)
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Borrowed synchronous command sink supplied by the frame owner. submit must consume commands immediate...
Definition widget_types.hpp:66
Sized action-backed popup plane, owned by one private managed Dialog activation. Use ui::popupMenu as...
Definition popup_menu.hpp:50
std::size_t visibleRowCount() const noexcept override
std::expected< CellSize, TreeError > measure(CellSize available) override
std::size_t panelCount() const noexcept
Node< Dialog > dialogRoot() const noexcept
std::optional< std::size_t > selectedIndex() const noexcept override
std::expected< void, TreeError > paint(PaintContext &context) override
void resetSelection() noexcept
Reset local selection before a new managed activation; no callback or tree access.
PopupMenu(GraphemeText empty, const std::vector< PopupEntry > &entries, const std::vector< ui::ActionRef > &leaves, PopupMenuOptions options, Node< Dialog > layer, ControlStyle style={}, SizePolicy policy=DEFAULT_MENU_POLICY)
Internal construction path after checked popup admission.
std::expected< void, TreeError > arrange(CellRect local) override
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object....
Definition widget.hpp:179
Weak UI-affine action identity; owner retirement never leaves an executable callback.
Definition ui_action.hpp:117
Public Portals API.
Definition action.hpp:8
constexpr SizePolicy DEFAULT_MENU_POLICY
Natural menu extent on both axes; callers may supply an ordinary explicit SizePolicy.
Definition menu.hpp:9
std::variant< ActionEvent, KeyEvent, TextInputEvent, PasteInputEvent, MouseInputEvent > RoutedEvent
Synchronous input value; callback borrows it only until return.
Definition action.hpp:47
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning advanced frame settings; legacy BorderOptions remains a literal value type.
Definition primitives.hpp:62
Owning arranged geometry; invalid geometry must never be used for hit-testing.
Definition widget_types.hpp:48
Owning finite popup entry; callbacks and leaf presentation remain in ActionSet.
Definition popup_menu.hpp:17
bool enabled
Structural branch admission; leaf admission comes from its action.
Definition popup_menu.hpp:23
bool submenu
True for a structural branch, including an empty branch.
Definition popup_menu.hpp:22
std::vector< PopupEntry > children
Owned submenu entries.
Definition popup_menu.hpp:20
ui::ActionRef action
Shared leaf identity; ignored for a submenu.
Definition popup_menu.hpp:18
std::optional< char32_t > mnemonic
Explicit scalar; ASCII comparison ignores case.
Definition popup_menu.hpp:21
std::string caption
Owning submenu caption, literal UTF-8.
Definition popup_menu.hpp:19
bool visible
Structural branch visibility; hidden branches consume no row.
Definition popup_menu.hpp:24
Immutable finite popup construction options; cell extents include panel borders.
Definition popup_menu.hpp:38
CellSize maximumPanelSize
Positive viewport-independent caps on the popup plane.
Definition popup_menu.hpp:41
std::int32_t panelGap
Nonnegative transparent cell gap between adjacent panels.
Definition popup_menu.hpp:42
std::size_t maxDepth
Positive tree depth including the root, at most 32.
Definition popup_menu.hpp:40
FrameOptions frame
Existing frame pattern/glyphs, title chrome and finite per-panel paint budget.
Definition popup_menu.hpp:43
std::size_t maxEntries
Total entries across all branches; duplicates count separately.
Definition popup_menu.hpp:39
Owning independent policies for width and height.
Definition layout.hpp:35
Owning deterministic width policy; no font or terminal matching promise.
Definition text.hpp:42