mirror of
https://github.com/VladimirMarkelov/clui.git
synced 2025-04-26 13:49:01 +08:00
closes #25 - maximize+restore view
This commit is contained in:
parent
0dc0e012e1
commit
7b9e30b8c7
16
composer.go
16
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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
44
window.go
44
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user