Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- The Wavy seek bar runs into its thumb again instead of stopping at its edge (#2168)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package io.github.aedev.flow.ui.components.musicplayer.controls
/**
* Where a wavy seek bar's two parts sit, in the track's own pixels. M3's Slider insets its track by
* half the thumb and centres the thumb at fraction × track width, so both parts are measured from
* there: each round cap stops [gap] short of the thumb's edge, whatever the fraction.
* there: each round cap stops [gap] short of the thumb's edge, whatever the fraction. With no gap the
* two caps meet at the thumb's centre, under it, so the line runs into the thumb (#2168): caps ending
* at its edge touch it at one point only and leave a notch above and below.
*/
internal object WavyTrackGeometry {
fun thumbCentre(
Expand All @@ -21,7 +23,7 @@ internal object WavyTrackGeometry {
thumbWidth: Float,
gap: Float,
stroke: Float,
): Float = maxOf(waveStart(stroke), thumbCentre(trackWidth, fraction) - thumbWidth / 2f - gap - stroke / 2f)
): Float = maxOf(waveStart(stroke), thumbCentre(trackWidth, fraction) - clearance(thumbWidth, gap) - stroke / 2f)

/** Where the straight rest of the track starts, mirroring [waveEnd] on the thumb's other side. */
fun restStart(
Expand All @@ -30,7 +32,13 @@ internal object WavyTrackGeometry {
thumbWidth: Float,
gap: Float,
stroke: Float,
): Float = thumbCentre(trackWidth, fraction) + thumbWidth / 2f + gap + stroke / 2f
): Float = thumbCentre(trackWidth, fraction) + clearance(thumbWidth, gap) + stroke / 2f

/** How far each cap stays from the thumb's centre. */
private fun clearance(
thumbWidth: Float,
gap: Float,
): Float = if (gap > 0f) thumbWidth / 2f + gap else 0f

fun trackEnd(
trackWidth: Float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class WavyTrackGeometryTest {

private fun thumbLeadingEdge(fraction: Float) = WavyTrackGeometry.thumbCentre(width, fraction) - thumb / 2f

private fun thumbTrailingEdge(fraction: Float) = WavyTrackGeometry.thumbCentre(width, fraction) + thumb / 2f

@Test
fun `the thumb centre is the fraction of the full track width`() {
assertThat(WavyTrackGeometry.thumbCentre(width, 0f)).isEqualTo(0f)
Expand All @@ -31,27 +33,35 @@ class WavyTrackGeometryTest {
}

@Test
fun `the wave's cap never passes the thumb's leading edge`() {
fun `with no gap the wave runs into the thumb and its cap stays under it`() {
for (step in 0..1000) {
val fraction = step / 1000f
if (waveEnd(fraction) > WavyTrackGeometry.waveStart(stroke)) {
assertThat(capEnd(fraction)).isAtMost(thumbLeadingEdge(fraction))
assertThat(capEnd(fraction)).isGreaterThan(thumbLeadingEdge(fraction))
assertThat(capEnd(fraction)).isAtMost(thumbTrailingEdge(fraction))
}
}
}

@Test
fun `with no gap both caps meet at the thumb's centre`() {
val restCapStart = WavyTrackGeometry.restStart(width, 0.5f, thumb, gap, stroke) - stroke / 2f

assertThat(capEnd(0.5f)).isEqualTo(500f)
assertThat(restCapStart).isEqualTo(500f)
}

@Test
fun `the wave stops the gap short of the thumb in the middle and at the end`() {
val withGap = { fraction: Float -> WavyTrackGeometry.waveEnd(width, fraction, thumb, 12f, stroke) + stroke / 2f }
assertThat(withGap(0.5f)).isEqualTo(500f - thumb / 2f - 12f)
assertThat(withGap(1f)).isEqualTo(1000f - thumb / 2f - 12f)
assertThat(capEnd(0.5f)).isEqualTo(thumbLeadingEdge(0.5f))
}

@Test
fun `the rest of the track starts past the thumb's trailing edge`() {
val restCapStart = WavyTrackGeometry.restStart(width, 0.5f, thumb, gap, stroke) - stroke / 2f
assertThat(restCapStart).isEqualTo(500f + thumb / 2f)
fun `with a gap the rest of the track starts past the thumb's trailing edge`() {
val restCapStart = WavyTrackGeometry.restStart(width, 0.5f, thumb, 12f, stroke) - stroke / 2f
assertThat(restCapStart).isEqualTo(500f + thumb / 2f + 12f)
assertThat(WavyTrackGeometry.restStart(width, 1f, thumb, gap, stroke)).isGreaterThan(WavyTrackGeometry.trackEnd(width, stroke))
}

Expand Down
Loading