Esempio n. 1
0
func draw(widget Widget, gc graphic.Context, clip geom.Rect, origin geom.Point) {
	bounds := widget.Bounds()

	if clip.Intersect(geom.Rect{
		X: bounds.X + origin.X,
		Y: bounds.Y + origin.Y,
		W: bounds.W,
		H: bounds.H,
	}).Empty() {
		return
	}

	gc.Save()
	gc.Configure(graphic.State{
		Transform: graphic.Translation(bounds.X, bounds.Y),
		Clip:      geom.Rect{W: bounds.W, H: bounds.H},
	})

	if d, ok := widget.(Drawable); ok {
		d.Draw(gc)
	}

	if c, ok := widget.(Container); ok {
		origin = bounds.Origin()

		for _, w := range c.Children() {
			draw(w, gc, clip, origin)
		}
	}

	gc.Restore()
}