diff --git a/main.go b/main.go index f8f4df7..e7bd3f2 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "fmt" + "math/rand" "os" + "time" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" @@ -22,11 +24,12 @@ type UI struct { Mode mode App *tview.Application Fields []field + Nodes []node // UI things Pages *tview.Pages TopFlex *tview.Flex - Field *tview.Box + Field *tview.Pages FieldBar *tview.Flex BottomBar *tview.Pages ExInput *tview.InputField @@ -83,15 +86,57 @@ type field struct { Selected bool } +type node struct { + Text string + Edges []*node + X int + Y int +} + +type Edge struct { +} + +func (e Edge) Draw(screen tcell.Screen) { + screen.SetContent(0, 0, '!', []rune{}, tcell.StyleDefault) +} + +func (e Edge) GetRect() (int, int, int, int) { + return 0, 0, 0, 0 +} + +func (e Edge) SetRect(x, y, width, height int) { +} + +func (e Edge) InputHandler() func(_ *tcell.EventKey, _ func(p tview.Primitive)) { + return func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {} +} + +func (e Edge) HasFocus() bool { + return false +} + +func (e Edge) Focus(delegate func(p tview.Primitive)) { +} + +func (e Edge) Blur() { +} + +func (e Edge) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { + return func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive) { + return false, nil + } +} + func NewUI() *UI { app := tview.NewApplication() ui := UI{ Mode: modeNormal, App: app, Fields: []field{{"scratch", true}, {"test", false}}, + Nodes: []node{}, Pages: tview.NewPages(), TopFlex: tview.NewFlex(), - Field: tview.NewBox(), + Field: tview.NewPages(), FieldBar: tview.NewFlex(), BottomBar: tview.NewPages(), ExInput: tview.NewInputField(), @@ -118,7 +163,33 @@ func NewUI() *UI { ui.FieldBar.SetDirection(tview.FlexColumn) + ui.Nodes = append(ui.Nodes, node{ + Text: "foobar\nbaz\nquux", + }) + ui.Nodes = append(ui.Nodes, node{ + Text: "hello\nthere\nhow", + }) + + x := 0 + y := 0 + + rand.Seed(time.Now().Unix()) + + for _, n := range ui.Nodes { + b := tview.NewTextView() + b.SetText(n.Text) + b.SetBorder(true) + b.SetRect(x, y, 10, 5) + x += 20 + ui.Field.AddPage(fmt.Sprintf("%d", rand.Intn(10000)), b, false, true) + } + + ui.Field.AddPage("edge", Edge{}, false, true) + app.SetBeforeDrawFunc(func(_ tcell.Screen) bool { + // Handle nodes + // TODO + // Handle field bar ui.FieldBar.Clear()