mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-07 19:14:12 +08:00
refactor: merge custom paddings to PaddingValues
This commit is contained in:
@@ -30,6 +30,7 @@ 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
|
||||
@@ -55,15 +56,12 @@ import com.highcapable.flexiui.utils.borderOrNot
|
||||
|
||||
@Immutable
|
||||
data class AreaBoxStyle(
|
||||
val paddings: AreaBoxPaddings,
|
||||
val padding: PaddingValues,
|
||||
val shape: Shape,
|
||||
val border: BorderStroke,
|
||||
val shadowSize: Dp
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class AreaBoxPaddings(val start: Dp, val top: Dp, val end: Dp, val bottom: Dp)
|
||||
|
||||
@Composable
|
||||
fun AreaBox(
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -145,12 +143,7 @@ private fun Modifier.areaBox(
|
||||
.background(color, style.shape)
|
||||
.borderOrNot(style.border, style.shape)
|
||||
.then(then)
|
||||
.padding(
|
||||
start = style.paddings.start,
|
||||
top = style.paddings.top,
|
||||
end = style.paddings.end,
|
||||
bottom = style.paddings.bottom
|
||||
)
|
||||
.padding(style.padding)
|
||||
}
|
||||
|
||||
object AreaBox {
|
||||
@@ -173,12 +166,7 @@ internal val DefaultAreaBoxShape: Shape = DefaultShapes.primary
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultAreaBoxStyle() = AreaBoxStyle(
|
||||
paddings = AreaBoxPaddings(
|
||||
start = defaultAreaBoxPadding(),
|
||||
top = defaultAreaBoxPadding(),
|
||||
end = defaultAreaBoxPadding(),
|
||||
bottom = defaultAreaBoxPadding()
|
||||
),
|
||||
padding = PaddingValues(LocalSizes.current.spacingPrimary),
|
||||
shape = LocalShapes.current.primary,
|
||||
border = defaultAreaBoxBorder(),
|
||||
shadowSize = DefaultAreaBoxShadowSize
|
||||
@@ -192,8 +180,4 @@ private fun defaultAreaBoxColor() = LocalColors.current.foregroundPrimary
|
||||
@ReadOnlyComposable
|
||||
private fun defaultAreaBoxBorder() = BorderStroke(LocalSizes.current.borderSizeTertiary, LocalColors.current.textPrimary)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultAreaBoxPadding() = LocalSizes.current.spacingPrimary
|
||||
|
||||
private val DefaultAreaBoxShadowSize = 0.dp
|
@@ -27,6 +27,7 @@ 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
|
||||
@@ -43,8 +44,6 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalShapes
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
@@ -63,14 +62,11 @@ data class ButtonColors(
|
||||
|
||||
@Immutable
|
||||
data class ButtonStyle(
|
||||
val paddings: ButtonPaddings,
|
||||
val padding: PaddingValues,
|
||||
val shape: Shape,
|
||||
val border: BorderStroke
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class ButtonPaddings(val start: Dp, val top: Dp, val end: Dp, val bottom: Dp)
|
||||
|
||||
@Composable
|
||||
fun Button(
|
||||
onClick: () -> Unit,
|
||||
@@ -108,7 +104,7 @@ fun Button(
|
||||
LocalProgressIndicatorColors provides localProgressIndicatorColors
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.buttonPadding(style),
|
||||
modifier = Modifier.padding(style.padding),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
header()
|
||||
@@ -142,7 +138,7 @@ fun IconButton(
|
||||
role = Role.Button,
|
||||
interactionSource = interactionSource,
|
||||
onClick = onClick
|
||||
).buttonPadding(style),
|
||||
).padding(style.padding),
|
||||
contentAlignment = Alignment.Center,
|
||||
) { CompositionLocalProvider(LocalIconTint provides colors.contentColor, content = content) }
|
||||
}
|
||||
@@ -172,7 +168,7 @@ fun IconToggleButton(
|
||||
enabled = enabled,
|
||||
role = Role.Checkbox,
|
||||
interactionSource = interactionSource
|
||||
).buttonPadding(style),
|
||||
).padding(style.padding),
|
||||
contentAlignment = Alignment.Center
|
||||
) { CompositionLocalProvider(LocalIconTint provides colors.contentColor, content = content) }
|
||||
}
|
||||
@@ -190,13 +186,6 @@ private fun Modifier.button(
|
||||
.then(then)
|
||||
}
|
||||
|
||||
private fun Modifier.buttonPadding(style: ButtonStyle) = padding(
|
||||
start = style.paddings.start,
|
||||
top = style.paddings.top,
|
||||
end = style.paddings.end,
|
||||
bottom = style.paddings.bottom
|
||||
)
|
||||
|
||||
object Button {
|
||||
val colors: ButtonColors
|
||||
@Composable
|
||||
@@ -249,11 +238,9 @@ private fun defaultIconButtonColors() = ButtonColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultButtonStyle() = ButtonStyle(
|
||||
paddings = ButtonPaddings(
|
||||
start = LocalSizes.current.spacingPrimary,
|
||||
top = LocalSizes.current.spacingSecondary,
|
||||
end = LocalSizes.current.spacingPrimary,
|
||||
bottom = LocalSizes.current.spacingSecondary
|
||||
padding = PaddingValues(
|
||||
horizontal = LocalSizes.current.spacingPrimary,
|
||||
vertical = LocalSizes.current.spacingSecondary
|
||||
),
|
||||
shape = when (LocalInAreaBox.current) {
|
||||
true -> LocalAreaBoxShape.current
|
||||
@@ -265,7 +252,7 @@ private fun defaultButtonStyle() = ButtonStyle(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultIconButtonStyle() = ButtonStyle(
|
||||
paddings = ButtonPaddings(0.dp, 0.dp, 0.dp, 0.dp),
|
||||
padding = PaddingValues(),
|
||||
shape = CircleShape,
|
||||
border = defaultButtonBorder()
|
||||
)
|
||||
|
@@ -46,6 +46,7 @@ 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
|
||||
@@ -108,6 +109,7 @@ import com.highcapable.flexiui.interaction.rippleClickable
|
||||
import com.highcapable.flexiui.resources.Icons
|
||||
import com.highcapable.flexiui.resources.icon.Dropdown
|
||||
import com.highcapable.flexiui.utils.borderOrNot
|
||||
import com.highcapable.flexiui.utils.horizontal
|
||||
import com.highcapable.flexiui.utils.orElse
|
||||
import com.highcapable.flexiui.utils.solidColor
|
||||
import com.highcapable.flexiui.utils.status
|
||||
@@ -132,7 +134,7 @@ data class DropdownMenuColors(
|
||||
|
||||
@Immutable
|
||||
data class DropdownListStyle(
|
||||
val paddings: DropdownListPaddings,
|
||||
val padding: PaddingValues,
|
||||
val shape: Shape,
|
||||
val endIconSize: Dp,
|
||||
val borderInactive: BorderStroke,
|
||||
@@ -147,9 +149,6 @@ data class DropdownMenuStyle(
|
||||
val borderStyle: AreaBoxStyle
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class DropdownListPaddings(val start: Dp, val top: Dp, val end: Dp, val bottom: Dp)
|
||||
|
||||
@Composable
|
||||
fun DropdownList(
|
||||
expanded: Boolean,
|
||||
@@ -204,7 +203,7 @@ fun DropdownList(
|
||||
}
|
||||
)
|
||||
) {
|
||||
val menuMaxWidth = maxWidth + style.paddings.start + style.paddings.end
|
||||
val menuMaxWidth = maxWidth + style.padding.horizontal
|
||||
// Note: If minWidth is not 0, a constant width is currently set.
|
||||
// At this time, the child layout must be completely filled into the parent layout.
|
||||
val needInflatable = minWidth > 0.dp
|
||||
@@ -427,12 +426,7 @@ private fun Modifier.dropdownList(
|
||||
.background(colors.backgroundColor, style.shape)
|
||||
.borderOrNot(border, style.shape)
|
||||
.then(then)
|
||||
.padding(
|
||||
start = style.paddings.start,
|
||||
top = style.paddings.top,
|
||||
end = style.paddings.end,
|
||||
bottom = style.paddings.bottom
|
||||
)
|
||||
.padding(style.padding)
|
||||
}
|
||||
|
||||
private fun calculateTransformOrigin(parentBounds: IntRect, menuBounds: IntRect): TransformOrigin {
|
||||
@@ -563,12 +557,7 @@ private fun defaultDropdownMenuColors() = DropdownMenuColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultDropdownListStyle() = DropdownListStyle(
|
||||
paddings = DropdownListPaddings(
|
||||
start = defaultDropdownListPadding(),
|
||||
top = defaultDropdownListPadding(),
|
||||
end = defaultDropdownListPadding(),
|
||||
bottom = defaultDropdownListPadding()
|
||||
),
|
||||
padding = PaddingValues(LocalSizes.current.spacingSecondary),
|
||||
shape = when (LocalInAreaBox.current) {
|
||||
true -> LocalAreaBoxShape.current
|
||||
else -> LocalShapes.current.secondary
|
||||
@@ -584,21 +573,11 @@ private fun defaultDropdownMenuStyle() = DropdownMenuStyle(
|
||||
inTransitionDuration = DefaultInTransitionDuration,
|
||||
outTransitionDuration = DefaultOutTransitionDuration,
|
||||
contentStyle = AreaBox.style.copy(
|
||||
paddings = AreaBoxPaddings(
|
||||
start = DefaultMenuContentPadding,
|
||||
top = 0.dp,
|
||||
end = DefaultMenuContentPadding,
|
||||
bottom = 0.dp
|
||||
),
|
||||
padding = PaddingValues(horizontal = DefaultMenuContentPadding),
|
||||
shape = LocalShapes.current.secondary
|
||||
),
|
||||
borderStyle = AreaBox.style.copy(
|
||||
paddings = AreaBoxPaddings(
|
||||
start = defaultDropdownListBorderPadding(),
|
||||
top = defaultDropdownListBorderPadding(),
|
||||
end = defaultDropdownListBorderPadding(),
|
||||
bottom = defaultDropdownListBorderPadding()
|
||||
),
|
||||
padding = PaddingValues(LocalSizes.current.spacingTertiary),
|
||||
shadowSize = LocalSizes.current.zoomSizeTertiary,
|
||||
shape = LocalShapes.current.primary
|
||||
)
|
||||
@@ -612,14 +591,6 @@ private fun defaultDropdownListInactiveBorder() = BorderStroke(LocalSizes.curren
|
||||
@ReadOnlyComposable
|
||||
private fun defaultDropdownListActiveBorder() = BorderStroke(LocalSizes.current.borderSizePrimary, LocalColors.current.themePrimary)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultDropdownListPadding() = LocalSizes.current.spacingSecondary
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultDropdownListBorderPadding() = LocalSizes.current.spacingTertiary
|
||||
|
||||
private val DefaultDropdownListMenuOffset = DpOffset((-10).dp, 10.dp)
|
||||
|
||||
private val DefaultMenuContentPadding = 16.dp
|
||||
|
@@ -26,6 +26,7 @@ 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
|
||||
@@ -34,7 +35,6 @@ import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import com.highcapable.flexiui.LocalColors
|
||||
import com.highcapable.flexiui.LocalSizes
|
||||
|
||||
@@ -46,20 +46,12 @@ data class SurfaceColors(
|
||||
val backgroundColor: Color
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class SurfaceStyle(
|
||||
val paddings: SurfacePaddings
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class SurfacePaddings(val start: Dp, val top: Dp, val end: Dp, val bottom: Dp)
|
||||
|
||||
@Composable
|
||||
fun Surface(
|
||||
modifier: Modifier = Modifier,
|
||||
initializer: Modifier.() -> Modifier = { Modifier },
|
||||
colors: SurfaceColors = Surface.colors,
|
||||
style: SurfaceStyle = Surface.style,
|
||||
padding: PaddingValues = Surface.padding,
|
||||
content: @Composable BoxScope.() -> Unit
|
||||
) {
|
||||
CompositionLocalProvider(
|
||||
@@ -67,24 +59,19 @@ fun Surface(
|
||||
backgroundPrimary = colors.backgroundColor,
|
||||
textPrimary = colors.contentColor
|
||||
)
|
||||
) { Box(Modifier.surface(colors, style, modifier, initializer), content = content) }
|
||||
) { Box(Modifier.surface(colors, padding, modifier, initializer), content = content) }
|
||||
}
|
||||
|
||||
private fun Modifier.surface(
|
||||
colors: SurfaceColors,
|
||||
style: SurfaceStyle,
|
||||
padding: PaddingValues,
|
||||
then: Modifier,
|
||||
initializer: Modifier.() -> Modifier
|
||||
) = composed {
|
||||
initializer()
|
||||
.background(colors.backgroundColor)
|
||||
.then(then)
|
||||
.padding(
|
||||
start = style.paddings.start,
|
||||
top = style.paddings.top,
|
||||
end = style.paddings.end,
|
||||
bottom = style.paddings.bottom
|
||||
)
|
||||
.padding(padding)
|
||||
}
|
||||
|
||||
object Surface {
|
||||
@@ -92,10 +79,10 @@ object Surface {
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = defaultSurfaceColors()
|
||||
val style: SurfaceStyle
|
||||
val padding: PaddingValues
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
get() = defaultSurfaceStyle()
|
||||
get() = defaultSurfacePadding()
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -107,15 +94,4 @@ private fun defaultSurfaceColors() = SurfaceColors(
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultSurfaceStyle() = SurfaceStyle(
|
||||
paddings = SurfacePaddings(
|
||||
start = defaultSurfacePaddings(),
|
||||
top = defaultSurfacePaddings(),
|
||||
end = defaultSurfacePaddings(),
|
||||
bottom = defaultSurfacePaddings()
|
||||
)
|
||||
)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultSurfacePaddings() = LocalSizes.current.spacingPrimary
|
||||
private fun defaultSurfacePadding() = PaddingValues(LocalSizes.current.spacingPrimary)
|
@@ -37,6 +37,7 @@ 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
|
||||
@@ -92,6 +93,8 @@ import com.highcapable.flexiui.resources.icon.Backspace
|
||||
import com.highcapable.flexiui.resources.icon.ViewerClose
|
||||
import com.highcapable.flexiui.resources.icon.ViewerOpen
|
||||
import com.highcapable.flexiui.utils.borderOrNot
|
||||
import com.highcapable.flexiui.utils.calculateEnd
|
||||
import com.highcapable.flexiui.utils.calculateStart
|
||||
import com.highcapable.flexiui.utils.orElse
|
||||
import com.highcapable.flexiui.utils.solidColor
|
||||
import com.highcapable.flexiui.utils.status
|
||||
@@ -116,7 +119,7 @@ data class AutoCompleteBoxColors(
|
||||
|
||||
@Immutable
|
||||
data class TextFieldStyle(
|
||||
val paddings: TextFieldPaddings,
|
||||
val padding: PaddingValues,
|
||||
val shape: Shape,
|
||||
val borderInactive: BorderStroke,
|
||||
val borderActive: BorderStroke,
|
||||
@@ -131,9 +134,6 @@ data class AutoCompleteOptions(
|
||||
val threshold: Int = 2
|
||||
)
|
||||
|
||||
@Immutable
|
||||
data class TextFieldPaddings(val start: Dp, val top: Dp, val end: Dp, val bottom: Dp)
|
||||
|
||||
@Composable
|
||||
fun TextField(
|
||||
value: TextFieldValue,
|
||||
@@ -365,7 +365,7 @@ fun PasswordTextField(
|
||||
if (value.text.isEmpty() && animatedSize == 0.dp) passwordVisible = defaultPasswordVisible
|
||||
IconToggleButton(
|
||||
modifier = Modifier.size(animatedSize).pointerHoverState(TextFieldPointerState.Common),
|
||||
style = IconButton.style.copy(paddings = DefaultDecorIconPaddings),
|
||||
style = IconButton.style.copy(padding = DefaultDecorIconPadding),
|
||||
checked = passwordVisible,
|
||||
onCheckedChange = {
|
||||
passwordVisible = it
|
||||
@@ -492,7 +492,7 @@ fun BackspaceTextField(
|
||||
focusRequester.requestFocus()
|
||||
},
|
||||
modifier = Modifier.width(animatedSize).pointerHoverState(TextFieldPointerState.Common),
|
||||
style = IconButton.style.copy(paddings = DefaultDecorIconPaddings),
|
||||
style = IconButton.style.copy(padding = DefaultDecorIconPadding),
|
||||
enabled = enabled,
|
||||
interactionSource = cInteractionSource
|
||||
) { Icon(imageVector = Icons.Backspace) }
|
||||
@@ -734,14 +734,9 @@ private fun Modifier.textFieldPadding(
|
||||
fitEnd: Boolean = false
|
||||
) = composed {
|
||||
when {
|
||||
!fitStart && !fitEnd -> padding(
|
||||
start = style.paddings.start,
|
||||
top = style.paddings.top,
|
||||
end = style.paddings.end,
|
||||
bottom = style.paddings.bottom
|
||||
)
|
||||
fitStart -> padding(start = style.paddings.start)
|
||||
fitEnd -> padding(end = style.paddings.end)
|
||||
!fitStart && !fitEnd -> padding(style.padding)
|
||||
fitStart -> padding(start = style.padding.calculateStart())
|
||||
fitEnd -> padding(end = style.padding.calculateEnd())
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
@@ -783,12 +778,7 @@ private fun defaultTextFieldColors() = TextFieldColors(
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultTextFieldStyle() = TextFieldStyle(
|
||||
paddings = TextFieldPaddings(
|
||||
start = defaultTextFieldPadding(),
|
||||
top = defaultTextFieldPadding(),
|
||||
end = defaultTextFieldPadding(),
|
||||
bottom = defaultTextFieldPadding()
|
||||
),
|
||||
padding = PaddingValues(LocalSizes.current.spacingSecondary),
|
||||
shape = when (LocalInAreaBox.current) {
|
||||
true -> LocalAreaBoxShape.current
|
||||
else -> LocalShapes.current.secondary
|
||||
@@ -806,9 +796,5 @@ private fun defaultTextFieldInactiveBorder() = BorderStroke(LocalSizes.current.b
|
||||
@ReadOnlyComposable
|
||||
private fun defaultTextFieldActiveBorder() = BorderStroke(LocalSizes.current.borderSizePrimary, LocalColors.current.themePrimary)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultTextFieldPadding() = LocalSizes.current.spacingSecondary
|
||||
|
||||
private val DefaultDecorIconSize = 24.dp
|
||||
private val DefaultDecorIconPaddings = ButtonPaddings(2.dp, 2.dp, 2.dp, 2.dp)
|
||||
private val DefaultDecorIconPadding = PaddingValues(2.dp)
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.utils
|
||||
|
||||
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)
|
@@ -27,6 +27,7 @@ import androidx.compose.foundation.ContextMenuItem
|
||||
import androidx.compose.foundation.ContextMenuRepresentation
|
||||
import androidx.compose.foundation.ContextMenuState
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.sizeIn
|
||||
@@ -207,30 +208,16 @@ internal fun defaultContextMenuColors() = ContextMenuColors(
|
||||
@ReadOnlyComposable
|
||||
internal fun defaultContextMenuStyle() = ContextMenuStyle(
|
||||
contentStyle = LocalContextMenuStyle.current.contentStyle ?: AreaBox.style.copy(
|
||||
paddings = AreaBoxPaddings(
|
||||
start = DefaultMenuContentPadding,
|
||||
top = 0.dp,
|
||||
end = DefaultMenuContentPadding,
|
||||
bottom = 0.dp
|
||||
),
|
||||
padding = PaddingValues(horizontal = DefaultMenuContentPadding),
|
||||
shape = LocalShapes.current.secondary
|
||||
),
|
||||
borderStyle = LocalContextMenuStyle.current.borderStyle ?: AreaBox.style.copy(
|
||||
paddings = AreaBoxPaddings(
|
||||
start = defaultContextMenuBorderPadding(),
|
||||
top = defaultContextMenuBorderPadding(),
|
||||
end = defaultContextMenuBorderPadding(),
|
||||
bottom = defaultContextMenuBorderPadding()
|
||||
),
|
||||
padding = PaddingValues(LocalSizes.current.spacingTertiary),
|
||||
shadowSize = LocalSizes.current.zoomSizeTertiary,
|
||||
shape = LocalShapes.current.primary
|
||||
)
|
||||
)
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
private fun defaultContextMenuBorderPadding() = LocalSizes.current.spacingTertiary
|
||||
|
||||
private val DefaultMenuContentMinWidth = 112.dp
|
||||
private val DefaultMenuContentMaxWidth = 280.dp
|
||||
private val DefaultMenuContentMinHeight = 32.dp
|
||||
|
Reference in New Issue
Block a user