Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 7893369

Browse files
✨ Support complex line shapes (#465)
- adds shared HexagonShape - adds shared TrapezoidShape - adds custom shapes to LineIcon Related: Traewelling/line-colors#27 Signed-off-by: The one with the braid <info@braid.business>
1 parent 52b7337 commit 7893369

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package de.hbch.traewelling.shared
2+
3+
import androidx.compose.ui.geometry.Size
4+
import androidx.compose.ui.graphics.Outline
5+
import androidx.compose.ui.graphics.Path
6+
import androidx.compose.ui.graphics.Shape
7+
import androidx.compose.ui.unit.Density
8+
9+
/**
10+
* Forms a hexagon shape with symmetric sides
11+
*/
12+
open class HexagonShape(val intent: Float = 0.2f, val peek: Float = 0.5f) : Shape {
13+
14+
15+
override fun createOutline(
16+
size: Size,
17+
layoutDirection: androidx.compose.ui.unit.LayoutDirection,
18+
density: Density
19+
): Outline {
20+
val path = Path().apply {
21+
moveTo(size.width * intent, 0f)
22+
lineTo(size.width * (1 - intent), 0f)
23+
lineTo(size.width, size.height * peek)
24+
lineTo(size.width * (1 - intent), size.height)
25+
lineTo(size.width * intent, size.height)
26+
lineTo(0f, size.height * peek)
27+
close()
28+
}
29+
return Outline.Generic(path)
30+
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.hbch.traewelling.shared
2+
3+
/**
4+
* Forms a trapezoid shape with a broad top and a narrow bottom side
5+
*/
6+
open class TrapezoidShape() : HexagonShape(peek = 0f) {
7+
8+
}

app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import androidx.compose.ui.unit.dp
2424
import androidx.lifecycle.ViewModelStoreOwner
2525
import androidx.lifecycle.viewmodel.compose.viewModel
2626
import de.hbch.traewelling.api.models.lineIcons.LineIconShape
27+
import de.hbch.traewelling.shared.HexagonShape
2728
import de.hbch.traewelling.shared.LineIcons
2829
import de.hbch.traewelling.shared.SettingsViewModel
30+
import de.hbch.traewelling.shared.TrapezoidShape
2931
import de.hbch.traewelling.theme.LineIconStyle
3032
import de.hbch.traewelling.theme.LocalFont
3133
import de.hbch.traewelling.util.getSwitzerlandLineName
@@ -54,8 +56,10 @@ fun LineIcon(
5456
}
5557

5658
val shape: Shape = when (lineIcon?.shape) {
59+
LineIconShape.hexagon -> HexagonShape()
5760
LineIconShape.pill -> RoundedCornerShape(percent = 50)
5861
LineIconShape.rectangle_rounded_corner -> RoundedCornerShape(percent = 20)
62+
LineIconShape.trapezoid -> TrapezoidShape()
5963
else -> RectangleShape
6064
}
6165
val borderColor: Color = lineIcon?.getBorderColor() ?: Color.Transparent

0 commit comments

Comments
 (0)