SetBorder compares borders before doing re-layout/draw
This commit is contained in:
parent
b926881233
commit
79f81688bb
35
box.go
35
box.go
@ -121,10 +121,29 @@ func (this *box) SetTexture (texture canvas.Texture) {
|
|||||||
this.invalidateDraw()
|
this.invalidateDraw()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *box) SetBorder (border ...tomo.Border) {
|
func (this *box) SetBorder (borders ...tomo.Border) {
|
||||||
this.border = border
|
previousBorderSum := this.borderSum()
|
||||||
this.invalidateLayout()
|
previousBorders := this.border
|
||||||
this.invalidateMinimum()
|
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) {
|
func (this *box) SetMinimumSize (size image.Point) {
|
||||||
@ -356,7 +375,11 @@ func (this *box) doMinimumSize () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var drawcnt int
|
||||||
func (this *box) doDraw () {
|
func (this *box) doDraw () {
|
||||||
|
// println("DRAW", drawcnt)
|
||||||
|
// drawcnt ++
|
||||||
|
|
||||||
if this.canvas == nil { return }
|
if this.canvas == nil { return }
|
||||||
if this.drawer != nil {
|
if this.drawer != nil {
|
||||||
this.drawBorders(this.canvas)
|
this.drawBorders(this.canvas)
|
||||||
@ -364,7 +387,11 @@ func (this *box) doDraw () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var laycnt int
|
||||||
func (this *box) doLayout () {
|
func (this *box) doLayout () {
|
||||||
|
// println("LAYOUT", laycnt)
|
||||||
|
// laycnt ++
|
||||||
|
|
||||||
this.innerClippingBounds = this.borderSum().Apply(this.bounds)
|
this.innerClippingBounds = this.borderSum().Apply(this.bounds)
|
||||||
if this.parent == nil { this.canvas = nil; return }
|
if this.parent == nil { this.canvas = nil; return }
|
||||||
parentCanvas := this.parent.canvas()
|
parentCanvas := this.parent.canvas()
|
||||||
|
Reference in New Issue
Block a user