mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-07 19:14:12 +08:00
refactor: merge PaddingValues to ComponentPadding
This commit is contained in:
@@ -29,7 +29,6 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -52,6 +51,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.LocalTypography
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.resources.Icons
|
||||
import com.highcapable.flexiui.resources.icon.ArrowNaviUp
|
||||
import com.highcapable.flexiui.resources.icon.FinishClose
|
||||
@@ -65,7 +65,7 @@ data class ActionBarColors(
|
||||
|
||||
@Immutable
|
||||
data class ActionBarStyle(
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val contentSpacing: Dp,
|
||||
val titleTextStyle: TextStyle,
|
||||
val subTextStyle: TextStyle,
|
||||
@@ -343,8 +343,8 @@ private fun defaultActionBarColors() = ActionBarColors(
|
||||
private fun defaultActionBarStyle() = ActionBarStyle(
|
||||
padding = when {
|
||||
LocalInSurface.current || LocalInAreaBox.current ->
|
||||
PaddingValues(vertical = LocalSizes.current.spacingPrimary)
|
||||
else -> PaddingValues(LocalSizes.current.spacingPrimary)
|
||||
ComponentPadding(vertical = LocalSizes.current.spacingPrimary)
|
||||
else -> ComponentPadding(LocalSizes.current.spacingPrimary)
|
||||
},
|
||||
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||
titleTextStyle = when (LocalActionBarType.current) {
|
||||
|
@@ -30,7 +30,6 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -53,11 +52,12 @@ import com.highcapable.flexiui.DefaultShapes
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.borderOrNot
|
||||
|
||||
@Immutable
|
||||
data class AreaBoxStyle(
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val shape: Shape,
|
||||
val border: BorderStroke,
|
||||
val shadowSize: Dp
|
||||
@@ -181,7 +181,7 @@ internal fun withAreaBoxShape(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultAreaBoxStyle() = AreaBoxStyle(
|
||||
padding = PaddingValues(LocalSizes.current.spacingPrimary),
|
||||
padding = ComponentPadding(LocalSizes.current.spacingPrimary),
|
||||
shape = LocalAreaBoxShape.current,
|
||||
border = defaultAreaBoxBorder(),
|
||||
shadowSize = DefaultAreaBoxShadowSize
|
||||
|
@@ -27,7 +27,6 @@ import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -47,6 +46,7 @@ import androidx.compose.ui.semantics.Role
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.borderOrNot
|
||||
import com.highcapable.flexiui.extension.orElse
|
||||
import com.highcapable.flexiui.extension.status
|
||||
@@ -64,7 +64,7 @@ data class ButtonColors(
|
||||
@Immutable
|
||||
data class ButtonStyle(
|
||||
val rippleStyle: RippleStyle,
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val shape: Shape,
|
||||
val border: BorderStroke
|
||||
)
|
||||
@@ -243,7 +243,7 @@ private fun defaultButtonColors() =
|
||||
@ReadOnlyComposable
|
||||
private fun defaultButtonStyle() = ButtonStyle(
|
||||
rippleStyle = defaultButtonRippleStyle(),
|
||||
padding = PaddingValues(
|
||||
padding = ComponentPadding(
|
||||
horizontal = LocalSizes.current.spacingPrimary,
|
||||
vertical = LocalSizes.current.spacingSecondary
|
||||
),
|
||||
@@ -270,7 +270,7 @@ private fun defaultIconButtonColors() = ButtonColors(
|
||||
@ReadOnlyComposable
|
||||
private fun defaultIconButtonStyle() = ButtonStyle(
|
||||
rippleStyle = defaultIconButtonRippleStyle(),
|
||||
padding = PaddingValues(),
|
||||
padding = ComponentPadding(),
|
||||
shape = LocalShapes.current.tertiary,
|
||||
border = defaultButtonBorder()
|
||||
)
|
||||
|
@@ -46,7 +46,6 @@ import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.BoxWithConstraintsScope
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -106,10 +105,8 @@ import androidx.compose.ui.window.PopupProperties
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.borderOrNot
|
||||
import com.highcapable.flexiui.extension.calculateEnd
|
||||
import com.highcapable.flexiui.extension.calculateStart
|
||||
import com.highcapable.flexiui.extension.horizontal
|
||||
import com.highcapable.flexiui.extension.orElse
|
||||
import com.highcapable.flexiui.extension.solidColor
|
||||
import com.highcapable.flexiui.extension.status
|
||||
@@ -138,7 +135,7 @@ data class DropdownMenuColors(
|
||||
|
||||
@Immutable
|
||||
data class DropdownListStyle(
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val shape: Shape,
|
||||
val endIconSize: Dp,
|
||||
val borderInactive: BorderStroke,
|
||||
@@ -227,7 +224,7 @@ fun DropdownList(
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onExpandedChange(false) },
|
||||
offset = DpOffset(-style.padding.calculateStart(), style.padding.calculateEnd()),
|
||||
offset = DpOffset(-style.padding.start, style.padding.end),
|
||||
modifier = Modifier.width(menuMaxWidth).heightIn(max = menuMaxHeight),
|
||||
colors = menuColors,
|
||||
style = menuStyle,
|
||||
@@ -568,7 +565,7 @@ private fun defaultDropdownMenuColors() = DropdownMenuColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultDropdownListStyle() = DropdownListStyle(
|
||||
padding = PaddingValues(LocalSizes.current.spacingSecondary),
|
||||
padding = ComponentPadding(LocalSizes.current.spacingSecondary),
|
||||
shape = withAreaBoxShape(),
|
||||
endIconSize = LocalSizes.current.iconSizeTertiary,
|
||||
borderInactive = defaultDropdownListInactiveBorder(),
|
||||
@@ -581,11 +578,11 @@ private fun defaultDropdownMenuStyle() = DropdownMenuStyle(
|
||||
inTransitionDuration = DefaultInTransitionDuration,
|
||||
outTransitionDuration = DefaultOutTransitionDuration,
|
||||
contentStyle = AreaBox.style.copy(
|
||||
padding = PaddingValues(horizontal = DefaultMenuContentPadding),
|
||||
padding = ComponentPadding(horizontal = DefaultMenuContentPadding),
|
||||
shape = LocalShapes.current.secondary
|
||||
),
|
||||
borderStyle = AreaBox.style.copy(
|
||||
padding = PaddingValues(LocalSizes.current.spacingTertiary),
|
||||
padding = ComponentPadding(LocalSizes.current.spacingTertiary),
|
||||
shadowSize = LocalSizes.current.zoomSizeTertiary,
|
||||
shape = LocalShapes.current.primary
|
||||
)
|
||||
|
@@ -57,6 +57,7 @@ import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.orElse
|
||||
import com.highcapable.flexiui.extension.status
|
||||
import com.highcapable.flexiui.interaction.Interaction
|
||||
@@ -74,7 +75,7 @@ data class NavigationColors(
|
||||
data class NavigationStyle(
|
||||
val boxStyle: AreaBoxStyle,
|
||||
val contentSpacing: Dp,
|
||||
val contentPadding: PaddingValues,
|
||||
val contentPadding: ComponentPadding,
|
||||
val contentShape: Shape
|
||||
)
|
||||
|
||||
@@ -248,7 +249,7 @@ private fun defaultNavigationColors() = NavigationColors(
|
||||
private fun defaultNavigationStyle() = NavigationStyle(
|
||||
boxStyle = AreaBox.style,
|
||||
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||
contentPadding = PaddingValues(
|
||||
contentPadding = ComponentPadding(
|
||||
horizontal = LocalSizes.current.spacingPrimary,
|
||||
vertical = LocalSizes.current.spacingSecondary
|
||||
),
|
||||
|
@@ -26,7 +26,6 @@ package com.highcapable.flexiui.component
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.displayCutoutPadding
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -34,16 +33,14 @@ import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.highcapable.flexiui.extension.bottom
|
||||
import com.highcapable.flexiui.extension.calculateEnd
|
||||
import com.highcapable.flexiui.extension.calculateStart
|
||||
import com.highcapable.flexiui.extension.top
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
|
||||
@Composable
|
||||
fun Scaffold(
|
||||
modifier: Modifier = Modifier,
|
||||
colors: SurfaceColors = Surface.colors,
|
||||
padding: PaddingValues = Surface.padding,
|
||||
padding: ComponentPadding = Surface.padding,
|
||||
fitsSystemBars: Boolean = true,
|
||||
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
@@ -52,15 +49,8 @@ fun Scaffold(
|
||||
navigation: @Composable () -> Unit = {},
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val outBoxPadding = PaddingValues(
|
||||
start = padding.calculateStart(),
|
||||
end = padding.calculateEnd(),
|
||||
bottom = padding.bottom
|
||||
)
|
||||
val inBoxPadding = PaddingValues(
|
||||
top = padding.top,
|
||||
bottom = padding.bottom
|
||||
)
|
||||
val outBoxPadding = padding.copy(top = 0.dp)
|
||||
val inBoxPadding = padding.copy(start = 0.dp, end = 0.dp)
|
||||
Surface(
|
||||
modifier = if (fitsSystemBars)
|
||||
Modifier.systemBarsPadding()
|
||||
|
@@ -26,7 +26,6 @@ package com.highcapable.flexiui.component
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
@@ -39,6 +38,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.debugInspectorInfo
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
|
||||
@Immutable
|
||||
data class SurfaceColors(
|
||||
@@ -51,7 +51,7 @@ fun Surface(
|
||||
modifier: Modifier = Modifier,
|
||||
initializer: @Composable Modifier.() -> Modifier = { Modifier },
|
||||
colors: SurfaceColors = Surface.colors,
|
||||
padding: PaddingValues = Surface.padding,
|
||||
padding: ComponentPadding = Surface.padding,
|
||||
content: @Composable BoxScope.() -> Unit
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
@@ -65,7 +65,7 @@ fun Surface(
|
||||
|
||||
private fun Modifier.surface(
|
||||
colors: SurfaceColors,
|
||||
padding: PaddingValues,
|
||||
padding: ComponentPadding,
|
||||
then: Modifier,
|
||||
initializer: @Composable Modifier.() -> Modifier
|
||||
) = composed(
|
||||
@@ -86,7 +86,7 @@ object Surface {
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = defaultSurfaceColors()
|
||||
val padding: PaddingValues
|
||||
val padding: ComponentPadding
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = defaultSurfacePadding()
|
||||
@@ -103,4 +103,4 @@ private fun defaultSurfaceColors() = SurfaceColors(
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultSurfacePadding() = PaddingValues(LocalSizes.current.spacingPrimary)
|
||||
private fun defaultSurfacePadding() = ComponentPadding(LocalSizes.current.spacingPrimary)
|
@@ -33,7 +33,6 @@ import androidx.compose.foundation.gestures.rememberDraggableState
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -62,8 +61,8 @@ import androidx.compose.ui.unit.dp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.borderOrNot
|
||||
import com.highcapable.flexiui.extension.horizontal
|
||||
import com.highcapable.flexiui.extension.status
|
||||
import com.highcapable.flexiui.interaction.clickable
|
||||
import kotlin.math.roundToInt
|
||||
@@ -77,7 +76,7 @@ data class SwitchColors(
|
||||
|
||||
@Immutable
|
||||
data class SwitchStyle(
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val contentSpacing: Dp,
|
||||
val thumbRadius: Dp,
|
||||
val thumbGain: Float,
|
||||
@@ -216,7 +215,7 @@ private fun defaultSwitchColors() = SwitchColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultSwitchStyle() = SwitchStyle(
|
||||
padding = PaddingValues(horizontal = DefaultSwitchPadding),
|
||||
padding = ComponentPadding(horizontal = DefaultSwitchPadding),
|
||||
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||
thumbRadius = DefaultThumbRadius,
|
||||
thumbGain = DefaultThumbGain,
|
||||
|
@@ -73,7 +73,7 @@ import androidx.compose.ui.unit.lerp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.horizontal
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.orElse
|
||||
import com.highcapable.flexiui.extension.status
|
||||
import com.highcapable.flexiui.interaction.rippleClickable
|
||||
@@ -89,7 +89,7 @@ data class TabColors(
|
||||
|
||||
@Immutable
|
||||
data class TabStyle(
|
||||
val contentPadding: PaddingValues,
|
||||
val contentPadding: ComponentPadding,
|
||||
val contentShape: Shape,
|
||||
val indicatorWidth: Dp,
|
||||
val indicatorHeight: Dp,
|
||||
@@ -445,7 +445,7 @@ private fun defaultTabColors() = TabColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultTabStyle() = TabStyle(
|
||||
contentPadding = PaddingValues(
|
||||
contentPadding = ComponentPadding(
|
||||
horizontal = LocalSizes.current.spacingPrimary,
|
||||
vertical = LocalSizes.current.spacingSecondary
|
||||
),
|
||||
|
@@ -37,7 +37,6 @@ import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -88,9 +87,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.PopupProperties
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
import com.highcapable.flexiui.extension.ComponentPadding
|
||||
import com.highcapable.flexiui.extension.borderOrNot
|
||||
import com.highcapable.flexiui.extension.calculateEnd
|
||||
import com.highcapable.flexiui.extension.calculateStart
|
||||
import com.highcapable.flexiui.extension.orElse
|
||||
import com.highcapable.flexiui.extension.solidColor
|
||||
import com.highcapable.flexiui.extension.status
|
||||
@@ -122,7 +120,7 @@ data class AutoCompleteBoxColors(
|
||||
@Immutable
|
||||
data class TextFieldStyle(
|
||||
val textStyle: TextStyle,
|
||||
val padding: PaddingValues,
|
||||
val padding: ComponentPadding,
|
||||
val shape: Shape,
|
||||
val borderInactive: BorderStroke,
|
||||
val borderActive: BorderStroke,
|
||||
@@ -742,8 +740,8 @@ private fun Modifier.textFieldPadding(
|
||||
) = composed {
|
||||
when {
|
||||
!fitStart && !fitEnd -> padding(style.padding)
|
||||
fitStart -> padding(start = style.padding.calculateStart())
|
||||
fitEnd -> padding(end = style.padding.calculateEnd())
|
||||
fitStart -> padding(start = style.padding.start)
|
||||
fitEnd -> padding(end = style.padding.end)
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
@@ -784,7 +782,7 @@ private fun defaultTextFieldColors() = TextFieldColors(
|
||||
@ReadOnlyComposable
|
||||
private fun defaultTextFieldStyle() = TextFieldStyle(
|
||||
textStyle = LocalTextStyle.current,
|
||||
padding = PaddingValues(LocalSizes.current.spacingSecondary),
|
||||
padding = ComponentPadding(LocalSizes.current.spacingSecondary),
|
||||
shape = withAreaBoxShape(),
|
||||
borderInactive = defaultTextFieldInactiveBorder(),
|
||||
borderActive = defaultTextFieldActiveBorder(),
|
||||
@@ -800,4 +798,4 @@ private fun defaultTextFieldInactiveBorder() = BorderStroke(LocalSizes.current.b
|
||||
private fun defaultTextFieldActiveBorder() = BorderStroke(LocalSizes.current.borderSizePrimary, LocalColors.current.themePrimary)
|
||||
|
||||
private val TextDecorIconSize = 24.dp
|
||||
private val TextDecorIconPadding = PaddingValues(2.dp)
|
||||
private val TextDecorIconPadding = ComponentPadding(2.dp)
|
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Flexi UI - A flexible and useful UI component library.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/BetterAndroid/FlexiUI
|
||||
*
|
||||
* Apache License Version 2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is created by fankes on 2023/11/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
package com.highcapable.flexiui.extension
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Stable
|
||||
fun ComponentPadding(all: Dp): ComponentPadding = ComponentPaddingImpl(all, all, all, all)
|
||||
|
||||
@Stable
|
||||
fun ComponentPadding(
|
||||
horizontal: Dp = 0.dp,
|
||||
vertical: Dp = 0.dp
|
||||
): ComponentPadding = ComponentPaddingImpl(horizontal, vertical, horizontal, vertical)
|
||||
|
||||
@Stable
|
||||
fun ComponentPadding(
|
||||
start: Dp = 0.dp,
|
||||
top: Dp = 0.dp,
|
||||
end: Dp = 0.dp,
|
||||
bottom: Dp = 0.dp
|
||||
): ComponentPadding = ComponentPaddingImpl(start, top, end, bottom)
|
||||
|
||||
@Stable
|
||||
interface ComponentPadding : PaddingValues {
|
||||
val start: Dp
|
||||
val top: Dp
|
||||
val end: Dp
|
||||
val bottom: Dp
|
||||
val horizontal: Dp
|
||||
val vertical: Dp
|
||||
|
||||
fun copy(
|
||||
start: Dp = this.start,
|
||||
top: Dp = this.top,
|
||||
end: Dp = this.end,
|
||||
bottom: Dp = this.bottom
|
||||
): ComponentPadding
|
||||
}
|
||||
|
||||
@Immutable
|
||||
private class ComponentPaddingImpl(
|
||||
override val start: Dp,
|
||||
override val top: Dp,
|
||||
override val end: Dp,
|
||||
override val bottom: Dp
|
||||
) : ComponentPadding {
|
||||
|
||||
override val horizontal get() = start + end
|
||||
override val vertical get() = top + bottom
|
||||
|
||||
override fun calculateLeftPadding(layoutDirection: LayoutDirection) =
|
||||
if (layoutDirection == LayoutDirection.Ltr) start else end
|
||||
|
||||
override fun calculateTopPadding() = top
|
||||
|
||||
override fun calculateRightPadding(layoutDirection: LayoutDirection) =
|
||||
if (layoutDirection == LayoutDirection.Ltr) end else start
|
||||
|
||||
override fun calculateBottomPadding() = bottom
|
||||
|
||||
override fun copy(start: Dp, top: Dp, end: Dp, bottom: Dp) = ComponentPadding(start, top, end, bottom)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ComponentPadding) return false
|
||||
return start == other.start &&
|
||||
top == other.top &&
|
||||
end == other.end &&
|
||||
bottom == other.bottom
|
||||
}
|
||||
|
||||
override fun hashCode() =
|
||||
((start.hashCode() * 31 + top.hashCode()) * 31 + end.hashCode()) *
|
||||
31 + bottom.hashCode()
|
||||
|
||||
override fun toString() = "ComponentPadding(start=$start, top=$top, end=$end, bottom=$bottom)"
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Flexi UI - A flexible and useful UI component library.
|
||||
* Copyright (C) 2019-2023 HighCapable
|
||||
* https://github.com/BetterAndroid/FlexiUI
|
||||
*
|
||||
* Apache License Version 2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is created by fankes on 2023/11/27.
|
||||
*/
|
||||
@file:Suppress("unused")
|
||||
|
||||
package com.highcapable.flexiui.extension
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.calculateEndPadding
|
||||
import androidx.compose.foundation.layout.calculateStartPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.left get() = calculateLeftPadding(LayoutDirection.Ltr)
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.top get() = calculateTopPadding()
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.bottom get() = calculateBottomPadding()
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.right get() = calculateRightPadding(LayoutDirection.Ltr)
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.horizontal get() = left + right
|
||||
|
||||
@Stable
|
||||
internal val PaddingValues.vertical get() = top + bottom
|
||||
|
||||
@Composable
|
||||
internal fun PaddingValues.calculateStart() = calculateStartPadding(LocalLayoutDirection.current)
|
||||
|
||||
@Composable
|
||||
internal fun PaddingValues.calculateEnd() = calculateEndPadding(LocalLayoutDirection.current)
|
Reference in New Issue
Block a user