Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fancy drag and drop for cell state #2280

Merged
merged 2 commits into from
Dec 28, 2024
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
Expand Up @@ -23,11 +23,11 @@
/**
* A finite rectangular region of a cell universe.
*
* This is represented by an [IntRect], with the [IntRect.topLeft] being the top-left most point (inclusive), and
* [IntRect.bottomRight] being the bottom-right most point (exclusive).
* This is represented by an [IntRect] [intRect], with the [IntRect.topLeft] being the top-left most point (inclusive),
* and [IntRect.bottomRight] being the bottom-right most point (exclusive).
*/
@JvmInline
value class CellWindow(private val intRect: IntRect) {
value class CellWindow(val intRect: IntRect) {

Check warning on line 30 in algorithm/src/jvmMain/kotlin/com/alexvanyo/composelife/model/CellWindow.kt

View check run for this annotation

Codecov / codecov/patch

algorithm/src/jvmMain/kotlin/com/alexvanyo/composelife/model/CellWindow.kt#L30

Added line #L30 was not covered by tests

init {
require(intRect.top <= intRect.bottom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.LayoutDirection

operator fun Rect.times(scale: Float): Rect =
Rect(
topLeft = topLeft * scale,
bottomRight = bottomRight * scale,
)

Check warning on line 30 in geometry/src/jbMain/kotlin/com/alexvanyo/composelife/geometry/RectExtensions.kt

View check run for this annotation

Codecov / codecov/patch

geometry/src/jbMain/kotlin/com/alexvanyo/composelife/geometry/RectExtensions.kt#L27-L30

Added lines #L27 - L30 were not covered by tests

operator fun Rect.div(scale: Float): Rect =
Rect(
topLeft = topLeft / scale,
bottomRight = bottomRight / scale,
)

Check warning on line 36 in geometry/src/jbMain/kotlin/com/alexvanyo/composelife/geometry/RectExtensions.kt

View check run for this annotation

Codecov / codecov/patch

geometry/src/jbMain/kotlin/com/alexvanyo/composelife/geometry/RectExtensions.kt#L33-L36

Added lines #L33 - L36 were not covered by tests

fun Rect.topStart(layoutDirection: LayoutDirection): Offset = when (layoutDirection) {
LayoutDirection.Ltr -> topLeft
LayoutDirection.Rtl -> topRight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.alexvanyo.composelife.ui.app.createComponent
import com.alexvanyo.composelife.ui.cells.CellWindowInjectEntryPoint
import com.alexvanyo.composelife.ui.cells.CellWindowLocalEntryPoint
import com.alexvanyo.composelife.ui.cells.cellStateDragAndDropTarget
import com.alexvanyo.composelife.ui.cells.rememberMutableCellStateDropStateHolder
import kotlinx.coroutines.test.runCurrent
import org.junit.runner.RunWith
import kotlin.test.Test
Expand Down Expand Up @@ -97,9 +98,11 @@ class LoadedCellStatePreviewTests : BaseUiInjectTest<TestComposeLifeApplicationC
Spacer(
modifier = Modifier
.testTag("TestDropTarget")
.cellStateDragAndDropTarget {
droppedCellState = it
}
.cellStateDragAndDropTarget(
rememberMutableCellStateDropStateHolder { _, cellState ->
droppedCellState = cellState
},
)
.size(100.dp)
.background(Color.Blue),
)
Expand All @@ -125,8 +128,8 @@ class LoadedCellStatePreviewTests : BaseUiInjectTest<TestComposeLifeApplicationC
downTime,
downTime,
MotionEvent.ACTION_DOWN,
loadedCellStatePreviewCenter.x.toFloat(),
loadedCellStatePreviewCenter.y.toFloat(),
loadedCellStatePreviewCenter.x,
loadedCellStatePreviewCenter.y,
0,
).apply {
source = InputDevice.SOURCE_TOUCHSCREEN
Expand All @@ -141,8 +144,8 @@ class LoadedCellStatePreviewTests : BaseUiInjectTest<TestComposeLifeApplicationC
downTime,
SystemClock.uptimeMillis(),
MotionEvent.ACTION_MOVE,
testDropTargetCenter.x.toFloat(),
testDropTargetCenter.y.toFloat(),
testDropTargetCenter.x,
testDropTargetCenter.y,
0,
).apply {
source = InputDevice.SOURCE_TOUCHSCREEN
Expand All @@ -154,8 +157,8 @@ class LoadedCellStatePreviewTests : BaseUiInjectTest<TestComposeLifeApplicationC
downTime,
SystemClock.uptimeMillis(),
MotionEvent.ACTION_UP,
testDropTargetCenter.x.toFloat(),
testDropTargetCenter.y.toFloat(),
testDropTargetCenter.x,
testDropTargetCenter.y,
0,
).apply {
source = InputDevice.SOURCE_TOUCHSCREEN
Expand Down
Loading
Loading