erm/internal/app/darktile/gui/resize.go
2021-07-30 23:29:20 +01:00

36 lines
665 B
Go

package gui
import (
"image"
)
// Layout provides the terminal gui size in pixels. Required to implement the ebiten interface.
func (g *GUI) Layout(outsideWidth, outsideHeight int) (int, int) {
w, h := outsideWidth, outsideHeight
if g.size.X != w || g.size.Y != h {
g.size = image.Point{
X: w,
Y: h,
}
g.resize(w, h)
}
return w, h
}
func (g *GUI) resize(w, h int) {
if g.fontManager.CharSize().X == 0 || g.fontManager.CharSize().Y == 0 {
return
}
cols := uint16(w / g.fontManager.CharSize().X)
rows := uint16(h / g.fontManager.CharSize().Y)
if g.terminal != nil && g.terminal.IsRunning() {
_ = g.terminal.SetSize(rows, cols)
}
}