mirror of https://github.com/rivo/tview.git
Primitive widths/heights should not become negative. Also fixed a
TextView issue where purging led to panics. Fixes #306
This commit is contained in:
parent
c3d1d4bcf9
commit
fc28d646d0
18
box.go
18
box.go
|
@ -88,7 +88,8 @@ func (b *Box) GetRect() (int, int, int, int) {
|
|||
}
|
||||
|
||||
// GetInnerRect returns the position of the inner rectangle (x, y, width,
|
||||
// height), without the border and without any padding.
|
||||
// height), without the border and without any padding. Width and height values
|
||||
// will clamp to 0 and thus never be negative.
|
||||
func (b *Box) GetInnerRect() (int, int, int, int) {
|
||||
if b.innerX >= 0 {
|
||||
return b.innerX, b.innerY, b.innerWidth, b.innerHeight
|
||||
|
@ -100,10 +101,17 @@ func (b *Box) GetInnerRect() (int, int, int, int) {
|
|||
width -= 2
|
||||
height -= 2
|
||||
}
|
||||
return x + b.paddingLeft,
|
||||
x, y, width, height = x+b.paddingLeft,
|
||||
y+b.paddingTop,
|
||||
width-b.paddingLeft-b.paddingRight,
|
||||
height-b.paddingTop-b.paddingBottom
|
||||
if width < 0 {
|
||||
width = 0
|
||||
}
|
||||
if height < 0 {
|
||||
height = 0
|
||||
}
|
||||
return x, y, width, height
|
||||
}
|
||||
|
||||
// SetRect sets a new position of the primitive. Note that this has no effect
|
||||
|
@ -318,6 +326,12 @@ func (b *Box) Draw(screen tcell.Screen) {
|
|||
b.innerHeight += b.innerY
|
||||
b.innerY = 0
|
||||
}
|
||||
if b.innerWidth < 0 {
|
||||
b.innerWidth = 0
|
||||
}
|
||||
if b.innerHeight < 0 {
|
||||
b.innerHeight = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Focus is called when this primitive receives focus.
|
||||
|
|
|
@ -939,8 +939,13 @@ func (t *TextView) Draw(screen tcell.Screen) {
|
|||
// If this view is not scrollable, we'll purge the buffer of lines that have
|
||||
// scrolled out of view.
|
||||
if !t.scrollable && t.lineOffset > 0 {
|
||||
if t.lineOffset <= len(t.index) {
|
||||
t.buffer = nil
|
||||
} else {
|
||||
t.buffer = t.buffer[t.index[t.lineOffset].Line:]
|
||||
}
|
||||
t.index = nil
|
||||
t.lineOffset = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue