[PR #480] [MERGED] fix(hitgrid): stale hit grid after scroll/translate #567

Closed
opened 2026-03-02 23:47:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/480
Author: @simonklee
Created: 1/6/2026
Status: Merged
Merged: 1/8/2026
Merged by: @kommander

Base: mainHead: ctrl-p-mouse


📝 Commits (10+)

  • 6f11e5d fix(hitgrid): stale hit grid after scroll/translate
  • 44f0af2 rebase main and use ArrayListUnmanaged
  • 48c5069 fix formatter error
  • 2a795cf core: guard render loop after destroy
  • e352507 fix(renderer): defer native teardown until frame completes
  • 1328f06 format
  • 6e5b5e2 perf(hitgrid): skip Yoga sync during hit grid rebuild
  • d66ee28 remove unused methods
  • e36f8bc simplify
  • 2b34ce6 pure command

📊 Changes

10 files changed (+1123 additions, -76 deletions)

View changed files

📝 packages/core/src/Renderable.ts (+9 -2)
packages/core/src/examples/scrollbox-mouse-test.ts (+112 -0)
packages/core/src/examples/scrollbox-overlay-hit-test.ts (+206 -0)
📝 packages/core/src/renderer.ts (+120 -70)
📝 packages/core/src/tests/renderer.destroy-during-render.test.ts (+46 -0)
packages/core/src/tests/scrollbox-hitgrid.test.ts (+393 -0)
📝 packages/core/src/types.ts (+3 -0)
📝 packages/core/src/zig.ts (+59 -0)
📝 packages/core/src/zig/lib.zig (+20 -0)
📝 packages/core/src/zig/renderer.zig (+155 -4)

📄 Description

Add immediate hit grid sync for scroll and translate changes

Before this change, when a scrollbox scrolled, the hit grid stayed stale until the next render completed. Hover states wouldn't update even though elements visually moved. Users would hover over items that had already scrolled away.

The fix adds on-demand hit grid sync. When translateX/Y changes, the renderer
marks the grid dirty and rechecks hover state. The renderer now:

  1. Marks the hit grid dirty
  2. Rechecks hover state using the latest pointer position
  3. Rebuilds the hit grid immediately (before the next render) if a hit test occurs while dirty

The hit grid rebuild mirrors the render traversal but uses screen coordinates for scissor rects. Buffered renderables need this because they render at (0,0) in their local buffer, but hit testing happens in screen space.

Captured renderable (during drag) is excluded from the hit grid so drop targets receive events correctly.

I added the demo from #467 as an example as well as another debug example i used when implementing it. Both should probably be deleted before merging. You can copy these examples to 'main' to see the difference between how things react in main vs the branch.

The PR is a slightly different approach than what you discussed in https://github.com/anomalyco/opentui/pull/470#issuecomment-3711893881 comment, and I don't mind if you prefer your approach, but maybe you'll find some ideas here.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/480 **Author:** [@simonklee](https://github.com/simonklee) **Created:** 1/6/2026 **Status:** ✅ Merged **Merged:** 1/8/2026 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `ctrl-p-mouse` --- ### 📝 Commits (10+) - [`6f11e5d`](https://github.com/anomalyco/opentui/commit/6f11e5d8b237bb0f2e95005debbd7c981bd05cc8) fix(hitgrid): stale hit grid after scroll/translate - [`44f0af2`](https://github.com/anomalyco/opentui/commit/44f0af2a6e7d14475b69b745bc1f6722649be76c) rebase main and use ArrayListUnmanaged - [`48c5069`](https://github.com/anomalyco/opentui/commit/48c50694c59035acecd6c858c5d39eda00cc843e) fix formatter error - [`2a795cf`](https://github.com/anomalyco/opentui/commit/2a795cf3efbed4fbd0abc6f8ae49cd8ffb208dfc) core: guard render loop after destroy - [`e352507`](https://github.com/anomalyco/opentui/commit/e352507a52b455e7ac73229e91a28f43f8b4adda) fix(renderer): defer native teardown until frame completes - [`1328f06`](https://github.com/anomalyco/opentui/commit/1328f06cd2c723b6201c92edad83c8831722b45d) format - [`6e5b5e2`](https://github.com/anomalyco/opentui/commit/6e5b5e2da7338892ca5199438727d8576f41cf11) perf(hitgrid): skip Yoga sync during hit grid rebuild - [`d66ee28`](https://github.com/anomalyco/opentui/commit/d66ee285ac6e701c0cdcbe1c47606c79a0a38717) remove unused methods - [`e36f8bc`](https://github.com/anomalyco/opentui/commit/e36f8bc8a38abfdf107192e6f55be9b74d34172c) simplify - [`2b34ce6`](https://github.com/anomalyco/opentui/commit/2b34ce692627d4246631b83516b54089dbb9ff0e) pure command ### 📊 Changes **10 files changed** (+1123 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/Renderable.ts` (+9 -2) ➕ `packages/core/src/examples/scrollbox-mouse-test.ts` (+112 -0) ➕ `packages/core/src/examples/scrollbox-overlay-hit-test.ts` (+206 -0) 📝 `packages/core/src/renderer.ts` (+120 -70) 📝 `packages/core/src/tests/renderer.destroy-during-render.test.ts` (+46 -0) ➕ `packages/core/src/tests/scrollbox-hitgrid.test.ts` (+393 -0) 📝 `packages/core/src/types.ts` (+3 -0) 📝 `packages/core/src/zig.ts` (+59 -0) 📝 `packages/core/src/zig/lib.zig` (+20 -0) 📝 `packages/core/src/zig/renderer.zig` (+155 -4) </details> ### 📄 Description Add immediate hit grid sync for scroll and translate changes Before this change, when a scrollbox scrolled, the hit grid stayed stale until the next render completed. Hover states wouldn't update even though elements visually moved. Users would hover over items that had already scrolled away. The fix adds on-demand hit grid sync. When translateX/Y changes, the renderer marks the grid dirty and rechecks hover state. The renderer now: 1. Marks the hit grid dirty 2. Rechecks hover state using the latest pointer position 3. Rebuilds the hit grid immediately (before the next render) if a hit test occurs while dirty The hit grid rebuild mirrors the render traversal but uses screen coordinates for scissor rects. Buffered renderables need this because they render at (0,0) in their local buffer, but hit testing happens in screen space. Captured renderable (during drag) is excluded from the hit grid so drop targets receive events correctly. I added the demo from #467 as an example as well as another debug example i used when implementing it. Both should probably be deleted before merging. You can copy these examples to 'main' to see the difference between how things react in main vs the branch. The PR is a slightly different approach than what you discussed in https://github.com/anomalyco/opentui/pull/470#issuecomment-3711893881 comment, and I don't mind if you prefer your approach, but maybe you'll find some ideas here. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:47:08 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#567
No description provided.