Sfoglia il codice sorgente

Add ui.NewMidFlex() func

rigormorrtiss 4 anni fa
parent
commit
a400ad306f
3 ha cambiato i file con 19 aggiunte e 11 eliminazioni
  1. 5 1
      discordo.go
  2. 4 2
      ui/app.go
  3. 10 8
      ui/flex.go

+ 5 - 1
discordo.go

@@ -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()
 }

+ 4 - 2
ui/app.go

@@ -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
 }

+ 10 - 8
ui/flex.go

@@ -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
 }