Skip to content
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

Make ComposePanel.windowContainer public #992

Merged
merged 6 commits into from Jan 18, 2024

Conversation

MatkovIvan
Copy link
Member

@MatkovIvan MatkovIvan commented Jan 15, 2024

Proposed Changes

Testing

Test: try to use this API with compose.layers.type=COMPONENT

@OptIn(ExperimentalComposeUiApi::class)
fun main() = SwingUtilities.invokeLater {
    System.setProperty("compose.swing.render.on.graphics", "true")
    System.setProperty("compose.layers.type", "COMPONENT")

    val window = JFrame()
    window.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE

    val contentPane = JLayeredPane()
    contentPane.layout = null

    val composePanel = ComposePanel()
    composePanel.setBounds(200, 200, 200, 200)
    composePanel.setContent {
        ComposeContent()
    }
    composePanel.windowContainer = contentPane  // Use the full window for dialogs
    contentPane.add(composePanel)
    
    window.contentPane.add(contentPane)
    window.setSize(800, 600)
    window.isVisible = true
}

@Composable
fun ComposeContent() {
    Box(Modifier.fillMaxSize().background(Color.Green)) {
        Dialog(onDismissRequest = {}) {
            Box(Modifier.size(100.dp).background(Color.Yellow))
        }
    }
}
Default windowContainer Full-size windowContainer
Screenshot 2024-01-17 at 17 35 26 Screenshot 2024-01-17 at 17 35 41

@m-sasha
Copy link

m-sasha commented Jan 17, 2024

Can you explain a bit why it needs to be public?

@igordmn
Copy link
Collaborator

igordmn commented Jan 17, 2024

Can you explain a bit why it needs to be public?

If I am not mistaken, It is needed for a case, when some small ComposePanel tries to show a popup/dialog outside of the panel. In this case, users should set layersContainer to the window.contentPane.

Worth to add an example.

Also, we need to change the description, so it can be included in the changelog and outside user can understand what the feature is about. And change the KDoc

@MatkovIvan MatkovIvan force-pushed the ivan.matkov/public-layers-container branch from 4563aec to 7c91c2f Compare January 17, 2024 16:30
@MatkovIvan MatkovIvan changed the title Make ComposePanel.layersContainer public Make ComposePanel.windowContainer public Jan 17, 2024
@MatkovIvan MatkovIvan force-pushed the ivan.matkov/public-layers-container branch from 6eea06c to d7b9f28 Compare January 17, 2024 19:37
@MatkovIvan MatkovIvan force-pushed the ivan.matkov/public-layers-container branch from d7b9f28 to 87379de Compare January 18, 2024 02:28
@MatkovIvan MatkovIvan merged commit 0f26ac5 into jb-main Jan 18, 2024
6 checks passed
@MatkovIvan MatkovIvan deleted the ivan.matkov/public-layers-container branch January 18, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants