Skip to content

Commit 3ceda9e

Browse files
PM-18388 add hyphens on segmented button labels (#4777)
1 parent 3f1a6e9 commit 3ceda9e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/components/segment/BitwardenSegmentedButton.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package com.x8bit.bitwarden.ui.platform.components.segment
33
import androidx.compose.foundation.BorderStroke
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.IntrinsicSize
67
import androidx.compose.foundation.layout.WindowInsets
78
import androidx.compose.foundation.layout.WindowInsetsSides
89
import androidx.compose.foundation.layout.displayCutout
910
import androidx.compose.foundation.layout.fillMaxWidth
11+
import androidx.compose.foundation.layout.height
1012
import androidx.compose.foundation.layout.navigationBars
1113
import androidx.compose.foundation.layout.only
1214
import androidx.compose.foundation.layout.padding
@@ -24,7 +26,9 @@ import androidx.compose.runtime.setValue
2426
import androidx.compose.ui.Modifier
2527
import androidx.compose.ui.graphics.Color
2628
import androidx.compose.ui.layout.onGloballyPositioned
29+
import androidx.compose.ui.platform.LocalConfiguration
2730
import androidx.compose.ui.platform.LocalDensity
31+
import androidx.compose.ui.text.style.Hyphens
2832
import androidx.compose.ui.unit.Density
2933
import androidx.compose.ui.unit.Dp
3034
import androidx.compose.ui.unit.dp
@@ -34,6 +38,8 @@ import com.x8bit.bitwarden.ui.platform.components.segment.color.bitwardenSegment
3438
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
3539
import kotlinx.collections.immutable.ImmutableList
3640

41+
private const val FONT_SCALE_THRESHOLD = 1.5f
42+
3743
/**
3844
* Displays a Bitwarden styled row of segmented buttons.
3945
*
@@ -82,7 +88,8 @@ fun BitwardenSegmentedButton(
8288
.onGloballyPositioned {
8389
weightedWidth = (it.size.width / options.size).toDp(density)
8490
}
85-
.padding(horizontal = 4.dp),
91+
.padding(horizontal = 2.dp, vertical = 2.dp)
92+
.height(IntrinsicSize.Min),
8693
space = 0.dp,
8794
) {
8895
options.forEachIndexed { index, option ->
@@ -100,6 +107,12 @@ fun SingleChoiceSegmentedButtonRowScope.SegmentedButtonOptionContent(
100107
option: SegmentedButtonState,
101108
modifier: Modifier = Modifier,
102109
) {
110+
val fontScale = LocalConfiguration.current.fontScale
111+
val labelVerticalPadding = if (fontScale > FONT_SCALE_THRESHOLD) {
112+
8.dp
113+
} else {
114+
0.dp
115+
}
103116
SegmentedButton(
104117
enabled = option.isEnabled,
105118
selected = option.isChecked,
@@ -110,7 +123,13 @@ fun SingleChoiceSegmentedButtonRowScope.SegmentedButtonOptionContent(
110123
label = {
111124
Text(
112125
text = option.text,
113-
style = BitwardenTheme.typography.labelLarge,
126+
style = BitwardenTheme.typography.labelLarge.copy(
127+
hyphens = Hyphens.Auto,
128+
),
129+
modifier = Modifier.padding(
130+
vertical = labelVerticalPadding,
131+
horizontal = 4.dp,
132+
),
114133
)
115134
},
116135
icon = {

app/src/main/java/com/x8bit/bitwarden/ui/tools/feature/generator/GeneratorScreen.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ private fun CoachMarkScope<ExploreGeneratorCoachMark>.MainStateOptionsItem(
665665
) {
666666
SegmentedButtonOptionContent(
667667
option = option,
668-
modifier = Modifier.width(weightedWidth),
668+
modifier = Modifier
669+
.fillMaxHeight()
670+
.width(weightedWidth),
669671
)
670672
}
671673
}
@@ -694,7 +696,9 @@ private fun CoachMarkScope<ExploreGeneratorCoachMark>.MainStateOptionsItem(
694696
) {
695697
SegmentedButtonOptionContent(
696698
option = option,
697-
modifier = Modifier.width(weightedWidth),
699+
modifier = Modifier
700+
.fillMaxHeight()
701+
.width(weightedWidth),
698702
)
699703
}
700704
}
@@ -723,15 +727,19 @@ private fun CoachMarkScope<ExploreGeneratorCoachMark>.MainStateOptionsItem(
723727
) {
724728
SegmentedButtonOptionContent(
725729
option = option,
726-
modifier = Modifier.width(weightedWidth),
730+
modifier = Modifier
731+
.fillMaxHeight()
732+
.width(weightedWidth),
727733
)
728734
}
729735
}
730736

731737
else -> {
732738
SegmentedButtonOptionContent(
733739
option = option,
734-
modifier = Modifier.width(weightedWidth),
740+
modifier = Modifier
741+
.fillMaxHeight()
742+
.width(weightedWidth),
735743
)
736744
}
737745
}

0 commit comments

Comments
 (0)