feat : math de molette infinie pour le sélecteur d'heure (MUI-39)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 09:59:28 +02:00
parent 661910a8d9
commit 9fdf324b0e
2 changed files with 68 additions and 0 deletions
@@ -0,0 +1,23 @@
export const VISIBLE_ROWS = 5
export const CENTER_OFFSET = (VISIBLE_ROWS - 1) / 2 // 2
/** Index de valeur logique (0..length-1) centré pour un scrollTop donné. */
export function valueIndexFromScroll(scrollTop: number, itemHeight: number, length: number): number {
const flat = Math.round(scrollTop / itemHeight) + CENTER_OFFSET
return ((flat % length) + length) % length
}
/** scrollTop qui centre l'index donné dans la copie du milieu (buffer à 3 copies). */
export function scrollTopForValueIndex(valueIndex: number, itemHeight: number, length: number): number {
const flat = length + valueIndex - CENTER_OFFSET
return flat * itemHeight
}
/** Recentre le scrollTop dans la copie du milieu [length, 2*length) si on a dérivé. */
export function loopCorrection(scrollTop: number, itemHeight: number, length: number): number {
const block = length * itemHeight
const centeredFlat = Math.round(scrollTop / itemHeight) + CENTER_OFFSET
if (centeredFlat < length) return scrollTop + block
if (centeredFlat >= 2 * length) return scrollTop - block
return scrollTop
}