Skip to content

feat(anchor): add Cx::anchor_placement and boundary-clamped El::anchored_in / anchor_rect_in - #1939

Merged
Hona merged 1 commit into
devfrom
feat/362-anchor-placement-bounds
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
feat/362-anchor-placement-bounds

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #362
Fixes #1380

Summary

  • Resolved anchor placement (Cx::anchor_placement, memo::anchor_placement): runtime::anchor::anchor_position now returns (x, y, Side, Align) and stores resolved_anchor: Option<(Side, Align)> on placed anchored nodes (NodeCold). Views and memo/region closures can query the resolved physical (Side, Align) after RTL mirroring, zoom, and flip clamping, participating in the existing PASSES/ECHOES settle loop and invalidating only when the resolved placement changes (never on non-flipping scrolls or resizes).
  • Boundary-clamped anchored overlays (El::anchored_in, anchor_rect_in): generalizes anchor_position and fit_bound to arbitrary bounds: [f32; 4], leaving pub struct Anchor unchanged. Chaining .anchored_in(boundary_key) after .anchored or .anchored_fit confines side flipping, alignment flipping, shift clamping, and fit sizing to the named boundary element's rect intersected with the window viewport, supporting forward-declared, scrolled, and zoomed boundaries and falling back to the window when the boundary key is missing or self-referential.
  • Outside answers followed: Floating UI's computePosition() resolved placement after flip middleware (Anchored popups: report which side a placement flipped to #362) and boundary option on detectOverflow / flip / shift / size middleware (Anchored overlays flip and clamp against the window only; add a boundary element #1380), paired with Rune's Cx::layout_with / memo::layout read-and-settle conventions.

API & Usage

use rune::{Align, Cx, El, Side, anchor_rect_in, col};

fn view(_: &(), cx: &mut Cx<()>) -> El {
    // Clamp a card inside a list pane so it flips left instead of covering an adjacent drawer.
    let card = col().key("card").w(256.0).h(80.0)
        .anchored("row-trigger", Side::Right, Align::Start, 8.0)
        .anchored_in("list-pane");

    // Open a nested submenu on the side the parent actually resolved to.
    let sub_side = cx.anchor_placement("card").map_or(Side::Right, |(side, _)| side);
    let sub = col().key("submenu").w(120.0).h(60.0)
        .anchored("card-item", sub_side, Align::Start, 4.0);

    // Pure geometry helper matching El::anchored_in.
    let _rect = anchor_rect_in(
        [380.0, 100.0, 480.0, 130.0],
        (256.0, 80.0),
        Side::Right,
        Align::Start,
        4.0,
        [100.0, 0.0, 500.0, 600.0],
    );

    col().child(card).child(sub)
}

Example & Docs

  • Added the rune-popover--bounded story in examples/kit-gallery/src/stories/overlays.rs (a list pane beside an inspector drawer with a movable trigger, El::anchored_in("bounded-list-pane"), and live memo::anchor_placement("bounded-card") readout).
  • Updated rustdoc on El::anchored_in, anchor_rect_in, Cx::anchor_placement, and memo::anchor_placement, updated crates/rune/README.md, and added changelog/unreleased/2026-11-24-anchor-placement-and-boundary.md.
  • Note: verified via headless runtime tests and cross-platform checks (Windows, macOS, Linux check, wasm32/webgl check); no live desktop window was opened.

@Hona
Hona force-pushed the feat/362-anchor-placement-bounds branch from 02bfcca to a35c527 Compare November 24, 2026 14:21
@Hona
Hona force-pushed the feat/362-anchor-placement-bounds branch from a35c527 to 828f60c Compare November 24, 2026 14:37
@Hona
Hona merged commit fa63637 into dev Nov 24, 2026
1 check passed
@Hona
Hona deleted the feat/362-anchor-placement-bounds branch November 24, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anchored overlays flip and clamp against the window only; add a boundary element Anchored popups: report which side a placement flipped to

1 participant