Allow vertically aligning checkbox and radio button rows

GitOrigin-RevId: 39f4b3d06ea95151cf6d29d0523173e4b7c12dd2
This commit is contained in:
Sebastiano Poggi
2024-03-19 16:16:58 +01:00
committed by intellij-monorepo-bot
parent bbf30af962
commit 85f9209fb3
2 changed files with 22 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ public fun Checkbox(
metrics: CheckboxMetrics = JewelTheme.checkboxStyle.metrics,
icons: CheckboxIcons = JewelTheme.checkboxStyle.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
val state by remember(checked) { mutableStateOf(ToggleableState(checked)) }
CheckboxImpl(
@@ -79,6 +80,7 @@ public fun Checkbox(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = null,
)
}
@@ -95,6 +97,7 @@ public fun TriStateCheckbox(
metrics: CheckboxMetrics = LocalCheckboxStyle.current.metrics,
icons: CheckboxIcons = LocalCheckboxStyle.current.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
CheckboxImpl(
state = state,
@@ -107,6 +110,7 @@ public fun TriStateCheckbox(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = null,
)
}
@@ -124,6 +128,7 @@ public fun TriStateCheckboxRow(
metrics: CheckboxMetrics = LocalCheckboxStyle.current.metrics,
icons: CheckboxIcons = LocalCheckboxStyle.current.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
CheckboxImpl(
state = state,
@@ -136,6 +141,7 @@ public fun TriStateCheckboxRow(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
) {
Text(text)
}
@@ -154,6 +160,7 @@ public fun CheckboxRow(
metrics: CheckboxMetrics = LocalCheckboxStyle.current.metrics,
icons: CheckboxIcons = LocalCheckboxStyle.current.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
val state by remember(checked) { mutableStateOf(ToggleableState(checked)) }
@@ -168,6 +175,7 @@ public fun CheckboxRow(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
) {
Text(text)
}
@@ -185,6 +193,7 @@ public fun CheckboxRow(
metrics: CheckboxMetrics = LocalCheckboxStyle.current.metrics,
icons: CheckboxIcons = LocalCheckboxStyle.current.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
content: @Composable RowScope.() -> Unit,
) {
CheckboxImpl(
@@ -198,6 +207,7 @@ public fun CheckboxRow(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = content,
)
}
@@ -214,6 +224,7 @@ public fun TriStateCheckboxRow(
metrics: CheckboxMetrics = LocalCheckboxStyle.current.metrics,
icons: CheckboxIcons = LocalCheckboxStyle.current.icons,
textStyle: TextStyle = LocalTextStyle.current,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
content: @Composable RowScope.() -> Unit,
) {
CheckboxImpl(
@@ -227,6 +238,7 @@ public fun TriStateCheckboxRow(
metrics = metrics,
icons = icons,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = content,
)
}
@@ -243,6 +255,7 @@ private fun CheckboxImpl(
outline: Outline,
interactionSource: MutableInteractionSource,
textStyle: TextStyle,
verticalAlignment: Alignment.Vertical,
content: (@Composable RowScope.() -> Unit)?,
) {
var checkboxState by remember(interactionSource) {
@@ -313,7 +326,7 @@ private fun CheckboxImpl(
Row(
wrapperModifier,
horizontalArrangement = Arrangement.spacedBy(metrics.iconContentGap),
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = verticalAlignment,
) {
Box(checkboxBoxModifier, contentAlignment = Alignment.TopStart) {
CheckBoxImage(checkboxPainter)

View File

@@ -55,6 +55,7 @@ public fun RadioButton(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
style: RadioButtonStyle = JewelTheme.radioButtonStyle,
textStyle: TextStyle = JewelTheme.defaultTextStyle,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
RadioButtonImpl(
selected = selected,
@@ -65,6 +66,7 @@ public fun RadioButton(
interactionSource = interactionSource,
style = style,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = null,
)
}
@@ -80,6 +82,7 @@ public fun RadioButtonRow(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
style: RadioButtonStyle = JewelTheme.radioButtonStyle,
textStyle: TextStyle = JewelTheme.defaultTextStyle,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
) {
RadioButtonImpl(
selected = selected,
@@ -90,6 +93,7 @@ public fun RadioButtonRow(
interactionSource = interactionSource,
style = style,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
) {
Text(text)
}
@@ -105,6 +109,7 @@ public fun RadioButtonRow(
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
style: RadioButtonStyle = JewelTheme.radioButtonStyle,
textStyle: TextStyle = JewelTheme.defaultTextStyle,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
content: @Composable RowScope.() -> Unit,
) {
RadioButtonImpl(
@@ -116,6 +121,7 @@ public fun RadioButtonRow(
interactionSource = interactionSource,
style = style,
textStyle = textStyle,
verticalAlignment = verticalAlignment,
content = content,
)
}
@@ -130,6 +136,7 @@ private fun RadioButtonImpl(
interactionSource: MutableInteractionSource,
style: RadioButtonStyle,
textStyle: TextStyle,
verticalAlignment: Alignment.Vertical,
content: (@Composable RowScope.() -> Unit)?,
) {
var radioButtonState by remember(interactionSource) {
@@ -197,7 +204,7 @@ private fun RadioButtonImpl(
Row(
wrapperModifier,
horizontalArrangement = Arrangement.spacedBy(metrics.iconContentGap),
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = verticalAlignment,
) {
Box(radioButtonBoxModifier, contentAlignment = Alignment.Center) {
RadioButtonImage(radioButtonPainter)