Set up attribute for rendering placement and size
This commit is contained in:
parent
2f1a186ce2
commit
7cfb59aeb9
@ -10,8 +10,9 @@ type ListEntry interface {
|
||||
}
|
||||
|
||||
type ListWidget struct {
|
||||
Constraints Constraints
|
||||
Attrs Attributes
|
||||
Constrs Constraints
|
||||
Attrs Attributes
|
||||
Size Size
|
||||
|
||||
cellLock sync.Mutex
|
||||
cells [][]Cell
|
||||
@ -27,6 +28,10 @@ type ListWidget struct {
|
||||
lastSize Size
|
||||
}
|
||||
|
||||
func (l *ListWidget) SetSize(size Size) {
|
||||
l.Size = size
|
||||
}
|
||||
|
||||
func (l *ListWidget) Render() [][]Cell {
|
||||
l.cellLock.Lock()
|
||||
defer l.cellLock.Unlock()
|
||||
@ -74,6 +79,10 @@ func (l *ListWidget) Render() [][]Cell {
|
||||
return append([][]Cell(nil), l.cells...)
|
||||
}
|
||||
|
||||
func (l ListWidget) Constraints() Constraints {
|
||||
return l.Constrs
|
||||
}
|
||||
|
||||
func (l *ListWidget) AddEntry(entry ListEntry) {
|
||||
if l.listBuf == nil {
|
||||
l.listBuf = make([][]Cell, 1)
|
||||
|
@ -6,6 +6,8 @@ type Scene struct {
|
||||
}
|
||||
|
||||
func (s *Scene) Render() {
|
||||
s.Window.SetSize(s.Terminal.Size())
|
||||
|
||||
c := make([]Cell, 0)
|
||||
|
||||
for _, row := range s.Window.Render() {
|
||||
|
@ -23,11 +23,6 @@ const (
|
||||
cup = "\x1b[%v;%vH"
|
||||
)
|
||||
|
||||
type Size struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Terminal struct {
|
||||
Event <-chan Event
|
||||
|
||||
|
@ -13,6 +13,14 @@ type Constraints struct {
|
||||
Right bool
|
||||
}
|
||||
|
||||
type Widget interface {
|
||||
Render() [][]Cell
|
||||
type Size struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
|
||||
type Widget interface {
|
||||
Render() [][]Cell
|
||||
Constraints() Constraints
|
||||
SetSize(size Size)
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package exhibit
|
||||
|
||||
type WindowWidget struct {
|
||||
Constraints Constraints
|
||||
Border Border
|
||||
Constrs Constraints
|
||||
Size Size
|
||||
Border Border
|
||||
|
||||
widgets []Widget
|
||||
}
|
||||
@ -15,6 +16,14 @@ func (w *WindowWidget) AddWidget(widget Widget) {
|
||||
w.widgets = append(w.widgets, widget)
|
||||
}
|
||||
|
||||
func (w *WindowWidget) SetSize(size Size) {
|
||||
w.Size = size
|
||||
}
|
||||
|
||||
func (w *WindowWidget) Constraints() Constraints {
|
||||
return w.Constrs
|
||||
}
|
||||
|
||||
func (w *WindowWidget) Render() [][]Cell {
|
||||
c := make([][]Cell, 0)
|
||||
|
||||
|
@ -78,7 +78,7 @@ func main() {
|
||||
|
||||
window = &exhibit.WindowWidget{}
|
||||
topAsks = &exhibit.ListWidget{}
|
||||
window.Constraints.Bottom = true
|
||||
window.Constrs.Bottom = true
|
||||
topAsks.SetBorder(true)
|
||||
topAsks.SetRightAlign(true)
|
||||
topAsks.Attrs.ForegroundColor = exhibit.FGYellow
|
||||
|
Reference in New Issue
Block a user