Skip to content

Commit

Permalink
feat: support complex shapes
Browse files Browse the repository at this point in the history
- adds shared HexagonShape
- adds shared TrapezoidShape
- adds custom shapes to LineIcon

Related: Traewelling/line-colors#27

Signed-off-by: The one with the braid <[email protected]>
  • Loading branch information
TheOneWithTheBraid committed Dec 24, 2024
1 parent 52b7337 commit ee46fb7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/src/main/kotlin/de/hbch/traewelling/shared/HexagonShape.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.hbch.traewelling.shared

import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Outline
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Density

/**
* Forms a hexagon shape with symmetric sides
*/
open class HexagonShape(val intent: Float = 0.2f, val peek: Float = 0.5f) : Shape {


override fun createOutline(
size: Size,
layoutDirection: androidx.compose.ui.unit.LayoutDirection,
density: Density
): Outline {
val path = Path().apply {
moveTo(size.width * intent, 0f)
lineTo(size.width * (1 - intent), 0f)
lineTo(size.width, size.height * peek)
lineTo(size.width * (1 - intent), size.height)
lineTo(size.width * intent, size.height)
lineTo(0f, size.height * peek)
close()
}
return Outline.Generic(path)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.hbch.traewelling.shared

/**
* Forms a trapezoid shape with a broad top and a narrow bottom side
*/
open class TrapezoidShape() : HexagonShape(peek = 0f) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import de.hbch.traewelling.api.models.lineIcons.LineIconShape
import de.hbch.traewelling.shared.HexagonShape
import de.hbch.traewelling.shared.LineIcons
import de.hbch.traewelling.shared.SettingsViewModel
import de.hbch.traewelling.shared.TrapezoidShape
import de.hbch.traewelling.theme.LineIconStyle
import de.hbch.traewelling.theme.LocalFont
import de.hbch.traewelling.util.getSwitzerlandLineName
Expand Down Expand Up @@ -54,8 +56,10 @@ fun LineIcon(
}

val shape: Shape = when (lineIcon?.shape) {
LineIconShape.hexagon -> HexagonShape()
LineIconShape.pill -> RoundedCornerShape(percent = 50)
LineIconShape.rectangle_rounded_corner -> RoundedCornerShape(percent = 20)
LineIconShape.trapezoid -> TrapezoidShape()
else -> RectangleShape
}
val borderColor: Color = lineIcon?.getBorderColor() ?: Color.Transparent
Expand Down

0 comments on commit ee46fb7

Please sign in to comment.