Compare commits

...

1 Commits

Author SHA1 Message Date
Trevor Slocum 1f56db95fe WIP table rendering issue 3 months ago
  1. 66
      app.go

66
app.go

@ -1,6 +1,7 @@
package main
import (
"strconv"
"time"
"code.rocketnine.space/tslocum/cview"
@ -15,7 +16,7 @@ const (
var (
app *cview.Application
uiGrid *cview.Grid
lobby *cview.List
userList *cview.Table
board *Board
actionBuffer *cview.TextView
gameBuffer *cview.TextView
@ -82,13 +83,48 @@ func setScreen(screen int) {
viewScreen = screen
if viewScreen == ScreenLobby {
board.SetVisible(false)
lobby.SetVisible(true)
userList.SetVisible(true)
} else {
lobby.SetVisible(false)
userList.SetVisible(false)
board.SetVisible(true)
}
}
func updateUserList(c *Client) {
u := userList
headerCell := func(t string) *cview.TableCell {
cell := cview.NewTableCell(t)
cell.SetSelectable(false)
return cell
}
selectableCell := func(t string) *cview.TableCell {
cell := cview.NewTableCell(t)
cell.SetSelectable(true)
return cell
}
u.SetCell(0, 0, headerCell("Rating"))
u.SetCell(0, 1, headerCell("Experience"))
u.SetCell(0, 2, headerCell("Status"))
cell := headerCell("Name")
cell.SetExpansion(1)
u.SetCell(0, 3, cell)
row := 1
for _, whoInfo := range c.who {
u.SetCell(row, 0, selectableCell(strconv.Itoa(whoInfo.rating)))
u.SetCell(row, 1, selectableCell(strconv.Itoa(whoInfo.experience)))
u.SetCell(row, 2, selectableCell("Test"))
cell := headerCell(whoInfo.username)
cell.SetExpansion(1)
cell.SetSelectable(true)
u.SetCell(row, 3, cell)
row++
}
}
func RunApp(c *Client) error {
app = cview.NewApplication()
app.EnableMouse(true)
@ -194,6 +230,13 @@ func RunApp(c *Client) error {
return event
}
if viewScreen == ScreenLobby {
switch event.Key() {
case tcell.KeyUp:
// Transform user list
}
}
if event.Key() == tcell.KeyTab {
if chatMode == ChatModeShout {
chatMode = ChatModeKibitz
@ -225,8 +268,12 @@ func RunApp(c *Client) error {
statusWriter = &bufferWriter{Buffer: statusBuffer}
gameWriter = &bufferWriter{Buffer: gameBuffer}
lobby = cview.NewList()
lobby.AddItem(cview.NewListItem("test"))
userList = cview.NewTable()
userList.SetFixed(1, 0)
userList.SetSelectable(true, false)
app.QueueUpdateDraw(func() {
updateUserList(c)
})
buildLayout := func(screenX int, screenY int) {
box := cview.NewBox()
@ -243,7 +290,7 @@ func RunApp(c *Client) error {
var currentScreen cview.Primitive
if viewScreen == ScreenLobby {
currentScreen = lobby
currentScreen = userList
} else {
currentScreen = board
}
@ -286,6 +333,13 @@ func RunApp(c *Client) error {
app.SetFocus(form)
} else {
logIn(c)
setScreen(ScreenLobby) // TODO temporary
go func() {
time.Sleep(2 * time.Second)
app.QueueUpdateDraw(func() {
updateUserList(c)
})
}()
}
go updateClock()

Loading…
Cancel
Save