Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82c8f5cd authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Allow for MR text to grow with font scaling

Test:  atest NavBarPillScreenshotTest
Fixes: 424717224
Flag: EXEMPT bugfix
Change-Id: I7e0cfc909a3799916a9f31c01db36fdfffc4cef3
parent 42ebb848
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -33,9 +33,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
@@ -43,6 +41,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
@@ -56,11 +55,17 @@ import com.android.systemui.res.R
@Composable
fun Chip(action: ActionViewModel, modifier: Modifier = Modifier) {
    val backgroundColor = if (isSystemInDarkTheme()) Color.Black else Color.White
    val density = LocalDensity.current
    val config = LocalConfiguration.current
    val isBoldTextEnabled by remember { derivedStateOf { config.fontWeightAdjustment > 0 } }
    val isBoldTextEnabled = config.fontWeightAdjustment > 0
    val fontScale = config.fontScale
    val chipTextStyle =
        MaterialTheme.typography.labelLarge.copy(
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium,
            fontSize =
                with(density) {
                    (MaterialTheme.typography.labelLarge.fontSize.value * fontScale).dp.toSp()
                },
        )

    val haptics = LocalHapticFeedback.current
+10 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
@@ -44,7 +45,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -145,10 +145,15 @@ fun NavBarPill(
            label = "expansion",
        )
    val config = LocalConfiguration.current
    val isBoldTextEnabled by remember { derivedStateOf { config.fontWeightAdjustment > 0 } }
    val isBoldTextEnabled = config.fontWeightAdjustment > 0
    val fontScale = config.fontScale
    val actionTextStyle =
        MaterialTheme.typography.labelMedium.copy(
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium,
            fontSize =
                with(density) {
                    (MaterialTheme.typography.labelMedium.fontSize.value * fontScale).dp.toSp()
                },
        )

    Box(
@@ -254,7 +259,8 @@ fun NavBarPill(
                                                    Color.Transparent
                                                }
                                            )
                                            .padding(4.dp),
                                            .height(28.dp)
                                            .padding(start = 6.dp, end = 6.dp),
                                ) {
                                    Image(
                                        painter = rememberDrawablePainter(action.icon.drawable),
+8 −2
Original line number Diff line number Diff line
@@ -136,11 +136,17 @@ fun ShortPill(
    var pillContentSize by remember { mutableStateOf(IntSize.Zero) }
    var pillContentPosition by remember { mutableStateOf(Offset.Zero) }

    val density = LocalDensity.current
    val config = LocalConfiguration.current
    val isBoldTextEnabled by remember { derivedStateOf { config.fontWeightAdjustment > 0 } }
    val fontScale = config.fontScale
    val actionTextStyle =
        MaterialTheme.typography.labelMedium.copy(
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium
            fontWeight = if (isBoldTextEnabled) FontWeight.Bold else FontWeight.Medium,
            fontSize =
                with(density) {
                    (MaterialTheme.typography.labelMedium.fontSize.value * fontScale).dp.toSp()
                },
        )

    Box(
@@ -254,7 +260,7 @@ fun ShortPill(

        // The layout for the expanded state (a single, centered button)
        if (expansionAlpha < 1f && pillContentSize != IntSize.Zero) {
            with(LocalDensity.current) {
            with(density) {
                val offsetX =
                    pillContentPosition.x.toDp() + (pillContentSize.width.toDp() / 2) -
                        (closeButtonSize / 2)