In Compose 1.6 resources library, how should we ha...
# compose-desktop
s
In Compose 1.6 resources library, how should we handle
Typography
? https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#fonts shows how we handle a Font, but there is no explanation how this works with Typography. 🧵
1
This is how I define my fonts until now:
Copy code
val roboto: FontFamily = FontFamily(
    Font(
        resource = "font/roboto_regular_hinted.ttf",
        weight = FontWeight.Normal,
        style = FontStyle.Normal
    ),
    Font(
        resource = "font/roboto_bold_hinted.ttf",
        weight = FontWeight.Bold,
        style = FontStyle.Normal
    ),
    Font(
        resource = "font/roboto_italic_hinted.ttf",
        weight = FontWeight.Normal,
        style = FontStyle.Italic
    )
)
And this is how I use Typography:
Copy code
val titleFontSize: TextUnit = 32.sp
val largeFontSize: TextUnit = 20.sp
val mediumFontSize: TextUnit = 16.sp
val smallerFontSize: TextUnit = 14.sp
val smallFontSize: TextUnit = 12.sp

val materialTypography = Typography(
    headlineLarge = TextStyle(
        fontFamily = roboto,
        fontWeight = FontWeight.SemiBold,
        fontSize = titleFontSize,
        // lineHeight = 40.sp,
        letterSpacing = 0.sp
    ),
    headlineMedium = TextStyle(
        fontFamily = roboto,
        fontWeight = FontWeight.SemiBold,
        fontSize = 28.sp,
        // lineHeight = 36.sp,
        letterSpacing = 0.sp
    ),
    headlineSmall = TextStyle(
        fontFamily = roboto,
        fontWeight = FontWeight.SemiBold,
        fontSize = 24.sp,
        // lineHeight = 32.sp,
        letterSpacing = 0.sp
    ),
    [... snip ...]
)
I managed so far to change the above to the new Font composable - but it's quite limiting as it is now required to be a @Composable ... I hope we can lift this requirement again.
But the Typography seems not to be compatible with the result of the Font compostable functions result.
Can we lift the requirement for
Font
to be
@Composable
?
m
Untitled.kt
This is a simplification of what I do. It was already Composable for me so using the new resource system didn't change anything.
👍 1