positionFractionFromTrackDy static method

double positionFractionFromTrackDy({
  1. required double localDy,
  2. required double trackHeight,
  3. required double thumbHeight,
})

Map pointer Y on the track to positionFraction (NOT inverted).

Uses thumb-leading-edge in the usable range — same as GtkRange mapping value = thumb_leading / usable * max_value.

Implementation

static double positionFractionFromTrackDy({
  required double localDy,
  required double trackHeight,
  required double thumbHeight,
}) {
  final usable = trackHeight - thumbHeight;
  if (usable <= 0) return 1.0;
  final leading = (localDy - thumbHeight / 2).clamp(0.0, usable);
  return (leading / usable).clamp(0.0, 1.0);
}