JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.57k stars 1.13k forks source link

Swing/AWT interoperability - GLCanvas, GLJPanel #614

Open imptah opened 3 years ago

imptah commented 3 years ago

I'm working on Desktop application with Map functionality, and I wanted to use WorldWind Java SDK (3D map framework). After adding JPanel with GLJPanel or GLCanvas to the SwingPanel, it doesn't render it. Is it somehow related to Skia? Does it expect to have GLJPanel or GLCanvas be successfully rendered?

olonho commented 3 years ago

Not sure if GLCanvas is compatible with the way Skia interoperates with AWT. What will happen if you'll try another direction, and put GLCanvas in Swing hierarchy, and use ComposePanel for Compose UI?

jimgoog commented 3 years ago

It seems that using a SwingPanel to add a JPanel does create a Swing hierarchy, so it seems like that should work, right @olonho ? Or what am I missing here?

@imptah Does the same code adding a JPanel with GLJPanel or GLCanvas work if Compose is not involved? It was unclear from your bug report if your code was tested/working without Compose. Do you have a snippet which demonstrates the issue?

imptah commented 3 years ago

Not sure if GLCanvas is compatible with the way Skia interoperates with AWT. What will happen if you'll try another direction, and put GLCanvas in Swing hierarchy, and use ComposePanel for Compose UI?

Vice versa, when use ComposePanel inside Swing hierarchy I had next results:

JFrame->JPanel with BorderLayout —- it works, and everything fine, if we are not needed visualize ComposePanel over GLCanvas;

JFrame->JPanel with OverlayLayout -- depends on what index inside of OverlayLayout we set for our ComposePanel it will be interactable and responsive for events or not.

JFrame->JLayeredPane — we can achieve ComposePanel visualized above GLCanvas, and both can responses for events, but ComposePanel background are not transparent.

imptah commented 3 years ago

The same code of JPanel with GLCanvas perfectly works without Compose. But when we are trying to do that inside SwingPanel it doesn't work as expected.

Here is repository with example.