mirror of https://github.com/gizak/termui.git
Add Block.chopOverflow and apply it to all widgets
This commit is contained in:
parent
d76e946a46
commit
b0a574c387
2
bar.go
2
bar.go
|
@ -120,5 +120,5 @@ func (bc *BarChart) Buffer() []Point {
|
|||
}
|
||||
}
|
||||
|
||||
return ps
|
||||
return bc.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
18
block.go
18
block.go
|
@ -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
|
||||
}
|
||||
|
|
2
chart.go
2
chart.go
|
@ -327,5 +327,5 @@ func (lc *LineChart) Buffer() []Point {
|
|||
ps = append(ps, lc.renderBraille()...)
|
||||
}
|
||||
|
||||
return ps
|
||||
return lc.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
2
gauge.go
2
gauge.go
|
@ -79,5 +79,5 @@ func (g *Gauge) Buffer() []Point {
|
|||
}
|
||||
ps = append(ps, p)
|
||||
}
|
||||
return ps
|
||||
return g.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
2
list.go
2
list.go
|
@ -100,5 +100,5 @@ func (l *List) Buffer() []Point {
|
|||
}
|
||||
}
|
||||
}
|
||||
return ps
|
||||
return l.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
2
p.go
2
p.go
|
@ -67,5 +67,5 @@ func (p *Par) Buffer() []Point {
|
|||
k++
|
||||
j += w
|
||||
}
|
||||
return ps
|
||||
return p.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
|
@ -152,5 +152,5 @@ func (sl *Sparklines) Buffer() []Point {
|
|||
oftY += l.displayHeight
|
||||
}
|
||||
|
||||
return ps
|
||||
return sl.Block.chopOverflow(ps)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue