From 85f9209fb31ae276cec985f58fcfe4136b03d54a Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Tue, 19 Mar 2024 16:16:58 +0100 Subject: [PATCH] Allow vertically aligning checkbox and radio button rows GitOrigin-RevId: 39f4b3d06ea95151cf6d29d0523173e4b7c12dd2 --- .../org/jetbrains/jewel/ui/component/Checkbox.kt | 15 ++++++++++++++- .../jetbrains/jewel/ui/component/RadioButton.kt | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Checkbox.kt b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Checkbox.kt index c8f927e124a4..d0b7a1b478ac 100644 --- a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Checkbox.kt +++ b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Checkbox.kt @@ -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) diff --git a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt index 8aa2f12b2b85..7a762dcf8ce1 100644 --- a/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt +++ b/platform/jewel/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/RadioButton.kt @@ -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)