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.33k stars 1.12k forks source link

(Desktop) minimumInteractiveComponentSize + size/width/height Modifier leads to inconsistent placement #4999

Open F-J-S-P opened 2 weeks ago

F-J-S-P commented 2 weeks ago

Describe the bug When using both .minimumInteractiveComponentSize() and .size()/.width()/.height() on the same composable, it is placed correctly when the value used for .size() is an even number and one pixel off (to the right for width, down for height, both for size) when it is an odd number. I noticed this when using IconButton scaling with AppTheme.fixedLineHeight (in this case 19), since IconButton has .minimumInteractiveComponentSize() integrated, but it is not restricted to them.

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior: Run this code snippet:

    import androidx.compose.foundation.*
    import androidx.compose.foundation.layout.*
    import androidx.compose.material3.*
    import androidx.compose.ui.*
    import androidx.compose.ui.graphics.Color
    import androidx.compose.ui.unit.*
    import androidx.compose.ui.window.*

    fun main() = application {
        Window(
            onCloseRequest = ::exitApplication,
            title = "ComposeBugTest",
        ) {
            Column{
                repeat(20) {
                    Box(
                        modifier = Modifier
                            .size((it+1).dp)
                            .minimumInteractiveComponentSize()
                            .background(Color.Green.copy(0.7f)),
                    )
                }
            }
        }
    }

Expected behavior 20 green boxes appear above each other without space between them and aligned with the window's left border.

Observed behavior 20 green boxes appear, every second one is shifted one pixel to the right and below, leading to unintended spaces and overlap.

Screenshots Screenshot from 2024-06-20 03-47-48

Additional context The Column + repeat is just to make the problem and how it's tied to odd numbers more obvious (the first box is not visible as it's fully inside the second one); the problem will also appear when using just a single box.

MatkovIvan commented 2 weeks ago
Screenshot 2024-06-20 at 08 50 01

It's reproducible on Android too. Even/odd vs what's happen there is probably just because of different density

MatkovIvan commented 2 weeks ago

@F-J-S-P could you please duplicate this issue to Google issue tracker (with main point about Android/common instead of Desktop)? Thanks

F-J-S-P commented 2 weeks ago

o7 https://issuetracker.google.com/issues/348199047