From 2fdec494fb1517c160a63175ad13ef3e5762d59a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 19 Jul 2022 10:34:21 +0300 Subject: [PATCH] Use Dp in features --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../kotlin/centre/sciprog/maps/compose/FeatureBuilder.kt | 6 +++--- .../kotlin/centre/sciprog/maps/compose/MapFeature.kt | 6 ++++-- .../kotlin/centre/sciprog/maps/compose/MapViewJvm.kt | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e589..8049c68 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 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 76c635f..9341cd3 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 @@ -3,11 +3,11 @@ package centre.sciprog.maps.compose import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.snapshots.SnapshotStateMap -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp typealias FeatureId = String @@ -71,7 +71,7 @@ fun FeatureBuilder.text( fun FeatureBuilder.image( position: Pair, image: ImageVector, - size: Size = Size(20f, 20f), + size: DpSize = DpSize(20.dp, 20.dp), zoomRange: IntRange = defaultZoomRange, id: FeatureId? = null, ) = addFeature(id, MapVectorImageFeature(position.toCoordinates(), image, size, zoomRange)) 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 0aec9a8..77f721d 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 @@ -9,7 +9,9 @@ import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.dp import centre.sciprog.maps.GeodeticMapCoordinates import centre.sciprog.maps.GmcBox import centre.sciprog.maps.wrapAll @@ -83,7 +85,7 @@ class MapBitmapImageFeature( class MapVectorImageFeature( val position: GeodeticMapCoordinates, val painter: Painter, - val size: Size, + val size: DpSize, zoomRange: IntRange = defaultZoomRange, ) : MapFeature(zoomRange) { override fun getBoundingBox(zoom: Int): GmcBox = GmcBox(position, position) @@ -93,7 +95,7 @@ class MapVectorImageFeature( fun MapVectorImageFeature( position: GeodeticMapCoordinates, image: ImageVector, - size: Size = Size(20f, 20f), + size: DpSize = DpSize(20.dp, 20.dp), zoomRange: IntRange = defaultZoomRange, ): MapVectorImageFeature = MapVectorImageFeature(position, rememberVectorPainter(image), size, zoomRange) 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 355975b..21ae734 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 @@ -9,6 +9,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.PathEffect import androidx.compose.ui.graphics.drawscope.* @@ -221,9 +222,10 @@ actual fun MapView( is MapBitmapImageFeature -> drawImage(feature.image, feature.position.toOffset()) is MapVectorImageFeature -> { val offset = feature.position.toOffset() - translate(offset.x - feature.size.width / 2, offset.y - feature.size.height / 2) { + val size = feature.size.toSize() + translate(offset.x - size.width / 2, offset.y - size.height / 2) { with(feature.painter) { - draw(feature.size) + draw(size) } } }