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
fun main() {
Window {
onActive {
val tray = Tray().apply {
icon(getImageIcon()) // custom function that returns BufferedImage
menu(
Item(
name = "About",
onClick = {
println("This is MyApp")
}
),
Item(
name = "Send notification",
onClick = {
tray.notify("Notification", "Message from MyApp!")
}
),
Item(
name = "Exit",
onClick = {
AppManager.exit()
}
)
)
}
onDispose {
tray.remove()
}
}
}
Window {
onActive {
val tray = Tray().apply {
icon(getImageIcon()) // custom function that returns BufferedImage
menu(
Item(
name = "About",
onClick = {
println("This is MyApp")
}
),
Item(
name = "Send notification",
onClick = {
tray.notify("Notification", "Message from MyApp!")
}
),
Item(
name = "Exit",
onClick = {
AppManager.exit()
}
)
)
}
onDispose {
tray.remove()
}
}
}
}
```
@ -70,20 +70,20 @@ import androidx.compose.material.Button
import androidx.compose.ui.window.Notifier
fun main() {
val message = "Some message!"
Window {
Column {
Button(onClick = { Notifier().notify("Notification.", message) }) {
Text(text = "Notify")
}
Button(onClick = { Notifier().warn("Warning.", message) }) {
Text(text = "Warning")
}
Button(onClick = { Notifier().error("Error.", message) }) {
Text(text = "Error")
}
}
}
val message = "Some message!"
Window {
Column {
Button(onClick = { Notifier().notify("Notification.", message) }) {
Text(text = "Notify")
}
Button(onClick = { Notifier().warn("Warning.", message) }) {
Text(text = "Warning")
}
Button(onClick = { Notifier().error("Error.", message) }) {
Text(text = "Error")
}
}
}
}
```
@ -102,40 +102,40 @@ import androidx.compose.ui.window.MenuBar
import java.awt.event.KeyEvent
fun main() {
AppManager.menu(
MenuBar(
Menu(
name = "Actions",
Item(
name = "About",
onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I)
),
Item(
name = "Exit",
onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X)
)
),
Menu(
name = "File",
Item(
name = "Copy",
onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C)
),
Item(
name = "Paste",
onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V)
)
)
)
)
Window {
// content
}
AppManager.menu(
MenuBar(
Menu(
name = "Actions",
Item(
name = "About",
onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I)
),
Item(
name = "Exit",
onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X)
)
),
Menu(
name = "File",
Item(
name = "Copy",
onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C)
),
Item(
name = "Paste",
onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V)
)
)
)
)
Window {
// content
}
}
```
@ -151,38 +151,38 @@ import androidx.compose.ui.window.MenuBar
import java.awt.event.KeyEvent
fun main() {
Window(
menuBar = MenuBar(
Menu(
name = "Actions",
Item(
name = "About",
onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I)
),
Item(
name = "Exit",
onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X)
)
),
Menu(
name = "File",
Item(
name = "Copy",
onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C)
),
Item(
name = "Paste",
onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V)
)
)
)
) {
// content
}
Window(
menuBar = MenuBar(
Menu(
name = "Actions",
Item(
name = "About",
onClick = { println("This is MyApp") },
shortcut = keyStroke(KeyEvent.VK_I)
),
Item(
name = "Exit",
onClick = { AppManager.exit() },
shortcut = keyStroke(KeyEvent.VK_X)
)
),
Menu(
name = "File",
Item(
name = "Copy",
onClick = { println("Copy operation.") },
shortcut = keyStroke(KeyEvent.VK_C)
),
Item(
name = "Paste",
onClick = { println("Paste operation.") },
shortcut = keyStroke(KeyEvent.VK_V)
)
)
)
) {
// 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
fun main() {
AppWindow().show {
// content
}
AppWindow().show {
// content
}
}
```
@ -33,19 +33,19 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.window.Dialog
fun main() {
Window {
val dialogState = remember { mutableStateOf(false) }
Button(onClick = { dialogState.value = true })
if (dialogState.value) {
Dialog(
onDismissEvent = { dialogState.value = false }
) {
// dialog's content
}
}
}
Window {
val dialogState = remember { mutableStateOf(false) }
Button(onClick = { dialogState.value = true })
if (dialogState.value) {
Dialog(
onDismissEvent = { dialogState.value = false }
) {
// dialog's content
}
}
}
}
```
@ -72,24 +72,24 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
fun main() {
Window(
title = "MyApp",
size = IntSize(800, 600),
location = IntOffset(200, 200),
centered = false, // true - by default
icon = getMyAppIcon(), // custom function that returns BufferedImage
menuBar = getMyAppMenuBar(), // custom function that returns MenuBar
undecorated = true, // false - by default
events = WindowEvents(
onOpen = { println("OnOpen") },
... // here may be other events
onResize = { size ->
println("Size: $size")
}
)
) {
// content
}
Window(
title = "MyApp",
size = IntSize(800, 600),
location = IntOffset(200, 200),
centered = false, // true - by default
icon = getMyAppIcon(), // custom function that returns BufferedImage
menuBar = getMyAppMenuBar(), // custom function that returns MenuBar
undecorated = true, // false - by default
events = WindowEvents(
onOpen = { println("OnOpen") },
... // here may be other events
onResize = { size ->
println("Size: $size")
}
)
) {
// content
}
}
```
@ -114,16 +114,16 @@ import androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window
fun main() {
Window {
val current = AppWindowAmbient.current
Button(
onClick = {
if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}")
}
}
)
}
Window {
val current = AppWindowAmbient.current
Button(
onClick = {
if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}")
}
}
)
}
}
```
@ -134,16 +134,16 @@ import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window
fun main() {
Window {
Button(
onClick = {
val current = AppManager.getCurrentFocusedWindow()
if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}")
}
}
)
}
Window {
Button(
onClick = {
val current = AppManager.getCurrentFocusedWindow()
if (current != null) {
println("Title: ${current.title} ${current.x} ${current.y}")
}
}
)
}
}
```
@ -160,16 +160,16 @@ import androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window
fun main() {
Window {
val current = AppWindowAmbient.current
Button(
onClick = {
if (current != null) {
current.setWindowCentered()
}
}
)
}
Window {
val current = AppWindowAmbient.current
Button(
onClick = {
if (current != null) {
current.setWindowCentered()
}
}
)
}
}
```
@ -193,17 +193,17 @@ import androidx.compose.desktop.Window
import androidx.compose.desktop.WindowEvents
fun main() {
Window(
events = WindowEvents(
onOpen = { println("OnOpen") },
... // here may be other events
onResize = { size ->
println("Size: $size")
}
)
) {
// content
}
Window(
events = WindowEvents(
onOpen = { println("OnOpen") },
... // here may be other events
onResize = { size ->
println("Size: $size")
}
)
) {
// content
}
}
```
@ -214,14 +214,14 @@ The AppManager class is used to customize the behavior of the entire application
1. Description of common application events
```kotlin
AppManager.onEvent(
onAppStart = { println("OnAppStart") },
onAppExit = { println("OnAppExit") }
onAppStart = { println("OnAppStart") },
onAppExit = { println("OnAppExit") }
)
```
2. Customization of common application context menu
```kotlin
AppManager.menu(
getCommonAppMenuBar() // custom function that returns MenuBar
getCommonAppMenuBar() // custom function that returns MenuBar
)
```
3. Access to the application windows list
@ -246,17 +246,16 @@ import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window
fun main() {
Window {
Button(
onClick = {
val current = AppManager.getCurrentFocusedWindow()
if (current != null) {
val jFrame = current.window
// do whatever you want with it, for example add some new listeners
}
}
)
}
Window {
Button(
onClick = {
val current = AppManager.getCurrentFocusedWindow()
if (current != null) {
val jFrame = current.window
// do whatever you want with it, for example add some new listeners
}
}
)
}
}
```

Loading…
Cancel
Save