Browse Source

Fix icon setting

pull/969/head
Nikolay Igotti 3 years ago
parent
commit
54ea726f91
  1. 18
      examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  2. 6
      examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

18
examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -1,14 +1,13 @@
package org.jetbrains.compose.demo.widgets.platform package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.composed import androidx.compose.ui.composed
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.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
import androidx.compose.ui.window.FrameWindowScope
import java.awt.Cursor
val AppFrame = staticCompositionLocalOf<FrameWindowScope> { error("Undefined repository") }
actual fun Modifier.pointerMoveFilter( actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean, onEnter: () -> Boolean,
@ -16,18 +15,11 @@ actual fun Modifier.pointerMoveFilter(
onMove: (Offset) -> Boolean onMove: (Offset) -> Boolean
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove) ): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier = composed { actual fun Modifier.cursorForHorizontalResize(): Modifier = composed {
var isHover by remember { mutableStateOf(false) } var isHover by remember { mutableStateOf(false) }
val window = AppFrame.current.window
window.cursor = if (isHover) {
Cursor(Cursor.E_RESIZE_CURSOR)
} else {
Cursor.getDefaultCursor()
}
pointerMoveFilter( pointerMoveFilter(
onEnter = { isHover = true; true }, onEnter = { isHover = true; true },
onExit = { isHover = false; true } onExit = { isHover = false; true }
) ).pointerIcon(if (isHover) PointerIcon.Crosshair else PointerIcon.Default)
} }

6
examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

@ -1,10 +1,8 @@
package org.jetbrains.compose.demo.widgets package org.jetbrains.compose.demo.widgets
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.* import androidx.compose.ui.window.*
import org.jetbrains.compose.demo.widgets.platform.AppFrame
import org.jetbrains.compose.demo.widgets.ui.MainView import org.jetbrains.compose.demo.widgets.ui.MainView
import java.awt.Dimension import java.awt.Dimension
import java.awt.Toolkit import java.awt.Toolkit
@ -15,9 +13,7 @@ fun main() {
title = "Widgets Gallery", title = "Widgets Gallery",
state = WindowState(size = WindowSize(size.width.dp, size.height.dp)), state = WindowState(size = WindowSize(size.width.dp, size.height.dp)),
) { ) {
CompositionLocalProvider(AppFrame provides this) { MainView()
MainView()
}
} }
} }

Loading…
Cancel
Save