Add action to toggle Show Layout Bounds in Compose UI #3300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an action to the ui-inspector module that toggles the showLayoutBounds value for all currently attached ComposePanels. It also registers an AWT hierarchy listener, if the toggle is on, to capture when a new ComposePanel is added to the hierarchy and make sure the setting is respected in cases where panels are detached and then re-attached (the setting is lost when the panel is detached as it disposes a lot of internal state).
Screen.Recording.2025-11-09.at.19.52.57.mov
When toggled, the action also tries to cause a recomposition in all the panels so that the bounds do start showing right away, but it doesn't seem to always work/cause a full redraw. Any interaction or change in bounds on the panels will cause the panels to redraw, and that is mostly good enough for now.
Given the approach is reflection-heavy, it is prone to breaking if there are changes in CMP internals; when we have a better, official API for it, we'll be able to have a more robust impl.
CC @igordmn @batya239 @jreznot
Note
Introduces an internal action that toggles
showLayoutBoundsfor all Compose panels, using reflection, auto-updates on panel attach via AWT listener, and registers the action in resources.ToggleComposeLayoutBoundsActionto toggleshowLayoutBoundsacross active Compose containers; updates presentation text based on state.LayoutBoundsTogglerto reflectively setowner.showLayoutBounds, invalidate layers, trigger revalidate/repaint, and listen for AWTHierarchyEventattachments.ComposeUtilto locate Compose containers (ComposePanel/ComposeWindow) and traverse to root layout nodes via reflection.ReflectHelperfor cached reflective field/method access.ToggleComposeLayoutBoundsinPlatformActions.xmlunder internal UI tools.action.ToggleComposeLayoutBounds.texttoActionsBundle.properties.Written by Cursor Bugbot for commit 0033818. This will update automatically on new commits. Configure here.