-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add more info about lwjgl integration #1738
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,53 @@ Note that: | |
- not all features are implemented | ||
- not all features are currently supported (Accessibility, Input Methods) | ||
- to pass some event information it is needed to pass it via AWT events (java.awt.KeyEvent and java.awt.MouseEvent). In the future versions of Compose we plan to get rid of the need of AWT events. | ||
- it has bugs (it doesn't show cursor in TextField) | ||
|
||
|
||
|
||
## Problems | ||
|
||
### Cursor In TextField | ||
This is easy, you need to provide `androidx.compose.ui.platform.WindowInfo` in CompositionLocal | ||
|
||
For example: | ||
```kotlin | ||
CompositionLocalProvider( | ||
LocalWindowInfo provides object : WindowInfo { override val isWindowFocused: Boolean = true } | ||
) { | ||
// Your App | ||
} | ||
``` | ||
|
||
|
||
### Popup | ||
Since Compose still use some AWT events (https://github.com/JetBrains/compose-jb/issues/1736), you can provide a fake contaniner. | ||
|
||
```kotlin | ||
val awtContainer = object : Container() {} | ||
|
||
// call it when your custom compose app changes window position | ||
fun onWindowUpdate(x: Int, y: Int, width: Int, height: Int) { | ||
awtContainer.setBounds(x, y, width, height) | ||
} | ||
|
||
CompositionLocalProvider( | ||
LocalLayerContainer provides awtContainer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This can be removed or changed if we could have something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, how do you able to use/access There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I just create a fake class and override in the classpath(Gradle default duplicate strategy should work). My current workaround is to create a package import androidx.compose.runtime.staticCompositionLocalOf
import your.package.awtContainer
val LocalLayerContainer: androidx.compose.runtime.ProvidableCompositionLocal<java.awt.Container> =
staticCompositionLocalOf { awtContainer } I am also trying to make a kotlin compiler plugin to remove all access modifiers and make everything public open. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Smart :). Could you add this into the doc? Also, could you describe in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
because we use
when I try to run:
How have you solved it?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, weird. I didn't run into a null pointer error (with ComposeSence). It might be caused by AWT headless property, try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works for me:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can avoid classpath hacks with just using |
||
) { | ||
// Your App | ||
} | ||
``` | ||
|
||
`LocalLayerContainer` is internal, so you need to use a trick. | ||
|
||
Create a package `androidx.compose.ui.awt` and create a file `LocalLayerContainer.desktop.kt` | ||
|
||
Put following code inside | ||
```kotlin | ||
import androidx.compose.runtime.staticCompositionLocalOf | ||
import your.package.yourFakeAwtContainer | ||
|
||
val LocalLayerContainer: androidx.compose.runtime.ProvidableCompositionLocal<java.awt.Container> = | ||
staticCompositionLocalOf { yourFakeAwtContainer } | ||
``` | ||
|
||
Then you would be able to access the internal `LocalLayerContainer` |
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.