From 5d3a40175de454ae485fa28a5728ad721942ab2d Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Fri, 26 Jan 2018 21:36:46 -0800 Subject: [PATCH] #79 - allow Windows to handle terminal resize event --- LICENSE | 2 +- changelog | 6 +++++- composer.go | 5 +++++ window.go | 13 +++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index f3b2d9c..4fdf775 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Vladimir V. Markelov +Copyright (c) 2015-2018 Vladimir V. Markelov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/changelog b/changelog index f5f4b56..d3ca627 100644 --- a/changelog +++ b/changelog @@ -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 diff --git a/composer.go b/composer.go index 004e321..9d530a9 100644 --- a/composer.go +++ b/composer.go @@ -686,6 +686,11 @@ func ProcessEvent(ev Event) { wnd.PlaceChildren() RefreshScreen() } + + if wnd.onScreenResize != nil { + wnd.onScreenResize(ev) + } + } case EventKey: comp.processKey(ev) diff --git a/window.go b/window.go index 3c77a9a..74660f2 100644 --- a/window.go +++ b/window.go @@ -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) {