4 Commits

2 changed files with 35 additions and 5 deletions

38
box.go
View File

@@ -117,14 +117,34 @@ func (this *box) SetColor (c color.Color) {
}
func (this *box) SetTexture (texture canvas.Texture) {
if this.texture == texture { return }
this.texture = xcanvas.AssertTexture(texture)
this.invalidateDraw()
}
func (this *box) SetBorder (border ...tomo.Border) {
this.border = border
this.invalidateLayout()
this.invalidateMinimum()
func (this *box) SetBorder (borders ...tomo.Border) {
previousBorderSum := this.borderSum()
previousBorders := this.border
this.border = borders
// only invalidate the layout if the border is sized differently
if this.borderSum() != previousBorderSum {
this.invalidateLayout()
this.invalidateMinimum()
return
}
// if the border takes up the same amount of space, only invalidate the
// drawing if it looks different
for index, newBorder := range this.border {
different :=
index >= len(previousBorders) ||
newBorder != previousBorders[index]
if different {
this.invalidateDraw()
return
}
}
}
func (this *box) SetMinimumSize (size image.Point) {
@@ -285,7 +305,7 @@ func (this *box) Draw (can canvas.Canvas) {
if this.transparent() && this.parent != nil {
this.parent.drawBackgroundPart(can)
}
pen.Rectangle(can.Bounds())
pen.Rectangle(this.Bounds())
}
func (this *box) drawBorders (can canvas.Canvas) {
@@ -356,7 +376,11 @@ func (this *box) doMinimumSize () {
}
}
// var drawcnt int
func (this *box) doDraw () {
// println("DRAW", drawcnt)
// drawcnt ++
if this.canvas == nil { return }
if this.drawer != nil {
this.drawBorders(this.canvas)
@@ -364,7 +388,11 @@ func (this *box) doDraw () {
}
}
// var laycnt int
func (this *box) doLayout () {
// println("LAYOUT", laycnt)
// laycnt ++
this.innerClippingBounds = this.borderSum().Apply(this.bounds)
if this.parent == nil { this.canvas = nil; return }
parentCanvas := this.parent.canvas()

View File

@@ -31,11 +31,13 @@ func (backend *Backend) NewContainerBox() tomo.ContainerBox {
}
func (this *containerBox) SetColor (c color.Color) {
if this.color == c { return }
this.box.SetColor(c)
this.invalidateTransparentChildren()
}
func (this *containerBox) SetTexture (texture canvas.Texture) {
if this.texture == texture { return }
this.box.SetTexture(texture)
this.invalidateTransparentChildren()
}