-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlayout.go
More file actions
117 lines (99 loc) · 3.48 KB
/
layout.go
File metadata and controls
117 lines (99 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package ui
import (
"bbrew/internal/ui/components"
"bbrew/internal/ui/theme"
"github.com/rivo/tview"
)
type LayoutInterface interface {
Setup()
Root() tview.Primitive
GetHeader() *components.Header
GetSearch() *components.Search
GetTable() *components.Table
GetDetails() *components.Details
GetOutput() *components.Output
GetLegend() *components.Legend
GetNotifier() *components.Notifier
GetModal() *components.Modal
GetHelpScreen() *components.HelpScreen
}
type Layout struct {
mainContent *tview.Grid
header *components.Header
search *components.Search
table *components.Table
details *components.Details
output *components.Output
legend *components.Legend
notifier *components.Notifier
modal *components.Modal
helpScreen *components.HelpScreen
theme *theme.Theme
}
func NewLayout(theme *theme.Theme) LayoutInterface {
return &Layout{
mainContent: tview.NewGrid(),
header: components.NewHeader(theme),
search: components.NewSearch(theme),
table: components.NewTable(theme),
details: components.NewDetails(theme),
output: components.NewOutput(theme),
legend: components.NewLegend(theme),
notifier: components.NewNotifier(theme),
modal: components.NewModal(theme),
helpScreen: components.NewHelpScreen(theme),
theme: theme,
}
}
func (l *Layout) setupLayout() {
// Header
headerContent := tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(l.header.View(), 0, 1, false).
AddItem(l.notifier.View(), 0, 1, false)
// Search and filters
searchRow := tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(l.search.Field(), 0, 1, false).
AddItem(l.search.Counter(), 0, 1, false)
filtersArea := tview.NewFrame(searchRow).
SetBorders(0, 0, 0, 0, 3, 3)
tableFrame := tview.NewFrame(l.table.View()).
SetBorders(0, 0, 0, 0, 3, 3)
// Left column with search and table
leftColumn := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(filtersArea, 2, 0, false).
AddItem(tableFrame, 0, 4, false)
// Right column with details and output
rightColumn := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(l.details.View(), 0, 2, false).
AddItem(l.output.View(), 0, 1, false)
// Central content
mainContent := tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(leftColumn, 0, 2, false).
AddItem(rightColumn, 0, 1, false)
// Footer
footerContent := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(l.legend.View(), 0, 1, false)
// Final layout
l.mainContent.
SetRows(1, 0, 1).
SetColumns(0).
SetBorders(true).
AddItem(headerContent, 0, 0, 1, 1, 0, 0, false).
AddItem(mainContent, 1, 0, 1, 1, 0, 0, true).
AddItem(footerContent, 2, 0, 1, 1, 0, 0, false)
}
func (l *Layout) Setup() {
l.setupLayout()
}
func (l *Layout) Root() tview.Primitive {
return l.mainContent
}
func (l *Layout) GetHeader() *components.Header { return l.header }
func (l *Layout) GetSearch() *components.Search { return l.search }
func (l *Layout) GetTable() *components.Table { return l.table }
func (l *Layout) GetDetails() *components.Details { return l.details }
func (l *Layout) GetOutput() *components.Output { return l.output }
func (l *Layout) GetLegend() *components.Legend { return l.legend }
func (l *Layout) GetNotifier() *components.Notifier { return l.notifier }
func (l *Layout) GetModal() *components.Modal { return l.modal }
func (l *Layout) GetHelpScreen() *components.HelpScreen { return l.helpScreen }