mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-08 11:34:18 +08:00
refactor: merge padding to buttonPadding function in TextField
This commit is contained in:
@@ -125,10 +125,6 @@ fun TextField(
|
|||||||
focused || hovered -> style.borderInactive
|
focused || hovered -> style.borderInactive
|
||||||
else -> style.borderInactive
|
else -> style.borderInactive
|
||||||
}.copy(animatedBorderWidth, SolidColor(animatedBorderColor))
|
}.copy(animatedBorderWidth, SolidColor(animatedBorderColor))
|
||||||
val topPadding = style.topPadding.orElse() ?: style.padding
|
|
||||||
val startPadding = style.startPadding.orElse() ?: style.padding
|
|
||||||
val bottomPadding = style.bottomPadding.orElse() ?: style.padding
|
|
||||||
val endPadding = style.endPadding.orElse() ?: style.padding
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.textField(
|
modifier = Modifier.textField(
|
||||||
colors = colors,
|
colors = colors,
|
||||||
@@ -140,16 +136,8 @@ fun TextField(
|
|||||||
),
|
),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
header?.also { Box(modifier = Modifier.padding(start = startPadding)) { it() } }
|
header?.also { Box(modifier = Modifier.textFieldPadding(style, fitStart = true)) { it() } }
|
||||||
Box(
|
Box(modifier = Modifier.weight(1f, fill = false).textFieldPadding(style)) {
|
||||||
modifier = Modifier.weight(1f, fill = false)
|
|
||||||
.padding(
|
|
||||||
top = topPadding,
|
|
||||||
start = startPadding,
|
|
||||||
bottom = bottomPadding,
|
|
||||||
end = endPadding
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
TextFieldStyle(colors) {
|
TextFieldStyle(colors) {
|
||||||
BasicTextField(
|
BasicTextField(
|
||||||
value = value,
|
value = value,
|
||||||
@@ -177,7 +165,7 @@ fun TextField(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
footer?.also { Box(modifier = Modifier.padding(end = endPadding)) { it() } }
|
footer?.also { Box(modifier = Modifier.textFieldPadding(style, fitEnd = true)) { it() } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +206,22 @@ private fun Modifier.textField(
|
|||||||
.borderOrNot(border, style.shape)
|
.borderOrNot(border, style.shape)
|
||||||
.then(modifier)
|
.then(modifier)
|
||||||
|
|
||||||
|
private fun Modifier.textFieldPadding(
|
||||||
|
style: TextFieldStyle,
|
||||||
|
fitStart: Boolean = false,
|
||||||
|
fitEnd: Boolean = false
|
||||||
|
) = when {
|
||||||
|
!fitStart && !fitEnd -> padding(
|
||||||
|
top = style.topPadding.orElse() ?: style.padding,
|
||||||
|
start = style.startPadding.orElse() ?: style.padding,
|
||||||
|
bottom = style.bottomPadding.orElse() ?: style.padding,
|
||||||
|
end = style.endPadding.orElse() ?: style.padding
|
||||||
|
)
|
||||||
|
fitStart -> padding(start = style.startPadding.orElse() ?: style.padding)
|
||||||
|
fitEnd -> padding(end = style.endPadding.orElse() ?: style.padding)
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
object TextField {
|
object TextField {
|
||||||
val colors: TextFieldColors
|
val colors: TextFieldColors
|
||||||
@Composable
|
@Composable
|
||||||
|
Reference in New Issue
Block a user