view_scroll refactored

This commit is contained in:
Timon Ringwald 2022-04-04 14:47:38 +02:00
parent 45c636ec33
commit 5ac1347366

View File

@ -55,6 +55,13 @@ func (v *ScrollView) Draw(buf *tui.ViewBuffer) {
copyBufferHeight = v.buf.Height() copyBufferHeight = v.buf.Height()
} }
// copy buffer
for x := 0; x < copyBufferWidth; x++ {
for y := 0; y < copyBufferHeight; y++ {
buf.Set(x, y, v.buf.Get(v.horizontalScrollOffset+x, v.verticalScrollOffset+y))
}
}
scrollVHeight := int(float64(buf.Height()) / float64(v.buf.Height()) * float64(v.height)) scrollVHeight := int(float64(buf.Height()) / float64(v.buf.Height()) * float64(v.height))
scrollVStart := int(math.Ceil(float64(v.verticalScrollOffset) / float64(v.buf.Height()) * float64(v.height))) scrollVStart := int(math.Ceil(float64(v.verticalScrollOffset) / float64(v.buf.Height()) * float64(v.height)))
@ -75,13 +82,6 @@ func (v *ScrollView) Draw(buf *tui.ViewBuffer) {
} }
} }
// copy buffer
for x := 0; x < copyBufferWidth; x++ {
for y := 0; y < copyBufferHeight; y++ {
buf.Set(x, y, v.buf.Get(v.horizontalScrollOffset+x, v.verticalScrollOffset+y))
}
}
// vertical scrollbar // vertical scrollbar
if scrollV { if scrollV {
for y := 0; y < v.height; y++ { for y := 0; y < v.height; y++ {