This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8706306
commit b4049c0
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
app/src/main/kotlin/com/intelligentbackpack/app/ui/shape/CutOutShape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.intelligentbackpack.app.ui.shape | ||
|
||
import androidx.compose.ui.geometry.CornerRadius | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.geometry.Rect | ||
import androidx.compose.ui.geometry.RoundRect | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.Outline | ||
import androidx.compose.ui.graphics.Path | ||
import androidx.compose.ui.graphics.PathOperation | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.LayoutDirection | ||
|
||
class CutOutShape : Shape { | ||
override fun createOutline( | ||
size: Size, | ||
layoutDirection: LayoutDirection, | ||
density: Density | ||
): Outline { | ||
val outlinePath = Path() | ||
outlinePath.addRect(Rect(Offset(0f, 0f), size)) | ||
|
||
val cutoutHeight = size.height * 0.3f | ||
val cutoutWidth = size.width * 0.75f | ||
val center = Offset(size.width / 2f, size.height / 2f) | ||
|
||
val cutoutPath = Path() | ||
cutoutPath.addRoundRect( | ||
RoundRect( | ||
Rect( | ||
topLeft = center - Offset( | ||
cutoutWidth / 2f, | ||
cutoutHeight / 2f | ||
), | ||
bottomRight = center + Offset( | ||
cutoutWidth / 2f, | ||
cutoutHeight / 2f | ||
) | ||
), | ||
cornerRadius = CornerRadius(16f, 16f) | ||
) | ||
) | ||
|
||
val finalPath = Path.combine( | ||
PathOperation.Difference, | ||
outlinePath, | ||
cutoutPath | ||
) | ||
|
||
return Outline.Generic(finalPath) | ||
} | ||
} |