Add origin calculations to widget rendering

This commit is contained in:
Kevin Cotugno 2017-12-30 12:08:07 -08:00
parent 958afee6c6
commit 7bc56f967d
5 changed files with 35 additions and 8 deletions

View File

@ -24,4 +24,6 @@ func (b *Block) SetSize(p image.Point) {
}
func (b *Block) SetOrigin(p image.Point) {
d := p.Sub(b.Rect.Min)
b.Rect = b.Rect.Add(d)
}

View File

@ -57,14 +57,29 @@ func (l *ListWidget) SetSize(p image.Point) {
l.block.SetSize(p)
}
func (l *ListWidget) Render() Block {
func (l *ListWidget) Origin() image.Point {
l.blockLock.Lock()
defer l.blockLock.Unlock()
return l.block.Rect.Min
}
func (l *ListWidget) SetOrigin(p image.Point) {
l.blockLock.Lock()
defer l.blockLock.Unlock()
l.block.SetOrigin(p)
}
func (l *ListWidget) Render(origin image.Point) Block {
l.blockLock.Lock()
defer l.blockLock.Unlock()
b := NewBlock(0, 0, 0, 0)
b.Rect = l.block.Rect
b.Rect = l.block.Rect.Add(origin)
for k, v := range l.block.Cells {
k = k.Add(origin)
b.Cells[k] = v
}
@ -125,6 +140,7 @@ func (l *ListWidget) recalculateCells() {
defer l.listLock.Unlock()
l.blockLock.Lock()
origin := l.block.Rect.Min
size := l.block.Rect.Size()
l.blockLock.Unlock()
@ -140,11 +156,12 @@ func (l *ListWidget) recalculateCells() {
for x := 0; x < size.X; x++ {
for y := 0; y < size.Y; y++ {
c := Cell{Value: ' '}
point := image.Pt(x, y).Add(origin)
if l.border {
cell, ok := l.borderCell(image.Point{x, y}, size)
cell, ok := l.borderCell(image.Pt(x, y), size)
if ok {
cells[image.Point{x, y}] = cell
cells[point] = cell
continue
}
}
@ -162,7 +179,7 @@ func (l *ListWidget) recalculateCells() {
c = l.list[y-by][i]
}
cells[image.Point{x, y}] = c
cells[point] = c
}
}
}

View File

@ -1,16 +1,20 @@
package exhibit
import (
"image"
)
type Scene struct {
Terminal *Terminal
Window Widget
}
func (s *Scene) Render() {
// s.Window.SetSize(s.Terminal.Size())
s.Window.SetSize(s.Terminal.Size())
c := make([]Cell, 0)
for k, v := range s.Window.Render().Cells {
for k, v := range s.Window.Render(image.Point{}).Cells {
v.Point = k
c = append(c, v)
}

View File

@ -217,6 +217,10 @@ func (t *Terminal) reconcileCells() {
continue
}
if c.Point.X < 0 || c.Point.Y < 0 {
continue
}
current := t.display.Cells[c.Point]
if current.Value == c.Value {

View File

@ -12,7 +12,7 @@ type Border struct {
}
type Widget interface {
Render() Block
Render(image.Point) Block
Size() image.Point
SetSize(image.Point)
Attributes() Attributes