Placement of a floating panel in a window.
An Anchor determines where a floating panel sits within an AppCore window. You pass it through ForegroundPanelOptions when adding a panel to the window's foreground layer, positioning overlays like toasts or dropdown menus.
This example floats a toast in the bottom-right corner of the window, nudged inward from the edge:
{ .width = "320px", .height = "80px",
.Offset(-16, -16) });
@ WindowCorner
A window corner, following the window.
Definition Anchor.h:115
A nullable smart pointer.
Definition RefPtr.h:126
@ BottomRight
Definition Anchor.h:22
Placement Forms
Static factory methods define where a panel appears:
Panels positioned with Anchor::WindowCorner() or Anchor::WindowCenter() follow the window as it resizes.
Calling Offset() on any form nudges the panel by horizontal and vertical offsets in logical pixels, applied after the form places the panel.
Anchoring Below an Element
Anchor::Below() takes a target panel and a rectangle in that panel's local logical pixels, which match the page's CSS pixels– so bounding rectangles from dom::Element::getBoundingClientRect() pass straight through without conversion.
The library updates the placement every frame from the target panel's current geometry, so the floating panel follows the target as it moves.
Two chained methods refine placement under Anchor::Below():
- Align() sets cross-axis alignment against the rectangle. Left edges align by default, or you can center the panel or align its right edge.
- Fit() handles panels that don't fit below the rectangle. AnchorFit::Flip places the panel above the rectangle instead.
This example positions a dropdown below a button from another panel, flipping it upward if space runs out:
{ .width = "240px", .height = "180px",
@ Below
Under an anchor rect in a target panel.
Definition Anchor.h:117
@ Flip
Definition Anchor.h:36
static constexpr Rect FromXYWH(float x, float y, float width, float height)
Create a Rect from an origin and a size (the DOMRect / CSS box convention).
Definition Geometry.h:424
A rectangle in CSS pixels, relative to the viewport (DOMRect).
Definition DOMRect.h:26
double height
The height (can be negative).
Definition DOMRect.h:30
double width
The width (can be negative).
Definition DOMRect.h:29
double y
The vertical position.
Definition DOMRect.h:28
double x
The horizontal position.
Definition DOMRect.h:27
- Note
- A floating panel's placement is fixed once the panel exists. See Foreground for how to move an existing panel.
- See also
- ForegroundPanelOptions::placement, Foreground::AddPanel(), dom::Element::getBoundingClientRect()
|
| | Anchor ()=default |
| | Create the default placement (the window origin).
|
| Anchor | Offset (double dx, double dy) const |
| | Nudge the placement by an offset, applied after the placement form resolves (every form, At() and the default origin included).
|
| Anchor | Align (AnchorAlign alignment) const |
| | Align the panel against the anchor rect's cross axis.
|
| Anchor | Fit (AnchorFit fit) const |
| | Choose the fit behavior when the panel does not fit on its preferred side.
|
| Kind | kind () const |
| | The placement form.
|
| AnchorCorner | corner () const |
| | The window corner (WindowCorner() forms).
|
| AnchorAlign | alignment () const |
| | The cross-axis alignment (Below() forms).
|
| AnchorFit | fit_mode () const |
| | The fit behavior (Below() forms).
|
| double | x () const |
| | The absolute x-position, in logical px (At() forms).
|
| double | y () const |
| | The absolute y-position, in logical px (At() forms).
|
| double | offset_x () const |
| | The x-offset applied after the placement form resolves, in logical px.
|
| double | offset_y () const |
| | The y-offset applied after the placement form resolves, in logical px.
|
| RefPtr< Panel > | target () const |
| | The target panel (Below() forms, null otherwise).
|
| const Rect & | rect () const |
| | The anchor rect, in the target panel's local logical px (Below() forms).
|