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
fun MainView() {
DisableSelection {
WidgetGalleryTheme() {
WidgetGalleryTheme {
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
import androidx.compose.desktop.LocalAppWindow
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.geometry.Offset
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(
onEnter: () -> Boolean,
onExit: () -> Boolean,
@ -20,10 +19,11 @@ actual fun Modifier.pointerMoveFilter(
actual fun Modifier.cursorForHorizontalResize(): Modifier = composed {
var isHover by remember { mutableStateOf(false) }
if (isHover) {
LocalAppWindow.current.window.cursor = Cursor(Cursor.E_RESIZE_CURSOR)
val window = AppFrame.current.window
window.cursor = if (isHover) {
Cursor(Cursor.E_RESIZE_CURSOR)
} else {
LocalAppWindow.current.window.cursor = Cursor.getDefaultCursor()
Cursor.getDefaultCursor()
}
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,
averageItemSize: Dp
) = androidx.compose.foundation.VerticalScrollbar(
rememberScrollbarAdapter(scrollState, itemCount, averageItemSize),
rememberScrollbarAdapter(scrollState),
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
import androidx.compose.desktop.Window
import androidx.compose.runtime.CompositionLocalProvider
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 java.awt.Dimension
import java.awt.Toolkit
import javax.swing.SwingUtilities.invokeLater
fun main() {
invokeLater {
Window(
val size = getPreferredWindowSize(600, 800)
singleWindowApplication (
title = "Widgets Gallery",
size = getPreferredWindowSize(600, 800),
state = WindowState(size = WindowSize(size.width.dp, size.height.dp)),
) {
CompositionLocalProvider(AppFrame provides this) {
MainView()
}
}

Loading…
Cancel
Save