From 516ea4231768a659e38ea4e46053636446ec971c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 22 Mar 2018 17:00:56 +0200 Subject: [PATCH] Use Flex as MainView base instead of Grid --- ui/view-main.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ui/view-main.go b/ui/view-main.go index f6efd8e..974ab47 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -36,7 +36,7 @@ import ( ) type MainView struct { - *tview.Grid + *tview.Flex roomList *tview.List roomView *tview.Pages @@ -50,13 +50,9 @@ type MainView struct { parent *GomuksUI } -func (view *MainView) addItem(p tview.Primitive, x, y, w, h int) { - view.Grid.AddItem(p, y, x, w, h, 0, 0, false) -} - func (ui *GomuksUI) NewMainView() tview.Primitive { mainView := &MainView{ - Grid: tview.NewGrid(), + Flex: tview.NewFlex(), roomList: tview.NewList(), roomView: tview.NewPages(), rooms: make(map[string]*widget.RoomView), @@ -67,17 +63,16 @@ func (ui *GomuksUI) NewMainView() tview.Primitive { parent: ui, } - mainView.SetColumns(30, 1, 0).SetRows(0) - mainView.roomList. ShowSecondaryText(false). SetSelectedBackgroundColor(tcell.ColorDarkGreen). SetSelectedTextColor(tcell.ColorWhite). SetBorderPadding(0, 0, 1, 0) - mainView.addItem(mainView.roomList, 0, 0, 1, 1) - mainView.addItem(widget.NewBorder(), 1, 0, 1, 1) - mainView.addItem(mainView.roomView, 2, 0, 1, 1) + mainView.SetDirection(tview.FlexColumn) + mainView.AddItem(mainView.roomList, 30, 0, false) + mainView.AddItem(widget.NewBorder(), 1, 0, false) + mainView.AddItem(mainView.roomView, 0, 1, true) ui.mainView = mainView @@ -231,7 +226,11 @@ func (view *MainView) SwitchRoom(roomIndex int) { return } view.currentRoomIndex = roomIndex % len(view.roomIDs) - view.roomView.SwitchToPage(view.CurrentRoomID()) + if !view.roomView.HasPage(view.CurrentRoomID()) { + debug.Print("Oh noes!", view.CurrentRoomID(), "has no page!") + } else { + view.roomView.SwitchToPage(view.CurrentRoomID()) + } view.roomList.SetCurrentItem(roomIndex) view.gmx.App().SetFocus(view) view.parent.Render()