Fix circle clickable radius
This commit is contained in:
parent
1bcae1f362
commit
2ed9d72029
@ -1,9 +1,9 @@
|
|||||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
import androidx.compose.desktop.ui.tooling.preview.Preview
|
import androidx.compose.desktop.ui.tooling.preview.Preview
|
||||||
import androidx.compose.material.Button
|
|
||||||
import androidx.compose.material.CursorDropdownMenu
|
import androidx.compose.material.CursorDropdownMenu
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.TextButton
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||||
import androidx.compose.ui.input.pointer.isSecondaryPressed
|
import androidx.compose.ui.input.pointer.isSecondaryPressed
|
||||||
@ -31,21 +31,6 @@ fun App() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(myPolygon.isNotEmpty()) {
|
|
||||||
featureState.group("polygon") {
|
|
||||||
multiLine(
|
|
||||||
myPolygon + myPolygon.first(),
|
|
||||||
)
|
|
||||||
myPolygon.forEachIndexed { index, xy ->
|
|
||||||
circle(xy, id = "point[$index]").draggable { _, to ->
|
|
||||||
myPolygon[index] = to.focus
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val mapState: XYViewScope = XYViewScope.remember(
|
val mapState: XYViewScope = XYViewScope.remember(
|
||||||
config = ViewConfig<XY>(
|
config = ViewConfig<XY>(
|
||||||
onClick = { event, point ->
|
onClick = { event, point ->
|
||||||
@ -59,8 +44,20 @@ fun App() {
|
|||||||
|
|
||||||
CursorDropdownMenu(clickPoint != null, { clickPoint = null }) {
|
CursorDropdownMenu(clickPoint != null, { clickPoint = null }) {
|
||||||
clickPoint?.let { point ->
|
clickPoint?.let { point ->
|
||||||
Button({
|
TextButton({
|
||||||
myPolygon.add(point)
|
myPolygon.add(point)
|
||||||
|
if (myPolygon.isNotEmpty()) {
|
||||||
|
featureState.group(id = "polygon") {
|
||||||
|
val pointRefs = myPolygon.mapIndexed { index, xy ->
|
||||||
|
circle(xy, id = "point[$index]").draggable { _, to ->
|
||||||
|
myPolygon[index] = to.focus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
draggableMultiLine(
|
||||||
|
pointRefs + pointRefs.first(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
clickPoint = null
|
clickPoint = null
|
||||||
}) {
|
}) {
|
||||||
Text("Create node")
|
Text("Create node")
|
||||||
|
@ -203,11 +203,15 @@ public data class PolygonFeature<T : Any>(
|
|||||||
public data class CircleFeature<T : Any>(
|
public data class CircleFeature<T : Any>(
|
||||||
override val space: CoordinateSpace<T>,
|
override val space: CoordinateSpace<T>,
|
||||||
override val center: T,
|
override val center: T,
|
||||||
public val size: Dp = 5.dp,
|
public val radius: Dp = 5.dp,
|
||||||
override val attributes: Attributes = Attributes.EMPTY,
|
override val attributes: Attributes = Attributes.EMPTY,
|
||||||
) : MarkerFeature<T> {
|
) : MarkerFeature<T> {
|
||||||
override fun getBoundingBox(zoom: Float): Rectangle<T> =
|
override fun getBoundingBox(zoom: Float): Rectangle<T> =
|
||||||
space.Rectangle(center, zoom, DpSize(size, size))
|
space.Rectangle(center, zoom, DpSize(radius * 2, radius * 2))
|
||||||
|
|
||||||
|
override fun contains(viewPoint: ViewPoint<T>): Boolean = with(space) {
|
||||||
|
viewPoint.focus.distanceTo(center, viewPoint.zoom) < radius
|
||||||
|
}
|
||||||
|
|
||||||
override fun withCoordinates(newCoordinates: T): Feature<T> = copy(center = newCoordinates)
|
override fun withCoordinates(newCoordinates: T): Feature<T> = copy(center = newCoordinates)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package center.sciprog.maps.features
|
package center.sciprog.maps.features
|
||||||
|
|
||||||
import center.sciprog.attributes.Attributes
|
import center.sciprog.attributes.Attributes
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
|
|
||||||
public fun <T : Any> FeatureGroup<T>.draggableLine(
|
public fun <T : Any> FeatureGroup<T>.draggableLine(
|
||||||
@ -68,3 +69,14 @@ public fun <T : Any> FeatureGroup<T>.draggableMultiLine(
|
|||||||
|
|
||||||
return drawLines()
|
return drawLines()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmName("draggableMultiLineFromPoints")
|
||||||
|
public fun <T : Any> FeatureGroup<T>.draggableMultiLine(
|
||||||
|
points: List<T>,
|
||||||
|
id: String? = null,
|
||||||
|
): FeatureRef<T, MultiLineFeature<T>> {
|
||||||
|
val pointRefs = points.map {
|
||||||
|
circle(it)
|
||||||
|
}
|
||||||
|
return draggableMultiLine(pointRefs, id)
|
||||||
|
}
|
@ -32,7 +32,7 @@ public fun <T : Any> DrawScope.drawFeature(
|
|||||||
is FeatureSelector -> drawFeature(state, painterCache, feature.selector(state.zoom))
|
is FeatureSelector -> drawFeature(state, painterCache, feature.selector(state.zoom))
|
||||||
is CircleFeature -> drawCircle(
|
is CircleFeature -> drawCircle(
|
||||||
color,
|
color,
|
||||||
feature.size.toPx(),
|
feature.radius.toPx(),
|
||||||
center = feature.center.toOffset()
|
center = feature.center.toOffset()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ fun FeatureStateSnapshot<XY>.generateSvg(
|
|||||||
|
|
||||||
is CircleFeature -> drawCircle(
|
is CircleFeature -> drawCircle(
|
||||||
color,
|
color,
|
||||||
feature.size.toPx(),
|
feature.radius.toPx(),
|
||||||
center = feature.center.toOffset(),
|
center = feature.center.toOffset(),
|
||||||
alpha = alpha
|
alpha = alpha
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user