mirror of
https://github.com/jroimartin/gocui.git
synced 2025-04-28 13:48:51 +08:00
More refactoring of View.draw()
This commit is contained in:
parent
6279571a82
commit
0814e8024f
34
view.go
34
view.go
@ -199,7 +199,6 @@ func (v *View) Rewind() {
|
|||||||
func (v *View) draw() error {
|
func (v *View) draw() error {
|
||||||
maxX, maxY := v.Size()
|
maxX, maxY := v.Size()
|
||||||
|
|
||||||
// This buffering takes care of v.ox
|
|
||||||
if v.Wrap {
|
if v.Wrap {
|
||||||
if len(v.WrapPrefix) >= maxX {
|
if len(v.WrapPrefix) >= maxX {
|
||||||
return errors.New("WrapPrefix bigger or equal to X size")
|
return errors.New("WrapPrefix bigger or equal to X size")
|
||||||
@ -211,34 +210,28 @@ func (v *View) draw() error {
|
|||||||
v.viewBuffer = nil
|
v.viewBuffer = nil
|
||||||
for _, line := range v.lines {
|
for _, line := range v.lines {
|
||||||
if v.Wrap {
|
if v.Wrap {
|
||||||
// Copy first line
|
if len(line) <= maxX {
|
||||||
// if v.ox >= len(line), then the line will be empty
|
v.viewBuffer = append(v.viewBuffer, line)
|
||||||
if v.ox < len(line) {
|
continue
|
||||||
v.viewBuffer = append(v.viewBuffer, line[v.ox:])
|
|
||||||
} else {
|
} else {
|
||||||
v.viewBuffer = append(v.viewBuffer, nil)
|
v.viewBuffer = append(v.viewBuffer, line[:maxX])
|
||||||
}
|
}
|
||||||
// Append wrapped lines with WrapPrefix
|
// Append remaining lines with WrapPrefix
|
||||||
for n := maxX; n < len(line); n += maxX - len(v.WrapPrefix) {
|
for n := maxX; n < len(line); n += maxX - len(v.WrapPrefix) {
|
||||||
if v.ox < len(line) {
|
wrappedLine := append(append([]rune(v.WrapPrefix), line[n:]...))
|
||||||
v.viewBuffer = append(v.viewBuffer,
|
if len(wrappedLine) <= maxX {
|
||||||
append([]rune(v.WrapPrefix), line[v.ox+n:]...))
|
v.viewBuffer = append(v.viewBuffer, wrappedLine)
|
||||||
} else {
|
} else {
|
||||||
v.viewBuffer = append(v.viewBuffer, nil)
|
v.viewBuffer = append(v.viewBuffer, wrappedLine[:maxX])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if v.ox < len(line) {
|
v.viewBuffer = append(v.viewBuffer, line)
|
||||||
v.viewBuffer = append(v.viewBuffer, line[v.ox:])
|
|
||||||
} else {
|
|
||||||
v.viewBuffer = append(v.viewBuffer, nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.tainted = false
|
v.tainted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// The actual drawing takes into account v.oy
|
|
||||||
if v.Autoscroll && len(v.viewBuffer) > maxY {
|
if v.Autoscroll && len(v.viewBuffer) > maxY {
|
||||||
v.oy = len(v.viewBuffer) - maxY
|
v.oy = len(v.viewBuffer) - maxY
|
||||||
}
|
}
|
||||||
@ -250,13 +243,18 @@ func (v *View) draw() error {
|
|||||||
if y >= maxY {
|
if y >= maxY {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for x, ch := range line {
|
x := 0
|
||||||
|
for j, ch := range line {
|
||||||
|
if j < v.ox {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if x >= maxX {
|
if x >= maxX {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err := v.setRune(x, y, ch); err != nil {
|
if err := v.setRune(x, y, ch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
x++
|
||||||
}
|
}
|
||||||
y++
|
y++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user