Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package androidx.compose.ui.awt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.layout.layoutId
Expand Down Expand Up @@ -341,4 +342,16 @@ class ComposeDialog : JDialog {

override fun removeMouseWheelListener(listener: MouseWheelListener) =
composePanel.removeMouseWheelListener(listener)

/**
* Set the visual debug option that shows bounds for all nodes in the hierarchy.
*/
@InternalComposeUiApi
var showLayoutBounds: Boolean
get() {
return composePanel.showLayoutBounds
}
set(value) {
composePanel.showLayoutBounds = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package androidx.compose.ui.awt
import androidx.compose.runtime.Composable
import androidx.compose.ui.ComposeFeatureFlags
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.LayerType
import androidx.compose.ui.awt.RenderSettings.SkiaSurface
import androidx.compose.ui.awt.RenderSettings.SwingGraphics
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.node.InternalCoreApi
import androidx.compose.ui.scene.ComposeContainer
import androidx.compose.ui.semantics.SemanticsOwner
import androidx.compose.ui.window.WindowExceptionHandler
Expand Down Expand Up @@ -171,7 +173,7 @@ class ComposePanel @ExperimentalComposeUiApi constructor(

override fun getPreferredSize(): Dimension? = if (isPreferredSizeSet) {
super.getPreferredSize()
} else {
} else {
_composeContainer?.preferredSize ?: Dimension(0, 0)
}

Expand Down Expand Up @@ -240,6 +242,8 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
// content.
val composeContainer = _composeContainer ?: createComposeContainer().also {
_composeContainer = it
@OptIn(InternalCoreApi::class)
it.showLayoutBounds = showLayoutBounds
val composeContent = _composeContent
if (composeContent != null) {
it.setContent(composeContent)
Expand Down Expand Up @@ -272,6 +276,7 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
focusManager.takeFocus(FocusDirection.Next)
}
}

else -> Unit
}
}
Expand Down Expand Up @@ -378,4 +383,17 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
fun renderImmediately() {
_composeContainer?.renderImmediately()
}

/**
* Set the visual debug option that shows bounds for all nodes in the hierarchy.
*/
@InternalComposeUiApi
var showLayoutBounds: Boolean = _composeContainer?.showLayoutBounds ?: false
set(value) {
// We're assuming we own the scene and thus this value, and nobody
// else will change it from under us, so we never get out of sync.
field = value
@OptIn(InternalCoreApi::class)
_composeContainer?.showLayoutBounds = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package androidx.compose.ui.awt
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.layout.layoutId
Expand Down Expand Up @@ -327,4 +328,16 @@ class ComposeWindow @ExperimentalComposeUiApi constructor(

override fun removeMouseWheelListener(listener: MouseWheelListener) =
composePanel.removeMouseWheelListener(listener)

/**
* Set the visual debug option that shows bounds for all nodes in the hierarchy.
*/
@InternalComposeUiApi
var showLayoutBounds: Boolean
get() {
return composePanel.showLayoutBounds
}
set(value) {
composePanel.showLayoutBounds = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,12 @@ internal class ComposeWindowPanel(
override fun removeMouseMotionListener(listener: MouseMotionListener) {
contentComponent.removeMouseMotionListener(listener)
}

var showLayoutBounds: Boolean
get() {
return _composeContainer?.showLayoutBounds ?: false
}
set(value) {
_composeContainer?.showLayoutBounds = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ internal class ComposeContainer(
val preferredSize by mediator::preferredSize
val semanticsOwners by mediator::semanticsOwners

var showLayoutBounds by mediator::showLayoutBounds

private var isDisposed = false
private var isDetached = true
private var isMinimized = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ internal class ComposeSceneMediator(
var compositionLocalContext: CompositionLocalContext?
get() = scene.compositionLocalContext
set(value) { scene.compositionLocalContext = value }
var showLayoutBounds: Boolean
get() = scene.showLayoutBounds
set(value) {
scene.showLayoutBounds = value
}


/**
* Provides the size of ComposeScene content inside infinity constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ internal class RootNodeOwner(
override val fontLoader = androidx.compose.ui.text.platform.FontLoader()
override val fontFamilyResolver = createFontFamilyResolver()
override val layoutDirection get() = _layoutDirection
override var showLayoutBounds = false
override var showLayoutBounds by mutableStateOf(false)
@InternalCoreApi
set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import androidx.compose.runtime.CompositionContext
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -40,8 +39,6 @@ import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.input.rotary.RotaryScrollEvent
import androidx.compose.ui.node.SnapshotInvalidationTracker
import androidx.compose.ui.platform.GlobalSnapshotManager
import androidx.compose.ui.platform.LocalPlatformScreenReader
import androidx.compose.ui.platform.LocalPlatformWindowInsets
import androidx.compose.ui.platform.ProvidePlatformCompositionLocals
import androidx.compose.ui.util.trace
import kotlin.concurrent.Volatile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.PointerInputEvent
import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.input.rotary.RotaryScrollEvent
import androidx.compose.ui.node.InternalCoreApi
import androidx.compose.ui.node.RootNodeOwner
import androidx.compose.ui.platform.PlatformContext
import androidx.compose.ui.platform.setContent
Expand Down Expand Up @@ -273,6 +274,13 @@ private class CanvasLayersComposeSceneImpl(
forEachOwner { it.draw(canvas) }
}

override var showLayoutBounds: Boolean = false
@OptIn(InternalCoreApi::class)
set(value) {
field = value
forEachOwner { it.owner.showLayoutBounds = value }
}

/**
* Find hovered owner for position of first pointer.
*/
Expand Down Expand Up @@ -560,6 +568,8 @@ private class CanvasLayersComposeSceneImpl(
private var onKeyEvent: ((KeyEvent) -> Boolean)? = null

init {
@OptIn(InternalCoreApi::class)
owner.owner.showLayoutBounds = showLayoutBounds
attachLayer(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,9 @@ sealed interface ComposeScene : AutoCloseable {
* provided by the [androidx.compose.runtime.Recomposer] of the current scene.
*/
suspend fun withMonotonicFrameClock(block: suspend () -> Unit)

/**
* Set the visual debug option that shows bounds for all nodes in the hierarchy.
*/
var showLayoutBounds: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.pointer.PointerInputEvent
import androidx.compose.ui.input.rotary.RotaryScrollEvent
import androidx.compose.ui.node.InternalCoreApi
import androidx.compose.ui.node.LayoutNode
import androidx.compose.ui.node.RootNodeOwner
import androidx.compose.ui.platform.setContent
Expand Down Expand Up @@ -192,6 +193,13 @@ private class PlatformLayersComposeSceneImpl(
mainOwner.draw(canvas)
}

override var showLayoutBounds: Boolean
get() = mainOwner.owner.showLayoutBounds
set(value) {
@OptIn(InternalCoreApi::class)
mainOwner.owner.showLayoutBounds = value
}

private fun onOwnerAppended(owner: RootNodeOwner) {
semanticsOwnerListener?.onSemanticsOwnerAppended(owner.semanticsOwner)
}
Expand Down
Loading