Ewald
06/03/2021, 2:59 PMdrawArc
? Sample in threadEwald
06/03/2021, 3:00 PM@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.Ewald
06/03/2021, 3:01 PMEwald
06/03/2021, 3:02 PMEwald
06/03/2021, 3:18 PMjim
06/03/2021, 7:55 PMEwald
06/03/2021, 8:18 PMIgor Demin
06/04/2021, 7:53 AMretina 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:
@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)
)
}
}
}
Ewald
06/04/2021, 7:55 AM0.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!Igor Demin
06/04/2021, 7:59 AMbuttons are no longer clickableIf you use Surface(Modifier.clickable) then this might be the case
Igor Demin
06/04/2021, 7:59 AMThe code that works:If you need circle that is the half of the Surface:
@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)
)
}
}
}
Ewald
06/04/2021, 8:00 AMButton
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 🤣Ewald
06/04/2021, 8:01 AM