From d95c61a6b1c15996ed48be169dfa2a2679e6ab2d Mon Sep 17 00:00:00 2001 From: akurasov <86794754+akurasov@users.noreply.github.com> Date: Mon, 16 Aug 2021 13:19:02 +0300 Subject: [PATCH] Fixes for Context menu tutorial (#1059) * Small fixes for Context Menu tutorial * Fixing Context Menu tutorial --- tutorials/Context_Menu/README.md | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tutorials/Context_Menu/README.md b/tutorials/Context_Menu/README.md index f0c2bb2696..9ea5695b07 100644 --- a/tutorials/Context_Menu/README.md +++ b/tutorials/Context_Menu/README.md @@ -11,6 +11,14 @@ There is out-of-the box context menu support for TextField and Selectable text. To enable standard context menu for a TextField you just need to put it inside DesktopMaterialTheme: ```kotlin +import androidx.compose.desktop.DesktopMaterialTheme +import androidx.compose.material.Text +import androidx.compose.material.TextField +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.window.singleWindowApplication + @OptIn(ExperimentalComposeUiApi::class, androidx.compose.foundation.ExperimentalFoundationApi::class) fun main() = singleWindowApplication(title = "Context menu") { DesktopMaterialTheme { //it is mandatory for Context Menu @@ -29,6 +37,12 @@ Standard context menu for TextField contains the following items based on text s Enabling standard context menu for a Text component is similar - you just need to make it selectable: ```kotlin +import androidx.compose.desktop.DesktopMaterialTheme +import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.material.Text +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.window.singleWindowApplication + @OptIn(ExperimentalComposeUiApi::class, androidx.compose.foundation.ExperimentalFoundationApi::class) fun main() = singleWindowApplication(title = "Context menu") { DesktopMaterialTheme { //it is mandatory for Context Menu @@ -44,6 +58,22 @@ Context menu for text contains just Copy action. To enable additional context menu items for TextField and Text components, ContextMenuDataProvider and ContextMenuItem elements are used: ```kotlin +import androidx.compose.desktop.DesktopMaterialTheme +import androidx.compose.foundation.ContextMenuDataProvider +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.material.Text +import androidx.compose.material.TextField +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ContextMenuItem +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.singleWindowApplication + @OptIn(ExperimentalComposeUiApi::class, androidx.compose.foundation.ExperimentalFoundationApi::class) fun main() = singleWindowApplication(title = "Context menu") { DesktopMaterialTheme { //it is mandatory for Context Menu @@ -79,6 +109,20 @@ In this example Text/TextField context menus will be extended with two additiona There is a possibility to create a context menu for an arbitary application window area. This is implemented using ContextMenuArea API that is similar to ContextMenuDataProvider. ```kotlin + +import androidx.compose.desktop.DesktopMaterialTheme +import androidx.compose.foundation.ContextMenuArea +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.ContextMenuItem +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.singleWindowApplication + @OptIn(ExperimentalComposeUiApi::class, androidx.compose.foundation.ExperimentalFoundationApi::class) fun main() = singleWindowApplication(title = "Context menu") { DesktopMaterialTheme { //it is mandatory for Context Menu