SetBorder compares borders before doing re-layout/draw

This commit is contained in:
Sasha Koshka 2024-05-15 01:07:52 -04:00
parent b926881233
commit 79f81688bb
1 changed files with 31 additions and 4 deletions

35
box.go
View File

@ -121,10 +121,29 @@ func (this *box) SetTexture (texture canvas.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) {
@ -356,7 +375,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 +387,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()