MBegemot
06/27/2021, 5:48 PM@Composable
fun dragablesquare(pTP: PlayTextParams, children: @Composable () -> Unit){
var offsetX by remember{ mutableStateOf(0f)}
Box(Modifier
.offset { IntOffset(offsetX.roundToInt(), 0) }
.draggable(
enabled = true,
orientation = Orientation.Horizontal,
state = rememberDraggableState { delta ->
offsetX += delta
},
onDragStopped = {
if(offsetX>0){ if(pTP.canIscrollOne(PlayTextParams.scroll.FORWARD)) pTP.setIndex(pTP.aIndex+1) }
else {
if(pTP.canIscrollOne(PlayTextParams.scroll.BACK))
pTP.setIndex(pTP.aIndex-1)
}
offsetX=0f
},
onDragStarted = { }
)
){
children()
}
}
Sorry for the bad formatting, but it's so crazy simple