diff --git a/src/view/view_layout.cpp b/src/view/view_layout.cpp index 7b23a41..f626551 100644 --- a/src/view/view_layout.cpp +++ b/src/view/view_layout.cpp @@ -954,12 +954,25 @@ void View::layoutTree() { YGNodeFreeRecursive(content.yoga); return; } + // The header stands at the top of the view as its content moves, and + // the content is clipped below it, so a record scrolling up passes + // under the header rather than being drawn and hit over it. + PlacementSpace bodySpace = childSpace; for (const Built& child : built.children) { const Node* item = node(child.id); const bool header = item != nullptr && flag(*item, "__scrollHeader"); - // The header stands at the top of the view as its content moves. - collect(child, left - scrollX * scale, - top - (header ? 0 : scrollY) * scale, childSpace); + if (!header) { + collect(child, left - scrollX * scale, top - scrollY * scale, + bodySpace); + continue; + } + collect(child, left - scrollX * scale, top, childSpace); + const float headerBottom = + top + (YGNodeLayoutGetTop(child.yoga) + + YGNodeLayoutGetHeight(child.yoga)) * scale; + const float clipBottom = bodySpace.clip.y + bodySpace.clip.height; + bodySpace.clip.y = std::clamp(headerBottom, bodySpace.clip.y, clipBottom); + bodySpace.clip.height = clipBottom - bodySpace.clip.y; } }; diff --git a/tests/view_test.cpp b/tests/view_test.cpp index ce0da8c..7b7a206 100644 --- a/tests/view_test.cpp +++ b/tests/view_test.cpp @@ -2269,6 +2269,45 @@ TEST_CASE("a gliding box is carried at once by its scroll") { CHECK(fixture.view.displayList()->quads.at(0).y0 == -60); } +namespace { + +/** A 100-point scroll pinning a 20-point header over a 300-point record, + * scrolled 60 points. */ +Stream recordUnderHeader() { + return Stream() + .create(1, "bureau-scroll", {{"width", 100}, {"height", 100}, + {"direction", "column"}, + {"scrollbar", "hidden"}, + {"offset", {{"y", 60}}}}) + .create(2, "bureau-box", {{"height", 20}, {"shrink", 0}, + {"__scrollHeader", true}}) + .create(3, "bureau-box", {{"height", 300}, {"shrink", 0}, + {"fill", "db32-black"}, + {"onHoverChange", true}}) + .append(1, 2).append(1, 3) + .append(0, 1); +} + +} // namespace + +TEST_CASE("a scrolled record is drawn only below its scroll's header") { + Fixture fixture; + fixture.commit(recordUnderHeader()); + REQUIRE(fixture.view.frame(0)); + const auto& list = *fixture.view.displayList(); + const auto& clip = list.clips.at(list.quads.at(0).clip); + CHECK(clip.y == 20); + CHECK(clip.height == 80); +} + +TEST_CASE("the pointer over a scroll's header misses the record under it") { + Fixture fixture; + fixture.commit(recordUnderHeader()); + REQUIRE(fixture.view.frame(0)); + fixture.view.pointer(pointer(bureau::PointerEvent::Kind::Move, 50, 10)); + CHECK(fixture.handled("onHoverChange").empty()); +} + TEST_CASE("under reduced motion a moved box stands in its new place at once") { Fixture fixture; fixture.view.setReducedMotion(true);