Merge branch 'isbm-enhanced-windows' into 'master'

Add possibility to hide/show windows in window manager

See merge request tslocum/cview!9
This commit is contained in:
Trevor Slocum 2020-10-19 17:10:59 +00:00
commit f2230ae3f8
2 changed files with 23 additions and 4 deletions

View File

@ -16,6 +16,7 @@ type Window struct {
x, y int
width, height int
fullscreen bool
visible bool
dragX, dragY int
dragWX, dragWY int
@ -32,9 +33,25 @@ func NewWindow(primitive Primitive) *Window {
dragWY: -1,
}
w.Box.focus = w
w.visible = true
return w
}
// IsVisible returns true if the window is visible
func (w *Window) IsVisible() bool {
return w.visible
}
// Show the window.
func (w *Window) Show() {
w.visible = true
}
// Hide the window.
func (w *Window) Hide() {
w.visible = false
}
// SetPosition sets the position of the window.
func (w *Window) SetPosition(x, y int) {
w.Lock()

View File

@ -73,7 +73,7 @@ func (wm *WindowManager) Draw(screen tcell.Screen) {
var hasFullScreen bool
for _, w := range wm.windows {
if !w.fullscreen {
if !w.fullscreen || !w.IsVisible() {
continue
}
@ -88,9 +88,11 @@ func (wm *WindowManager) Draw(screen tcell.Screen) {
}
for _, w := range wm.windows {
w.SetBorder(true)
w.SetRect(x+w.x, x+w.y, w.width, w.height)
w.Draw(screen)
if w.IsVisible() {
w.SetBorder(true)
w.SetRect(x+w.x, x+w.y, w.width, w.height)
w.Draw(screen)
}
}
}