Begin adding widget constraints

This commit is contained in:
Kevin Cotugno 2017-12-28 00:10:37 -08:00
parent c5339a9ae4
commit 4291bfb210
4 changed files with 38 additions and 7 deletions

View File

@ -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...)
}

View File

@ -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)

View File

@ -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
}

View File

@ -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()