Browse Source

Fix widgets gallery example

pull/1288/head
Nikolay Igotti 3 years ago
parent
commit
6ac15ac3d0
  1. 2
      examples/widgets-gallery/android/build.gradle.kts
  2. 6
      examples/widgets-gallery/build.gradle.kts
  3. 10
      examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt
  4. 7
      examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt
  5. 5
      examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  6. 11
      examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt
  7. 15
      examples/widgets-gallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

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

@ -5,7 +5,7 @@ plugins {
}
android {
compileSdk = 30
compileSdk = 31
defaultConfig {
minSdk = 26

6
examples/widgets-gallery/build.gradle.kts

@ -8,10 +8,10 @@ buildscript {
dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1")
classpath("com.android.tools.build:gradle:7.0.0")
classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.0-master-build413")
classpath("com.android.tools.build:gradle:4.2.0")
// __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.5.21"))
classpath(kotlin("gradle-plugin", version = "1.5.31"))
}
}

10
examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt

@ -2,21 +2,23 @@ package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.vectorResource
import org.jetbrains.compose.demo.widgets.platform.R
@Composable
actual fun imageResource(res: String): ImageBitmap {
actual fun imageResource(res: String): Painter {
val id = drawableId(res)
return ImageBitmap.imageResource(id)
return painterResource(id)
}
@Composable
actual fun vectorResource(res: String): ImageVector {
actual fun vectorResource(res: String): Painter {
val id = drawableId(res)
return ImageVector.vectorResource(id)
return painterResource(id)
}
// TODO: improve resource loading

7
examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt

@ -1,12 +1,11 @@
package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.painter.Painter
@Composable
expect fun imageResource(res: String): ImageBitmap
expect fun imageResource(res: String): Painter
@Composable
expect fun vectorResource(res: String): ImageVector
expect fun vectorResource(res: String): Painter

5
examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -4,10 +4,11 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerMoveFilter
import java.awt.Cursor
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
@ -16,4 +17,4 @@ actual fun Modifier.pointerMoveFilter(
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier =
pointerIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)))
Modifier.pointerHoverIcon(PointerIcon.Crosshair)

11
examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt

@ -1,14 +1,13 @@
package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorXmlResource
import androidx.compose.ui.res.imageResource as bitmapImage
import androidx.compose.ui.res.loadXmlImageVector
import androidx.compose.ui.res.painterResource
@Composable
actual fun imageResource(res: String) =
bitmapImage(res)
actual fun imageResource(res: String): Painter = painterResource(res)
@Composable
actual fun vectorResource(res: String): ImageVector =
vectorXmlResource(res)
actual fun vectorResource(res: String): Painter = painterResource(res)

15
examples/widgets-gallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

@ -1,18 +1,13 @@
package org.jetbrains.compose.demo.widgets
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowSize
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import androidx.compose.ui.window.singleWindowApplication
import org.jetbrains.compose.demo.widgets.ui.MainView
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "Widgets Gallery",
state = WindowState(size = WindowSize(800.dp, 600.dp))
) {
fun main() = singleWindowApplication(
title = "Widgets Gallery", state = WindowState(size = DpSize(800.dp, 800.dp))
) {
MainView()
}
}
Loading…
Cancel
Save