Browse Source

Fixed tabs in tutorials.

pull/15/head
Roman Sedaikin 4 years ago
parent
commit
3ae3e3bbc1
  1. 220
      tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md
  2. 179
      tutorials/Window_API/WindowManagement.md

220
tutorials/Tray_Notifications_MenuBar/TrayNotifierMenuBar.md

@ -21,36 +21,36 @@ import androidx.compose.ui.window.Item
import androidx.compose.ui.window.Tray import androidx.compose.ui.window.Tray
fun main() { fun main() {
Window { Window {
onActive { onActive {
val tray = Tray().apply { val tray = Tray().apply {
icon(getImageIcon()) // custom function that returns BufferedImage icon(getImageIcon()) // custom function that returns BufferedImage
menu( menu(
Item( Item(
name = "About", name = "About",
onClick = { onClick = {
println("This is MyApp") println("This is MyApp")
} }
), ),
Item( Item(
name = "Send notification", name = "Send notification",
onClick = { onClick = {
tray.notify("Notification", "Message from MyApp!") tray.notify("Notification", "Message from MyApp!")
} }
), ),
Item( Item(
name = "Exit", name = "Exit",
onClick = { onClick = {
AppManager.exit() AppManager.exit()
} }
) )
) )
} }
onDispose { onDispose {
tray.remove() tray.remove()
} }
} }
} }
} }
``` ```
@ -70,20 +70,20 @@ import androidx.compose.material.Button
import androidx.compose.ui.window.Notifier import androidx.compose.ui.window.Notifier
fun main() { fun main() {
val message = "Some message!" val message = "Some message!"
Window { Window {
Column { Column {
Button(onClick = { Notifier().notify("Notification.", message) }) { Button(onClick = { Notifier().notify("Notification.", message) }) {
Text(text = "Notify") Text(text = "Notify")
} }
Button(onClick = { Notifier().warn("Warning.", message) }) { Button(onClick = { Notifier().warn("Warning.", message) }) {
Text(text = "Warning") Text(text = "Warning")
} }
Button(onClick = { Notifier().error("Error.", message) }) { Button(onClick = { Notifier().error("Error.", message) }) {
Text(text = "Error") Text(text = "Error")
} }
} }
} }
} }
``` ```
@ -102,40 +102,40 @@ import androidx.compose.ui.window.MenuBar
import java.awt.event.KeyEvent import java.awt.event.KeyEvent
fun main() { fun main() {
AppManager.menu( AppManager.menu(
MenuBar( MenuBar(
Menu( Menu(
name = "Actions", name = "Actions",
Item( Item(
name = "About", name = "About",
onClick = { println("This is MyApp") }, onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I) shortcut = keyStroke(KeyEvent.VK_I)
), ),
Item( Item(
name = "Exit", name = "Exit",
onClick = { AppManager.exit() }, onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X) shortcut = keyStroke(KeyEvent.VK_X)
) )
), ),
Menu( Menu(
name = "File", name = "File",
Item( Item(
name = "Copy", name = "Copy",
onClick = { println("Copy operation.") }, onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C) shortcut = keyStroke(KeyEvent.VK_C)
), ),
Item( Item(
name = "Paste", name = "Paste",
onClick = { println("Paste operation.") }, onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V) shortcut = keyStroke(KeyEvent.VK_V)
) )
) )
) )
) )
Window { Window {
// content // content
} }
} }
``` ```
@ -151,38 +151,38 @@ import androidx.compose.ui.window.MenuBar
import java.awt.event.KeyEvent import java.awt.event.KeyEvent
fun main() { fun main() {
Window( Window(
menuBar = MenuBar( menuBar = MenuBar(
Menu( Menu(
name = "Actions", name = "Actions",
Item( Item(
name = "About", name = "About",
onClick = { println("This is MyApp") }, onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I) shortcut = keyStroke(KeyEvent.VK_I)
), ),
Item( Item(
name = "Exit", name = "Exit",
onClick = { AppManager.exit() }, onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X) shortcut = keyStroke(KeyEvent.VK_X)
) )
), ),
Menu( Menu(
name = "File", name = "File",
Item( Item(
name = "Copy", name = "Copy",
onClick = { println("Copy operation.") }, onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C) shortcut = keyStroke(KeyEvent.VK_C)
), ),
Item( Item(
name = "Paste", name = "Paste",
onClick = { println("Paste operation.") }, onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V) shortcut = keyStroke(KeyEvent.VK_V)
) )
) )
) )
) { ) {
// content // content
} }
} }
``` ```

179
tutorials/Window_API/WindowManagement.md

@ -12,9 +12,9 @@ The main class for creating windows is AppWindow. The easiest way to create and
import androidx.compose.desktop.AppWindow import androidx.compose.desktop.AppWindow
fun main() { fun main() {
AppWindow().show { AppWindow().show {
// content // content
} }
} }
``` ```
@ -33,19 +33,19 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
fun main() { fun main() {
Window { Window {
val dialogState = remember { mutableStateOf(false) } val dialogState = remember { mutableStateOf(false) }
Button(onClick = { dialogState.value = true }) Button(onClick = { dialogState.value = true })
if (dialogState.value) { if (dialogState.value) {
Dialog( Dialog(
onDismissEvent = { dialogState.value = false } onDismissEvent = { dialogState.value = false }
) { ) {
// dialog's content // dialog's content
} }
} }
} }
} }
``` ```
@ -72,24 +72,24 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
fun main() { fun main() {
Window( Window(
title = "MyApp", title = "MyApp",
size = IntSize(800, 600), size = IntSize(800, 600),
location = IntOffset(200, 200), location = IntOffset(200, 200),
centered = false, // true - by default centered = false, // true - by default
icon = getMyAppIcon(), // custom function that returns BufferedImage icon = getMyAppIcon(), // custom function that returns BufferedImage
menuBar = getMyAppMenuBar(), // custom function that returns MenuBar menuBar = getMyAppMenuBar(), // custom function that returns MenuBar
undecorated = true, // false - by default undecorated = true, // false - by default
events = WindowEvents( events = WindowEvents(
onOpen = { println("OnOpen") }, onOpen = { println("OnOpen") },
... // here may be other events ... // here may be other events
onResize = { size -> onResize = { size ->
println("Size: $size") println("Size: $size")
} }
) )
) { ) {
// content // content
} }
} }
``` ```
@ -114,16 +114,16 @@ import androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
fun main() { fun main() {
Window { Window {
val current = AppWindowAmbient.current val current = AppWindowAmbient.current
Button( Button(
onClick = { onClick = {
if (current != null) { if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}") println("Title: ${current.title} ${current.x} ${current.y}")
} }
} }
) )
} }
} }
``` ```
@ -134,16 +134,16 @@ import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
fun main() { fun main() {
Window { Window {
Button( Button(
onClick = { onClick = {
val current = AppManager.getCurrentFocusedWindow() val current = AppManager.getCurrentFocusedWindow()
if (current != null) { if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}") println("Title: ${current.title} ${current.x} ${current.y}")
} }
} }
) )
} }
} }
``` ```
@ -160,16 +160,16 @@ import androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
fun main() { fun main() {
Window { Window {
val current = AppWindowAmbient.current val current = AppWindowAmbient.current
Button( Button(
onClick = { onClick = {
if (current != null) { if (current != null) {
current.setWindowCentered() current.setWindowCentered()
} }
} }
) )
} }
} }
``` ```
@ -193,17 +193,17 @@ import androidx.compose.desktop.Window
import androidx.compose.desktop.WindowEvents import androidx.compose.desktop.WindowEvents
fun main() { fun main() {
Window( Window(
events = WindowEvents( events = WindowEvents(
onOpen = { println("OnOpen") }, onOpen = { println("OnOpen") },
... // here may be other events ... // here may be other events
onResize = { size -> onResize = { size ->
println("Size: $size") println("Size: $size")
} }
) )
) { ) {
// content // content
} }
} }
``` ```
@ -214,14 +214,14 @@ The AppManager class is used to customize the behavior of the entire application
1. Description of common application events 1. Description of common application events
```kotlin ```kotlin
AppManager.onEvent( AppManager.onEvent(
onAppStart = { println("OnAppStart") }, onAppStart = { println("OnAppStart") },
onAppExit = { println("OnAppExit") } onAppExit = { println("OnAppExit") }
) )
``` ```
2. Customization of common application context menu 2. Customization of common application context menu
```kotlin ```kotlin
AppManager.menu( AppManager.menu(
getCommonAppMenuBar() // custom function that returns MenuBar getCommonAppMenuBar() // custom function that returns MenuBar
) )
``` ```
3. Access to the application windows list 3. Access to the application windows list
@ -246,17 +246,16 @@ import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window import androidx.compose.desktop.Window
fun main() { fun main() {
Window { Window {
Button( Button(
onClick = { onClick = {
val current = AppManager.getCurrentFocusedWindow() val current = AppManager.getCurrentFocusedWindow()
if (current != null) { if (current != null) {
val jFrame = current.window val jFrame = current.window
// do whatever you want with it, for example add some new listeners // do whatever you want with it, for example add some new listeners
} }
} }
) )
} }
} }
``` ```

Loading…
Cancel
Save