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.95k stars 1.16k forks source link

Context menu height does not account for windowMargin #3513

Open dzirbel opened 1 year ago

dzirbel commented 1 year ago

Describe the bug Popups have no mechanism to reduce their maximum width or height based on a provided margin around the window. For context menus where rememberPopupPositionProviderAtPosition() accepts an argument windowMargin, this means that (in 1.4.3) a context menu with a height exceeding the height of the window will be shifted down by this windowMargin but its height will still be the window height.

In 1.5.0-dev1152 the behavior is changed (because PopupLayout now does position.x.coerceIn(0, windowSize.width - contentSize.width)), so that the popup is not cut off, but the windowMargin is no longer respected when the popup size is larger than the window size. Ideally it would coerce the size to windowSize.width - contentSize.width) - 2 * windowMargin at most.

Affected platforms

Versions

To Reproduce This isn't trivial to clearly reproduce since DefaultContextMenuRepresentation doesn't allow configuring the windowMargin and its default of 4 dp is too small to be obviously noticeable. The issue can be demonstrated on the bug/windowMargin branch of my project: https://github.com/dzirbel/compose-material-context-menu/tree/bug/windowMargin with ./gradlew :demo:run.

Of note:

Expected behavior Context menu sizes should be bounded by windowSize - 2 * windowMargin. This could be done in a few ways:

Screenshots With a windowMargin of 30 dp to make the discrepancy clear (the scrollbar is all the way at the bottom); in 1.4.3:

Screenshot from 2023-08-16 14-49-07

and in 1.5.0-dev1152:

Screenshot from 2023-08-16 15-12-22

Additional context See also discussion in https://github.com/JetBrains/compose-multiplatform/issues/3493; cc @m-sasha

okushnikov commented 3 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.