#79 - allow Windows to handle terminal resize event

This commit is contained in:
Vladimir Markelov 2018-01-26 21:36:46 -08:00
parent c7750d4e42
commit 5d3a40175d
4 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 Vladimir V. Markelov <vmatroskin@gmail.com>
Copyright (c) 2015-2018 Vladimir V. Markelov <vmatroskin@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,4 +1,8 @@
2018-01-25 - version 0.7.0
2018-01-26 - version 0.7.0
[+] Added new event handler for Window: set a callback OnScreenResize if you
want to handle terminal resize event
2018-01-25 - version 0.7.0
[+] Added new methods to Composer: BeginUpdate and EndUpdate to use in
multithreading application. Call BeginUpdate before creating a new Window or
manipulating Composer Windows if the code runs in separate thread. And

View File

@ -686,6 +686,11 @@ func ProcessEvent(ev Event) {
wnd.PlaceChildren()
RefreshScreen()
}
if wnd.onScreenResize != nil {
wnd.onScreenResize(ev)
}
}
case EventKey:
comp.processKey(ev)

View File

@ -20,8 +20,9 @@ type Window struct {
immovable bool
fixedSize bool
onClose func(Event) bool
onKeyDown func(Event) bool
onClose func(Event) bool
onKeyDown func(Event) bool
onScreenResize func(Event)
}
func CreateWindow(x, y, w, h int, title string) *Window {
@ -256,14 +257,22 @@ func (c *Window) ProcessEvent(ev Event) bool {
return false
}
// OnClose sets the callback that is called when the Window is about to destroy
func (w *Window) OnClose(fn func(Event) bool) {
w.onClose = fn
}
// OnKeyDown sets the callback that is called when a user presses a key
// while the Window is active
func (w *Window) OnKeyDown(fn func(Event) bool) {
w.onKeyDown = fn
}
// OnScreenResize sets the callback that is called when size of terminal changes
func (w *Window) OnScreenResize(fn func(Event)) {
w.onScreenResize = fn
}
// SetMaximized opens the view to full screen or restores its
// previous size
func (w *Window) SetMaximized(maximize bool) {