Browse Source

Add a ttf font to the resources demo app

ok/repr-ios-release_chat-mpp-1.6.0beta01
Konstantin Tskhovrebov 11 months ago
parent
commit
3c7260ea51
  1. BIN
      components/resources/demo/shared/src/commonMain/composeResources/font/Workbench-Regular.ttf
  2. 38
      components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt
  3. 30
      components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/StringRes.kt

BIN
components/resources/demo/shared/src/commonMain/composeResources/font/Workbench-Regular.ttf

Binary file not shown.

38
components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt

@ -29,13 +29,37 @@ fun FontRes(paddingValues: PaddingValues) {
Text( Text(
modifier = Modifier.padding(8.dp), modifier = Modifier.padding(8.dp),
text = """ text = """
val fontAwesome = FontFamily(Font(Res.fonts.font_awesome))
val symbols = arrayOf(0xf1ba, 0xf238, 0xf21a, 0xf1bb, 0xf1b8, 0xf09b, 0xf269, 0xf1d0, 0xf15a, 0xf293, 0xf1c6)
Text( Text(
modifier = Modifier.padding(16.dp), modifier = Modifier.padding(16.dp),
fontFamily = fontAwesome, fontFamily = FontFamily(Font(Res.font.workbench_regular)),
style = MaterialTheme.typography.headlineLarge, style = MaterialTheme.typography.headlineLarge,
text = symbols.joinToString(" ") { it.toChar().toString() } text = "brown fox jumps over the lazy dog"
)
""".trimIndent(),
color = MaterialTheme.colorScheme.onPrimaryContainer,
softWrap = false
)
}
Text(
modifier = Modifier.padding(16.dp),
fontFamily = FontFamily(Font(Res.font.workbench_regular)),
style = MaterialTheme.typography.headlineLarge,
text = "brown fox jumps over the lazy dog"
)
OutlinedCard(
modifier = Modifier.padding(16.dp).fillMaxWidth(),
shape = RoundedCornerShape(4.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer)
) {
Text(
modifier = Modifier.padding(8.dp),
text = """
Text(
modifier = Modifier.padding(16.dp),
fontFamily = FontFamily(Font(Res.font.font_awesome)),
style = MaterialTheme.typography.headlineLarge,
text ="\uf1ba \uf238 \uf21a \uf1bb \uf1b8 \uf09b \uf269 \uf1d0 \uf15a \uf293 \uf1c6"
) )
""".trimIndent(), """.trimIndent(),
color = MaterialTheme.colorScheme.onPrimaryContainer, color = MaterialTheme.colorScheme.onPrimaryContainer,
@ -43,13 +67,11 @@ fun FontRes(paddingValues: PaddingValues) {
) )
} }
val fontAwesome = FontFamily(Font(Res.font.font_awesome))
val symbols = arrayOf(0xf1ba, 0xf238, 0xf21a, 0xf1bb, 0xf1b8, 0xf09b, 0xf269, 0xf1d0, 0xf15a, 0xf293, 0xf1c6)
Text( Text(
modifier = Modifier.padding(16.dp), modifier = Modifier.padding(16.dp),
fontFamily = fontAwesome, fontFamily = FontFamily(Font(Res.font.font_awesome)),
style = MaterialTheme.typography.headlineLarge, style = MaterialTheme.typography.headlineLarge,
text = symbols.joinToString(" ") { it.toChar().toString() } text ="\uf1ba \uf238 \uf21a \uf1bb \uf1b8 \uf09b \uf269 \uf1d0 \uf15a \uf293 \uf1c6"
) )
} }
} }

30
components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/StringRes.kt

@ -1,30 +1,16 @@
package org.jetbrains.compose.resources.demo.shared package org.jetbrains.compose.resources.demo.shared
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CardDefaults import androidx.compose.material3.*
import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.*
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import components.resources.demo.shared.generated.resources.Res import components.resources.demo.shared.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.resources.stringArrayResource import org.jetbrains.compose.resources.stringArrayResource
import org.jetbrains.compose.resources.readResourceBytes import org.jetbrains.compose.resources.stringResource
@Composable @Composable
fun StringRes(paddingValues: PaddingValues) { fun StringRes(paddingValues: PaddingValues) {
@ -56,7 +42,7 @@ fun StringRes(paddingValues: PaddingValues) {
modifier = Modifier.padding(16.dp).fillMaxWidth(), modifier = Modifier.padding(16.dp).fillMaxWidth(),
value = stringResource(Res.string.app_name), value = stringResource(Res.string.app_name),
onValueChange = {}, onValueChange = {},
label = { Text("Text(stringResource(Res.string.app_name)") }, label = { Text("Text(stringResource(Res.string.app_name))") },
enabled = false, enabled = false,
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
disabledTextColor = MaterialTheme.colorScheme.onSurface, disabledTextColor = MaterialTheme.colorScheme.onSurface,
@ -68,7 +54,7 @@ fun StringRes(paddingValues: PaddingValues) {
modifier = Modifier.padding(16.dp).fillMaxWidth(), modifier = Modifier.padding(16.dp).fillMaxWidth(),
value = stringResource(Res.string.hello), value = stringResource(Res.string.hello),
onValueChange = {}, onValueChange = {},
label = { Text("Text(stringResource(Res.string.hello)") }, label = { Text("Text(stringResource(Res.string.hello))") },
enabled = false, enabled = false,
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
disabledTextColor = MaterialTheme.colorScheme.onSurface, disabledTextColor = MaterialTheme.colorScheme.onSurface,
@ -80,7 +66,7 @@ fun StringRes(paddingValues: PaddingValues) {
modifier = Modifier.padding(16.dp).fillMaxWidth(), modifier = Modifier.padding(16.dp).fillMaxWidth(),
value = stringResource(Res.string.multi_line), value = stringResource(Res.string.multi_line),
onValueChange = {}, onValueChange = {},
label = { Text("Text(stringResource(Res.string.multi_line)") }, label = { Text("Text(stringResource(Res.string.multi_line))") },
enabled = false, enabled = false,
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
disabledTextColor = MaterialTheme.colorScheme.onSurface, disabledTextColor = MaterialTheme.colorScheme.onSurface,
@ -92,7 +78,7 @@ fun StringRes(paddingValues: PaddingValues) {
modifier = Modifier.padding(16.dp).fillMaxWidth(), modifier = Modifier.padding(16.dp).fillMaxWidth(),
value = stringResource(Res.string.str_template, "User_name", 100), value = stringResource(Res.string.str_template, "User_name", 100),
onValueChange = {}, onValueChange = {},
label = { Text("Text(stringResource(Res.string.str_template, \"User_name\", 100)") }, label = { Text("Text(stringResource(Res.string.str_template, \"User_name\", 100))") },
enabled = false, enabled = false,
colors = TextFieldDefaults.colors( colors = TextFieldDefaults.colors(
disabledTextColor = MaterialTheme.colorScheme.onSurface, disabledTextColor = MaterialTheme.colorScheme.onSurface,

Loading…
Cancel
Save