Browse Source

Fix tutorials

sync/2021-07-28
Igor Demin 3 years ago
parent
commit
af4c148a09
  1. 2
      templates/desktop-template/build.gradle.kts
  2. 9
      tutorials/Desktop_Components/README.md
  3. 2
      tutorials/Getting_Started/README.md
  4. 6
      tutorials/Image_And_Icons_Manipulations/README.md
  5. 9
      tutorials/Mouse_Events/README.md
  6. 2
      tutorials/Native_distributions_and_local_execution/README.md
  7. 2
      tutorials/Navigation/README.md
  8. 2
      tutorials/Swing_Integration/README.md
  9. 2
      tutorials/Tray_Notifications_MenuBar_new/README.md
  10. 22
      tutorials/Window_API_new/README.md

2
templates/desktop-template/build.gradle.kts

@ -5,7 +5,7 @@ plugins {
// __KOTLIN_COMPOSE_VERSION__ // __KOTLIN_COMPOSE_VERSION__
kotlin("jvm") version "1.5.21" kotlin("jvm") version "1.5.21"
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.5.0-build270") id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.0.0-sync-2021-07-28-build290")
} }
repositories { repositories {

9
tutorials/Desktop_Components/README.md

@ -28,14 +28,12 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowState import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication( fun main() = singleWindowApplication(
title = "Scrollbars", title = "Scrollbars",
state = WindowState(width = 250.dp, height = 400.dp) state = WindowState(width = 250.dp, height = 400.dp)
@ -114,7 +112,6 @@ import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -122,7 +119,6 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
@OptIn(ExperimentalComposeUiApi::class)
fun main() = application { fun main() = application {
Window( Window(
onCloseRequest = ::exitApplication, onCloseRequest = ::exitApplication,
@ -197,7 +193,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -205,7 +200,6 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
@OptIn(ExperimentalComposeUiApi::class)
fun main() = application { fun main() = application {
Window( Window(
onCloseRequest = ::exitApplication, onCloseRequest = ::exitApplication,
@ -319,8 +313,7 @@ fun main() = application {
} }
}, },
delay = 600, // in milliseconds delay = 600, // in milliseconds
tooltipPlacement = TooltipPlacement( tooltipPlacement = TooltipPlacement.CursorPoint(
anchor = TooltipPlacement.Anchor.Pointer,
alignment = Alignment.BottomEnd, alignment = Alignment.BottomEnd,
offset = if (index % 2 == 0) DpOffset(-16.dp, 0.dp) else DpOffset.Zero // tooltip offset offset = if (index % 2 == 0) DpOffset(-16.dp, 0.dp) else DpOffset.Zero // tooltip offset
) )

2
tutorials/Getting_Started/README.md

@ -102,14 +102,12 @@ import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
@OptIn(ExperimentalComposeUiApi::class)
fun main() = application { fun main() = application {
Window( Window(
onCloseRequest = ::exitApplication, onCloseRequest = ::exitApplication,

6
tutorials/Image_And_Icons_Manipulations/README.md

@ -13,12 +13,10 @@ Using images from application resources is very simple. Suppose we have a PNG im
```kotlin ```kotlin
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
Image( Image(
painter = painterResource("sample.png"), // ImageBitmap painter = painterResource("sample.png"), // ImageBitmap
@ -44,7 +42,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.graphics.painter.BitmapPainter
@ -65,7 +62,6 @@ import org.xml.sax.InputSource
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
val density = LocalDensity.current val density = LocalDensity.current
Column { Column {
@ -147,7 +143,6 @@ You may want to draw raw image data, in which case you can use `Canvas` and` dra
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
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.graphics.ImageBitmap import androidx.compose.ui.graphics.ImageBitmap
@ -163,7 +158,6 @@ import org.jetbrains.skija.ImageInfo
private val sample = useResource("sample.png", ::loadImageBitmap) private val sample = useResource("sample.png", ::loadImageBitmap)
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
val bitmap = remember { bitmapFromByteArray(sample.getBytes(), sample.width, sample.height) } val bitmap = remember { bitmapFromByteArray(sample.getBytes(), sample.width, sample.height) }
Canvas( Canvas(

9
tutorials/Mouse_Events/README.md

@ -26,13 +26,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
var count by remember { mutableStateOf(0) } var count by remember { mutableStateOf(0) }
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) {
@ -80,13 +78,11 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
var color by remember { mutableStateOf(Color(0, 0, 0)) } var color by remember { mutableStateOf(Color(0, 0, 0)) }
Box( Box(
@ -119,7 +115,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
@ -128,7 +123,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
Column( Column(
Modifier.background(Color.White), Modifier.background(Color.White),
@ -172,11 +166,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
@OptIn(ExperimentalComposeUiApi::class, ExperimentalDesktopApi::class) @OptIn(ExperimentalDesktopApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
var clickableText by remember { mutableStateOf("Click me!") } var clickableText by remember { mutableStateOf("Click me!") }

2
tutorials/Native_distributions_and_local_execution/README.md

@ -464,11 +464,9 @@ import androidx.compose.material.Text
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
import java.awt.Desktop import java.awt.Desktop
@OptIn(ExperimentalComposeUiApi::class)
fun main() { fun main() {
var text by mutableStateOf("Hello, World!") var text by mutableStateOf("Hello, World!")

2
tutorials/Navigation/README.md

@ -293,12 +293,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.window.singleWindowApplication import androidx.compose.ui.window.singleWindowApplication
import com.arkivanov.decompose.extensions.compose.jetbrains.rememberRootComponent import com.arkivanov.decompose.extensions.compose.jetbrains.rememberRootComponent
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication( fun main() = singleWindowApplication(
title = "Navigation tutorial" title = "Navigation tutorial"
) { ) {

2
tutorials/Swing_Integration/README.md

@ -147,7 +147,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel import androidx.compose.ui.awt.SwingPanel
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -158,7 +157,6 @@ import javax.swing.BoxLayout
import javax.swing.JButton import javax.swing.JButton
import javax.swing.JPanel import javax.swing.JPanel
@OptIn(ExperimentalComposeUiApi::class)
fun main() = singleWindowApplication { fun main() = singleWindowApplication {
val counter = remember { mutableStateOf(0) } val counter = remember { mutableStateOf(0) }

2
tutorials/Tray_Notifications_MenuBar_new/README.md

@ -1,4 +1,4 @@
# Menu, tray, notifications (new Composable API, experimental) # Menu, tray, notifications
## What is covered ## What is covered

22
tutorials/Window_API_new/README.md

@ -1,4 +1,4 @@
# Top level windows management (new Composable API, experimental) # Top level windows management
## What is covered ## What is covered
@ -185,7 +185,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.key import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ApplicationScope import androidx.compose.ui.window.ApplicationScope
import androidx.compose.ui.window.MenuBar import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
@ -201,7 +200,6 @@ fun main() = application {
} }
} }
@OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
private fun ApplicationScope.MyWindow( private fun ApplicationScope.MyWindow(
state: MyWindowState state: MyWindowState
@ -440,16 +438,26 @@ fun main() = SwingUtilities.invokeLater {
You can also access ComposeWindow in the Composable `Window` scope: You can also access ComposeWindow in the Composable `Window` scope:
```kotlin ```kotlin
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.Window import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import java.awt.Cursor import java.awt.datatransfer.DataFlavor
import java.awt.dnd.DnDConstants
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetAdapter
import java.awt.dnd.DropTargetDropEvent
@OptIn(ExperimentalComposeUiApi::class)
fun main() = application { fun main() = application {
Window(onCloseRequest = ::exitApplication) { Window(onCloseRequest = ::exitApplication) {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
window.cursor = Cursor(Cursor.CROSSHAIR_CURSOR) window.dropTarget = DropTarget().apply {
addDropTargetListener(object : DropTargetAdapter() {
override fun drop(event: DropTargetDropEvent) {
event.acceptDrop(DnDConstants.ACTION_COPY);
val fileName = event.transferable.getTransferData(DataFlavor.javaFileListFlavor)
println(fileName)
}
})
}
} }
} }
} }

Loading…
Cancel
Save