]> git.cworth.org Git - lmno.games/commit
Use "spacer" tiles to get correct inter-word spacing for claimed words
authorCarl Worth <cworth@cworth.org>
Mon, 9 Mar 2026 05:24:07 +0000 (22:24 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 9 Mar 2026 05:24:07 +0000 (22:24 -0700)
commit4cabc26d11d35e628e1629188440e1dbf8e3f7f8
tree368c9ceb681e5426d1fecb28027d5380e4f5620b
parentfdf1af582e270e3071941287e83ad9ad01f9d4e7
Use "spacer" tiles to get correct inter-word spacing for claimed words

Previously, we had the code computing an expected gap between tiles,
(and setting it as the "column-gap" CSS attribute). But this proved
fragile. In practice, it's hard to predict exactly what a browser will
do, (particular with things like sub-pixel rendering, etc.), so it's
easy for a calculation like this to be off.

And we saw that in practice. Tiles in one row would be a pixel or two
off (hrozintonally) from tiles in the next row. Being so close, but
not quite exactly the same was distracting (especially for someone who
looks closely and pays attention to details like this).

What we do instead, in this commit, is place an invisible "spacer"
tile between each word. This way, the browser is doing the exact same
computation for the "spacer" tiles and the "real" tiles, so they will
match.

That much is simple. The real trick comes when one word ends precisely
at the right edge of the view and then the "spacer" tile wraps on to
the next row. This results in the first word in that row being offset
to the right by the spacer tile, but we don't want that.

To account for this, we use a resizeObserver to notice when any
resizing happens, and in that case we walk through the tiles and
notice whenever the "offsetTop" of a spacer tile is larger than the
"offsetTop" of the previous tile. This indicates that that spacer tile
got wrapped. And in this case we style that spacer to have zero width.

Phew! That's a lot of text to explain a fair amount of code, all just
to correct a rendering error where tiles were just off by about a
single pixel.
anagrams/anagrams.css
anagrams/anagrams.jsx