closes #25 - maximize+restore view

This commit is contained in:
Vladimir Markelov 2015-10-30 15:12:35 -07:00
parent 0dc0e012e1
commit 7b9e30b8c7
3 changed files with 61 additions and 6 deletions

View File

@ -323,6 +323,12 @@ func (c *Composer) processKeySeq(ev term.Event) bool {
switch ev.Key {
case term.KeyCtrlH:
return c.moveActiveWindowToBottom()
case term.KeyCtrlM:
v := c.topView()
maximized := v.Maximized()
v.SetMaximized(!maximized)
c.refreshScreen(true)
return true
default:
return false
}
@ -389,6 +395,11 @@ func (c *Composer) processMouseClick(ev term.Event) {
}
} else if hit == HitButtonBottom {
c.moveActiveWindowToBottom()
} else if hit == HitButtonMaximize {
v := c.topView()
maximized := v.Maximized()
v.SetMaximized(!maximized)
c.refreshScreen(true)
}
}
@ -476,6 +487,11 @@ func (c *Composer) Theme() Theme {
return c.themeManager
}
// Size returns size of the console(visible) buffer
func (c *Composer) Size() (int, int) {
return term.Size()
}
func (c *Composer) Logger() *log.Logger {
return c.logger
}

View File

@ -15,6 +15,8 @@ type Screen interface {
PutEvent(event Event)
// DestroyView removes view from the view list and makes the next view in the view stack active. It is not possible to destroy the last view - Screen must have at least one visible view
DestroyView(view View)
// Size returns size of the console(visible) buffer
Size() (width int, height int)
Logger() *log.Logger
}
@ -206,6 +208,11 @@ type View interface {
// RecalculateConstraints used by containers to recalculate new minimal size
// depending on its children constraints after a new child is added
RecalculateConstraints()
// SetMaximized opens the view to full screen or restores its
// previous size
SetMaximized(maximize bool)
// Maximized returns if the view is in full screen mode
Maximized() bool
Logger() *log.Logger
}

View File

@ -9,12 +9,18 @@ import (
// Window is an implemetation of View managed by Composer.
type Window struct {
ControlBase
buttons ViewButton
canvas Canvas
parent Screen
pack PackType
children []Control
controls []Control
buttons ViewButton
canvas Canvas
parent Screen
pack PackType
children []Control
controls []Control
maximized bool
// maximization support
origWidth int
origHeight int
origX int
origY int
// dialog support
modal bool
onClose func(Event)
@ -551,3 +557,29 @@ func (w *Window) Modal() bool {
func (w *Window) OnClose(fn func(Event)) {
w.onClose = fn
}
// SetMaximized opens the view to full screen or restores its
// previous size
func (w *Window) SetMaximized(maximize bool) {
if maximize == w.maximized {
return
}
if maximize {
w.origX, w.origY = w.Pos()
w.origWidth, w.origHeight = w.Size()
w.maximized = true
w.SetPos(0, 0)
width, height := w.parent.Size()
w.SetSize(width, height)
} else {
w.maximized = false
w.SetPos(w.origX, w.origY)
w.SetSize(w.origWidth, w.origHeight)
}
}
// Maximized returns if the view is in full screen mode
func (w *Window) Maximized() bool {
return w.maximized
}