-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #575 from kiwicom/border-expand
Rework drawing expanded border
- Loading branch information
Showing
18 changed files
with
146 additions
and
96 deletions.
There are no files selected for viewing
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
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
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
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
45 changes: 45 additions & 0 deletions
45
ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/utils/DrawScopeExtensions.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,45 @@ | ||
package kiwi.orbit.compose.ui.utils | ||
|
||
import androidx.compose.ui.geometry.CornerRadius | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.graphics.BlendMode | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
import androidx.compose.ui.graphics.drawscope.Stroke | ||
import kotlin.math.max | ||
|
||
/** | ||
* Draws round rect, but the redius is defined by the outer radius of the stroke. | ||
*/ | ||
internal fun DrawScope.drawStrokeOutlineRoundRect( | ||
color: Color, | ||
topLeft: Offset, | ||
size: Size, | ||
cornerRadius: CornerRadius, | ||
stroke: Stroke, | ||
alpha: Float = 1.0f, | ||
colorFilter: ColorFilter? = null, | ||
blendMode: BlendMode = DrawScope.DefaultBlendMode, | ||
) { | ||
// Stroked rounded rect with the corner radius | ||
// shrunk by half of the stroke width. This will ensure that the | ||
// outer curvature of the rounded rectangle will have the desired | ||
// corner radius. | ||
drawRoundRect( | ||
color = color, | ||
topLeft = topLeft + Offset(stroke.width / 2f, stroke.width / 2f), | ||
size = Size(size.width - stroke.width, size.height - stroke.width), | ||
cornerRadius = cornerRadius.shrink(stroke.width / 2f), | ||
alpha = alpha, | ||
style = stroke, | ||
colorFilter = colorFilter, | ||
blendMode = blendMode, | ||
) | ||
} | ||
|
||
private fun CornerRadius.shrink(value: Float): CornerRadius = CornerRadius( | ||
max(0f, this.x - value), | ||
max(0f, this.y - value), | ||
) |
17 changes: 17 additions & 0 deletions
17
ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/utils/ExpandedCornerSize.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,17 @@ | ||
package kiwi.orbit.compose.ui.utils | ||
|
||
import androidx.compose.foundation.shape.CornerSize | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.Dp | ||
|
||
internal class ExpandedCornerSize( | ||
private val original: CornerSize, | ||
private val extraSize: Dp, | ||
) : CornerSize { | ||
override fun toPx(shapeSize: Size, density: Density): Float { | ||
val originalSize = original.toPx(shapeSize, density) | ||
if (originalSize == 0f) return originalSize | ||
return originalSize + with(density) { extraSize.toPx() } | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...rc/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkboxField.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...est/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkboxField_big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...st/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkboxField_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkbox_big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...rc/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_checkbox_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_coupon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.