mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-28 11:41:59 -07:00
Keep tab badges visible when the tab label is too long
Fixes #4165
Fixes #3423
Closes #3424
(cherry picked from commit b19c8abeba)
This commit is contained in:
+26
-15
@@ -1,12 +1,12 @@
|
||||
package tachiyomi.presentation.core.components.material
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.layout.Layout
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.offset
|
||||
import androidx.compose.ui.unit.sp
|
||||
import tachiyomi.presentation.core.components.Pill
|
||||
|
||||
@@ -14,20 +14,31 @@ import tachiyomi.presentation.core.components.Pill
|
||||
fun TabText(text: String, badgeCount: Int? = null) {
|
||||
val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (badgeCount != null) {
|
||||
Pill(
|
||||
text = "$badgeCount",
|
||||
color = MaterialTheme.colorScheme.onBackground.copy(alpha = pillAlpha),
|
||||
fontSize = 10.sp,
|
||||
Layout(
|
||||
content = {
|
||||
Text(
|
||||
text = text,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (badgeCount != null) {
|
||||
Pill(
|
||||
text = "$badgeCount",
|
||||
color = MaterialTheme.colorScheme.onBackground.copy(alpha = pillAlpha),
|
||||
fontSize = 10.sp,
|
||||
)
|
||||
}
|
||||
},
|
||||
) { measurables, constraints ->
|
||||
val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
|
||||
val badge = measurables.getOrNull(1)?.measure(looseConstraints)
|
||||
val badgeWidth = badge?.width ?: 0
|
||||
// The label gets what the badge leaves, unlike with Modifier.weight even in scrollable rows' unbounded tabs
|
||||
val label = measurables[0].measure(looseConstraints.offset(horizontal = -badgeWidth))
|
||||
val height = maxOf(label.height, badge?.height ?: 0)
|
||||
layout(label.width + badgeWidth, height) {
|
||||
label.placeRelative(0, (height - label.height) / 2)
|
||||
badge?.placeRelative(label.width, (height - badge.height) / 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user