Skip to content

Commit

Permalink
experimenting with drag-only behavior in drag mode (have to grab a ci…
Browse files Browse the repository at this point in the history
…rcle to drag it)
  • Loading branch information
pier-bezuhoff committed Jan 25, 2024
1 parent fec4d82 commit 0e77c24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ Built with [Compose Multiplatform](https://github.com/JetBrains/compose-multipla
- [x] Web (via WASM; doesn't work on mobile because of the [panning issue](https://github.com/JetBrains/compose-multiplatform/issues/3491))
- [ ] macOS/iOS if ever get an Apple dev account (have to notarize/staple binaries)

## Installation
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/pier-bezuhoff/Dodeclusters/build.yml?branch=master&event=push)](https://github.com/pier-bezuhoff/Dodeclusters/actions)
[Deployed here](https://pier-bezuhoff.github.io/Dodeclusters/) from the `github-pages` branch
[Live deployed here](https://pier-bezuhoff.github.io/Dodeclusters/) from the `github-pages` branch
Binaries for Linux, Window and Android are stored [here](https://drive.google.com/drive/folders/1abGxbUhnnr4mGyZERKv4ePH--us66Wd4?usp=drive_link).


## Roadmap:
Expand Down
1 change: 0 additions & 1 deletion composeApp/src/commonMain/kotlin/ui/EditClusterScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ fun EditClusterContent(
color = clusterPartColor,
alpha = clusterPathAlpha
)
// println("draw parts")
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions composeApp/src/commonMain/kotlin/ui/EditClusterViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class EditClusterViewModel(
fun loadFromJSON(json: String) {
try {
val cluster = Json.decodeFromString(Cluster.serializer(), json)
translation.value = Offset.Zero
selection.clear()
parts.clear()
circles.clear()
Expand Down Expand Up @@ -376,20 +377,23 @@ class EditClusterViewModel(
}
}

fun onDown(position: Offset) {
fun onDown(visiblePosition: Offset) {
// no need for onUp since all actions occur after onDown
handleIsDown.value = when (val h = handle.value) {
is Handle.Radius -> {
val circle = circles[h.ix]
val right = circle.offset + Offset(circle.radius.toFloat(), 0f)
selectPoint(listOf(right), position) != null
selectPoint(listOf(right), visiblePosition) != null
}
is Handle.Scale -> {
val topRight = getSelectionRect().topRight
selectPoint(listOf(topRight), position) != null
selectPoint(listOf(topRight), visiblePosition) != null
}
else -> false // other handles are multiselect's rotate
}
// NOTE: this enables drag-only behavior, disallows moving circles without grabbing them
if (DRAG_ONLY && !handleIsDown.value && selectionMode.value == SelectionMode.Drag)
reselectCircleAt(visiblePosition)
}

// MAYBE: handle key arrows as panning
Expand Down Expand Up @@ -547,6 +551,9 @@ class EditClusterViewModel(
}

companion object {
/** In drag mode: disallows moving around things that are selected but not grabbed,
* but enables simple drag&drop behavior that is other only available after long press */
const val DRAG_ONLY = true
const val SELECTION_EPSILON = 20f
const val HISTORY_SIZE = 100

Expand Down Expand Up @@ -581,6 +588,7 @@ sealed class Handle(open val ixs: List<Int>) {
data class Radius(val ix: Int): Handle(listOf(ix))
data class Scale(override val ixs: List<Int>): Handle(ixs)
// data class Rotation(override val ixs: List<Int>): Handle(ixs)
// 'delete' handle in m-select
}

/** params for copy/delete animations */
Expand Down

0 comments on commit 0e77c24

Please sign in to comment.