Skip to content

PopupHandle supports content anchored to a view and content positioned at an explicit window point.

#include <huxerui/huxerui.h>
using namespace huxerui;
[[huxerui::composable]]
View DetailsAction() {
auto popup = UsePopup();
auto target = UseViewHandle();
return Button("Details").With(target).OnClick([popup, target] {
popup.Show(target, [](PopupContext context) {
return Column {
Text("This surface follows the Details button."),
Button("Close").OnClick([context] { context.Dismiss(); }),
}.With(Padding(16.0F), Spacing(8.0F), Background(UseTheme().colors.surface));
}, {.placement = {AnchorSide::Below, AnchorAlignment::Start}});
});
}

Bind the target to one mounted view with .With(target). The popup follows its final bounds through layout, scrolling, and presentation transforms. It follows a replacement that takes over the same binding and closes when the binding loses its target. ShowAt(point, ...) uses a fixed window point. Factories may receive PopupContext to dismiss themselves.

PopupOptions controls preferred side/alignment, gap, viewport margin, offset, outside/cancel dismissal, focus trapping, and the dismissal callback. Placement may flip or constrain to remain usable inside the viewport.

Popup content keeps the semantics declared by its child views. Set trap_focus for interactive floating surfaces that must contain keyboard and accessibility focus, and give application-defined content an explicit label or role when its visible children are not self-describing.

  • UsePopup() -> PopupHandle.
  • Show(const ViewHandle&, factory, PopupOptions = {}).
  • ShowAtAnchor(const ViewHandle&, Rect, factory, PopupOptions = {}) and ShowAt(Point, factory, PopupOptions = {}).
  • Context-aware and bound-argument factory overloads.
  • Dismiss(LayerId); PopupContext::Id() and Dismiss().
  • AnchorSide, AnchorAlignment, AnchorPlacement, and PopupOptions.

See Menu for structured actions and Tooltip for descriptive hints.

Operation Anchor and result
Show(target, factory, options) Uses the full bounds of the view bound to the target. Returns LayerId.
ShowAtAnchor(target, Rect, factory, options) Uses a rectangle local to that mounted view, for example a caret or selection range. Returns LayerId.
ShowAt(Point, factory, options) Uses a fixed point in window DIPs, not desktop pixels. Returns LayerId.
Update(id, factory) Replaces content while keeping the anchored request; returns whether it was updated.
UpdateAnchor(id, Rect) Updates an existing local-rectangle anchor without recreating content; returns whether it was updated.
Dismiss(id) Dismisses the matching request; false for a stale request.

Factories can be ViewFactory or PopupFactory (View(PopupContext)), with copyable bound-argument overloads. Obtain the popup and target handles in composition and show the surface from an event. A missing target or a target from another window throws std::logic_error. Capture factory inputs by value so they remain alive for the layer.

placement defaults to Below/Start. gap is 4 DIPs, viewport_margin is 8 DIPs, and offset defaults to zero. Above/Below align horizontally; Left/Right align vertically. These values express preferred placement, not permission to draw outside the safe viewport.

dismiss_on_outside_press and dismiss_on_cancel default to true. A supplied on_dismiss_request owns those requests instead of automatic dismissal. trap_focus defaults to false; retain_anchor_focus also defaults to false and supports suggestions that should leave focus in their anchor editor. Choose a coherent focus policy rather than enabling both for every popup.

Popup has no standard title/message surface or PopupStyle: your content owns padding, background, border, radius, and any content-specific presentation visuals. Use the typed Menu or Dialog service when those semantics already match the task.