JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.17k stars 1.11k forks source link

Material3 Icon and Text vertical alignment is abnormal. #4825

Closed kingsword09 closed 1 month ago

kingsword09 commented 1 month ago

Describe the bug The demo I downloaded from kmp.jetbrains.com for testing Icon and Text vertical alignment works fine on the Android end, but it is not vertically centered on desktop jvm and iOS.

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior:

  1. Run this code snippet:

      import androidx.compose.foundation.layout.Column
      import androidx.compose.foundation.layout.Row
      import androidx.compose.foundation.layout.fillMaxWidth
      import androidx.compose.foundation.layout.height
      import androidx.compose.material3.Icon
      import androidx.compose.material.MaterialTheme
      import androidx.compose.material3.Text
      import androidx.compose.material.icons.Icons
      import androidx.compose.material.icons.outlined.Verified
      import androidx.compose.runtime.Composable
      import androidx.compose.ui.Alignment
      import androidx.compose.ui.Modifier
      import androidx.compose.ui.unit.dp
      import org.jetbrains.compose.ui.tooling.preview.Preview
    
      @Composable
      @Preview
      fun App() {
        MaterialTheme {
          Column(
            Modifier.fillMaxWidth().height(50.dp),
            horizontalAlignment = Alignment.CenterHorizontally
          ) {
            Row(
              modifier = Modifier.fillMaxWidth(),
              verticalAlignment = Alignment.CenterVertically
            ) {
              Icon(imageVector = Icons.Outlined.Verified, null)
              Text("test")
            }
          }
        }
      }
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Expected behavior Hoping for the icon and text to align vertically in the center.

Screenshots Desktop: image

iOS: image

Android: image

Additional context The Android and iOS platform meets the requirements, but Desktop do not.

MatkovIvan commented 1 month ago

Different platforms have different default fonts, so the exact position of glyphs may vary a bit. To get equal positioning - use the same font (from resources for example)

Screenshot 2023-11-09 at 11 53 39

Marking it as duplicate as it was answered a few times already (1, 2, ...). The only leftover is to support all lineHeightStyle values: #2602, but it won't affect the case in the description of this issue