Fork tview

This commit is contained in:
Trevor Slocum 2019-10-17 18:15:01 -07:00
parent 92273d1c31
commit 2d0385ffb4
4 changed files with 43 additions and 52 deletions

View file

@ -13,10 +13,9 @@ import (
"git.sr.ht/~tslocum/netris/pkg/event"
"git.sr.ht/~tslocum/netris/pkg/game"
"git.sr.ht/~tslocum/netris/pkg/mino"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/tslocum/tview"
)
var (
@ -97,7 +96,7 @@ var (
func initGUI() (*tview.Application, error) {
app = tview.NewApplication()
app.SetBeforeDrawFunc(handleResize)
app.SetAfterResizeFunc(handleResize)
inputView = tview.NewInputField().
SetText(DefaultStatusText).
@ -361,47 +360,46 @@ func resetGameSettingsForm() {
})
}
func handleResize(screen tcell.Screen) bool {
func handleResize(screen tcell.Screen) {
newScreenW, newScreenH = screen.Size()
if newScreenW != screenW || newScreenH != screenH {
screenW, screenH = newScreenW, newScreenH
if !fixedBlockSize {
if screenW >= 80 && screenH >= 44 {
blockSize = 2
} else {
blockSize = 1
}
}
multiplayerMatrixSize = (screenW - ((10 * blockSize) + 16)) / ((10 * blockSize) + 4)
inputHeight = 1
mainHeight = (20 * blockSize) + 2
if screenH > mainHeight+5 {
mainHeight += 2
inputHeight++
} else if screenH > mainHeight+2 {
mainHeight++
}
newLogLines = (screenH - mainHeight) - inputHeight
if newLogLines > 0 {
showLogLines = newLogLines
} else {
showLogLines = 1
}
gameGrid.SetRows(mainHeight, inputHeight, -1).SetColumns(1, 4+(10*blockSize), 10, -1)
logMutex.Lock()
renderLogMessages = true
logMutex.Unlock()
draw <- event.DrawAll
return true
if newScreenW == screenW && newScreenH == screenH {
return
}
return false
screenW, screenH = newScreenW, newScreenH
if !fixedBlockSize {
if screenW >= 80 && screenH >= 44 {
blockSize = 2
} else {
blockSize = 1
}
}
multiplayerMatrixSize = (screenW - ((10 * blockSize) + 16)) / ((10 * blockSize) + 4)
inputHeight = 1
mainHeight = (20 * blockSize) + 2
if screenH > mainHeight+5 {
mainHeight += 2
inputHeight++
} else if screenH > mainHeight+2 {
mainHeight++
}
newLogLines = (screenH - mainHeight) - inputHeight
if newLogLines > 0 {
showLogLines = newLogLines
} else {
showLogLines = 1
}
gameGrid.SetRows(mainHeight, inputHeight, -1).SetColumns(1, 4+(10*blockSize), 10, -1)
logMutex.Lock()
renderLogMessages = true
logMutex.Unlock()
draw <- event.DrawAll
}
func drawAll() {

View file

@ -8,7 +8,7 @@ import (
"git.sr.ht/~tslocum/netris/pkg/event"
"git.sr.ht/~tslocum/netris/pkg/game"
"git.sr.ht/~tslocum/netris/pkg/mino"
"github.com/rivo/tview"
"github.com/tslocum/tview"
)
var (

5
go.mod
View file

@ -9,9 +9,6 @@ require (
github.com/gdamore/tcell v1.3.0
github.com/gliderlabs/ssh v0.2.2
github.com/mattn/go-isatty v0.0.10
github.com/rivo/tview v0.0.0-20191017100741-c35e6b2b4c98
github.com/rivo/uniseg v0.1.0 // indirect
github.com/tslocum/tview v0.0.0-20191018010543-3246547dc836
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/text v0.3.2 // indirect
)

8
go.sum
View file

@ -8,8 +8,6 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.1.2 h1:Afe8cU6SECC06UmvaJ55Jr3Eh0tz/ywLjqWYqjGZp3s=
github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE=
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
@ -20,12 +18,10 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/rivo/tview v0.0.0-20191017100741-c35e6b2b4c98 h1:nPfVK45RSX656/m0SXLl0GfhQbBgIUjojrbVxpOA8Ak=
github.com/rivo/tview v0.0.0-20191017100741-c35e6b2b4c98/go.mod h1:+rKjP5+h9HMwWRpAfhIkkQ9KE3m3Nz5rwn7YtUpwgqk=
github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44 h1:XKCbzPvK4/BbMXoMJOkYP2ANxiAEO0HM1xn6psSbXxY=
github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/tslocum/tview v0.0.0-20191018010543-3246547dc836 h1:Lh1HUlmWHmVY+wJUlNpZEOSdxxzU61VOSIkYDPYqYWs=
github.com/tslocum/tview v0.0.0-20191018010543-3246547dc836/go.mod h1:vUK8oe0CfwPjo5JouPDJq6g9+KsPiASsJP4yndpkzTg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=