tui

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2017 License: MIT Imports: 8 Imported by: 0

README

tui: Terminal UI for Go

Build Status GoDoc Go Report Card License MIT stability-unstable

A UI library for terminal applications.

tui (pronounced tooey) provides a higher-level programming model for building rich terminal applications. It lets you build layout-based user interfaces that (should) gracefully handle resizing for you.

Screenshot

Installation

go get github.com/marcusolsson/tui-go

Usage

package main

import "github.com/marcusolsson/tui-go"

func main() {
	box := tui.NewVBox(
		tui.NewLabel("tui-go"),
	)

	ui := tui.New(box)
	ui.SetKeybinding("Esc", func() { ui.Quit() })

	if err := ui.Run(); err != nil {
		panic(err)
	}
}

If you want to know what it is like to build terminal applications with tui-go, check out some of the examples.

Documentation

The documentation is rather bare at the moment due to the API changing pretty frequently. You can however explore the API in its current form at godoc.org.

For now, the best way to learn tui-go is to study and learn from the examples.

Contributing

If you're using tui-go for your application, please let me know what works well for you, and especially what doesn't (bug reports are greatly appreciated!).

Pull requests are very much welcome! Check out the current issues to find out how you can help. If you do find anything interesting, please assign yourself to that issue so that others know you're working on it. If you want to contribute a feature not currently not listed, please create a new issue with a description of what you want to do.

Please post any feature requests you might have. Smaller requests might end up being implemented rather quickly and larger ones will be considered for the road map.

Contributors

tui-go is mainly influenced by Qt and offers a similar programming model that has been adapted to Go and the terminal.

For an overview of the alternatives for writing terminal user interfaces, check out this article by AppliedGo.

License

tui-go is released under the MIT License.

Documentation

Overview

Package tui is a library for building user interfaces for the terminal.

Widgets

Widgets are the main building blocks of any user interface. They allow us to present information and interact with our application. It receives keyboard and mouse events from the terminal and draws a representation of itself.

lbl := tui.NewLabel("Hello, World!")

Layouts

Widgets are structured using layouts. Layouts are powerful tools that let you position your widgets without having to specify their exact coordinates.

box := tui.NewVBox(
	tui.NewLabel("Press the button to continue ..."),
	tui.NewButton("Continue"),
)

Here, the VBox will ensure that the Button will be placed underneath the Label. There are currently three layouts to choose from; VBox, HBox and Grid.

Size policies

Sizing of widgets is controlled by its SizePolicy. For now, you can read more about how size policies work in the Qt docs:

http://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum

Index

Constants

View Source
const (
	KeyBackspace  = KeyBS
	KeyTab        = KeyTAB
	KeyEsc        = KeyESC
	KeyEscape     = KeyESC
	KeyEnter      = KeyCR
	KeyBackspace2 = KeyDEL
)

These are aliases for other keys.

Variables

View Source
var DefaultFocusChain = &SimpleFocusChain{
	widgets: make([]Widget, 0),
}

DefaultFocusChain is the default focus chain.

View Source
var DefaultTheme = &Theme{
	styles: map[string]Style{
		"list.item.selected":  {Reverse: true},
		"table.cell.selected": {Reverse: true},
		"button.focused":      {Reverse: true},
		"box.focused":         {Reverse: true},
	},
}

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment is used to set the direction in which widgets are laid out.

const (
	Horizontal Alignment = iota
	Vertical
)

Available alignment options.

type Box

type Box struct {
	WidgetBase
	// contains filtered or unexported fields
}

Box is a layout for placing widgets either horizontally or vertically. If horizontally, all widgets will have the same height. If vertically, they will all have the same width.

func NewHBox

func NewHBox(c ...Widget) *Box

NewHBox returns a new horizontally aligned Box.

func NewVBox

func NewVBox(c ...Widget) *Box

NewVBox returns a new vertically aligned Box.

func (*Box) Alignment

func (b *Box) Alignment() Alignment

Alignment returns the current alignment of the Box.

func (*Box) Append

func (b *Box) Append(w Widget)

Append adds the given widget at the end of the Box.

func (*Box) Draw

func (b *Box) Draw(p *Painter)

Draw recursively draws the widgets it contains.

func (*Box) Insert added in v0.2.0

func (b *Box) Insert(i int, w Widget)

Insert adds the widget into the Box at a given index.

func (*Box) IsFocused

func (b *Box) IsFocused() bool

IsFocused return true if one of the children is focused.

func (*Box) MinSizeHint

func (b *Box) MinSizeHint() image.Point

MinSizeHint returns the minimum size hint for the layout.

func (*Box) OnKeyEvent

func (b *Box) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles an event and propagates it to all children.

func (*Box) Prepend added in v0.2.0

func (b *Box) Prepend(w Widget)

Prepend adds the given widget at the start of the Box.

func (*Box) Resize

func (b *Box) Resize(size image.Point)

Resize recursively updates the size of the Box and all the widgets it contains. This is a potentially expensive operation and should be invoked with restraint.

Resize is called by the layout engine and is not intended to be used by end users.

func (*Box) SetBorder

func (b *Box) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

func (*Box) SetTitle

func (b *Box) SetTitle(title string)

SetTitle sets the title of the box.

func (*Box) SizeHint

func (b *Box) SizeHint() image.Point

SizeHint returns the recommended size hint for the layout.

type Button

type Button struct {
	WidgetBase
	// contains filtered or unexported fields
}

Button is a widget that can be activated to perform some action, or to answer a question.

func NewButton

func NewButton(text string) *Button

NewButton returns a new Button with the given text as the label.

func (*Button) Draw

func (b *Button) Draw(p *Painter)

Draw draws the button.

func (*Button) OnActivated

func (b *Button) OnActivated(fn func(b *Button))

OnActivated allows a custom function to be run whenever the button is activated.

func (*Button) OnKeyEvent

func (b *Button) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles keys events.

func (*Button) SizeHint

func (b *Button) SizeHint() image.Point

SizeHint returns the recommended size hint for the button.

type Color

type Color int
const (
	ColorDefault Color = iota
	ColorBlack
	ColorWhite
	ColorRed
	ColorGreen
	ColorBlue
	ColorCyan
	ColorMagenta
	ColorYellow
)

type Entry

type Entry struct {
	WidgetBase
	// contains filtered or unexported fields
}

Entry is a one-line text editor. It lets the user supply the application with text, e.g., to input user and password information.

func NewEntry

func NewEntry() *Entry

NewEntry returns a new Entry.

func (*Entry) Draw

func (e *Entry) Draw(p *Painter)

Draw draws the entry.

func (*Entry) OnChanged

func (e *Entry) OnChanged(fn func(entry *Entry))

OnChanged sets a function to be run whenever the content of the entry has been changed.

func (*Entry) OnKeyEvent

func (e *Entry) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*Entry) OnSubmit

func (e *Entry) OnSubmit(fn func(entry *Entry))

OnSubmit sets a function to be run whenever the user submits the entry (by pressing KeyEnter).

func (*Entry) SetText

func (e *Entry) SetText(text string)

SetText sets the text content of the entry.

func (*Entry) SizeHint

func (e *Entry) SizeHint() image.Point

SizeHint returns the recommended size hint for the entry.

func (*Entry) Text

func (e *Entry) Text() string

Text returns the text content of the entry.

type FocusChain

type FocusChain interface {
	FocusNext(w Widget) Widget
	FocusPrev(w Widget) Widget
	FocusDefault() Widget
}

FocusChain enables custom focus traversal when Tab or Backtab is pressed.

type Grid

type Grid struct {
	WidgetBase
	// contains filtered or unexported fields
}

Grid is a widget that lays out widgets in a grid.

func NewGrid

func NewGrid(cols, rows int) *Grid

NewGrid returns a new Grid.

func (*Grid) AppendRow

func (g *Grid) AppendRow(row ...Widget)

AppendRow adds a new row at the end.

func (*Grid) Draw

func (g *Grid) Draw(p *Painter)

Draw draws the grid.

func (*Grid) MinSizeHint

func (g *Grid) MinSizeHint() image.Point

MinSizeHint returns the minimum size hint for the grid.

func (*Grid) OnKeyEvent

func (g *Grid) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*Grid) Resize

func (g *Grid) Resize(size image.Point)

Resize recursively updates the size of the Grid and all the widgets it contains. This is a potentially expensive operation and should be invoked with restraint.

Resize is called by the layout engine and is not intended to be used by end users.

func (*Grid) SetBorder

func (g *Grid) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

func (*Grid) SetCell

func (g *Grid) SetCell(pos image.Point, w Widget)

SetCell sets or replaces the contents of a cell.

func (*Grid) SetColumnStretch

func (g *Grid) SetColumnStretch(col, stretch int)

SetColumnStretch sets the stretch factor for a given column. If stretch > 0, the column will expand to fill up available space. If multiple columns have a stretch factor > 0, stretch determines how much space the column get in respect to the others. E.g. by setting SetColumnStretch(0, 1) and SetColumnStretch(1, 2), the second column will fill up twice as much space as the first one.

func (*Grid) SetRowStretch

func (g *Grid) SetRowStretch(row, stretch int)

SetRowStretch sets the stretch factor for a given row. For more on stretch factors, see SetColumnStretch.

func (*Grid) SizeHint

func (g *Grid) SizeHint() image.Point

SizeHint returns the recommended size hint for the grid.

type Key

type Key int16

Key represents both normal and special keys. For normal letters, KeyRune is used together with the Rune field in the KeyEvent.

const (
	KeyRune Key = iota + 256
	KeyUp
	KeyDown
	KeyRight
	KeyLeft
	KeyUpLeft
	KeyUpRight
	KeyDownLeft
	KeyDownRight
	KeyCenter
	KeyPgUp
	KeyPgDn
	KeyHome
	KeyEnd
	KeyInsert
	KeyDelete
	KeyHelp
	KeyExit
	KeyClear
	KeyCancel
	KeyPrint
	KeyPause
	KeyBacktab
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyF13
	KeyF14
	KeyF15
	KeyF16
	KeyF17
	KeyF18
	KeyF19
	KeyF20
	KeyF21
	KeyF22
	KeyF23
	KeyF24
	KeyF25
	KeyF26
	KeyF27
	KeyF28
	KeyF29
	KeyF30
	KeyF31
	KeyF32
	KeyF33
	KeyF34
	KeyF35
	KeyF36
	KeyF37
	KeyF38
	KeyF39
	KeyF40
	KeyF41
	KeyF42
	KeyF43
	KeyF44
	KeyF45
	KeyF46
	KeyF47
	KeyF48
	KeyF49
	KeyF50
	KeyF51
	KeyF52
	KeyF53
	KeyF54
	KeyF55
	KeyF56
	KeyF57
	KeyF58
	KeyF59
	KeyF60
	KeyF61
	KeyF62
	KeyF63
	KeyF64
)

These are named keys that can be handled.

const (
	KeyCtrlSpace Key = iota
	KeyCtrlA
	KeyCtrlB
	KeyCtrlC
	KeyCtrlD
	KeyCtrlE
	KeyCtrlF
	KeyCtrlG
	KeyCtrlH
	KeyCtrlI
	KeyCtrlJ
	KeyCtrlK
	KeyCtrlL
	KeyCtrlM
	KeyCtrlN
	KeyCtrlO
	KeyCtrlP
	KeyCtrlQ
	KeyCtrlR
	KeyCtrlS
	KeyCtrlT
	KeyCtrlU
	KeyCtrlV
	KeyCtrlW
	KeyCtrlX
	KeyCtrlY
	KeyCtrlZ
	KeyCtrlLeftSq // Escape
	KeyCtrlBackslash
	KeyCtrlRightSq
	KeyCtrlCarat
	KeyCtrlUnderscore
)

These are the supported control keys.

const (
	KeyNUL Key = iota
	KeySOH
	KeySTX
	KeyETX
	KeyEOT
	KeyENQ
	KeyACK
	KeyBEL
	KeyBS
	KeyTAB
	KeyLF
	KeyVT
	KeyFF
	KeyCR
	KeySO
	KeySI
	KeyDLE
	KeyDC1
	KeyDC2
	KeyDC3
	KeyDC4
	KeyNAK
	KeySYN
	KeyETB
	KeyCAN
	KeyEM
	KeySUB
	KeyESC
	KeyFS
	KeyGS
	KeyRS
	KeyUS
	KeyDEL Key = 0x7F
)

These are the defined ASCII values for key codes.

type KeyEvent

type KeyEvent struct {
	Key       Key
	Rune      rune
	Modifiers ModMask
}

KeyEvent represents a key press.

func (*KeyEvent) Name

func (ev *KeyEvent) Name() string

Name returns a user-friendly description of the key press.

type Label

type Label struct {
	WidgetBase
	// contains filtered or unexported fields
}

Label is a widget to display read-only text.

func NewLabel

func NewLabel(text string) *Label

NewLabel returns a new Label.

func (*Label) Draw

func (l *Label) Draw(p *Painter)

Draw draws the label.

func (*Label) MinSizeHint

func (l *Label) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Label) SetStyleName

func (l *Label) SetStyleName(style string)

func (*Label) SetText

func (l *Label) SetText(text string)

SetText sets the text content of the label.

func (*Label) SetWordWrap

func (l *Label) SetWordWrap(enabled bool)

SetWordWrap sets whether text content should be wrapped.

func (*Label) SizeHint

func (l *Label) SizeHint() image.Point

SizeHint returns the recommended size for the label.

type List

type List struct {
	WidgetBase
	// contains filtered or unexported fields
}

List is a widget for displaying and selecting items.

func NewList

func NewList() *List

NewList returns a new List with no selection.

func (*List) AddItems

func (l *List) AddItems(items ...string)

func (*List) Draw

func (l *List) Draw(p *Painter)

Draw draws the list.

func (*List) Length

func (l *List) Length() int

func (*List) OnItemActivated

func (l *List) OnItemActivated(fn func(*List))

func (*List) OnKeyEvent

func (l *List) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles terminal events.

func (*List) OnSelectionChanged

func (l *List) OnSelectionChanged(fn func(*List))

func (*List) RemoveItem

func (l *List) RemoveItem(i int)

func (*List) RemoveItems

func (l *List) RemoveItems()

func (*List) Select

func (l *List) Select(i int)

Select calls SetSelected and the OnSelectionChanged function.

func (*List) Selected

func (l *List) Selected() int

func (*List) SelectedItem

func (l *List) SelectedItem() string

func (*List) SetSelected

func (l *List) SetSelected(i int)

func (*List) SizeHint

func (l *List) SizeHint() image.Point

SizeHint returns the recommended size for the list.

type ModMask

type ModMask int16

ModMask is a mask of modifier keys.

const (
	ModShift ModMask = 1 << iota
	ModCtrl
	ModAlt
	ModMeta
	ModNone ModMask = 0
)

Modifiers that can be sent with a KeyEvent or a MouseEvent.

type MouseEvent

type MouseEvent struct {
	Pos image.Point
}

MouseEvent represents the event where a mouse button was pressed or released.

type Padder

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

Padder is a widget to fill out space.

func NewPadder

func NewPadder(x, y int, w Widget) *Padder

NewPadder returns a new Padder.

func (*Padder) Draw

func (p *Padder) Draw(painter *Painter)

Draw draws the padded widget.

func (*Padder) IsFocused

func (p *Padder) IsFocused() bool

IsFocused returns true if the widget is focused.

func (*Padder) MinSizeHint

func (p *Padder) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Padder) OnKeyEvent

func (p *Padder) OnKeyEvent(ev KeyEvent)

func (*Padder) Resize

func (p *Padder) Resize(size image.Point)

Resize updates the size of the padded widget.

func (*Padder) SetFocused

func (p *Padder) SetFocused(f bool)

SetFocused set the focus on the widget.

func (*Padder) Size

func (p *Padder) Size() image.Point

Size returns the size of the padded widget.

func (*Padder) SizeHint

func (p *Padder) SizeHint() image.Point

SizeHint returns the recommended size for the padded widget.

func (*Padder) SizePolicy

func (p *Padder) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type Painter

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

Painter provides operations to paint on a surface.

func NewPainter

func NewPainter(s Surface, p *Theme) *Painter

NewPainter returns a new instance of Painter.

func (*Painter) Begin

func (p *Painter) Begin()

Begin prepares the surface for painting.

func (*Painter) DrawCursor

func (p *Painter) DrawCursor(x, y int)

func (*Painter) DrawHorizontalLine

func (p *Painter) DrawHorizontalLine(x1, x2, y int)

func (*Painter) DrawRect

func (p *Painter) DrawRect(x, y, w, h int)

DrawRect paints a rectangle.

func (*Painter) DrawRune

func (p *Painter) DrawRune(x, y int, r rune)

DrawRune paints a rune at the given coordinate.

func (*Painter) DrawText

func (p *Painter) DrawText(x, y int, text string)

DrawText paints a string starting at the given coordinate.

func (*Painter) DrawVerticalLine

func (p *Painter) DrawVerticalLine(x, y1, y2 int)

func (*Painter) End

func (p *Painter) End()

End finalizes any painting that has been made.

func (*Painter) FillRect

func (p *Painter) FillRect(x, y, w, h int)

func (*Painter) Repaint

func (p *Painter) Repaint(w Widget)

Repaint clears the surface, draws the scene and flushes it.

func (*Painter) Restore

func (p *Painter) Restore()

Restore pops the latest transform from the stack.

func (*Painter) RestoreStyle

func (p *Painter) RestoreStyle()

func (*Painter) SetStyle

func (p *Painter) SetStyle(s Style)

func (*Painter) Translate

func (p *Painter) Translate(x, y int)

Translate pushes a new translation transform to the stack.

func (*Painter) WithMask

func (p *Painter) WithMask(r image.Rectangle, fn func(*Painter))

func (*Painter) WithStyle

func (p *Painter) WithStyle(n string, fn func(*Painter))

type Progress

type Progress struct {
	WidgetBase
	// contains filtered or unexported fields
}

Progress is a widget to display a progress bar.

func NewProgress

func NewProgress(max int) *Progress

NewProgress returns a new Progress.

func (*Progress) Draw

func (p *Progress) Draw(painter *Painter)

Draw draws the progress bar.

func (*Progress) MinSizeHint

func (p *Progress) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Progress) SetCurrent

func (p *Progress) SetCurrent(c int)

func (*Progress) SetMax

func (p *Progress) SetMax(m int)

func (*Progress) SizeHint

func (p *Progress) SizeHint() image.Point

SizeHint returns the recommended size for the progress bar.

type SimpleFocusChain

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

SimpleFocusChain represents a ring of widgets where focus is loops to the first widget when it reaches the end.

func (*SimpleFocusChain) FocusDefault

func (c *SimpleFocusChain) FocusDefault() Widget

FocusDefault returns the default widget for when there is no widget currently focused.

func (*SimpleFocusChain) FocusNext

func (c *SimpleFocusChain) FocusNext(current Widget) Widget

FocusNext returns the widget in the ring that is after the given widget.

func (*SimpleFocusChain) FocusPrev

func (c *SimpleFocusChain) FocusPrev(current Widget) Widget

FocusPrev returns the widget in the ring that is before the given widget.

func (*SimpleFocusChain) Set

func (c *SimpleFocusChain) Set(ws ...Widget)

Set sets the widgets in the focus chain. Widgets will received focus in the order widgets were passed.

type SizePolicy

type SizePolicy int
const (
	Preferred SizePolicy = iota
	Minimum
	Maximum
	Expanding
)

type Spacer

type Spacer struct {
	WidgetBase
}

Spacer is a widget to fill out space.

func NewSpacer

func NewSpacer() *Spacer

NewSpacer returns a new Spacer.

func (*Spacer) MinSizeHint

func (s *Spacer) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Spacer) SizeHint

func (s *Spacer) SizeHint() image.Point

SizeHint returns the recommended size for the spacer.

func (*Spacer) SizePolicy

func (s *Spacer) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type StatusBar

type StatusBar struct {
	WidgetBase
	// contains filtered or unexported fields
}

StatusBar is a widget to display status information.

func NewStatusBar

func NewStatusBar(text string) *StatusBar

NewStatusBar returns a new StatusBar.

func (*StatusBar) Draw

func (b *StatusBar) Draw(p *Painter)

Draw draws the status bar.

func (*StatusBar) SetPermanentText

func (b *StatusBar) SetPermanentText(text string)

func (*StatusBar) SetText

func (b *StatusBar) SetText(text string)

func (*StatusBar) SizeHint

func (b *StatusBar) SizeHint() image.Point

SizeHint returns the recommended size for the status bar.

func (*StatusBar) SizePolicy

func (b *StatusBar) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type Style

type Style struct {
	Fg      Color
	Bg      Color
	Reverse bool

	Bold      bool
	Underline bool
}

type Surface

type Surface interface {
	SetCell(x, y int, ch rune, s Style)
	SetCursor(x, y int)
	HideCursor()
	Begin()
	End()
	Size() image.Point
}

Surface defines a surface that can be painted on.

type Table

type Table struct {
	*Grid
	// contains filtered or unexported fields
}

Table is a widget that lays out widgets in a table.

func NewTable

func NewTable(cols, rows int) *Table

NewTable returns a new Table.

func (*Table) Draw

func (t *Table) Draw(p *Painter)

Draw draws the table.

func (*Table) OnItemActivated

func (t *Table) OnItemActivated(fn func(*Table))

OnItemActivated sets the function that is called when an item was activated.

func (*Table) OnKeyEvent

func (t *Table) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles an event and propagates it to all children.

func (*Table) OnSelectionChanged

func (t *Table) OnSelectionChanged(fn func(*Table))

OnSelectionChanged sets the function that is called when an item was selected.

func (*Table) Select

func (t *Table) Select(i int)

Select calls SetSelected and the OnSelectionChanged function.

func (*Table) Selected

func (t *Table) Selected() int

Selected returns the index of the currently selected item.

func (*Table) SetSelected

func (t *Table) SetSelected(i int)

SetSelected changes the currently selected item.

type TextEdit

type TextEdit struct {
	WidgetBase
	// contains filtered or unexported fields
}

TextEdit is a multi-line text editor.

func NewTextEdit

func NewTextEdit() *TextEdit

NewTextEdit returns a new TextEdit.

func (*TextEdit) Draw

func (e *TextEdit) Draw(p *Painter)

Draw draws the entry.

func (*TextEdit) OnKeyEvent

func (e *TextEdit) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles terminal events.

func (*TextEdit) OnTextChanged

func (e *TextEdit) OnTextChanged(fn func(entry *TextEdit))

OnTextChanged sets a function to be run whenever the text content of the widget has been changed.

func (*TextEdit) SetText

func (e *TextEdit) SetText(text string)

SetText sets the text content of the entry.

func (*TextEdit) SizeHint

func (e *TextEdit) SizeHint() image.Point

SizeHint returns the recommended size for the entry.

func (*TextEdit) Text

func (e *TextEdit) Text() string

Text returns the text content of the entry.

type Theme

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

func NewTheme

func NewTheme() *Theme

func (*Theme) HasStyle

func (p *Theme) HasStyle(name string) bool

func (*Theme) SetStyle

func (p *Theme) SetStyle(n string, i Style)

func (*Theme) Style

func (p *Theme) Style(name string) Style

type UI

type UI interface {
	SetWidget(w Widget)
	SetTheme(p *Theme)
	SetKeybinding(seq string, fn func())
	SetFocusChain(ch FocusChain)
	Run() error
	Update(fn func())
	Quit()
}

func New

func New(root Widget) UI

type Widget

type Widget interface {
	Draw(p *Painter)
	MinSizeHint() image.Point
	Size() image.Point
	SizeHint() image.Point
	SizePolicy() (SizePolicy, SizePolicy)
	Resize(size image.Point)
	OnKeyEvent(ev KeyEvent)
	SetFocused(bool)
	IsFocused() bool
}

Widget defines common operations on widgets.

type WidgetBase

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

func (*WidgetBase) Draw

func (w *WidgetBase) Draw(p *Painter)

func (*WidgetBase) IsFocused

func (w *WidgetBase) IsFocused() bool

func (*WidgetBase) MinSizeHint

func (w *WidgetBase) MinSizeHint() image.Point

func (*WidgetBase) OnKeyEvent

func (w *WidgetBase) OnKeyEvent(ev KeyEvent)

func (*WidgetBase) Resize

func (w *WidgetBase) Resize(size image.Point)

func (*WidgetBase) SetFocused

func (w *WidgetBase) SetFocused(f bool)

func (*WidgetBase) SetSizePolicy

func (w *WidgetBase) SetSizePolicy(h, v SizePolicy)

func (*WidgetBase) Size

func (w *WidgetBase) Size() image.Point

func (*WidgetBase) SizeHint

func (w *WidgetBase) SizeHint() image.Point

func (*WidgetBase) SizePolicy

func (w *WidgetBase) SizePolicy() (SizePolicy, SizePolicy)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL