1

My Goal

I have gotten a simple Photoshop File I want to recreate what I see there Pixel by Pixel. My Target Device will NEVER change the Display Resolution or anything else.

photoshop

It should be pretty simple right? The values in Pixel are clear

  • width = 111
  • height = 66
  • padding after divider = 15
  • padding after "PM" = 15
  • padding between "TIME" and "PM" = 8
  • pixelSize for "TIME" = 24
  • pixelSize for "PM" = 15

My Code:

    Row(
        modifier = Modifier
            .width(PixelToDp(111))
            .height(PixelToDp(66))
            .fillMaxSize()
            .background(colorResource(R.color.black)),
        horizontalArrangement = Arrangement.Start,
        verticalAlignment = Alignment.CenterVertically
    ) {

        Image(
            painter = painterResource(id = R.drawable.statusbar_splitline),
            contentDescription = null,
            modifier = Modifier.padding(end = PixelToDp(pixelSize = 15))
        )

        Row(
            verticalAlignment = Alignment.CenterVertically
        ) {
            BentleyText(
                text = "12:34",
                pixelSize = 24,
                modifier = Modifier.padding(end = PixelToDp(pixelSize = 8))
            )
            BentleyText(
                text = "PM", pixelSize = 15,
                modifier = Modifier
                    .padding(end = PixelToDp(pixelSize = 15))
                    .width(IntrinsicSize.Min) //this is something im trying?
            )

        }
    }

Where I convert Pixel to SP for Text related stuff

@Composable
fun BentleyText(
    text: String,
    modifier: Modifier = Modifier,
    color: Color = colorResource(id = R.color.white),
    pixelSize: Int = 14

) {
    val pixelSizeInSp = with(LocalDensity.current) { pixelSize.toSp() }
    Text(
    text,
        modifier = modifier,
        fontFamily = Font(R.font.bentleyw1g_smcon_light_mib3).toFontFamily(),
        fontStyle = Font(R.font.bentleyw1g_smcon_light_mib3).style,
        fontWeight = Font(R.font.bentleyw1g_smcon_light_mib3).weight,

        color = color,
        fontSize = pixelSizeInSp
    )
}

Where I convert Pixel to DP for everything else

@Composable
fun PixelToDp(pixelSize: Int): Dp {
    return with(LocalDensity.current) { pixelSize.toDp() }
}

Problem

I try to use the exact same values as shown here but everything is way off. First the Font Size doesn't match my Photoshop file's fontSize. Second the gap after the padding is also way off. The only thing that seems to be correct is the Width and the Height.

my_result

The preview shows me this Lines(Guides)

enter image description here

Can anyone help me understand Jetpack Compose with this trivial task?

Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38
Ojav
  • 678
  • 6
  • 22
  • 1
    Do you really have to use `IntrinsicSize.Min` for the width? Why not just set an own value and check what works(even though its not the right choice)? – Sambhav Khandelwal Oct 24 '22 at 09:08
  • No I dont have to. This was my attempt to fix the padding issue I saw the Guides and assumed it starts with a predefined spacing or something. With setting an `own value` you mean `width(15.dp)`. This I have tried. – Ojav Oct 24 '22 at 09:23
  • Not sure if this would help, https://stackoverflow.com/questions/67664786/how-to-remove-space-below-text-baseline-in-jetpack-compose/68794477#68794477 – z.g.y Oct 24 '22 at 11:45
  • how did you achieve this? – Fusion Developers Feb 10 '23 at 04:27

0 Answers0