Browse Source

Move to the new windows API

pull/969/head
Nikolay Igotti 3 years ago
parent
commit
a7bde4a5dc
  1. 2
      examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt
  2. 16
      examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  3. 2
      examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Scrollbar.kt
  4. 13
      examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt

2
examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt

@ -33,7 +33,7 @@ import org.jetbrains.compose.demo.widgets.ui.utils.withoutWidthConstraints
@Composable @Composable
fun MainView() { fun MainView() {
DisableSelection { DisableSelection {
WidgetGalleryTheme() { WidgetGalleryTheme {
WidgetsPanel() WidgetsPanel()
} }
} }

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

@ -1,16 +1,15 @@
package org.jetbrains.compose.demo.widgets.platform package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.desktop.LocalAppWindow import androidx.compose.runtime.*
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.composed import androidx.compose.ui.composed
import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
import androidx.compose.ui.window.FrameWindowScope
import java.awt.Cursor import java.awt.Cursor
val AppFrame = staticCompositionLocalOf<FrameWindowScope> { error("Undefined repository") }
actual fun Modifier.pointerMoveFilter( actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean, onEnter: () -> Boolean,
onExit: () -> Boolean, onExit: () -> Boolean,
@ -20,10 +19,11 @@ actual fun Modifier.pointerMoveFilter(
actual fun Modifier.cursorForHorizontalResize(): Modifier = composed { actual fun Modifier.cursorForHorizontalResize(): Modifier = composed {
var isHover by remember { mutableStateOf(false) } var isHover by remember { mutableStateOf(false) }
if (isHover) { val window = AppFrame.current.window
LocalAppWindow.current.window.cursor = Cursor(Cursor.E_RESIZE_CURSOR) window.cursor = if (isHover) {
Cursor(Cursor.E_RESIZE_CURSOR)
} else { } else {
LocalAppWindow.current.window.cursor = Cursor.getDefaultCursor() Cursor.getDefaultCursor()
} }
pointerMoveFilter( pointerMoveFilter(

2
examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Scrollbar.kt

@ -25,6 +25,6 @@ actual fun VerticalScrollbar(
itemCount: Int, itemCount: Int,
averageItemSize: Dp averageItemSize: Dp
) = androidx.compose.foundation.VerticalScrollbar( ) = androidx.compose.foundation.VerticalScrollbar(
rememberScrollbarAdapter(scrollState, itemCount, averageItemSize), rememberScrollbarAdapter(scrollState),
modifier modifier
) )

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

@ -1,18 +1,21 @@
package org.jetbrains.compose.demo.widgets package org.jetbrains.compose.demo.widgets
import androidx.compose.desktop.Window 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.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
import javax.swing.SwingUtilities.invokeLater
fun main() { fun main() {
invokeLater { val size = getPreferredWindowSize(600, 800)
Window( singleWindowApplication (
title = "Widgets Gallery", title = "Widgets Gallery",
size = getPreferredWindowSize(600, 800), state = WindowState(size = WindowSize(size.width.dp, size.height.dp)),
) { ) {
CompositionLocalProvider(AppFrame provides this) {
MainView() MainView()
} }
} }

Loading…
Cancel
Save