
-- 두 요소의 가로 스크롤을 비율로 맞춘다. 서로 리스너를 건다
sync :: Box -> Box -> Ignore -> (IO (), Ignore)
sync source target ignore
| ignore == Just source = (pure (), Nothing) -- 내가 일으킨 이벤트 하나를 건너뛴다
| scrollLeft target == next = (pure (), ignore) -- 값이 같으면 이벤트도 안 온다 — 표시하면 다음 사용자 스크롤을 삼킨다
| otherwise = (scrollLeft target := next, Just target)
where ratio = scrollLeft source / (scrollWidth source - clientWidth source)
next = round (ratio * (scrollWidth target - clientWidth target))
-- 동기 플래그로는 못 막는다: scroll 이벤트는 넣는 순간이 아니라 다음 렌더링에 온다
isSyncing := True >> scrollLeft target := next >> isSyncing := False -- 이벤트가 올 때 이미 False