# compose


09/13/2020, 2:57 AM
I’m trying to write a painter that can draw other Painters but I’m not sure what the draw code is supposed to look like. I have
Copy code
Contaner(val painters: List<Painter>): Painter {
  override val intrinsicSize = Size(
    painters.maxOf { it.width },
    painters.sumBy { it.heightRespectingAspectRatio }

  override fun DrawScope.onDraw() {
    var offset = Offset.Zero
    painters.fastForEach { 
      it.??? // :( not sure what to place here, I dont have access to the draw method of the individual painters, how do I tell the painter to draw into the containers canvas 
The end goal, if its clear from the
calculation, is to create a painter that will place each individual painter, in a vertical column, kinda like stitching images together vertically. I want to then be able to run transformations on the container painter (scale, pan etc) driven by gestures.

Zach Klippenstein (he/him) [MOD]

09/13/2020, 4:54 PM
Painters have two receivers: the painter itself, and the drawscope. DrawScope is the more "immediate" receiver (it's the extension receiver), so you can't call onDraw on the painter itself. I think you need to do something like
with(it) { onDraw() }

Nader Jawad

09/16/2020, 1:04 AM
Yes in this case it would be
with(it) { childpainter.draw() }
as the
method is protected and is part of the implementation but
is part of the public API