Skip to content

Commit

Permalink
Library: Change padding field to non-null value
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Jun 5, 2020
1 parent e7c516e commit e74303d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
25 changes: 10 additions & 15 deletions neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ class NeumorphShapeDrawable : Drawable {
}

private fun getBoundsInternal(): Rect {
return drawableState.padding?.let { padding ->
return drawableState.padding.let { padding ->
val bounds = super.getBounds()
Rect(
bounds.left + padding.left,
bounds.top + padding.top,
bounds.right - padding.right,
bounds.bottom - padding.bottom
)
} ?: super.getBounds()
}
}

private fun getBoundsAsRectF(): RectF {
Expand All @@ -162,10 +162,7 @@ class NeumorphShapeDrawable : Drawable {
}

fun setPadding(left: Int, top: Int, right: Int, bottom: Int) {
if (drawableState.padding == null) {
drawableState.padding = Rect()
}
drawableState.padding?.set(left, top, right, bottom)
drawableState.padding.set(left, top, right, bottom)
invalidateSelf()
}

Expand Down Expand Up @@ -301,8 +298,8 @@ class NeumorphShapeDrawable : Drawable {
}

private fun calculateOutlinePath(bounds: RectF, path: Path) {
val left = drawableState.padding?.left?.toFloat() ?: 0f
val top = drawableState.padding?.top?.toFloat() ?: 0f
val left = drawableState.padding.left.toFloat()
val top = drawableState.padding.top.toFloat()
val right = left + bounds.width()
val bottom = top + bounds.height()
path.reset()
Expand Down Expand Up @@ -378,7 +375,7 @@ class NeumorphShapeDrawable : Drawable {
val blurProvider: BlurProvider
var inEditMode: Boolean = false

var padding: Rect? = null
var padding: Rect = Rect()
var fillColor: ColorStateList? = null
var strokeColor: ColorStateList? = null
var strokeWidth = 0f
Expand Down Expand Up @@ -406,18 +403,16 @@ class NeumorphShapeDrawable : Drawable {
shapeAppearanceModel = orig.shapeAppearanceModel
blurProvider = orig.blurProvider
inEditMode = orig.inEditMode
padding = Rect(orig.padding)
fillColor = orig.fillColor
strokeColor = orig.strokeColor
strokeWidth = orig.strokeWidth
alpha = orig.alpha
shapeType = orig.shapeType
shadowElevation = orig.shadowElevation
shadowColorLight = orig.shadowColorLight
shadowColorDark = orig.shadowColorDark
fillColor = orig.fillColor
strokeColor = orig.strokeColor
strokeWidth = orig.strokeWidth
paintStyle = orig.paintStyle
if (orig.padding != null) {
padding = Rect(orig.padding)
}
}

override fun newDrawable(): Drawable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ internal class FlatShape(
val left: Float
val top: Float
val padding = drawableState.padding
if (padding != null) {
left = padding.left.toFloat()
top = padding.top.toFloat()
} else {
left = 0f
top = 0f
}
left = padding.left.toFloat()
top = padding.top.toFloat()
lightShadowBitmap?.let {
val offset = -elevation - z
drawBitmap(it, offset + left, offset + top, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ internal class PressedShape(
val left: Float
val top: Float
val padding = drawableState.padding
if (padding != null) {
left = padding.left.toFloat()
top = padding.top.toFloat()
} else {
left = 0f
top = 0f
}
left = padding.left.toFloat()
top = padding.top.toFloat()
drawBitmap(it, left, top, null)
}
}
Expand Down

0 comments on commit e74303d

Please sign in to comment.