Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fee19b9d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "STL added IntOffset <-> Int to SpaceVectorConverter" into main

parents e6a5b640 ca0e87be
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -132,11 +132,7 @@ internal class MultiPointerDraggableNode(
    var onFirstPointerDown: () -> Unit,
    swipeDetector: SwipeDetector = DefaultSwipeDetector,
    private val dispatcher: NestedScrollDispatcher,
) :
    DelegatingNode(),
    PointerInputModifierNode,
    CompositionLocalConsumerModifierNode,
    SpaceVectorConverter {
) : DelegatingNode(), PointerInputModifierNode, CompositionLocalConsumerModifierNode {
    private val pointerTracker = delegate(SuspendingPointerInputModifierNode { pointerTracker() })
    private val pointerInput = delegate(SuspendingPointerInputModifierNode { pointerInput() })
    private val velocityTracker = VelocityTracker()
@@ -151,13 +147,13 @@ internal class MultiPointerDraggableNode(

    private var converter = SpaceVectorConverter(orientation)

    override fun Offset.toFloat(): Float = with(converter) { this@toFloat.toFloat() }
    fun Offset.toFloat(): Float = with(converter) { this@toFloat.toFloat() }

    override fun Velocity.toFloat(): Float = with(converter) { this@toFloat.toFloat() }
    fun Velocity.toFloat(): Float = with(converter) { this@toFloat.toFloat() }

    override fun Float.toOffset(): Offset = with(converter) { this@toOffset.toOffset() }
    fun Float.toOffset(): Offset = with(converter) { this@toOffset.toOffset() }

    override fun Float.toVelocity(): Velocity = with(converter) { this@toVelocity.toVelocity() }
    fun Float.toVelocity(): Velocity = with(converter) { this@toVelocity.toVelocity() }

    var orientation: Orientation = orientation
        set(value) {
+25 −14
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.compose.ui.util

import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.Velocity

interface SpaceVectorConverter {
@@ -25,9 +26,13 @@ interface SpaceVectorConverter {

    fun Velocity.toFloat(): Float

    fun IntOffset.toInt(): Int

    fun Float.toOffset(): Offset

    fun Float.toVelocity(): Velocity

    fun Int.toIntOffset(): IntOffset
}

fun SpaceVectorConverter(orientation: Orientation) =
@@ -36,24 +41,30 @@ fun SpaceVectorConverter(orientation: Orientation) =
        Orientation.Vertical -> VerticalConverter
    }

private val HorizontalConverter =
    object : SpaceVectorConverter {
private data object HorizontalConverter : SpaceVectorConverter {
    override fun Offset.toFloat() = x

    override fun Velocity.toFloat() = x

    override fun IntOffset.toInt() = x

    override fun Float.toOffset() = Offset(this, 0f)

    override fun Float.toVelocity() = Velocity(this, 0f)

    override fun Int.toIntOffset() = IntOffset(this, 0)
}

private val VerticalConverter =
    object : SpaceVectorConverter {
private data object VerticalConverter : SpaceVectorConverter {
    override fun Offset.toFloat() = y

    override fun Velocity.toFloat() = y

    override fun IntOffset.toInt() = y

    override fun Float.toOffset() = Offset(0f, this)

    override fun Float.toVelocity() = Velocity(0f, this)

    override fun Int.toIntOffset() = IntOffset(0, this)
}