Skip to content

Conversation

@rock3r
Copy link

@rock3r rock3r commented Nov 11, 2025

This exposes a showLayoutBounds property on ComposePanel (desktop only) that allows users to turn on or off the showLayoutBounds property on the root layout node owner(s).

The change mostly pipes the property up to the ComposePanel, but has no public API impact. The new property is also annotated as experimental. The Skiko RootNodeOwner's showLayoutBounds is now also a state, to cause a full recomposition when the value changes and see it reflected in the UI.

Screen.Recording.2025-11-12.at.13.04.16.mov

Fixes https://youtrack.jetbrains.com/issue/CMP-9264/Expose-API-on-ComposePanel-to-toggle-showLayoutBounds

Testing

Manual testing as it's not automatable:

/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.compose.mpp.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.unit.dp
import java.awt.BorderLayout
import java.awt.Dimension
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.SwingUtilities

fun main() {
    SwingUtilities.invokeLater { swingMain() }
}

@OptIn(ExperimentalComposeUiApi::class)
private fun swingMain() {
    val frame = JFrame("Show layout bounds")
    frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
    frame.minimumSize = Dimension(500, 400)
    frame.isResizable = false

    val mainPanel = JPanel(BorderLayout()).apply {
        val composePanel = ComposePanel()

        composePanel.setContent {
            Column(
                Modifier.fillMaxSize().padding(12.dp)
            ) {
                BasicText("Text 123 text")

                Spacer(Modifier.height(10.dp))

                Box(
                    Modifier.border(1.dp, Color.LightGray, RoundedCornerShape(4.dp))
                        .background(Color.White, RoundedCornerShape(4.dp))
                        .clip(RoundedCornerShape(4.dp)).clickable {
                            composePanel.showLayoutBounds = !composePanel.showLayoutBounds
                        }.padding(horizontal = 16.dp, vertical = 8.dp)
                ) {
                    BasicText("Toggle layout bounds")
                }

                Spacer(Modifier.height(10.dp))

                FlowRow(
                    horizontalArrangement = Arrangement.spacedBy(10.dp),
                    verticalArrangement = Arrangement.spacedBy(10.dp)
                ) {
                    repeat(25) {
                        Row(
                            Modifier.padding(2.dp).clickable {}.pointerHoverIcon(
                                PointerIcon.Hand
                            ), verticalAlignment = Alignment.CenterVertically
                        ) {
                            Box(
                                Modifier.size(16.dp)
                                    .background(Color.LightGray, RoundedCornerShape(4.dp))
                            )
                            Spacer(Modifier.width(2.dp))
                            BasicText(
                                "Text", Modifier.background(Color.White).hoverable(
                                    remember { MutableInteractionSource() })
                            )
                            BasicText(" $it")
                        }
                    }
                }
            }
        }

        add(composePanel, BorderLayout.CENTER)
    }

    frame.contentPane.add(mainPanel, BorderLayout.CENTER)
    frame.isVisible = true
}

Release Notes

N/A

@igordmn igordmn self-requested a review November 11, 2025 17:52
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature freeze for 1.10 has already happened, blocking until we create a release branch

@rock3r rock3r force-pushed the sebp/add-showLayoutBounds-api branch from cae0284 to f41302c Compare November 12, 2025 12:03
@rock3r
Copy link
Author

rock3r commented Nov 12, 2025

Thanks @MatkovIvan for the help making this better :)

@rock3r rock3r force-pushed the sebp/add-showLayoutBounds-api branch 2 times, most recently from fdfc226 to 08b2853 Compare November 12, 2025 14:12
@rock3r rock3r force-pushed the sebp/add-showLayoutBounds-api branch 2 times, most recently from 515704a to 7d69010 Compare November 12, 2025 18:27
This exposes a showLayoutBounds property on ComposePanel (desktop only)
that allows users to turn on or off the showLayoutBounds property on
the root layout node owner(s).

The change mostly pipes the property up to the ComposePanel, but has no
public API impact. The new property is also annotated as experimental.
The Skiko RootNodeOwner's showLayoutBounds is now also a state, to cause
a full recomposition when the value changes and see it reflected in the
UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants