Did anything change with relation to `drawArc`? S...
# compose-desktop
e
Did anything change with relation to
drawArc
? Sample in thread
Previously, this code worked:
Copy code
@Composable
fun sample() {
    val radius = 50f
    Surface(Modifier.size(200.dp)) {
        Canvas(modifier = Modifier.fillMaxSize()) {
            drawCircle(Color.DarkGray, radius * 2, style = Stroke(75f))
            drawArc(
                color = Color.Red,
                startAngle = 0f,
                sweepAngle = 125f,
                useCenter = false,
                topLeft = Offset(size.width / 4, size.height / 4),
                size = Size(
                    radius * 2,
                    radius * 2
                ),
                style = Stroke(75.0f)
            )
        }
    }
}
It drew a gray background circle, with a red arc on it. It's just a sample to reproduce the problem. My REAL code is for course beautiful and elegant and so forth. Now, in
0.4
, it draws the same, but the arc is half the size it used to be. I need to multiply the radius by 4 instead of 2 to get the result.
Expected vs Reality
It is very likely I just don't know what I'm doing, so if that's the case, tell me gently 🤣
This is running on MacOS with Metal, I believe, which leads me to think it could be related to the new rendering, but I will need to check up on that before I log it as a bug.
j
cc @Igor Demin sounds retina density related.
e
Ah, it is the exact same Mac, if that helps. I will make some time tomorrow to configure the OpenGL or Software Renderer and see what happens. Perhaps something slipped in with the move to Metal.
i
retina density related.
Yes, in the snippet above we use the different units:
size.width
that is 200.dp (200 * 2.0 pixels on retina macOs) and
radius
that is 50 pixels. The code that works:
Copy code
@Composable
fun sample() {
//    val radius = 100 * LocalDensity.current.density
    Surface(Modifier.size(200.dp)) {
        Canvas(modifier = Modifier.fillMaxSize()) {
            val radius = size.width / 2f
            drawCircle(Color.DarkGray, radius = radius, style = Stroke(75f))
            drawArc(
                color = Color.Red,
                startAngle = 0f,
                sweepAngle = 125f,
                useCenter = false,
                topLeft = Offset(0f, 0f),
                size = Size(radius * 2, radius * 2),
                style = Stroke(75.0f)
            )
        }
    }
}
e
It's an interesting change - I've noticed that on my main project, after upgrading to
0.4.0
, buttons are no longer clickable, which is really weird. I've reverted for now. Once I've hit my deadline, I'll circle back, upgrade again and go through everything and ensure the same units are used everywhere. Thanks!
i
buttons are no longer clickable
If you use Surface(Modifier.clickable) then this might be the case
The code that works:
If you need circle that is the half of the Surface:
Copy code
@Composable
fun sample() {
//    val radius = 50 * LocalDensity.current.density
    Surface(Modifier.size(200.dp)) {
        Canvas(modifier = Modifier.fillMaxSize()) {
            val radius = size.width / 4f
            drawCircle(Color.DarkGray, radius = radius, style = Stroke(75f))
            drawArc(
                color = Color.Red,
                startAngle = 0f,
                sweepAngle = 125f,
                useCenter = false,
                topLeft = this.center - Offset(radius, radius),
                size = Size(radius * 2, radius * 2),
                style = Stroke(75.0f)
            )
        }
    }
}
👍 1
e
Ah, no, these are actual
Button
instances. They just stopped working. Reverting back to
0.3.2
resolved it 👍 I will extract that UI into a small code example and test it over the weekend, I'm just rushing to hit my deadline 🤣
I am doing a lot of mouse position tracking, so it might even be that. But I'll come up with an example and then post that for help. Thank you!