Buffer is now reallocated on window size change

This commit is contained in:
Sasha Koshka 2022-11-11 22:46:07 -05:00
parent 05c448f058
commit c865f7146a

View File

@ -150,14 +150,13 @@ func (backend *Backend) handleXEvent (event xgb.Event) {
backend.metrics.windowHeight = newHeight backend.metrics.windowHeight = newHeight
if sizeChanged { if sizeChanged {
// compress events
configureEvent = configureEvent =
backend.compressConfigureNotify(configureEvent) backend.compressConfigureNotify(configureEvent)
// TODO: remove draw functions from reallocate canvas,
// resize and rebind canvas // and only reallocate when drawing and the window
// dimensions have changed
backend.reallocateCanvas() backend.reallocateCanvas()
backend.application.SetSize(backend.calculateBufferSize())
// notify application of resize
backend.channel <- stone.EventResize { } backend.channel <- stone.EventResize { }
} }
} }
@ -204,6 +203,16 @@ func (backend *Backend) calculateWindowSize () (x, y int) {
return return
} }
func (backend *Backend) calculateBufferSize () (width, height int) {
width =
(backend.metrics.windowWidth - backend.metrics.padding * 2) /
backend.metrics.cellWidth
height =
(backend.metrics.windowHeight - backend.metrics.padding * 2) /
backend.metrics.cellHeight
return
}
func (backend *Backend) reallocateCanvas () { func (backend *Backend) reallocateCanvas () {
backend.drawLock.Lock() backend.drawLock.Lock()
defer backend.drawLock.Unlock() defer backend.drawLock.Unlock()