Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/view/view_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
39 changes: 39 additions & 0 deletions tests/view_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading