Browse Source

Update graphics-2d and widgets-gallery to the new resources library

andrei.salavei/accessibility-lib
Konstantin Tskhovrebov 11 months ago
parent
commit
392c9c58cc
  1. 0
      examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/clock.png
  2. 0
      examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/compose_community_primary.xml
  3. 0
      examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/flag.png
  4. 0
      examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/mine.png
  5. 92
      examples/graphics-2d/shared/build.gradle.kts
  6. 7
      examples/graphics-2d/shared/src/commonMain/kotlin/minesweeper/MineSweeper.common.kt
  7. 13
      examples/graphics-2d/shared/src/commonMain/kotlin/minesweeper/Widgets.kt
  8. 3
      examples/graphics-2d/shared/src/commonMain/kotlin/visualeffects/RotatingWords.kt
  9. 0
      examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/clock.png
  10. 0
      examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/compose_community_primary.xml
  11. 0
      examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/flag.png
  12. 0
      examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/mine.png
  13. 2
      examples/widgets-gallery/shared/build.gradle.kts
  14. 2
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/data/DemoDataProvider.kt
  15. 13
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Res.kt
  16. 16
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt
  17. 8
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt
  18. 10
      examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt
  19. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_instagram.xml
  20. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_send.xml
  21. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_twitter.xml
  22. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p1.jpeg
  23. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p2.jpeg
  24. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p3.jpeg
  25. 0
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p6.jpeg
  26. 5
      examples/widgets-gallery/shared/src/commonMain/resources/composeRes/values/strings.xml

0
examples/graphics-2d/jsApp/src/jsMain/resources/assets/clock.png → examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/clock.png

Before

Width:  |  Height:  |  Size: 896 B

After

Width:  |  Height:  |  Size: 896 B

0
examples/graphics-2d/jsApp/src/jsMain/resources/compose-community-primary.xml → examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/compose_community_primary.xml

0
examples/graphics-2d/jsApp/src/jsMain/resources/assets/flag.png → examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/flag.png

Before

Width:  |  Height:  |  Size: 780 B

After

Width:  |  Height:  |  Size: 780 B

0
examples/graphics-2d/jsApp/src/jsMain/resources/assets/mine.png → examples/graphics-2d/jsApp/src/jsMain/resources/composeRes/images/mine.png

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

92
examples/graphics-2d/shared/build.gradle.kts

@ -1,7 +1,3 @@
@file:Suppress("OPT_IN_IS_NOT_ENABLED")
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
plugins {
kotlin("multiplatform")
@ -19,15 +15,11 @@ kotlin {
browser()
}
macosX64 {
binaries {
executable {
entryPoint = "main"
}
}
}
macosArm64 {
binaries {
listOf(
macosX64(),
macosArm64()
).forEach { macosTarget ->
macosTarget.binaries {
executable {
entryPoint = "main"
}
@ -45,67 +37,27 @@ kotlin {
}
}
val enableKjsWorkaround = project.properties["workaround.kotlin.js.kt60852"] == "true"
fun KotlinDependencyHandler.addCommonDependencies() {
implementation(compose.ui)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
}
sourceSets {
val commonMain by getting {
dependencies {
if (!enableKjsWorkaround) {
addCommonDependencies()
}
}
commonMain.dependencies {
implementation(compose.ui)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation("org.jetbrains.compose.components:components-resources:1.6.0-dev1306")
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
api("androidx.activity:activity-compose:1.7.2")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")
}
}
val iosMain by creating {
dependsOn(commonMain)
}
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosArm64Main by getting {
dependsOn(iosMain)
commonTest.dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-annotations-common"))
}
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
androidMain.dependencies {
api("androidx.activity:activity-compose:1.7.2")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")
}
val desktopMain by getting {
dependencies {
implementation(compose.desktop.common)
}
}
val macosMain by creating {
dependsOn(commonMain)
}
val macosArm64Main by getting {
dependsOn(macosMain)
}
val jsMain by getting {
dependencies {
if (enableKjsWorkaround) {
addCommonDependencies()
}
}
val desktopMain by getting
desktopMain.dependencies {
implementation(compose.desktop.common)
}
}
}

7
examples/graphics-2d/shared/src/commonMain/kotlin/minesweeper/MineSweeper.common.kt

@ -12,12 +12,13 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.*
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
import org.jetbrains.compose.resources.painterResource
import kotlin.math.max
@OptIn(ExperimentalResourceApi::class)
@Composable
fun loadImage(res: String): Painter = painterResource(res)
fun loadImage(img: ImageResource): Painter = painterResource(img)
expect fun hasRightClick(): Boolean
@ -77,9 +78,9 @@ fun MineSweeper(requestWindowSize: ((width: Dp, height: Dp) -> Unit)? = null) =
Row {
Column {
val bombsLeft = max(game.bombs - game.flagsSet, 0)
IndicatorWithIcon("assets/clock.png", "Seconds", game.seconds)
IndicatorWithIcon(ImageResource("composeRes/images/clock.png"), "Seconds", game.seconds)
Box(modifier = Modifier.size(2.dp)) {}
IndicatorWithIcon("assets/mine.png", "Bombs Left", bombsLeft)
IndicatorWithIcon(ImageResource("composeRes/images/mine.png"), "Bombs Left", bombsLeft)
}
Column(modifier = Modifier.padding(8.dp)) {

13
examples/graphics-2d/shared/src/commonMain/kotlin/minesweeper/Widgets.kt

@ -17,6 +17,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.jetbrains.compose.resources.ImageResource
@Composable
fun OpenedCell(cell: Cell) {
@ -30,9 +31,9 @@ fun OpenedCell(cell: Cell) {
}
@Composable
fun CellWithIcon(src: String, alt: String) {
fun CellWithIcon(img: ImageResource, alt: String) {
Image(
painter = loadImage(src),
painter = loadImage(img),
contentDescription = alt,
modifier = Modifier.fillMaxSize().padding(Dp(4.0f))
)
@ -40,20 +41,20 @@ fun CellWithIcon(src: String, alt: String) {
@Composable
fun Mine() {
CellWithIcon(src = "assets/mine.png", alt = "Bomb")
CellWithIcon(ImageResource("composeRes/images/mine.png"), alt = "Bomb")
}
@Composable
fun Flag() {
CellWithIcon(src = "assets/flag.png", alt = "Flag")
CellWithIcon(ImageResource("composeRes/images/flag.png"), alt = "Flag")
}
@Composable
fun IndicatorWithIcon(iconPath: String, alt: String, value: Int) {
fun IndicatorWithIcon(img: ImageResource, alt: String, value: Int) {
Box(modifier = Modifier.background(Color(0x8e, 0x6e, 0x0e))) {
Row(verticalAlignment = Alignment.CenterVertically) {
Box(modifier = Modifier.size(40.dp, 40.dp)) {
CellWithIcon(iconPath, alt)
CellWithIcon(img, alt)
}
Box(modifier = Modifier.size(56.dp, 36.dp)) {

3
examples/graphics-2d/shared/src/commonMain/kotlin/visualeffects/RotatingWords.kt

@ -21,6 +21,7 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class)
@ -46,7 +47,7 @@ fun Words() {
)
)
val logoImg = painterResource("compose-community-primary.xml")
val logoImg = painterResource(ImageResource("composeRes/images/compose_community_primary.xml"))
val baseLogo = DpOffset(350.dp, 270.dp)

0
examples/graphics-2d/shared/src/commonMain/resources/assets/clock.png → examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/clock.png

Before

Width:  |  Height:  |  Size: 896 B

After

Width:  |  Height:  |  Size: 896 B

0
examples/graphics-2d/shared/src/commonMain/resources/compose-community-primary.xml → examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/compose_community_primary.xml

0
examples/graphics-2d/shared/src/commonMain/resources/assets/flag.png → examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/flag.png

Before

Width:  |  Height:  |  Size: 780 B

After

Width:  |  Height:  |  Size: 780 B

0
examples/graphics-2d/shared/src/commonMain/resources/assets/mine.png → examples/graphics-2d/shared/src/commonMain/resources/composeRes/images/mine.png

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

2
examples/widgets-gallery/shared/build.gradle.kts

@ -32,7 +32,7 @@ kotlin {
implementation(compose.material)
implementation(compose.materialIconsExtended)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation("org.jetbrains.compose.components:components-resources:1.6.0-dev1306")
}
}
val androidMain by getting {

2
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/data/DemoDataProvider.kt

@ -1,8 +1,6 @@
package org.jetbrains.compose.demo.widgets.data
import org.jetbrains.compose.demo.widgets.data.model.Item
import org.jetbrains.compose.demo.widgets.data.model.Tweet
import org.jetbrains.compose.demo.widgets.platform.Res
object DemoDataProvider {
val item = Item(

13
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Res.kt

@ -1,18 +1,7 @@
package org.jetbrains.compose.demo.widgets.platform
object Res {
object drawable {
val p1 = "drawable-nodpi/p1.jpeg"
val p2 = "drawable-nodpi/p2.jpeg"
val p3 = "drawable-nodpi/p3.jpeg"
val p6 = "drawable-nodpi/p6.jpeg"
val ic_instagram = "drawable/ic_instagram.xml"
val ic_send = "drawable/ic_send.xml"
val ic_twitter = "drawable/ic_twitter.xml"
}
object string {
object strings {
val spotify_nav_home = "Home"
val spotify_nav_search = "Search"
val spotify_nav_library = "Your Library"

16
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt

@ -21,6 +21,7 @@ import org.jetbrains.compose.demo.widgets.theme.twitterColor
import org.jetbrains.compose.demo.widgets.ui.utils.SubtitleText
import org.jetbrains.compose.demo.widgets.ui.utils.TitleText
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
@Composable
fun AppBars() {
@ -53,12 +54,12 @@ private fun TopAppBarsDemo() {
elevation = 8.dp,
navigationIcon = {
IconButton(onClick = {}) {
Icon(painterResource(Res.drawable.ic_instagram), contentDescription = "Instagram")
Icon(painterResource(ImageResource("composeRes/images/ic_instagram.xml")), contentDescription = "Instagram")
}
},
actions = {
IconButton(onClick = {}) {
Icon(painterResource(Res.drawable.ic_send), contentDescription = "Send")
Icon(painterResource(ImageResource("composeRes/images/ic_send.xml")), contentDescription = "Send")
}
}
)
@ -68,7 +69,7 @@ private fun TopAppBarsDemo() {
TopAppBar(
title = {
Icon(
painterResource(Res.drawable.ic_twitter),
painterResource(ImageResource("composeRes/images/ic_twitter.xml")),
contentDescription = "Twitter",
tint = twitterColor,
modifier = Modifier.fillMaxWidth()
@ -79,7 +80,7 @@ private fun TopAppBarsDemo() {
elevation = 8.dp,
navigationIcon = {
Image(
painterResource(Res.drawable.p6),
painterResource(ImageResource("composeRes/images/p6.jpeg")),
contentDescription = "",
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
.requiredSize(32.dp).clip(CircleShape)
@ -111,6 +112,7 @@ private fun BottomAppBarDemo() {
}
}
@OptIn(ExperimentalResourceApi::class)
@Composable
private fun NavigationBarDemo() {
Spacer(modifier = Modifier.height(16.dp))
@ -121,19 +123,19 @@ private fun NavigationBarDemo() {
icon = { Icon(Icons.Outlined.Home, contentDescription = "Home") },
selected = navItemState.value == NavType.HOME,
onClick = { navItemState.value = NavType.HOME },
label = { Text(text = Res.string.spotify_nav_home) },
label = { Text(text = Res.strings.spotify_nav_home) },
)
BottomNavigationItem(
icon = { Icon(Icons.Outlined.Search, contentDescription = "Search") },
selected = navItemState.value == NavType.SEARCH,
onClick = { navItemState.value = NavType.SEARCH },
label = { Text(text = Res.string.spotify_nav_search) }
label = { Text(text = Res.strings.spotify_nav_search) }
)
BottomNavigationItem(
icon = { Icon(Icons.Outlined.LibraryMusic, contentDescription = "LibraryMusic") },
selected = navItemState.value == NavType.LIBRARY,
onClick = { navItemState.value = NavType.LIBRARY },
label = { Text(text = Res.string.spotify_nav_library) }
label = { Text(text = Res.strings.spotify_nav_library) }
)
}

8
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt

@ -15,10 +15,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.demo.widgets.platform.Res
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.demo.widgets.ui.utils.SubtitleText
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
@Composable
fun Chips() {
@ -33,9 +33,9 @@ fun Chips() {
modifier = Modifier.padding(horizontal = 8.dp)
)
Spacer(modifier = Modifier.padding(8.dp))
CustomImageChip(text = "custom", imageId = Res.drawable.p2, selected = true)
CustomImageChip(text = "custom", imageId = ImageResource("composeRes/images/p2.jpeg"), selected = true)
Spacer(modifier = Modifier.padding(8.dp))
CustomImageChip(text = "custom2", imageId = Res.drawable.p6, selected = false)
CustomImageChip(text = "custom2", imageId = ImageResource("composeRes/images/p6.jpeg"), selected = false)
}
SubtitleText(subtitle = "Buttons with circle clipping.")
Column(modifier = Modifier.padding(8.dp)) {
@ -62,7 +62,7 @@ fun Chips() {
@Composable
private fun CustomImageChip(
text: String,
imageId: String,
imageId: ImageResource,
selected: Boolean,
modifier: Modifier = Modifier
) {

10
examples/widgets-gallery/shared/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt

@ -11,10 +11,10 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.demo.widgets.data.DemoDataProvider
import org.jetbrains.compose.demo.widgets.platform.Res
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.demo.widgets.theme.typography
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.ImageResource
@OptIn(ExperimentalMaterialApi::class, ExperimentalResourceApi::class)
@Composable
@ -54,7 +54,7 @@ fun UICards() {
) {
Row {
Image(
painterResource(Res.drawable.p3),
painterResource(ImageResource("composeRes/images/p3.jpeg")),
contentDescription = null,
modifier = Modifier.requiredSize(60.dp)
)
@ -78,7 +78,7 @@ fun UICards() {
Divider(modifier = Modifier.padding(4.dp))
ListItem(text = { Text(item.title) }, secondaryText = { Text(item.subtitle) }, icon = {
Image(
painterResource(Res.drawable.p3),
painterResource(ImageResource("composeRes/images/p3.jpeg")),
contentDescription = null
)
})
@ -87,7 +87,7 @@ fun UICards() {
ListItem(
text = { Text(item.title) },
secondaryText = { Text(item.subtitle) },
icon = { Image(painterResource(Res.drawable.p1), contentDescription = null) },
icon = { Image(painterResource(ImageResource("composeRes/images/p1.jpeg")), contentDescription = null) },
overlineText = { Text("Overline text") },
singleLineSecondaryText = false
)
@ -95,7 +95,7 @@ fun UICards() {
ListItem(
text = { Text(item.title) },
secondaryText = { Text(item.subtitle) },
icon = { Image(painterResource(Res.drawable.p2), contentDescription = null) },
icon = { Image(painterResource(ImageResource("composeRes/images/p2.jpeg")), contentDescription = null) },
trailing = { Icon(Icons.Default.ShoppingCart, contentDescription = null) },
singleLineSecondaryText = false
)

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable/ic_instagram.xml → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_instagram.xml

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable/ic_send.xml → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_send.xml

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable/ic_twitter.xml → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/ic_twitter.xml

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable-nodpi/p1.jpeg → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p1.jpeg

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable-nodpi/p2.jpeg → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p2.jpeg

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable-nodpi/p3.jpeg → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p3.jpeg

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

0
examples/widgets-gallery/shared/src/commonMain/resources/drawable-nodpi/p6.jpeg → examples/widgets-gallery/shared/src/commonMain/resources/composeRes/images/p6.jpeg

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

5
examples/widgets-gallery/shared/src/commonMain/resources/composeRes/values/strings.xml

@ -0,0 +1,5 @@
<resources>
<string name="spotify_nav_home">Home</string>
<string name="spotify_nav_search">Search</string>
<string name="spotify_nav_library">Your Library</string>
</resources>
Loading…
Cancel
Save