Add Block.chopOverflow and apply it to all widgets
This commit is contained in:
gizak 2015-04-09 16:40:49 -04:00
parent d76e946a46
commit b0a574c387
7 changed files with 24 additions and 6 deletions

2
bar.go
View File

@ -120,5 +120,5 @@ func (bc *BarChart) Buffer() []Point {
}
}
return ps
return bc.Block.chopOverflow(ps)
}

View File

@ -122,3 +122,21 @@ func (d *Block) SetY(y int) {
func (d *Block) SetWidth(w int) {
d.Width = w
}
// chop the overflow parts
func (d *Block) chopOverflow(ps []Point) []Point {
nps := make([]Point, 0, len(ps))
x := d.X
y := d.Y
w := d.Width
h := d.Height
for _, v := range ps {
if v.X >= x &&
v.X < x+w &&
v.Y >= y &&
v.Y < y+h {
nps = append(nps, v)
}
}
return nps
}

View File

@ -327,5 +327,5 @@ func (lc *LineChart) Buffer() []Point {
ps = append(ps, lc.renderBraille()...)
}
return ps
return lc.Block.chopOverflow(ps)
}

View File

@ -79,5 +79,5 @@ func (g *Gauge) Buffer() []Point {
}
ps = append(ps, p)
}
return ps
return g.Block.chopOverflow(ps)
}

View File

@ -100,5 +100,5 @@ func (l *List) Buffer() []Point {
}
}
}
return ps
return l.Block.chopOverflow(ps)
}

2
p.go
View File

@ -67,5 +67,5 @@ func (p *Par) Buffer() []Point {
k++
j += w
}
return ps
return p.Block.chopOverflow(ps)
}

View File

@ -152,5 +152,5 @@ func (sl *Sparklines) Buffer() []Point {
oftY += l.displayHeight
}
return ps
return sl.Block.chopOverflow(ps)
}