https://kotlinlang.org logo
#compose
Title
# compose
l

loloof64

02/02/2021, 2:18 PM
Hi again. I'm trying to build a Canvas, but I don't know how. I've been looking at https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas, but Canvas is an interface, and I don't know if there is a class implementing it.
j

Joost Klitsie

02/02/2021, 2:22 PM
What are you exactly trying to do?
l

loloof64

02/02/2021, 2:24 PM
I'm trying to draw a yellow circle inside a red rectangle. (I'm going to play with animations)
j

Joost Klitsie

02/02/2021, 2:26 PM
I am using a DrawModifier
to draw stuff
l

loloof64

02/02/2021, 2:27 PM
Thank you. I'm gonna look at its definition 😃
j

Joost Klitsie

02/02/2021, 2:27 PM
Copy code
override fun ContentDrawScope.draw() {
 // Call drawing functions
I am unsure if this fits your exact needs, but might be a good starting point 🙂
l

loloof64

02/02/2021, 2:28 PM
Thank you. I'm going to look at the ContentDrawScope documentation also, and then try to implement it 🙂
j

Joost Klitsie

02/02/2021, 2:43 PM
Im adding a DrawModifier
Copy code
Box(modifier = Modifier.myDrawModifier) {.. }
👍 1
Copy code
fun myDrawModifier(): Modifier = composed {
    return SomeDrawModifier()
}

private class SomeDrawModifier() {
}: DrawModifier {
    override fun ContentDrawScope.draw() {
    }

}
👍 1
l

loloof64

02/02/2021, 3:09 PM
Thank you very much 🙂 Also, I think I had the wrong import : I should use
import androidx.compose.foundation.Canvas
Finally this worked :)