Documentation
¶
Overview ¶
Package winman implements a basic yet powerful window manager that can be used with tview (github.com/rivo/tview).
It supports floating windows that can be dragged, resized and maximized. Windows can have buttons on the title bar, for example to close them, help commands or maximize / minimize.
Windows can also be modal, meaning that other windows don't receive input while a modal window is on top.
You can control whether the user can drag or resize windows around the screen.
Windows can overlap each other by setting their Z-index ¶
Any tview.Primitive can be added to a window.
Index ¶
- Constants
- Variables
- type Button
- type ButtonSide
- type ClipRegion
- func (cr *ClipRegion) Clear()
- func (cr *ClipRegion) Fill(ch rune, style tcell.Style)
- func (cr *ClipRegion) InRect(x, y int) bool
- func (cr *ClipRegion) SetCell(x int, y int, style tcell.Style, ch ...rune)
- func (cr *ClipRegion) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)
- func (cr *ClipRegion) ShowCursor(x int, y int)
- type Manager
- func (wm *Manager) AddWindow(window Window) *Manager
- func (wm *Manager) Center(window Window) *Manager
- func (wm *Manager) Draw(screen tcell.Screen)
- func (wm *Manager) Focus(delegate func(p tview.Primitive))
- func (wm *Manager) GetZ(window Window) int
- func (wm *Manager) HasFocus() bool
- func (wm *Manager) MouseHandler() ...
- func (wm *Manager) NewWindow() *WindowBase
- func (wm *Manager) RemoveWindow(window Window) *Manager
- func (wm *Manager) SetZ(window Window, newZ int) *Manager
- func (wm *Manager) Window(z int) Window
- func (wm *Manager) WindowCount() int
- type Rect
- type Stack
- func (s Stack) Find(f func(item interface{}) bool) interface{}
- func (s Stack) IndexOf(searchItem interface{}) int
- func (s Stack) Item(i int) interface{}
- func (s *Stack) Move(item interface{}, targetIndex int)
- func (s *Stack) Pop() interface{}
- func (s *Stack) Push(newItem interface{})
- func (s *Stack) Remove(item interface{})
- type Window
- type WindowBase
- func (w *WindowBase) AddButton(button *Button) *WindowBase
- func (w *WindowBase) ButtonCount() int
- func (w *WindowBase) Draw(screen tcell.Screen)
- func (w *WindowBase) Focus(delegate func(p tview.Primitive))
- func (w *WindowBase) GetButton(i int) *Button
- func (w *WindowBase) GetRoot() tview.Primitive
- func (w *WindowBase) HasBorder() bool
- func (w *WindowBase) HasFocus() bool
- func (w *WindowBase) Hide() *WindowBase
- func (w *WindowBase) IsDraggable() bool
- func (w *WindowBase) IsMaximized() bool
- func (w *WindowBase) IsModal() bool
- func (w *WindowBase) IsResizable() bool
- func (w *WindowBase) IsVisible() bool
- func (w *WindowBase) Maximize() *WindowBase
- func (w *WindowBase) MouseHandler() ...
- func (w *WindowBase) Restore() *WindowBase
- func (w *WindowBase) SetBorder(show bool) *WindowBase
- func (w *WindowBase) SetDraggable(draggable bool) *WindowBase
- func (w *WindowBase) SetModal(modal bool) *WindowBase
- func (w *WindowBase) SetResizable(resizable bool) *WindowBase
- func (w *WindowBase) SetRoot(root tview.Primitive) *WindowBase
- func (w *WindowBase) SetTitle(text string) *WindowBase
- func (w *WindowBase) Show() *WindowBase
- type WindowEdge
Constants ¶
const ( // ButtonLeft will set the button to be drawn on the left ButtonLeft = iota // ButtonRight will set the button to be drawn on the right ButtonRight )
const WindowZBottom = 0
WindowZBottom is used with SetZ to move a window to the bottom
const WindowZTop = -1
WindowZTop is used with SetZ to move a window to the top
Variables ¶
var MinWindowHeight = 3
MinWindowHeight sets the minimum height a window can have as part of a window manager
var MinWindowWidth = 3
MinWindowWidth sets the minimum width a window can have as part of a window manager
Functions ¶
This section is empty.
Types ¶
type Button ¶
type Button struct { Symbol rune // icon for the button Alignment ButtonSide // alignment of the button, left or right OnClick func() // callback to be invoked when the button is clicked // contains filtered or unexported fields }
Button represents a button on the window title bar
type ClipRegion ¶
type ClipRegion struct { tcell.Screen // contains filtered or unexported fields }
ClipRegion implements tcell.Screen and only allows setting content within a defined region
func NewClipRegion ¶
func NewClipRegion(screen tcell.Screen, x, y, width, height int) *ClipRegion
NewClipRegion Creates a new clipped screen with the given rectangular coordinates
func (*ClipRegion) Fill ¶
func (cr *ClipRegion) Fill(ch rune, style tcell.Style)
Fill implements tcell.Screen.Fill
func (*ClipRegion) InRect ¶
func (cr *ClipRegion) InRect(x, y int) bool
InRect returns true if the given coordinates are within this clipped region
func (*ClipRegion) SetCell ¶
func (cr *ClipRegion) SetCell(x int, y int, style tcell.Style, ch ...rune)
SetCell is an older API, and will be removed. Please use SetContent instead; SetCell is implemented in terms of SetContent.
func (*ClipRegion) SetContent ¶
func (cr *ClipRegion) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style)
SetContent sets the contents of the given cell location. If the coordinates are out of range, then the operation is ignored.
The first rune is the primary non-zero width rune. The array that follows is a possible list of combining characters to append, and will usually be nil (no combining characters.)
The results are not displayed until Show() or Sync() is called.
Note that wide (East Asian full width) runes occupy two cells, and attempts to place character at next cell to the right will have undefined effects. Wide runes that are printed in the last column will be replaced with a single width space on output.
func (*ClipRegion) ShowCursor ¶
func (cr *ClipRegion) ShowCursor(x int, y int)
ShowCursor is used to display the cursor at a given location. If the coordinates -1, -1 are given or are otherwise outside the dimensions of the screen, the cursor will be hidden.
type Manager ¶
Manager represents a Window Manager primitive
func NewWindowManager ¶
func NewWindowManager() *Manager
NewWindowManager returns a ready to use window manager
func (*Manager) Draw ¶
func (wm *Manager) Draw(screen tcell.Screen)
Draw draws this primitive onto the screen. implements tview.Primitive.Draw
func (*Manager) Focus ¶
Focus is called when this primitive receives focus implements tview.Primitive.Focus
func (*Manager) GetZ ¶
GetZ returns the z index of the given window returns -1 if the given window is not part of this manager
func (*Manager) HasFocus ¶
HasFocus returns whether or not this primitive has focus. implements tview.Focusable
func (*Manager) MouseHandler ¶
func (wm *Manager) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)
MouseHandler returns the mouse handler for this primitive. implements tview.Primitive.MouseHandler
func (*Manager) NewWindow ¶
func (wm *Manager) NewWindow() *WindowBase
NewWindow creates a new (hidden) window and adds it to this window manager
func (*Manager) RemoveWindow ¶
RemoveWindow removes the given window from this window manager
func (*Manager) SetZ ¶
SetZ moves the given window to the given z index The special constants WindowZTop and WindowZBottom can be used
func (*Manager) WindowCount ¶
WindowCount returns the number of windows managed by this window manager
type Rect ¶
Rect represents rectangular coordinates
type Stack ¶
type Stack []interface{}
Stack represents a stack of unique items
func (Stack) Find ¶
Find searches the stack top down for an item that meets the custom criteria specified by the passed function
func (Stack) Item ¶
Item returns the given item from the stack returns nil if the index is out of bounds
func (*Stack) Move ¶
Move finds an item in the stack and places it at the given index, shifting items up or down to make space
func (*Stack) Pop ¶
func (s *Stack) Pop() interface{}
Pop pops the stack returning and removing the topmost element
type Window ¶
type Window interface { tview.Primitive // IsModal defines this window as modal. When a window is modal, input cannot go to other windows IsModal() bool // HasFocus returns true when this window has the focus HasFocus() bool // IsMaximized returns true when the window is maximized and takes all the space available to the // Window Manager IsMaximized() bool // IsResizable returns true when the window can be resized by the user IsResizable() bool // IsDraggable returns true when the window can be moved by the user by dragging // the title bar IsDraggable() bool // IsVisible returns true when the window has to be drawn and can receive focus IsVisible() bool // HasBorder returns true if the window must have a border HasBorder() bool }
Window interface defines primitives that can be managed by the Window Manager
type WindowBase ¶
type WindowBase struct { *tview.Box Draggable bool //whether this window can be dragged around with the mouse Resizable bool // whether this window is user-resizable Modal bool // whether this window is modal Visible bool // whether this window is rendered // contains filtered or unexported fields }
WindowBase defines a basic window
func (*WindowBase) AddButton ¶
func (w *WindowBase) AddButton(button *Button) *WindowBase
AddButton adds a new window button to the title bar
func (*WindowBase) ButtonCount ¶
func (w *WindowBase) ButtonCount() int
ButtonCount returns the number of buttons in the window title bar
func (*WindowBase) Draw ¶
func (w *WindowBase) Draw(screen tcell.Screen)
Draw draws this primitive on to the screen
func (*WindowBase) Focus ¶
func (w *WindowBase) Focus(delegate func(p tview.Primitive))
Focus is called when this primitive receives focus.
func (*WindowBase) GetButton ¶
func (w *WindowBase) GetButton(i int) *Button
GetButton returns the given button
func (*WindowBase) GetRoot ¶
func (w *WindowBase) GetRoot() tview.Primitive
GetRoot returns the primitive that represents the main content of the window
func (*WindowBase) HasBorder ¶
func (w *WindowBase) HasBorder() bool
HasBorder returns true if this window has a border windows without border cannot be resized or dragged by the user
func (*WindowBase) HasFocus ¶
func (w *WindowBase) HasFocus() bool
HasFocus returns whether or not this primitive has focus.
func (*WindowBase) IsDraggable ¶
func (w *WindowBase) IsDraggable() bool
IsDraggable returns true if this window can be dragged by the user
func (*WindowBase) IsMaximized ¶
func (w *WindowBase) IsMaximized() bool
IsMaximized returns true if this window is maximized
func (*WindowBase) IsModal ¶
func (w *WindowBase) IsModal() bool
IsModal returns true if this window is modal
func (*WindowBase) IsResizable ¶
func (w *WindowBase) IsResizable() bool
IsResizable returns true if the user may resize this window
func (*WindowBase) IsVisible ¶
func (w *WindowBase) IsVisible() bool
IsVisible returns true if this window is rendered and may get focus
func (*WindowBase) Maximize ¶
func (w *WindowBase) Maximize() *WindowBase
Maximize signals the window manager to resize this window to the maximum size available
func (*WindowBase) MouseHandler ¶
func (w *WindowBase) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)
MouseHandler returns a mouse handler for this primitive
func (*WindowBase) Restore ¶
func (w *WindowBase) Restore() *WindowBase
Restore restores the window to the size it had before maximizing
func (*WindowBase) SetBorder ¶
func (w *WindowBase) SetBorder(show bool) *WindowBase
SetBorder sets the flag indicating whether or not the box should have a border.
func (*WindowBase) SetDraggable ¶
func (w *WindowBase) SetDraggable(draggable bool) *WindowBase
SetDraggable sets if this window can be dragged by the user
func (*WindowBase) SetModal ¶
func (w *WindowBase) SetModal(modal bool) *WindowBase
SetModal makes this window modal. A modal window captures all input
func (*WindowBase) SetResizable ¶
func (w *WindowBase) SetResizable(resizable bool) *WindowBase
SetResizable sets if this window can be resized
func (*WindowBase) SetRoot ¶
func (w *WindowBase) SetRoot(root tview.Primitive) *WindowBase
SetRoot sets the main content of the window
func (*WindowBase) SetTitle ¶
func (w *WindowBase) SetTitle(text string) *WindowBase
SetTitle sets the window title
type WindowEdge ¶
type WindowEdge int16
WindowEdge enumerates the different window edges and corners
const ( EdgeNone WindowEdge = iota EdgeTop EdgeRight EdgeBottom EdgeLeft EdgeBottomRight EdgeBottomLeft )
Different window edges