From 5e548fcc654aab95938e968d59fe00c1b4b8dede Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 19 Jul 2022 10:16:53 +0300 Subject: [PATCH] change logic of drawFeature to draw relative to offset --- demo/src/jvmMain/kotlin/Main.kt | 3 ++- .../kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt | 2 +- .../kotlin/centre/sciprog/maps/compose/MapFeature.kt | 2 +- .../jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/demo/src/jvmMain/kotlin/Main.kt b/demo/src/jvmMain/kotlin/Main.kt index 18594d4..c1654b7 100644 --- a/demo/src/jvmMain/kotlin/Main.kt +++ b/demo/src/jvmMain/kotlin/Main.kt @@ -6,6 +6,7 @@ import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Home import androidx.compose.runtime.* +import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.window.Window @@ -66,7 +67,7 @@ fun App() { custom(position = pointThree) { drawRect( color = Color.Red, - topLeft = it, + topLeft = Offset(-10f, -10f), size = Size(20f, 20f) ) } diff --git a/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt b/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt index 2457de9..76c635f 100644 --- a/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt +++ b/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt @@ -48,7 +48,7 @@ fun FeatureBuilder.custom( position: Pair, zoomRange: IntRange = defaultZoomRange, id: FeatureId? = null, - drawFeature: DrawScope.(Offset) -> Unit, + drawFeature: DrawScope.() -> Unit, ) = addFeature(id, MapDrawFeature(position.toCoordinates(), zoomRange, drawFeature)) fun FeatureBuilder.line( diff --git a/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/MapFeature.kt b/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/MapFeature.kt index e4cb1bc..0aec9a8 100644 --- a/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/MapFeature.kt +++ b/maps-kt-compose/src/commonMain/kotlin/centre/sciprog/maps/compose/MapFeature.kt @@ -36,7 +36,7 @@ class MapFeatureSelector(val selector: (zoom: Int) -> MapFeature) : MapFeature(d class MapDrawFeature( val position: GeodeticMapCoordinates, zoomRange: IntRange = defaultZoomRange, - val drawFeature: DrawScope.(Offset) -> Unit, + val drawFeature: DrawScope.() -> Unit, ) : MapFeature(zoomRange) { override fun getBoundingBox(zoom: Int): GmcBox { //TODO add box computation diff --git a/maps-kt-compose/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt b/maps-kt-compose/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt index 0621513..355975b 100644 --- a/maps-kt-compose/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt +++ b/maps-kt-compose/src/jvmMain/kotlin/centre/sciprog/maps/compose/MapViewJvm.kt @@ -239,7 +239,9 @@ actual fun MapView( } is MapDrawFeature -> { val offset = feature.position.toOffset() - feature.drawFeature(this, offset) + translate (offset.x, offset.y) { + feature.drawFeature(this) + } } is MapFeatureGroup -> { feature.children.values.forEach {