Skip to content

feat(scroll): add El::no_scroll_anchor and virtual-row descendant anchoring - #1989

Merged
Hona merged 1 commit into
devfrom
feat/364-scroll-anchor-opt-out
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
feat/364-scroll-anchor-opt-out

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #364
Fixes #1679

Summary

  • El::no_scroll_anchor() (crates/rune/src/el/scroll.rs): opt-in equivalent of CSS Scroll Anchoring Level 1 §2.1 overflow-anchor: none, stored on ScrollEdges (no size increase on El or Node).
    • On a child or virtual row (such as a top loading placeholder), skips that element and its subtree during anchor selection in both El::scroll_anchor() and VirtualList.
    • On a virtual_rows / virtualize container or its scroll viewport, disables automatic virtual-list anchoring so prepends at offset 0 reveal at the top without shifting existing defaults.
    • Per-row flags in VirtualList::row_no_anchor stay lazily unallocated when unused, preserving zero extra allocations on initial load and rekey.
  • Interior descendant anchoring inside mounted virtual_rows (crates/rune/src/runtime/scroll/anchor.rs, sticky.rs, commit/measure.rs, commit/remount.rs): follows CSS Scroll Anchoring Level 1 §2.2 Anchor Node Selection.
    • El::scroll_anchor() descends into a tall mounted virtual_rows row whose top starts above the viewport top to capture a bounded chain of visible interior candidates, promoting the first surviving live candidate in apply_keeps if the primary node is removed or begins exiting.
    • Whole-row virtual lists whose first visible row starts in view continue using VirtualList's row-level anchor path; unmounted rows fall back via Keep::virtual_row.
    • Coarse st.shift_anchor(delta) in measure.rs and remount.rs is skipped while scroll_requests.owns(&scroll_path), preventing double-shifts when a Keep owns the viewport.
  • Example & docs: added the interactive Lists/Scroll anchoring story in examples/playground/src/scroll_anchor_story.rs, updated rustdoc on El::scroll_anchor / El::no_scroll_anchor and crates/rune/README.md, and added a changelog fragment.

Usage

use rune::{GrowthSpec, ScrollSpec, col, el, text};

// Exclude a top loading placeholder so prepended pages anchor to the first real row:
let loading = el().key("loading").h(36.0).no_scroll_anchor();

// Disable virtual-list anchoring on a streaming search list so new top hits show at offset 0:
let search = col().scroll(ScrollSpec::default()).child(
    col().growth(GrowthSpec::default()).no_scroll_anchor().virtualize(24.0).child(loading),
);

// Keep a visible descendant still when height changes above it inside a tall virtual row:
let feed = col().scroll(ScrollSpec::default()).scroll_anchor().child(
    col().growth(GrowthSpec::default()).virtual_rows(
        1,
        700.0,
        |_, _| "message".into(),
        |hide: &bool, _| {
            col()
                .child(col().h(300.0))
                .children((!*hide).then(|| col().h(120.0)))
                .child(text("Current passage").key("passage"))
                .child(col().h(600.0))
        },
    ),
);

Anchor selection flow

flowchart TD
    A["scroll_anchor() viewport"] --> B{"Child no_scroll_anchor() / sticky / exiting?"}
    B -- Yes --> C["Skip subtree, try next sibling"]
    B -- No --> D{"Virtual list container?"}
    D -- Yes --> E{"Row top < viewport top - 0.5?"}
    E -- No --> F["Leave to VirtualList whole-row anchor"]
    E -- Yes --> G["Descend into mounted row (CSS §2.2)"]
    G --> H["Capture primary + surviving fallbacks + virtual_row"]
    H --> I["Skip coarse shift_anchor while Keep owns viewport"]
    I --> J{"Primary live after commit?"}
    J -- Yes --> K["follow_keeps tracks drawn Y"]
    J -- No --> L{"Surviving fallback live?"}
    L -- Yes --> K
    L -- No --> M["apply_keeps restores via virtual_row & remounts"]
Loading

@Hona
Hona force-pushed the feat/364-scroll-anchor-opt-out branch from cadbdc3 to 9ba1916 Compare November 24, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant