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. 17
      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 { android {
compileSdk = 30 compileSdk = 31
defaultConfig { defaultConfig {
minSdk = 26 minSdk = 26

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

@ -8,10 +8,10 @@ buildscript {
dependencies { dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1") classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.0-master-build413")
classpath("com.android.tools.build:gradle:7.0.0") classpath("com.android.tools.build:gradle:4.2.0")
// __KOTLIN_COMPOSE_VERSION__ // __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.runtime.Composable
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.imageResource import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.vectorResource import androidx.compose.ui.res.vectorResource
import org.jetbrains.compose.demo.widgets.platform.R import org.jetbrains.compose.demo.widgets.platform.R
@Composable @Composable
actual fun imageResource(res: String): ImageBitmap { actual fun imageResource(res: String): Painter {
val id = drawableId(res) val id = drawableId(res)
return ImageBitmap.imageResource(id) return painterResource(id)
} }
@Composable @Composable
actual fun vectorResource(res: String): ImageVector { actual fun vectorResource(res: String): Painter {
val id = drawableId(res) val id = drawableId(res)
return ImageVector.vectorResource(id) return painterResource(id)
} }
// TODO: improve resource loading // 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 package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable 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
@Composable @Composable
expect fun imageResource(res: String): ImageBitmap expect fun imageResource(res: String): Painter
@Composable @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.Modifier
import androidx.compose.ui.geometry.Offset 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.pointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
import java.awt.Cursor import java.awt.Cursor
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.pointerMoveFilter( actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean, onEnter: () -> Boolean,
onExit: () -> Boolean, onExit: () -> Boolean,
@ -16,4 +17,4 @@ actual fun Modifier.pointerMoveFilter(
@OptIn(ExperimentalComposeUiApi::class) @OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier = 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 package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorXmlResource import androidx.compose.ui.res.loadXmlImageVector
import androidx.compose.ui.res.imageResource as bitmapImage import androidx.compose.ui.res.painterResource
@Composable @Composable
actual fun imageResource(res: String) = actual fun imageResource(res: String): Painter = painterResource(res)
bitmapImage(res)
@Composable @Composable
actual fun vectorResource(res: String): ImageVector = actual fun vectorResource(res: String): Painter = painterResource(res)
vectorXmlResource(res)

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

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