Skip to content
Snippets Groups Projects
mainView.go 1.21 KiB
Newer Older
  • Learn to ignore specific revisions
  • package views
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    	"github.com/rivo/tview"
    	"google.golang.org/grpc"
    )
    
    
    type MainView struct {
    	pages              *tview.Pages
    	mainFlexBox        *tview.Flex
    	commandsListView   *CommandListView
    	resultAndInputView *ResultAndInputView
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	v := &MainView{
    		pages:              tview.NewPages(),
    		mainFlexBox:        createFlexBox(tview.FlexColumn),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		commandsListView:   NewCommandListView(),
    
    Malte Bauch's avatar
    Malte Bauch committed
    		resultAndInputView: NewResultAndInputView(),
    	}
    
    	v.commandsListView.GetCommands(app, v.resultAndInputView, conn)
    
    
    	commandsFlexBox := createFlexBox(tview.FlexRow)
    	commandsFlexBox.AddItem(v.commandsListView.GetContent(), 0, 40, true)
    
    	resultAndInputFlexBox := createFlexBox(tview.FlexRow)
    	resultAndInputFlexBox.AddItem(v.resultAndInputView.GetContent(), 0, 10, false)
    
    	v.mainFlexBox.
    		AddItem(commandsFlexBox, 0, 1, true).
    		AddItem(resultAndInputFlexBox, 0, 4, false)
    
    	v.pages.AddPage("main", v.mainFlexBox, true, true)
    
    	return v
    }
    
    func (mv *MainView) GetContent() tview.Primitive {
    	return mv.pages
    }
    
    func createFlexBox(direction int) *tview.Flex {
    	fb := tview.NewFlex().SetDirection(direction)
    	return fb
    }