diff --git a/composer.go b/composer.go index 8122d6b..b44acc5 100644 --- a/composer.go +++ b/composer.go @@ -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 } diff --git a/interface.go b/interface.go index fe7a150..69fb981 100644 --- a/interface.go +++ b/interface.go @@ -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 } diff --git a/window.go b/window.go index 2982d09..211deed 100644 --- a/window.go +++ b/window.go @@ -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 +}