Add ui.NewMidFlex() func

This commit is contained in:
rigormorrtiss 2021-07-28 00:13:56 +04:00
parent 14fa4cca81
commit a400ad306f
3 changed files with 19 additions and 11 deletions

View file

@ -32,7 +32,7 @@ func main() {
channelsList = ui.NewChannelsList(onChannelsListSelected)
messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged)
mainFlex = ui.NewMainFlex(guildsDropDown, channelsList, messagesTextView)
app = ui.NewApp()
app = ui.NewApp(onAppInputCapture)
token := util.GetPassword("token")
if token != "" {
@ -50,6 +50,10 @@ func main() {
}
}
func onAppInputCapture(event *tcell.EventKey) *tcell.EventKey {
return event
}
func onLoginFormQuitButtonSelected() {
app.Stop()
}

View file

@ -1,12 +1,14 @@
package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func NewApp() (app *tview.Application) {
func NewApp(onAppInputCapture func(event *tcell.EventKey) *tcell.EventKey) (app *tview.Application) {
app = tview.NewApplication().
EnableMouse(true)
EnableMouse(true).
SetInputCapture(onAppInputCapture)
return
}

View file

@ -5,17 +5,19 @@ import (
)
func NewMainFlex(guildsDropDown *tview.DropDown, channelsList *tview.List, messagesTextView *tview.TextView) (mainFlex *tview.Flex) {
midFlex := NewMidFlex(channelsList, messagesTextView)
mainFlex = tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(guildsDropDown, 3, 1, false).
AddItem(
tview.NewFlex().
AddItem(channelsList, 20, 1, false).
AddItem(messagesTextView, 0, 3, false),
0,
1,
false,
)
AddItem(midFlex, 0, 1, false)
return
}
func NewMidFlex(channelsList *tview.List, messagesTextView *tview.TextView) (midFlex *tview.Flex) {
midFlex = tview.NewFlex().
AddItem(channelsList, 20, 1, false).
AddItem(messagesTextView, 0, 3, false)
return
}