Created
December 19, 2022 09:07
-
-
Save mori-atsushi/a6942ccbf463adcbdf6833e5148d61a7 to your computer and use it in GitHub Desktop.
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
package com.moriatsushi.compose | |
import androidx.compose.foundation.layout.PaddingValues | |
import androidx.compose.runtime.Stable | |
import androidx.compose.ui.unit.Dp | |
import androidx.compose.ui.unit.LayoutDirection | |
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues { | |
return AddedPaddingValues(this, other) | |
} | |
@Stable | |
private class AddedPaddingValues( | |
private val first: PaddingValues, | |
private val second: PaddingValues, | |
) : PaddingValues { | |
override fun calculateBottomPadding(): Dp { | |
return first.calculateBottomPadding() + | |
second.calculateBottomPadding() | |
} | |
override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp { | |
return first.calculateLeftPadding(layoutDirection) + | |
second.calculateLeftPadding(layoutDirection) | |
} | |
override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp { | |
return first.calculateRightPadding(layoutDirection) + | |
second.calculateRightPadding(layoutDirection) | |
} | |
override fun calculateTopPadding(): Dp { | |
return first.calculateTopPadding() + | |
second.calculateTopPadding() | |
} | |
override fun toString(): String { | |
return "($first + $second)" | |
} | |
override fun equals(other: Any?): Boolean { | |
if (this === other) { | |
return true | |
} | |
if (other !is AddedPaddingValues) { | |
return false | |
} | |
return first == other.first && second == other.second | |
} | |
override fun hashCode(): Int { | |
var result = first.hashCode() | |
result = 31 * result + second.hashCode() | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment