-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new page for context menus #273
base: master
Are you sure you want to change the base?
Conversation
ElviraMustafina
commented
Nov 13, 2024
- new page for context menus
- new screenshots
- minor updates to code samples: added titles for windows, updated comments
- added info about localization
|
||
The default context menu for a text field includes the following actions, depending on the cursor's position and the | ||
selection range: Copy, Cut, Paste, and Select All. | ||
To enable the standard context menu in the text field, just use the `TextField` component from the Material theme. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enable the standard context menu in the text field, just use the `TextField` component from the Material theme. | |
The default context menu is available by default in the material `TextField` or the foundation `BasicTextField`. |
We have 3 text fields:
androidx.compose.foundation.text.BasicTextField
androidx.compose.material.TextField
androidx.compose.material3.TextField
all contain the default context menu.
The new item adjusts to the text selection: | ||
|
||
```kotlin | ||
import androidx.compose.foundation.ContextMenuDataProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import androidx.compose.foundation.ContextMenuDataProvider | |
import androidx.compose.foundation.ContextMenuDataProvider | |
import androidx.compose.foundation.ContextMenuItem | |
import androidx.compose.foundation.ContextMenuState | |
import androidx.compose.foundation.ExperimentalFoundationApi | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.text.LocalTextContextMenu | |
import androidx.compose.foundation.text.TextContextMenu | |
import androidx.compose.foundation.text.selection.SelectionContainer | |
import androidx.compose.material.Text | |
import androidx.compose.material.TextField | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.CompositionLocalProvider | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import androidx.compose.ui.platform.LocalUriHandler | |
import androidx.compose.ui.text.AnnotatedString | |
import androidx.compose.ui.window.singleWindowApplication | |
import java.net.URLEncoder | |
import java.nio.charset.Charset | |
fun main() = singleWindowApplication { | |
CustomTextMenuProvider { | |
Column { | |
SelectionContainer { | |
Text("Hello, Compose!") | |
} | |
var text by remember { mutableStateOf("") } | |
TextField(text, { text = it }) | |
} | |
} | |
} | |
@OptIn(ExperimentalFoundationApi::class) | |
@Composable | |
fun CustomTextMenuProvider(content: @Composable () -> Unit) { |
We had an issue in the previous version - we used ComposePanel
, but it isn't related to this section. We should use just standard entry point. The screenshot and behaviour don't change with the new code.
## Swing interoperability | ||
|
||
If you are embedding Compose code into an existing Swing application and need the context menu to match the appearance and | ||
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `TextContextMenu` uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `TextContextMenu` uses | |
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `LocalTextContextMenu` uses |