Skip to content

Commit

Permalink
Made CompassButton more customizable (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalgwo authored Jan 17, 2025
1 parent 7d0bd13 commit 1a735b1
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import dev.sargunv.maplibrecompose.compose.CameraState
import dev.sargunv.maplibrecompose.material3.generated.Res
Expand All @@ -42,23 +45,27 @@ public fun CompassButton(
modifier: Modifier = Modifier,
onClick: () -> Unit = {},
colors: ButtonColors = ButtonDefaults.elevatedButtonColors(),
contentDescription: String = "Compass",
contentDescription: String = stringResource(Res.string.compass),
size: Dp = 48.dp,
contentPadding: PaddingValues = PaddingValues(size / 6),
shape: Shape = CircleShape,
needlePainter: Painter = painterResource(Res.drawable.compass_needle),
) {
val coroutineScope = rememberCoroutineScope()
ElevatedButton(
modifier = modifier.size(48.dp).aspectRatio(1f),
modifier = modifier.size(size).aspectRatio(1f),
onClick = {
coroutineScope.launch {
cameraState.animateTo(cameraState.position.copy(bearing = 0.0, tilt = 0.0))
}
onClick()
},
shape = CircleShape,
shape = shape,
colors = colors,
contentPadding = PaddingValues(8.dp),
contentPadding = contentPadding,
) {
Image(
painter = painterResource(Res.drawable.compass_needle),
painter = needlePainter,
contentDescription = contentDescription,
modifier =
Modifier.fillMaxSize()
Expand All @@ -76,6 +83,11 @@ public fun DisappearingCompassButton(
modifier: Modifier = Modifier,
onClick: () -> Unit = {},
colors: ButtonColors = ButtonDefaults.elevatedButtonColors(),
contentDescription: String = stringResource(Res.string.compass),
size: Dp = 48.dp,
contentPadding: PaddingValues = PaddingValues(size / 6),
shape: Shape = CircleShape,
needlePainter: Painter = painterResource(Res.drawable.compass_needle),
visibilityDuration: Duration = 1.seconds,
enterTransition: EnterTransition = fadeIn(),
exitTransition: ExitTransition = fadeOut(),
Expand Down Expand Up @@ -108,7 +120,11 @@ public fun DisappearingCompassButton(
modifier = modifier,
onClick = onClick,
colors = colors,
contentDescription = stringResource(Res.string.compass),
contentDescription = contentDescription,
size = size,
contentPadding = contentPadding,
shape = shape,
needlePainter = needlePainter,
)
}
}

0 comments on commit 1a735b1

Please sign in to comment.