Skip to content

Instantly share code, notes, and snippets.

@delacrixmorgan
Created December 30, 2022 10:26
Show Gist options
  • Save delacrixmorgan/96f66496f441b83ecbe190a86ded088b to your computer and use it in GitHub Desktop.
Save delacrixmorgan/96f66496f441b83ecbe190a86ded088b to your computer and use it in GitHub Desktop.
Compose UI - Outline Button with Lines
val lineThickness = 4F
Modifier
.fillMaxWidth()
.border(
width = lineThickness.dp,
color = Color.Red,
shape = drawOutlineButtonLine(OutlineButtonLine.Top, lineThickness)
)
private fun drawOutlineButtonLine(outlineButtonLine: OutlineButtonLine, lineThickness: Float): Shape {
return GenericShape { size, _ ->
when (outlineButtonLine) {
OutlineButtonLine.Top -> {
// 1) Top-left corner
moveTo(0f, 0f)
// 2) Top-right corner
lineTo(size.width, 0f)
// 3) Top-right corner
lineTo(size.width, 0f + lineThickness)
// 4) Top-left corner
lineTo(0f, 0f + lineThickness)
}
OutlineButtonLine.Bottom -> {
// 1) Bottom-left corner
moveTo(0f, size.height)
// 2) Bottom-right corner
lineTo(size.width, size.height)
// 3) Top-right corner
lineTo(size.width, size.height - lineThickness)
// 4) Top-left corner
lineTo(0f, size.height - lineThickness)
}
}
}
}
enum class OutlineButtonLine {
Top,
Bottom
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment