CopyTo copies the content of this canvas onto the destination canvas. This canvas can have an offset when compared to the destination canvas, i.e. the area of this canvas doesn't have to be zero-based.
(dst *Canvas)
| 215 | // This canvas can have an offset when compared to the destination canvas, i.e. |
| 216 | // the area of this canvas doesn't have to be zero-based. |
| 217 | func (c *Canvas) CopyTo(dst *Canvas) error { |
| 218 | if !c.area.In(dst.Area()) { |
| 219 | return fmt.Errorf("the canvas area %v doesn't fit or lie inside the destination canvas area %v", c.area, dst.Area()) |
| 220 | } |
| 221 | |
| 222 | fn := setCellFunc(func(p image.Point, r rune, opts ...cell.Option) error { |
| 223 | if _, err := dst.SetCell(p, r, opts...); err != nil { |
| 224 | return fmt.Errorf("dst.SetCell => %v", err) |
| 225 | } |
| 226 | return nil |
| 227 | }) |
| 228 | |
| 229 | // Neither of the two canvases (source and destination) have to be zero |
| 230 | // based. Canvas is not zero based if it is positioned elsewhere, i.e. |
| 231 | // providing a smaller view of another canvas. |
| 232 | // E.g. a widget can assign a smaller portion of its canvas to a component |
| 233 | // in order to restrict drawing of this component to a smaller area. To do |
| 234 | // this it can create a sub-canvas. This sub-canvas can have a specific |
| 235 | // starting position other than image.Point{0, 0} relative to the parent |
| 236 | // canvas. Copying this sub-canvas back onto the parent accounts for this |
| 237 | // offset. |
| 238 | offset := c.area.Min |
| 239 | return c.copyTo(offset, fn) |
| 240 | } |