diff --git a/exhibit/list_widget.go b/exhibit/list_widget.go index 1278641..860bffb 100644 --- a/exhibit/list_widget.go +++ b/exhibit/list_widget.go @@ -95,8 +95,10 @@ func (l *ListWidget) Render() [][]Cell { } } - l.lastSize.X = sx - l.lastSize.Y = sy + l.size.X = sx + l.size.Y = sy + l.lastSize = l.size + return append([][]Cell(nil), l.cells...) } diff --git a/exhibit/scene.go b/exhibit/scene.go index 12c2cf7..af28eaf 100644 --- a/exhibit/scene.go +++ b/exhibit/scene.go @@ -6,7 +6,7 @@ type Scene struct { } func (s *Scene) Render() { - s.Window.SetSize(s.Terminal.Size()) +// s.Window.SetSize(s.Terminal.Size()) c := make([]Cell, 0) diff --git a/exhibit/window_widget.go b/exhibit/window_widget.go index d24f013..34f6d4a 100644 --- a/exhibit/window_widget.go +++ b/exhibit/window_widget.go @@ -41,11 +41,21 @@ func (w *WindowWidget) SetSize(s Size) { } func (w *WindowWidget) Render() [][]Cell { + if w.size.X == 0 || w.size.Y == 0 { + return w.renderContent() + } else { + return w.renderSize() + } +} + +func (w *WindowWidget) renderContent() [][]Cell { c := make([][]Cell, 0) var y int + for _, w := range w.widgets { for _, row := range w.Render() { + t := make([]Cell, len(row)) c = append(c, t) @@ -60,3 +70,15 @@ func (w *WindowWidget) Render() [][]Cell { return c } + +func (w *WindowWidget) renderSize() [][]Cell { + c := make([][]Cell, w.size.Y) + + for y := 0; y < w.size.Y; y++ { + for x := 0; x < w.size.X; x++ { + c[y][x] = Cell{Pos: Position{X: x, Y: y}} + } + } + + return c +} diff --git a/spectator.go b/spectator.go index 79ed9ab..7ee7882 100644 --- a/spectator.go +++ b/spectator.go @@ -169,19 +169,26 @@ func main() { aIt := asks.Iterator() var low, high decimal.Decimal - for i := num - 1; i >= 0; i-- { + asks := make([]ListEntry, num) + for i := 0; i < num; i++ { aIt.Next() entries := aIt.Value().(Entries) price, size := flatten(entries) - topAsks.AddEntry(ListEntry{Value: size.StringFixed(8), - Attrs: exhibit.Attributes{ForegroundColor: exhibit.FGBlue}}) + asks[i] = ListEntry{Value: size.StringFixed(8), + Attrs: exhibit.Attributes{ForegroundColor: + exhibit.FGBlue}} - if i == num-1 { + if i == 0 { low = price } } + + for i := num - 1; i >= 0; i-- { + topAsks.AddEntry(asks[i]) + } + topAsks.Commit() bIt := bids.Iterator()