wm: github.com/cznic/wm Index | Files | Directories

package wm

import "github.com/cznic/wm"

Package wm is a terminal window manager.

Screenshot

An example content of a terminal window (colors cannot be shown here):

Use mouse to resize the window or scroll the view.
Arrow keys change the viewport of the focused window.
To focus the desktop, click on it.
<Esc> or 'q' to quit.

                    ┌ view_demo.go ─────────────────────────────────────────────────────[X]┐
                    │                                                                     ▴│
                    │                                                                     ░│
 ┌ view.go ─────────│Use mouse to resize the window or scroll the view.                   ░│
 │        "github.co│e the viewport of the focused window.                                ▒│
 │        "github.co│ktop, click on it.                                                   ▒│
 │)                 │quit.`                                                               ░│
 │                  │                                                                     ░│
 │// Meter provides │                                                                     ░│────[X]┐
 │type Meter interfa│'\n'}                                                                ░│      ▴│
 │        // Metrics│                                                                     ░│      ░│
 │        // result │arent *wm.Window, x, y int, title string, src []byte) {              ░│      ░│
 │        // reflect│rent.Size()                                                          ░│      ░│
 │        // values │ || y < 0 {                                                          ░│, len(░│
 │        // output │x = rand.Intn(sz.Width - sz.Width/5)                                 ░│      ░│
 │        Metrics(vi│y = rand.Intn(sz.Height - sz.Height/5)                               ░│)     ░│
 │}                 │                                                                     ░│s:%d: ░│
 │                  │ent.NewChild(wm.Rectangle{wm.Position{x, y}, wm.Size{0, 0}})         ░│      ░│
 │// View displays c│seButton(true)                                                       ░│      ░│
 │◂▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│le(title)                                                            ░│      ░│
 └──────────────────│.HasSuffix(src, nl) {                                                ░│      ▒│
                    │src = src[:len(src)-1]                                               ░│      ▒│
                    │                                                                     ▾│OOK   ▒│
                    │◂░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░▸ │)     ▒│
                    └──────────────────────────────────────────────────────────────────────┘%d:\n"▒│

Changelog

2016-12-16: Initial release of the accompanying toolkit package: http://github.com/cznic/wm/tree/master/tk

2016-11-25: Windows now support views (viewports). See Windows.Origin and friends.

2015-12-11: WM now uses no locks and renders 2 to 3 times faster. The price is that any methods of Application, Desktop or Window must be called only from a function that was enqueued by Application.Post or Application.PostWait.

Index

Package Files

app.go desktop.go etc.go event.go handler.go mouse.go nodbg.go theme.go window.go

func AddOnMouseHandler Uses

func AddOnMouseHandler(l **OnMouseHandlerList, h OnMouseHandler, finalizer func())

AddOnMouseHandler adds a handler to the handler list.

func AddOnPaintHandler Uses

func AddOnPaintHandler(l **OnPaintHandlerList, h OnPaintHandler, finalizer func())

AddOnPaintHandler adds a handler to the handler list.

func AddOnSetBoolHandler Uses

func AddOnSetBoolHandler(l **OnSetBoolHandlerList, h OnSetBoolHandler, finalizer func())

AddOnSetBoolHandler adds a handler to the handler list.

func AddOnSetIntHandler Uses

func AddOnSetIntHandler(l **OnSetIntHandlerList, h OnSetIntHandler, finalizer func())

AddOnSetIntHandler adds a handler to the handler list.

func AddOnSetPositionHandler Uses

func AddOnSetPositionHandler(l **OnSetPositionHandlerList, h OnSetPositionHandler, finalizer func())

AddOnSetPositionHandler adds a handler to the handler list.

func AddOnSetSizeHandler Uses

func AddOnSetSizeHandler(l **OnSetSizeHandlerList, h OnSetSizeHandler, finalizer func())

AddOnSetSizeHandler adds a handler to the handler list.

func AddOnSetStyleHandler Uses

func AddOnSetStyleHandler(l **OnSetStyleHandlerList, h OnSetStyleHandler, finalizer func())

AddOnSetStyleHandler adds a handler to the handler list.

func RemoveOnMouseHandler Uses

func RemoveOnMouseHandler(l **OnMouseHandlerList)

RemoveOnMouseHandler undoes the most recent call to AddOnMouseHandler.

func RemoveOnPaintHandler Uses

func RemoveOnPaintHandler(l **OnPaintHandlerList)

RemoveOnPaintHandler undoes the most recent call to AddOnPaintHandler.

func RemoveOnSetBoolHandler Uses

func RemoveOnSetBoolHandler(l **OnSetBoolHandlerList)

RemoveOnSetBoolHandler undoes the most recent call to AddOnSetBoolHandler.

func RemoveOnSetIntHandler Uses

func RemoveOnSetIntHandler(l **OnSetIntHandlerList)

RemoveOnSetIntHandler undoes the most recent call to AddOnSetIntHandler.

func RemoveOnSetPositionHandler Uses

func RemoveOnSetPositionHandler(l **OnSetPositionHandlerList)

RemoveOnSetPositionHandler undoes the most recent call to AddOnSetPositionHandler.

func RemoveOnSetSizeHandler Uses

func RemoveOnSetSizeHandler(l **OnSetSizeHandlerList)

RemoveOnSetSizeHandler undoes the most recent call to AddOnSetSizeHandler.

func RemoveOnSetStyleHandler Uses

func RemoveOnSetStyleHandler(l **OnSetStyleHandlerList)

RemoveOnSetStyleHandler undoes the most recent call to AddOnSetStyleHandler.

type Application Uses

type Application struct {
    // contains filtered or unexported fields
}

Application represents an interactive terminal application.

Application methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait. The only exception is Application.Wait, it can be called from any goroutine.

var (
    // App is the instance of Application created by NewApplication.
    App *Application
)

func NewApplication Uses

func NewApplication(theme *Theme) (*Application, error)

NewApplication returns a newly created Application or an error, if any.

// Skeleton example.
func main() {
	app, err := wm.NewApplication(theme)
	if err != nil {
		log.Fatalf("error: %v", err)
	}

	...

	if err = app.Wait(); err != nil {
		log.Fatal(err)
	}
}

Calling this function more than once will panic.

func (*Application) BeginUpdate Uses

func (a *Application) BeginUpdate()

BeginUpdate marks the start of one or more updates to the application screen.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Application) ChildWindowStyle Uses

func (a *Application) ChildWindowStyle() WindowStyle

ChildWindowStyle returns the style assigned to new child windows.

func (*Application) ClickDuration Uses

func (a *Application) ClickDuration() time.Duration

ClickDuration returns the maximum duration of a single click. Holding a mouse button for any longer duration generates a drag event instead.

func (*Application) Colors Uses

func (a *Application) Colors() int

Colors returns the number of colors the host terminal supports. All colors are assumed to use the ANSI color map. If a terminal is monochrome, it will return 0.

func (*Application) Desktop Uses

func (a *Application) Desktop() (d *Desktop)

Desktop returns the currently active desktop.

func (*Application) DesktopStyle Uses

func (a *Application) DesktopStyle() WindowStyle

DesktopStyle returns the style assigned to new desktops.

func (*Application) DoubleClickDuration Uses

func (a *Application) DoubleClickDuration() time.Duration

DoubleClickDuration returns the maximum duration of a double click. Mouse click not followed by another one within the DoubleClickDuration is a single click.

func (*Application) EndUpdate Uses

func (a *Application) EndUpdate()

EndUpdate marks the end of one or more updates to the application screen.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Application) Exit Uses

func (a *Application) Exit(err error)

Exit terminates the interactive terminal application and returns err from Wait(). Only the first call of this method is considered.

func (*Application) NewDesktop Uses

func (a *Application) NewDesktop() *Desktop

NewDesktop returns a newly created desktop.

func (*Application) OnKey Uses

func (a *Application) OnKey(h OnKeyHandler, finalize func())

OnKey sets a key event handler. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetClickDuration Uses

func (a *Application) OnSetClickDuration(h OnSetDurationHandler, finalize func())

OnSetClickDuration sets a handler invoked on SetClickDuration. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetDesktop Uses

func (a *Application) OnSetDesktop(h OnSetDesktopHandler, finalize func())

OnSetDesktop sets a handler invoked on SetDesktop. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetDoubleClickDuration Uses

func (a *Application) OnSetDoubleClickDuration(h OnSetDurationHandler, finalize func())

OnSetDoubleClickDuration sets a handler invoked on SetDoubleClickDuration. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetSize Uses

func (a *Application) OnSetSize(h OnSetSizeHandler, finalize func())

OnSetSize sets a handler invoked on resizing the application screen. When the event handler is removed, finalize is called, if not nil.

func (*Application) Post Uses

func (a *Application) Post(f func())

Post puts f in the event queue, if the queue is not full, and executes it on dequeuing the event.

func (*Application) PostWait Uses

func (a *Application) PostWait(f func())

PostWait puts f in the event queue and executes it on dequeuing the event.

func (*Application) RemoveOnKey Uses

func (a *Application) RemoveOnKey()

RemoveOnKey undoes the most recent OnKey call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetClickDuration Uses

func (a *Application) RemoveOnSetClickDuration()

RemoveOnSetClickDuration undoes the most recent OnSetClickDuration call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetDesktop Uses

func (a *Application) RemoveOnSetDesktop()

RemoveOnSetDesktop undoes the most recent OnSetDesktop call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetDoubleClickDuration Uses

func (a *Application) RemoveOnSetDoubleClickDuration()

RemoveOnSetDoubleClickDuration undoes the most recent OnSetDoubleClickDuration call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetSize Uses

func (a *Application) RemoveOnSetSize()

RemoveOnSetSize undoes the most recent OnSetSize call. The function will panic if there is no handler set.

func (*Application) Run Uses

func (a *Application) Run(setup func()) error

Run is a shorthand for

app.PostWait(setup)
return app.Wait()

func (*Application) SetClickDuration Uses

func (a *Application) SetClickDuration(d time.Duration)

SetClickDuration sets the maximum duration of a single click. Holding a mouse button for any longer duration generates a drag event instead.

func (*Application) SetDesktop Uses

func (a *Application) SetDesktop(d *Desktop)

SetDesktop sets the currently active desktop. Passing nil d will panic.

func (*Application) SetDoubleClickDuration Uses

func (a *Application) SetDoubleClickDuration(d time.Duration)

SetDoubleClickDuration sets the maximum duration of a single click. Mouse click not followed by another one within the DoubleClickDuration is a single click.

Note: Setting DoubleClickDuration to zero disables double click support.

func (*Application) Size Uses

func (a *Application) Size() (s Size)

Size returns the size of the terminal the application runs in.

func (*Application) Sync Uses

func (a *Application) Sync()

Sync updates every character cell of the application screen.

func (*Application) Wait Uses

func (a *Application) Wait() error

Wait blocks until the interactive terminal application terminates.

Calling this method more than once will panic.

type Desktop Uses

type Desktop struct {
    // contains filtered or unexported fields
}

Desktop represents a virtual screen. An application has one or more independent desktops, of which only one is visible at any given moment.

A desktop initially contains only the automatically created root window.

Desktop methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait.

func (*Desktop) FocusedWindow Uses

func (d *Desktop) FocusedWindow() *Window

FocusedWindow returns the window with focus, if any.

func (*Desktop) OnSetFocusedWindow Uses

func (d *Desktop) OnSetFocusedWindow(h OnSetWindowHandler, finalize func())

OnSetFocusedWindow sets a handler invoked on SetFocusedWindow. When the event handler is removed, finalize is called, if not nil.

func (*Desktop) OnSetSelection Uses

func (d *Desktop) OnSetSelection(h OnSetRectangleHandler, finalize func())

OnSetSelection sets a handler invoked on SetSelection. When the event handler is removed, finalize is called, if not nil.

func (*Desktop) RemoveOnSetFocusedWindow Uses

func (d *Desktop) RemoveOnSetFocusedWindow()

RemoveOnSetFocusedWindow undoes the most recent OnSetFocusedWindow call. The function will panic if there is no handler set.

func (*Desktop) RemoveOnSetSelection Uses

func (d *Desktop) RemoveOnSetSelection()

RemoveOnSetSelection undoes the most recent OnSetSelection call. The function will panic if there is no handler set.

func (*Desktop) Root Uses

func (d *Desktop) Root() *Window

Root returns the root window of d.

func (*Desktop) Selection Uses

func (d *Desktop) Selection() Rectangle

Selection returns the area of the desktop shown in reverse.

func (*Desktop) SetFocusedWindow Uses

func (d *Desktop) SetFocusedWindow(w *Window)

SetFocusedWindow sets the focused window.

func (*Desktop) SetSelection Uses

func (d *Desktop) SetSelection(area Rectangle)

SetSelection sets the area of the desktop shown in reverse.

func (*Desktop) Show Uses

func (d *Desktop) Show()

Show sets d as the application active desktop.

type OnCloseHandler Uses

type OnCloseHandler func(w *Window, prev OnCloseHandler)

OnCloseHandler is called on window close. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnKeyHandler Uses

type OnKeyHandler func(w *Window, prev OnKeyHandler, key tcell.Key, mod tcell.ModMask, r rune) bool

OnKeyHandler handles key events. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution. The handler should return true if it consumes the event and it should not be considered by other subscribed handlers.

type OnMouseHandler Uses

type OnMouseHandler func(w *Window, prev OnMouseHandler, button tcell.ButtonMask, screenPos, winPos Position, mods tcell.ModMask) bool

OnMouseHandler handles mouse events. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution. The handler should return true if it consumes the event and it should not be considered by other subscribed handlers.

type OnMouseHandlerList Uses

type OnMouseHandlerList struct {
    // contains filtered or unexported fields
}

OnMouseHandlerList represents a list of handlers subscribed to an event.

func (*OnMouseHandlerList) Clear Uses

func (l *OnMouseHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnMouseHandlerList) Handle Uses

func (l *OnMouseHandlerList) Handle(w *Window, button tcell.ButtonMask, screenPos, winPos Position, mods tcell.ModMask) bool

Handle performs handling mouse events.

type OnPaintHandler Uses

type OnPaintHandler func(w *Window, prev OnPaintHandler, ctx PaintContext)

OnPaintHandler handles paint requests. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

OnPaint handlers can safely try to modify window cells outside of the area argument as such attempts will be silently ignored. In other words, an OnPaintHandler cannot affect any window cell outside of the area argument.

type OnPaintHandlerList Uses

type OnPaintHandlerList struct {
    // contains filtered or unexported fields
}

OnPaintHandlerList represents a list of handlers subscribed to an event.

func (*OnPaintHandlerList) Clear Uses

func (l *OnPaintHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnPaintHandlerList) Handle Uses

func (l *OnPaintHandlerList) Handle(w *Window, ctx PaintContext)

Handle performs painting of ctx.

type OnSetBoolHandler Uses

type OnSetBoolHandler func(w *Window, prev OnSetBoolHandler, dst *bool, src bool)

OnSetBoolHandler handles requests to change values of type bool. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetBoolHandlerList Uses

type OnSetBoolHandlerList struct {
    // contains filtered or unexported fields
}

OnSetBoolHandlerList represents a list of handlers subscribed to an event.

func (*OnSetBoolHandlerList) Clear Uses

func (l *OnSetBoolHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetBoolHandlerList) Handle Uses

func (l *OnSetBoolHandlerList) Handle(w *Window, dst *bool, src bool)

Handle performs updating of dst from src or calling and associated handler.

type OnSetDesktopHandler Uses

type OnSetDesktopHandler func(w *Window, prev OnSetDesktopHandler, dst **Desktop, src *Desktop)

OnSetDesktopHandler handles requests to change values of type *Desktop. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetDurationHandler Uses

type OnSetDurationHandler func(w *Window, prev OnSetDurationHandler, dst *time.Duration, src time.Duration)

OnSetDurationHandler handles requests to change values of type time.Duration. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetIntHandler Uses

type OnSetIntHandler func(w *Window, prev OnSetIntHandler, dst *int, src int)

OnSetIntHandler handles requests to change values of type int. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetIntHandlerList Uses

type OnSetIntHandlerList struct {
    // contains filtered or unexported fields
}

OnSetIntHandlerList represents a list of handlers subscribed to an event.

func (*OnSetIntHandlerList) Clear Uses

func (l *OnSetIntHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetIntHandlerList) Handle Uses

func (l *OnSetIntHandlerList) Handle(w *Window, dst *int, src int)

Handle performs updating of dst from src or calling and associated handler.

type OnSetPositionHandler Uses

type OnSetPositionHandler func(w *Window, prev OnSetPositionHandler, dst *Position, src Position)

OnSetPositionHandler handles requests to change values of type Position. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetPositionHandlerList Uses

type OnSetPositionHandlerList struct {
    // contains filtered or unexported fields
}

OnSetPositionHandlerList represents a list of handlers subscribed to an event.

func (*OnSetPositionHandlerList) Clear Uses

func (l *OnSetPositionHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetPositionHandlerList) Handle Uses

func (l *OnSetPositionHandlerList) Handle(w *Window, dst *Position, src Position)

Handle performs updating of dst from src or calling and associated handler.

type OnSetRectangleHandler Uses

type OnSetRectangleHandler func(w *Window, prev OnSetRectangleHandler, dst *Rectangle, src Rectangle)

OnSetRectangleHandler handles requests to change values of type Rectangle. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetSizeHandler Uses

type OnSetSizeHandler func(w *Window, prev OnSetSizeHandler, dst *Size, src Size)

OnSetSizeHandler handles requests to change values of type Size. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetSizeHandlerList Uses

type OnSetSizeHandlerList struct {
    // contains filtered or unexported fields
}

OnSetSizeHandlerList represents a list of handlers subscribed to an event.

func (*OnSetSizeHandlerList) Clear Uses

func (l *OnSetSizeHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetSizeHandlerList) Handle Uses

func (l *OnSetSizeHandlerList) Handle(w *Window, dst *Size, src Size)

Handle performs updating of dst from src or calling and associated handler.

type OnSetStringHandler Uses

type OnSetStringHandler func(w *Window, prev OnSetStringHandler, dst *string, src string)

OnSetStringHandler handles requests to change values of type String. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetStyleHandler Uses

type OnSetStyleHandler func(w *Window, prev OnSetStyleHandler, dst *Style, src Style)

OnSetStyleHandler handles requests to change values of type Style. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetStyleHandlerList Uses

type OnSetStyleHandlerList struct {
    // contains filtered or unexported fields
}

OnSetStyleHandlerList represents a list of handlers subscribed to an event.

func (*OnSetStyleHandlerList) Clear Uses

func (l *OnSetStyleHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetStyleHandlerList) Handle Uses

func (l *OnSetStyleHandlerList) Handle(w *Window, dst *Style, src Style)

Handle performs updating of dst from src or calling and associated handler.

type OnSetWindowHandler Uses

type OnSetWindowHandler func(w *Window, prev OnSetWindowHandler, dst **Window, src *Window)

OnSetWindowHandler handles requests to change values of type *Window. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetWindowStyleHandler Uses

type OnSetWindowStyleHandler func(w *Window, prev OnSetWindowStyleHandler, dst *WindowStyle, src WindowStyle)

OnSetWindowStyleHandler handles requests to change values of type WindowStyle. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type PaintContext Uses

type PaintContext struct {
    Rectangle
    // contains filtered or unexported fields
}

PaintContext represents the context passed to paint handlers.

type Position Uses

type Position struct {
    X, Y int
}

Position represents 2D coordinates.

func (Position) In Uses

func (p Position) In(r Rectangle) bool

In returns whether p is inside r.

type Rectangle Uses

type Rectangle struct {
    Position
    Size
}

Rectangle represents a 2D area.

func NewRectangle Uses

func NewRectangle(x1, y1, x2, y2 int) Rectangle

NewRectangle returns a Rectangle from 4 coordinates.

func (*Rectangle) Clip Uses

func (r *Rectangle) Clip(s Rectangle) bool

Clip sets r to the intersection of r and s and returns a boolean value indicating whether the result is of non zero size.

func (*Rectangle) Has Uses

func (r *Rectangle) Has(p Position) bool

Has returns whether r contains p.

type Size Uses

type Size struct {
    Width, Height int
}

Size represents 2D dimensions.

func (*Size) IsZero Uses

func (s *Size) IsZero() bool

IsZero returns whether s.Width or s.Height is zero.

type Style Uses

type Style struct {
    Foreground tcell.Color
    Background tcell.Color
    Attr       tcell.AttrMask
}

Style represents a text style.

func NewStyle Uses

func NewStyle(s tcell.Style) Style

NewStyle returns Style having values filled from s.

func (*Style) IsZero Uses

func (s *Style) IsZero() bool

IsZero returns whether s is the zero value of Style.

func (Style) TCellStyle Uses

func (s Style) TCellStyle() tcell.Style

TCellStyle converts a Style to a tcell.Style value.

type Theme Uses

type Theme struct {
    ChildWindow WindowStyle
    Desktop     WindowStyle
}

Theme represents visual styles of UI elements.

func (*Theme) Clear Uses

func (t *Theme) Clear()

Clear sets t to its zero value.

func (*Theme) ReadFrom Uses

func (t *Theme) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads t from r in JSON format. Values of fields having no JSON data are preserved.

func (*Theme) WriteTo Uses

func (t *Theme) WriteTo(w io.Writer) (int64, error)

WriteTo writes t to w in JSON format.

type Window Uses

type Window struct {
    // contains filtered or unexported fields
}

Window represents a rectangular area of a screen. A window can have borders on all of its sides and a title.

Window methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait.

func (*Window) Area Uses

func (w *Window) Area() Rectangle

Area returns the area of the window.

func (*Window) BeginUpdate Uses

func (w *Window) BeginUpdate()

BeginUpdate marks the start of one or more updates to w.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Window) BorderBottom Uses

func (w *Window) BorderBottom() int

BorderBottom returns the height of the bottom border.

func (*Window) BorderBottomArea Uses

func (w *Window) BorderBottomArea() (r Rectangle)

BorderBottomArea returns the area of the bottom border.

func (*Window) BorderLeft Uses

func (w *Window) BorderLeft() int

BorderLeft returns the width of the left border.

func (*Window) BorderLeftArea Uses

func (w *Window) BorderLeftArea() (r Rectangle)

BorderLeftArea returns the area of the left border.

func (*Window) BorderRight Uses

func (w *Window) BorderRight() int

BorderRight returns the width of the right border.

func (*Window) BorderRightArea Uses

func (w *Window) BorderRightArea() (r Rectangle)

BorderRightArea returns the area of the right border.

func (*Window) BorderStyle Uses

func (w *Window) BorderStyle() Style

BorderStyle returns the border style.

func (*Window) BorderTop Uses

func (w *Window) BorderTop() int

BorderTop returns the height of the top border.

func (*Window) BorderTopArea Uses

func (w *Window) BorderTopArea() (r Rectangle)

BorderTopArea returns the area of the top border.

func (*Window) BringToFront Uses

func (w *Window) BringToFront()

BringToFront puts a child window on top of all its siblings. The method has no effect if w is a root window.

func (*Window) Child Uses

func (w *Window) Child(n int) (r *Window)

Child returns the nth child window or nil if no such exists.

func (*Window) Children Uses

func (w *Window) Children() (r int)

Children returns the number of child windows.

func (*Window) ClientArea Uses

func (w *Window) ClientArea() Rectangle

ClientArea returns the client area.

func (*Window) ClientAreaStyle Uses

func (w *Window) ClientAreaStyle() Style

ClientAreaStyle returns the client area style.

func (*Window) ClientPosition Uses

func (w *Window) ClientPosition() Position

ClientPosition returns the position of the client area relative to w.

func (*Window) ClientSize Uses

func (w *Window) ClientSize() Size

ClientSize returns the size of the client area.

func (*Window) Close Uses

func (w *Window) Close()

Close closes w.

func (*Window) CloseButton Uses

func (w *Window) CloseButton() bool

CloseButton returns whether the window shows a close button.

func (*Window) Desktop Uses

func (w *Window) Desktop() *Desktop

Desktop returns which Desktop w appears on.

func (*Window) EndUpdate Uses

func (w *Window) EndUpdate()

EndUpdate marks the end of one or more updates to w.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Window) Focus Uses

func (w *Window) Focus() bool

Focus returns wheter the window is focused.

func (*Window) Invalidate Uses

func (w *Window) Invalidate(area Rectangle)

Invalidate marks a window area for repaint.

func (*Window) InvalidateClientArea Uses

func (w *Window) InvalidateClientArea(area Rectangle)

InvalidateClientArea marks an area of the client area for repaint.

func (*Window) NewChild Uses

func (w *Window) NewChild(area Rectangle) *Window

NewChild creates a child window.

func (*Window) OnClick Uses

func (w *Window) OnClick(h OnMouseHandler, finalize func())

OnClick sets a mouse click event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnClickBorder Uses

func (w *Window) OnClickBorder(h OnMouseHandler, finalize func())

OnClickBorder sets a mouse click border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnClose Uses

func (w *Window) OnClose(h OnCloseHandler, finalize func())

OnClose sets a window close event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDoubleClick Uses

func (w *Window) OnDoubleClick(h OnMouseHandler, finalize func())

OnDoubleClick sets a mouse double click event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDoubleClickBorder Uses

func (w *Window) OnDoubleClickBorder(h OnMouseHandler, finalize func())

OnDoubleClickBorder sets a mouse double click border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDrag Uses

func (w *Window) OnDrag(h OnMouseHandler, finalize func())

OnDrag sets a mouse drag event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDragBorder Uses

func (w *Window) OnDragBorder(h OnMouseHandler, finalize func())

OnDragBorder sets a mouse drag border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDrop Uses

func (w *Window) OnDrop(h OnMouseHandler, finalize func())

OnDrop sets a mouse drop event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnKey Uses

func (w *Window) OnKey(h OnKeyHandler, finalize func())

OnKey sets a key event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnMouseMove Uses

func (w *Window) OnMouseMove(h OnMouseHandler, finalize func())

OnMouseMove sets a mouse move event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnPaintBorderBottom Uses

func (w *Window) OnPaintBorderBottom(h OnPaintHandler, finalize func())

OnPaintBorderBottom sets a bottom border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderBottom(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	w := w.BorderBottomArea().Width
	for x := 0; x < w; x++ {
		var r rune
		switch x {
		case 0:
			r = tcell.RuneLLCorner
		case w - 1:
			r = tcell.RuneLRCorner
		default:
			r = tcell.RuneHLine
		}
		w.SetCell(x, 0, r, nil, style)
	}
}

...

w.OnPaintBorderBottom(onPaintBorderBottom, nil)
w.SetBorderBottom(1)

func (*Window) OnPaintBorderLeft Uses

func (w *Window) OnPaintBorderLeft(h OnPaintHandler, finalize func())

OnPaintBorderLeft sets a left border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderLeft(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	h := w.BorderLeftArea().Height
	for y := 0; y < h; y++ {
		var r rune
		switch y {
		case 0:
			r = tcell.RuneULCorner
		case h - 1:
			r = tcell.RuneLLCorner
		default:
			r = tcell.RuneVLine
		}
		w.SetCell(0, y, r, nil, style)
	}
}

...

w.OnPaintBorderLeft(onPaintBorderLeft, nil)
w.SetBorderLeft(1)

func (*Window) OnPaintBorderRight Uses

func (w *Window) OnPaintBorderRight(h OnPaintHandler, finalize func())

OnPaintBorderRight sets a right border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderRight(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	h := w.BorderRightArea().Height
	for y := 0; y < h; y++ {
		var r rune
		switch y {
		case 0:
			r = tcell.RuneURCorner
		case h - 1:
			r = tcell.RuneLRCorner
		default:
			r = tcell.RuneVLine
		}
		w.SetCell(0, y, r, nil, style)
	}
}

...

w.OnPaintBorderRight(onPaintBorderRight, nil)
w.SetBorderRight(1)

func (*Window) OnPaintBorderTop Uses

func (w *Window) OnPaintBorderTop(h OnPaintHandler, finalize func())

OnPaintBorderTop sets a top border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderTop(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	w := w.BorderTopArea().Width
	for x := 0; x < w; x++ {
		var r rune
		switch x {
		case 0:
			r = tcell.RuneULCorner
		case w - 1:
			r = tcell.RuneURCorner
		default:
			r = tcell.RuneHLine
		}
		w.SetCell(x, 0, r, nil, style)
	}
}

...

w.OnPaintBorderTop(onPaintBorderTop, nil)
w.SetBorderTop(1)

func (*Window) OnPaintClientArea Uses

func (w *Window) OnPaintClientArea(h OnPaintHandler, finalize func())

OnPaintClientArea sets a client area paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintClientArea(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	w.Printf(0, 0, w.Style(), "Hello 世界!\nTime: %s", time.Now())
}

...

w.OnPaintClientArea(onPaintClientArea, nil)

func (*Window) OnPaintTitle Uses

func (w *Window) OnPaintTitle(h OnPaintHandler, finalize func())

OnPaintTitle sets a window title paint handler. When the event handler is removed, finalize is called, if not nil. Example:

if s := w.Title(); s != "" {
	w.Printf(0, 0, w.Style().Title, " %s ", s)
}

func (*Window) OnSetBorderBottom Uses

func (w *Window) OnSetBorderBottom(h OnSetIntHandler, finalize func())

OnSetBorderBottom sets a handler invoked on SetBorderBottom. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderLeft Uses

func (w *Window) OnSetBorderLeft(h OnSetIntHandler, finalize func())

OnSetBorderLeft sets a handler invoked on SetBorderLeft. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderRight Uses

func (w *Window) OnSetBorderRight(h OnSetIntHandler, finalize func())

OnSetBorderRight sets a handler invoked on SetBorderRight. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderStyle Uses

func (w *Window) OnSetBorderStyle(h OnSetStyleHandler, finalize func())

OnSetBorderStyle sets a handler invoked on SetBorderStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderTop Uses

func (w *Window) OnSetBorderTop(h OnSetIntHandler, finalize func())

OnSetBorderTop sets a handler invoked on SetBorderTop. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetClientAreaStyle Uses

func (w *Window) OnSetClientAreaStyle(h OnSetStyleHandler, finalize func())

OnSetClientAreaStyle sets a handler invoked on SetClientAreaStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetClientSize Uses

func (w *Window) OnSetClientSize(h OnSetSizeHandler, finalize func())

OnSetClientSize sets a handler invoked on SetClientSize. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetCloseButton Uses

func (w *Window) OnSetCloseButton(h OnSetBoolHandler, finalize func())

OnSetCloseButton sets a handler invoked on SetCloseButton. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetFocus Uses

func (w *Window) OnSetFocus(h OnSetBoolHandler, finalize func())

OnSetFocus sets a handler invoked on SetFocus. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetOrigin Uses

func (w *Window) OnSetOrigin(h OnSetPositionHandler, finalize func())

OnSetOrigin sets a handler invoked on SetOrigin. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetPosition Uses

func (w *Window) OnSetPosition(h OnSetPositionHandler, finalize func())

OnSetPosition sets a handler invoked on SetPosition. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetSize Uses

func (w *Window) OnSetSize(h OnSetSizeHandler, finalize func())

OnSetSize sets a handler invoked on SetSize. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetStyle Uses

func (w *Window) OnSetStyle(h OnSetWindowStyleHandler, finalize func())

OnSetStyle sets a handler invoked on SetStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetTitle Uses

func (w *Window) OnSetTitle(h OnSetStringHandler, finalize func())

OnSetTitle sets a handler invoked on SetTitle. When the event handler is removed, finalize is called, if not nil.

func (*Window) Origin Uses

func (w *Window) Origin() Position

Origin returns the window's origin..

func (*Window) Parent Uses

func (w *Window) Parent() *Window

Parent returns the window's parent. Root windows have nil parent.

func (*Window) Position Uses

func (w *Window) Position() Position

Position returns the window position relative to its parent.

func (*Window) Printf Uses

func (w *Window) Printf(x, y int, style Style, format string, arg ...interface{})

Printf prints format with arguments at x, y. Calling this method outside of an OnPaint handler is ignored.

Special handling:

'\t'	x, y = x + 8 - x%8, y
'\n'	x, y = 0, y+1
'\r'	x, y = 0, y

func (*Window) RemoveOnClick Uses

func (w *Window) RemoveOnClick()

RemoveOnClick undoes the most recent OnClick call. The function will panic if there is no handler set.

func (*Window) RemoveOnClickBorder Uses

func (w *Window) RemoveOnClickBorder()

RemoveOnClickBorder undoes the most recent OnClickBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnClose Uses

func (w *Window) RemoveOnClose()

RemoveOnClose undoes the most recent OnClose call. The function will panic if there is no handler set.

func (*Window) RemoveOnDoubleClick Uses

func (w *Window) RemoveOnDoubleClick()

RemoveOnDoubleClick undoes the most recent OnDoubleClick call. The function will panic if there is no handler set.

func (*Window) RemoveOnDoubleClickBorder Uses

func (w *Window) RemoveOnDoubleClickBorder()

RemoveOnDoubleClickBorder undoes the most recent OnDoubleClickBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnDrag Uses

func (w *Window) RemoveOnDrag()

RemoveOnDrag undoes the most recent OnDrag call. The function will panic if there is no handler set.

func (*Window) RemoveOnDragBorder Uses

func (w *Window) RemoveOnDragBorder()

RemoveOnDragBorder undoes the most recent OnDragBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnDrop Uses

func (w *Window) RemoveOnDrop()

RemoveOnDrop undoes the most recent OnDrop call. The function will panic if there is no handler set.

func (*Window) RemoveOnKey Uses

func (w *Window) RemoveOnKey()

RemoveOnKey undoes the most recent OnKey call. The function will panic if there is no handler set.

func (*Window) RemoveOnMouseMove Uses

func (w *Window) RemoveOnMouseMove()

RemoveOnMouseMove undoes the most recent OnMouseMove call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderBottom Uses

func (w *Window) RemoveOnPaintBorderBottom()

RemoveOnPaintBorderBottom undoes the most recent OnPaintBorderBottom call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderLeft Uses

func (w *Window) RemoveOnPaintBorderLeft()

RemoveOnPaintBorderLeft undoes the most recent OnPaintBorderLeft call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderRight Uses

func (w *Window) RemoveOnPaintBorderRight()

RemoveOnPaintBorderRight undoes the most recent OnPaintBorderRight call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderTop Uses

func (w *Window) RemoveOnPaintBorderTop()

RemoveOnPaintBorderTop undoes the most recent OnPaintBorderTop call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintClientArea Uses

func (w *Window) RemoveOnPaintClientArea()

RemoveOnPaintClientArea undoes the most recent OnPaintClientArea call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintTitle Uses

func (w *Window) RemoveOnPaintTitle()

RemoveOnPaintTitle undoes the most recent OnPaintTitle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderBottom Uses

func (w *Window) RemoveOnSetBorderBottom()

RemoveOnSetBorderBottom undoes the most recent OnSetBorderBottom call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderLeft Uses

func (w *Window) RemoveOnSetBorderLeft()

RemoveOnSetBorderLeft undoes the most recent OnSetBorderLeft call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderRight Uses

func (w *Window) RemoveOnSetBorderRight()

RemoveOnSetBorderRight undoes the most recent OnSetBorderRight call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderStyle Uses

func (w *Window) RemoveOnSetBorderStyle()

RemoveOnSetBorderStyle undoes the most recent OnSetBorderStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderTop Uses

func (w *Window) RemoveOnSetBorderTop()

RemoveOnSetBorderTop undoes the most recent OnSetBorderTop call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetClientAreaStyle Uses

func (w *Window) RemoveOnSetClientAreaStyle()

RemoveOnSetClientAreaStyle undoes the most recent OnSetClientAreaStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetClientSize Uses

func (w *Window) RemoveOnSetClientSize()

RemoveOnSetClientSize undoes the most recent OnSetClientSize call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetCloseButton Uses

func (w *Window) RemoveOnSetCloseButton()

RemoveOnSetCloseButton undoes the most recent OnSetCloseButton call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetFocus Uses

func (w *Window) RemoveOnSetFocus()

RemoveOnSetFocus undoes the most recent OnSetFocus call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetOrigin Uses

func (w *Window) RemoveOnSetOrigin()

RemoveOnSetOrigin undoes the most recent OnSetOrigin call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetPosition Uses

func (w *Window) RemoveOnSetPosition()

RemoveOnSetPosition undoes the most recent OnSetPosition call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetSize Uses

func (w *Window) RemoveOnSetSize()

RemoveOnSetSize undoes the most recent OnSetSize call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetStyle Uses

func (w *Window) RemoveOnSetStyle()

RemoveOnSetStyle undoes the most recent OnSetStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetTitle Uses

func (w *Window) RemoveOnSetTitle()

RemoveOnSetTitle undoes the most recent OnSetTitle call. The function will panic if there is no handler set.

func (*Window) Rendered Uses

func (w *Window) Rendered() time.Duration

Rendered returns how long the last desktop rendering took. Valid only for desktop's root window.

func (*Window) SetBorderBottom Uses

func (w *Window) SetBorderBottom(v int)

SetBorderBottom sets the height of the bottom border.

func (*Window) SetBorderLeft Uses

func (w *Window) SetBorderLeft(v int)

SetBorderLeft sets the width of the left border.

func (*Window) SetBorderRight Uses

func (w *Window) SetBorderRight(v int)

SetBorderRight sets the width of the right border.

func (*Window) SetBorderStyle Uses

func (w *Window) SetBorderStyle(s Style)

SetBorderStyle sets the border style.

func (*Window) SetBorderTop Uses

func (w *Window) SetBorderTop(v int)

SetBorderTop sets the height of the top border.

func (*Window) SetCell Uses

func (w *Window) SetCell(x, y int, mainc rune, combc []rune, style tcell.Style)

SetCell renders a single character cell. Calling this method outside of an OnPaint* handler is ignored.

func (*Window) SetClientAreaStyle Uses

func (w *Window) SetClientAreaStyle(s Style)

SetClientAreaStyle sets the client area style.

func (*Window) SetClientSize Uses

func (w *Window) SetClientSize(s Size)

SetClientSize sets the size of the client area.

func (*Window) SetCloseButton Uses

func (w *Window) SetCloseButton(v bool)

SetCloseButton sets whether the window shows a close button.

func (*Window) SetFocus Uses

func (w *Window) SetFocus(v bool)

SetFocus sets whether the window is focused.

func (*Window) SetOrigin Uses

func (w *Window) SetOrigin(p Position)

SetOrigin sets the origin of the window. By default the origin of a window is (0, 0). When a paint handler is invoked the window's origin is subtracted from the coordinates the handler paints to. Also, the PaintContext.Rectangle value passed to the handler is adjusted accordingly.

Setting origin other than (0, 0) provides a view into the content created by the respective paint handlers. The mechanism aids in displaying scrolling content.

Negative values of p.X or p.Y are ignored.

func (*Window) SetPosition Uses

func (w *Window) SetPosition(p Position)

SetPosition sets the window position relative to its parent.

func (*Window) SetSize Uses

func (w *Window) SetSize(s Size)

SetSize sets the window size.

func (*Window) SetStyle Uses

func (w *Window) SetStyle(s WindowStyle)

SetStyle sets the window style.

func (*Window) SetTitle Uses

func (w *Window) SetTitle(s string)

SetTitle sets the window title.

func (*Window) Size Uses

func (w *Window) Size() Size

Size returns the window size.

func (*Window) Style Uses

func (w *Window) Style() WindowStyle

Style returns the window style.

func (*Window) Title Uses

func (w *Window) Title() string

Title returns the window title.

type WindowStyle Uses

type WindowStyle struct {
    Border     Style
    ClientArea Style
    Title      Style
}

WindowStyle represents visual styles of a Window.

Directories

PathSynopsis
tkPackage tk is a wm[0] toolkit.

Package wm imports 12 packages (graph) and is imported by 2 packages. Updated 2018-12-20. Refresh now. Tools for package owners.