Skip to content

Commit 3e8e60d

Browse files
committed
refactor: Apply Spotless and reformat WhiskeyCompass
- Improve formatting of the `WhiskeyCompass` composable. - Migrated Spotless plugin to use version catalog alias in build files. - Increased the rendering margin in `WhiskeyCompass` to prevent visual pop-in.
1 parent 162b245 commit 3e8e60d

5 files changed

Lines changed: 46 additions & 22 deletions

File tree

.kotlin/sessions/kotlin-compiler-17720919123303405947.salive

Whitespace-only changes.

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
alias(libs.plugins.spotless) apply false
3+
}

maps3d-compose-demo/src/main/java/com/example/maps3dcomposedemo/widgets/WhiskeyCompass.kt

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ fun WhiskeyCompass(
7979
showCardinalLabels: Boolean = true,
8080
// Added for clarity
8181
cardinalLabelInterval: Int = 45,
82-
cardinalLabelTextStyle: TextStyle = MaterialTheme.typography.labelMedium.copy(fontWeight = FontWeight.Bold, textAlign = TextAlign.Center),
82+
cardinalLabelTextStyle: TextStyle = MaterialTheme.typography.labelMedium.copy(
83+
fontWeight = FontWeight.Bold,
84+
textAlign = TextAlign.Center
85+
),
8386
cardinalLabelVerticalOffset: Dp = 4.dp,
8487

8588
majorTickHeight: Dp = 25.dp,
@@ -139,10 +142,10 @@ fun WhiskeyCompass(
139142
val absoluteDegree = repetitionBaseDegree + degreeInRepetition
140143
val xPos = absoluteDegree * pixelsPerDegree
141144

142-
val visibilityMargin = canvasWidth
143-
if (xPos < -xOffset + canvasWidth + visibilityMargin && xPos > -xOffset - visibilityMargin) {
145+
if (xPos < -xOffset + canvasWidth + canvasWidth && xPos > -xOffset - canvasWidth) {
144146
val isMajorTickEquivalent = degreeInRepetition % 10 == 0
145-
val isMinorTickEquivalent = degreeInRepetition % 5 == 0 && !isMajorTickEquivalent
147+
val isMinorTickEquivalent =
148+
degreeInRepetition % 5 == 0 && !isMajorTickEquivalent
146149

147150
if (isMajorTickEquivalent) {
148151
val tickTopY = tickCenterY - majorTickHeightPx / 2f
@@ -154,8 +157,12 @@ fun WhiskeyCompass(
154157
strokeWidth = majorTickStrokeWidthPx,
155158
)
156159

157-
if (showCardinalLabels && measuredCardinalLabels.containsKey(degreeInRepetition)) {
158-
val measuredText = measuredCardinalLabels.getValue(degreeInRepetition)
160+
if (showCardinalLabels && measuredCardinalLabels.containsKey(
161+
degreeInRepetition
162+
)
163+
) {
164+
val measuredText =
165+
measuredCardinalLabels.getValue(degreeInRepetition)
159166
drawText(
160167
textLayoutResult = measuredText,
161168
topLeft = Offset(
@@ -176,17 +183,16 @@ fun WhiskeyCompass(
176183
}
177184

178185
if (showDegreeLabels && degreeInRepetition % degreeLabelInterval == 0) {
179-
val tickBottomY = tickCenterY + (
180-
if (isMajorTickEquivalent) {
181-
majorTickHeightPx
182-
} else if (isMinorTickEquivalent) {
183-
minorTickHeightPx
184-
} else {
185-
0f
186-
}
187-
) / 2f
186+
val tickBottomY = tickCenterY + (if (isMajorTickEquivalent) {
187+
majorTickHeightPx
188+
} else if (isMinorTickEquivalent) {
189+
minorTickHeightPx
190+
} else {
191+
0f
192+
}) / 2f
188193
val labelText = degreeInRepetition.toString()
189-
val measuredText = textMeasurer.measure(labelText, style = degreeLabelTextStyle)
194+
val measuredText =
195+
textMeasurer.measure(labelText, style = degreeLabelTextStyle)
190196
drawText(
191197
textLayoutResult = measuredText,
192198
topLeft = Offset(
@@ -237,7 +243,11 @@ private fun FlatWhiskeyCompassPreview() {
237243
horizontalAlignment = Alignment.CenterHorizontally,
238244
verticalArrangement = Arrangement.spacedBy(16.dp),
239245
) {
240-
Text("Default Flat Compass Strip", color = Color.White, style = MaterialTheme.typography.titleMedium)
246+
Text(
247+
"Default Flat Compass Strip",
248+
color = Color.White,
249+
style = MaterialTheme.typography.titleMedium
250+
)
241251
WhiskeyCompass(
242252
heading = 45f,
243253
modifier = Modifier.fillMaxWidth(),
@@ -246,7 +256,11 @@ private fun FlatWhiskeyCompassPreview() {
246256
)
247257

248258
Spacer(modifier = Modifier.height(16.dp))
249-
Text("Customized Labels & Ticks", color = Color.White, style = MaterialTheme.typography.titleMedium)
259+
Text(
260+
"Customized Labels & Ticks",
261+
color = Color.White,
262+
style = MaterialTheme.typography.titleMedium
263+
)
250264
WhiskeyCompass(
251265
heading = 123f,
252266
modifier = Modifier.fillMaxWidth(),
@@ -257,7 +271,10 @@ private fun FlatWhiskeyCompassPreview() {
257271
pixelsPerDegree = 12f,
258272
degreeLabelInterval = 10,
259273
degreeLabelTextStyle = MaterialTheme.typography.bodySmall.copy(color = Color(0xFF81D4FA)),
260-
cardinalLabelTextStyle = MaterialTheme.typography.labelLarge.copy(color = Color.White, fontWeight = FontWeight.Bold),
274+
cardinalLabelTextStyle = MaterialTheme.typography.labelLarge.copy(
275+
color = Color.White,
276+
fontWeight = FontWeight.Bold
277+
),
261278
majorTickHeight = 30.dp,
262279
minorTickHeight = 18.dp,
263280
degreeLabelVerticalOffset = 6.dp,
@@ -266,7 +283,11 @@ private fun FlatWhiskeyCompassPreview() {
266283
)
267284

268285
Spacer(modifier = Modifier.height(16.dp))
269-
Text("No Cardinal Labels", color = Color.White, style = MaterialTheme.typography.titleMedium)
286+
Text(
287+
"No Cardinal Labels",
288+
color = Color.White,
289+
style = MaterialTheme.typography.titleMedium
290+
)
270291
WhiskeyCompass(
271292
heading = 210f,
272293
modifier = Modifier.fillMaxWidth(),

maps3d-compose/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ plugins {
1818
alias(libs.plugins.android.library)
1919
alias(libs.plugins.kotlin.android)
2020
alias(libs.plugins.kotlin.compose)
21-
id("com.diffplug.spotless") version "6.25.0"
21+
alias(libs.plugins.spotless)
2222
}
2323

2424
configure<com.diffplug.gradle.spotless.SpotlessExtension> {

snippets/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
alias(libs.plugins.android.library) apply false
2121
alias(libs.plugins.kotlin.compose) apply false
2222
alias(libs.plugins.secrets.gradle.plugin) apply false
23-
id("com.diffplug.spotless") version "6.25.0"
23+
alias(libs.plugins.spotless)
2424
}
2525

2626
subprojects {

0 commit comments

Comments
 (0)