tap method

({bool haptic, FSliderActiveThumb? thumb}) tap(
  1. double offset
)

Taps the slider at given offset, in logical pixels, along the track.

Returns a record where:

  • thumb is the edge that was moved, or null if no edge was moved.
  • haptic is true when the caller should fire a tick haptic.

The offset is relative to the origin defined by FSlider.layout.

Implementation

({FSliderActiveThumb? thumb, bool haptic}) tap(double offset) {
  if (interaction == .slide || interaction == .slideThumb) {
    return (thumb: null, haptic: false);
  }

  FSliderActiveThumb? thumb;
  var haptic = false;

  if (_value case final old?) {
    thumb = switch (active) {
      (min: true, max: true) when offset < old.pixels.min => .min,
      (min: true, max: true) when old.pixels.max < offset => .max,
      (min: true, max: false) => .min,
      (min: false, max: true) => .max,
      _ => null,
    };

    if (thumb != null) {
      value = old.move(min: thumb == .min, to: offset);
      haptic = old != value && _ticks.contains(thumb == .min ? value.pixels.min : value.pixels.max);
    }
  }

  return (thumb: thumb, haptic: haptic);
}