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:
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- type Alignment
- type Box
- func (b *Box) Alignment() Alignment
- func (b *Box) Append(w Widget)
- func (b *Box) Draw(p *Painter)
- func (b *Box) Insert(i int, w Widget)
- func (b *Box) IsFocused() bool
- func (b *Box) Length() int
- func (b *Box) MinSizeHint() image.Point
- func (b *Box) OnKeyEvent(ev KeyEvent)
- func (b *Box) Prepend(w Widget)
- func (b *Box) Remove(i int)
- func (b *Box) Resize(size image.Point)
- func (b *Box) SetBorder(enabled bool)
- func (b *Box) SetTitle(title string)
- func (b *Box) SizeHint() image.Point
- type Button
- type Color
- type Decoration
- type EchoMode
- type Entry
- func (e *Entry) Draw(p *Painter)
- func (e *Entry) OnChanged(fn func(entry *Entry))
- func (e *Entry) OnKeyEvent(ev KeyEvent)
- func (e *Entry) OnSubmit(fn func(entry *Entry))
- func (e *Entry) SetEchoMode(m EchoMode)
- func (e *Entry) SetText(text string)
- func (e *Entry) SizeHint() image.Point
- func (e *Entry) Text() string
- type FocusChain
- type Grid
- func (g *Grid) AppendRow(row ...Widget)
- func (g *Grid) Draw(p *Painter)
- func (g *Grid) MinSizeHint() image.Point
- func (g *Grid) OnKeyEvent(ev KeyEvent)
- func (g *Grid) RemoveRow(index int)
- func (g *Grid) RemoveRows()
- func (g *Grid) Resize(size image.Point)
- func (g *Grid) SetBorder(enabled bool)
- func (g *Grid) SetCell(pos image.Point, w Widget)
- func (g *Grid) SetColumnStretch(col, stretch int)
- func (g *Grid) SetRowStretch(row, stretch int)
- func (g *Grid) SizeHint() image.Point
- type Key
- type KeyEvent
- type Label
- func (l *Label) Draw(p *Painter)
- func (l *Label) MinSizeHint() image.Point
- func (l *Label) Resize(size image.Point)
- func (l *Label) SetStyleName(style string)
- func (l *Label) SetText(text string)
- func (l *Label) SetWordWrap(enabled bool)
- func (l *Label) SizeHint() image.Point
- func (l *Label) Text() string
- type List
- func (l *List) AddItems(items ...string)
- func (l *List) Draw(p *Painter)
- func (l *List) Length() int
- func (l *List) OnItemActivated(fn func(*List))
- func (l *List) OnKeyEvent(ev KeyEvent)
- func (l *List) OnSelectionChanged(fn func(*List))
- func (l *List) RemoveItem(i int)
- func (l *List) RemoveItems()
- func (l *List) Select(i int)
- func (l *List) Selected() int
- func (l *List) SelectedItem() string
- func (l *List) SetSelected(i int)
- func (l *List) SizeHint() image.Point
- type Logger
- type ModMask
- type MouseEvent
- type Padder
- func (p *Padder) Draw(painter *Painter)
- func (p *Padder) IsFocused() bool
- func (p *Padder) MinSizeHint() image.Point
- func (p *Padder) OnKeyEvent(ev KeyEvent)
- func (p *Padder) Resize(size image.Point)
- func (p *Padder) SetFocused(f bool)
- func (p *Padder) Size() image.Point
- func (p *Padder) SizeHint() image.Point
- func (p *Padder) SizePolicy() (SizePolicy, SizePolicy)
- type Painter
- func (p *Painter) Begin()
- func (p *Painter) DrawCursor(x, y int)
- func (p *Painter) DrawHorizontalLine(x1, x2, y int)
- func (p *Painter) DrawRect(x, y, w, h int)
- func (p *Painter) DrawRune(x, y int, r rune)
- func (p *Painter) DrawText(x, y int, text string)
- func (p *Painter) DrawVerticalLine(x, y1, y2 int)
- func (p *Painter) End()
- func (p *Painter) FillRect(x, y, w, h int)
- func (p *Painter) Repaint(w Widget)
- func (p *Painter) Restore()
- func (p *Painter) SetStyle(s Style)
- func (p *Painter) Translate(x, y int)
- func (p *Painter) WithMask(r image.Rectangle, fn func(*Painter))
- func (p *Painter) WithStyle(n string, fn func(*Painter))
- type Progress
- type RuneBuffer
- func (r *RuneBuffer) Backspace()
- func (r *RuneBuffer) CursorPos() image.Point
- func (r *RuneBuffer) Delete()
- func (r *RuneBuffer) Kill()
- func (r *RuneBuffer) Len() int
- func (r *RuneBuffer) MoveBackward()
- func (r *RuneBuffer) MoveForward()
- func (r *RuneBuffer) MoveToLineEnd()
- func (r *RuneBuffer) MoveToLineStart()
- func (r *RuneBuffer) Pos() int
- func (r *RuneBuffer) Runes() []rune
- func (r *RuneBuffer) Set(buf []rune)
- func (r *RuneBuffer) SetMaxWidth(w int)
- func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)
- func (r *RuneBuffer) SplitByLine() []string
- func (r *RuneBuffer) String() string
- func (r *RuneBuffer) Width() int
- func (r *RuneBuffer) WriteRune(s rune)
- func (r *RuneBuffer) WriteRunes(s []rune)
- type ScrollArea
- func (s *ScrollArea) Draw(p *Painter)
- func (s *ScrollArea) MinSizeHint() image.Point
- func (s *ScrollArea) Resize(size image.Point)
- func (s *ScrollArea) Scroll(dx, dy int)
- func (s *ScrollArea) ScrollToBottom()
- func (s *ScrollArea) ScrollToTop()
- func (s *ScrollArea) SetAutoscrollToBottom(autoscroll bool)
- func (s *ScrollArea) SizeHint() image.Point
- type SimpleFocusChain
- type SizePolicy
- type Spacer
- type StatusBar
- type Style
- type Surface
- type Table
- func (t *Table) Draw(p *Painter)
- func (t *Table) OnItemActivated(fn func(*Table))
- func (t *Table) OnKeyEvent(ev KeyEvent)
- func (t *Table) OnSelectionChanged(fn func(*Table))
- func (t *Table) RemoveRow(index int)
- func (t *Table) RemoveRows()
- func (t *Table) Select(i int)
- func (t *Table) Selected() int
- func (t *Table) SetSelected(i int)
- type TestSurface
- func (s *TestSurface) Begin()
- func (s *TestSurface) BgColors() string
- func (s *TestSurface) Decorations() string
- func (s *TestSurface) End()
- func (s *TestSurface) FgColors() string
- func (s *TestSurface) HideCursor()
- func (s *TestSurface) SetCell(x, y int, ch rune, style Style)
- func (s *TestSurface) SetCursor(x, y int)
- func (s *TestSurface) Size() image.Point
- func (s *TestSurface) String() string
- type TextEdit
- type Theme
- type UI
- type Widget
- type WidgetBase
- func (w *WidgetBase) Draw(p *Painter)
- func (w *WidgetBase) IsFocused() bool
- func (w *WidgetBase) MinSizeHint() image.Point
- func (w *WidgetBase) OnKeyEvent(ev KeyEvent)
- func (w *WidgetBase) Resize(size image.Point)
- func (w *WidgetBase) SetFocused(f bool)
- func (w *WidgetBase) SetSizePolicy(h, v SizePolicy)
- func (w *WidgetBase) Size() image.Point
- func (w *WidgetBase) SizeHint() image.Point
- func (w *WidgetBase) SizePolicy() (SizePolicy, SizePolicy)
Constants ¶
const ( KeyBackspace = KeyBS KeyTab = KeyTAB KeyEsc = KeyESC KeyEscape = KeyESC KeyEnter = KeyCR KeyBackspace2 = KeyDEL )
These are aliases for other keys.
Variables ¶
var DefaultFocusChain = &SimpleFocusChain{ widgets: make([]Widget, 0), }
DefaultFocusChain is the default focus chain.
var DefaultTheme = &Theme{ styles: map[string]Style{ "list.item.selected": {Reverse: DecorationOn}, "table.cell.selected": {Reverse: DecorationOn}, "button.focused": {Reverse: DecorationOn}, }, }
DefaultTheme is a theme with reasonable defaults.
Functions ¶
Types ¶
type Alignment ¶
type Alignment int
Alignment is used to set the direction in which widgets are laid out.
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 (*Box) MinSizeHint ¶
MinSizeHint returns the minimum size hint for the layout.
func (*Box) OnKeyEvent ¶
OnKeyEvent handles an event and propagates it to all children.
func (*Box) Resize ¶
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.
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 (*Button) OnActivated ¶
OnActivated allows a custom function to be run whenever the button is activated.
func (*Button) OnKeyEvent ¶
OnKeyEvent handles keys events.
type Decoration ¶ added in v0.3.0
type Decoration int
Decoration represents a bold/underline/etc. state
const ( DecorationInherit Decoration = iota DecorationOn DecorationOff )
Decoration modes: Inherit from parent widget, explicitly on, or explicitly off.
type EchoMode ¶ added in v0.4.0
type EchoMode int
EchoMode is used to determine the visibility of Entry text.
const ( // EchoModeNormal displays the characters as they're being entered. EchoModeNormal EchoMode = iota // EchoModeNoEcho disables text display. This is useful for when the length // of the password should be kept secret. EchoModeNoEcho // EchoModePassword replaces all characters with asterisks. EchoModePassword )
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 (*Entry) OnChanged ¶
OnChanged sets a function to be run whenever the content of the entry has been changed.
func (*Entry) OnSubmit ¶
OnSubmit sets a function to be run whenever the user submits the entry (by pressing KeyEnter).
func (*Entry) SetEchoMode ¶ added in v0.4.0
SetEchoMode sets the echo mode 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 (*Grid) MinSizeHint ¶
MinSizeHint returns the minimum size hint for the grid.
func (*Grid) RemoveRows ¶ added in v0.3.0
func (g *Grid) RemoveRows()
RemoveRows will remove all the rows in grid
func (*Grid) Resize ¶
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) SetColumnStretch ¶
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 ¶
SetRowStretch sets the stretch factor for a given row. For more on stretch factors, see SetColumnStretch.
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 Label ¶
type Label struct { WidgetBase // contains filtered or unexported fields }
Label is a widget to display read-only text.
func (*Label) MinSizeHint ¶
MinSizeHint returns the minimum size the widget is allowed to be.
func (*Label) SetStyleName ¶
SetStyleName sets the identifier used for custom styling.
func (*Label) SetWordWrap ¶
SetWordWrap sets whether text content should be wrapped.
type List ¶
type List struct { WidgetBase // contains filtered or unexported fields }
List is a widget for displaying and selecting items.
func (*List) OnItemActivated ¶
OnItemActivated gets called when activated (through pressing KeyEnter).
func (*List) OnKeyEvent ¶
OnKeyEvent handles terminal events.
func (*List) OnSelectionChanged ¶
OnSelectionChanged gets called whenever a new item is selected.
func (*List) RemoveItem ¶
RemoveItem removes the item at the given position.
func (*List) RemoveItems ¶
func (l *List) RemoveItems()
RemoveItems clears all the items from the list.
func (*List) SelectedItem ¶
SelectedItem returns the currently selected item.
func (*List) SetSelected ¶
SetSelected sets the currently selected item.
type Logger ¶ added in v0.4.0
type Logger interface {
Printf(format string, args ...interface{})
}
Logger provides a interface for the standard logger.
type MouseEvent ¶
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. It adds empty space of a specified size to the outside of its contained Widget.
func NewPadder ¶
NewPadder returns a new Padder. The enclosed Widget is given horizontal margin of x on the right and x on the left, and a vertical margin of y on the top and y on the bottom.
func (*Padder) MinSizeHint ¶
MinSizeHint returns the minimum size the widget is allowed to be.
func (*Padder) SetFocused ¶
SetFocused set the focus on the 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 ¶
NewPainter returns a new instance of Painter.
func (*Painter) DrawCursor ¶
DrawCursor draws the cursor at the given position.
func (*Painter) DrawHorizontalLine ¶
DrawHorizontalLine paints a horizontal line using box characters.
func (*Painter) DrawVerticalLine ¶
DrawVerticalLine paints a vertical line using box characters.
func (*Painter) Restore ¶
func (p *Painter) Restore()
Restore pops the latest transform from the stack.
type Progress ¶
type Progress struct { WidgetBase // contains filtered or unexported fields }
Progress is a widget to display a progress bar.
func (*Progress) MinSizeHint ¶
MinSizeHint returns the minimum size the widget is allowed to be.
func (*Progress) SetCurrent ¶
SetCurrent sets the current progress.
type RuneBuffer ¶ added in v0.3.0
type RuneBuffer struct {
// contains filtered or unexported fields
}
RuneBuffer provides readline functionality for text widgets.
func (*RuneBuffer) Backspace ¶ added in v0.3.0
func (r *RuneBuffer) Backspace()
Backspace deletes the rune left of the cursor.
func (*RuneBuffer) CursorPos ¶ added in v0.3.0
func (r *RuneBuffer) CursorPos() image.Point
CursorPos returns the coordinate for the cursor for a given width.
func (*RuneBuffer) Delete ¶ added in v0.3.0
func (r *RuneBuffer) Delete()
Delete deletes the rune at the current cursor position.
func (*RuneBuffer) Kill ¶ added in v0.3.0
func (r *RuneBuffer) Kill()
Kill deletes all runes from the cursor until the end of the line.
func (*RuneBuffer) Len ¶ added in v0.3.0
func (r *RuneBuffer) Len() int
Len returns the number of runes in the buffer.
func (*RuneBuffer) MoveBackward ¶ added in v0.3.0
func (r *RuneBuffer) MoveBackward()
MoveBackward moves the cursor back by one rune.
func (*RuneBuffer) MoveForward ¶ added in v0.3.0
func (r *RuneBuffer) MoveForward()
MoveForward moves the cursor forward by one rune.
func (*RuneBuffer) MoveToLineEnd ¶ added in v0.3.0
func (r *RuneBuffer) MoveToLineEnd()
MoveToLineEnd moves the cursor to the end of the current line.
func (*RuneBuffer) MoveToLineStart ¶ added in v0.3.0
func (r *RuneBuffer) MoveToLineStart()
MoveToLineStart moves the cursor to the start of the current line.
func (*RuneBuffer) Pos ¶ added in v0.3.0
func (r *RuneBuffer) Pos() int
Pos returns the current index in the buffer.
func (*RuneBuffer) Runes ¶ added in v0.3.0
func (r *RuneBuffer) Runes() []rune
Runes return the buffer
func (*RuneBuffer) Set ¶ added in v0.3.0
func (r *RuneBuffer) Set(buf []rune)
Set the buffer and the index at the end of the buffer.
func (*RuneBuffer) SetMaxWidth ¶ added in v0.3.0
func (r *RuneBuffer) SetMaxWidth(w int)
SetMaxWidth sets the maximum text width.
func (*RuneBuffer) SetWithIdx ¶ added in v0.3.0
func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)
SetWithIdx set the the buffer with a given index.
func (*RuneBuffer) SplitByLine ¶ added in v0.3.0
func (r *RuneBuffer) SplitByLine() []string
SplitByLine returns the lines for a given width.
func (*RuneBuffer) String ¶ added in v0.3.0
func (r *RuneBuffer) String() string
func (*RuneBuffer) Width ¶ added in v0.3.0
func (r *RuneBuffer) Width() int
Width returns the width of the rune buffer, taking into account for CJK.
func (*RuneBuffer) WriteRune ¶ added in v0.3.0
func (r *RuneBuffer) WriteRune(s rune)
WriteRune appends a rune to the buffer.
func (*RuneBuffer) WriteRunes ¶ added in v0.3.0
func (r *RuneBuffer) WriteRunes(s []rune)
WriteRunes appends runes to the buffer.
type ScrollArea ¶ added in v0.3.0
type ScrollArea struct { WidgetBase Widget Widget // contains filtered or unexported fields }
ScrollArea is a widget to fill out space.
func NewScrollArea ¶ added in v0.3.0
func NewScrollArea(w Widget) *ScrollArea
NewScrollArea returns a new ScrollArea.
func (*ScrollArea) Draw ¶ added in v0.3.0
func (s *ScrollArea) Draw(p *Painter)
Draw draws the scroll area.
func (*ScrollArea) MinSizeHint ¶ added in v0.3.0
func (s *ScrollArea) MinSizeHint() image.Point
MinSizeHint returns the minimum size the widget is allowed to be.
func (*ScrollArea) Resize ¶ added in v0.3.0
func (s *ScrollArea) Resize(size image.Point)
Resize resizes the scroll area and the underlying widget.
func (*ScrollArea) Scroll ¶ added in v0.3.0
func (s *ScrollArea) Scroll(dx, dy int)
Scroll shifts the views over the content.
func (*ScrollArea) ScrollToBottom ¶ added in v0.4.0
func (s *ScrollArea) ScrollToBottom()
ScrollToBottom ensures the bottom-most part of the scroll area is visible.
func (*ScrollArea) ScrollToTop ¶ added in v0.4.0
func (s *ScrollArea) ScrollToTop()
ScrollToTop resets the vertical scroll position.
func (*ScrollArea) SetAutoscrollToBottom ¶ added in v0.4.0
func (s *ScrollArea) SetAutoscrollToBottom(autoscroll bool)
SetAutoscrollToBottom makes sure the content is scrolled to bottom on resize.
func (*ScrollArea) SizeHint ¶ added in v0.3.0
func (s *ScrollArea) SizeHint() image.Point
SizeHint returns the size hint of the underlying widget.
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
SizePolicy determines the space occupied by a widget.
const ( // Preferred interprets the size hint as the preferred size. Preferred SizePolicy = iota // Minimum allows the widget to shrink down to the size hint. Minimum // Maximum allows the widget to grow up to the size hint. Maximum // Expanding makes the widget expand to the available space. Expanding )
type Spacer ¶
type Spacer struct {
WidgetBase
}
Spacer is a widget to fill out space.
func (*Spacer) MinSizeHint ¶
MinSizeHint returns the minimum size the widget is allowed to be.
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 (*StatusBar) SetPermanentText ¶
SetPermanentText sets the permanent text of 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 Decoration Bold Decoration Underline Decoration }
Style determines how a cell should be painted. The zero value uses default from
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 (*Table) OnItemActivated ¶
OnItemActivated sets the function that is called when an item was activated.
func (*Table) OnKeyEvent ¶
OnKeyEvent handles an event and propagates it to all children.
func (*Table) OnSelectionChanged ¶
OnSelectionChanged sets the function that is called when an item was selected.
func (*Table) RemoveRows ¶ added in v0.3.0
func (t *Table) RemoveRows()
RemoveRows removes all the rows added to the table.
func (*Table) SetSelected ¶
SetSelected changes the currently selected item.
type TestSurface ¶ added in v0.3.0
type TestSurface struct {
// contains filtered or unexported fields
}
A TestSurface implements the Surface interface with local buffers, and provides accessors to check the output of a draw operation on the Surface.
func NewTestSurface ¶ added in v0.3.0
func NewTestSurface(w, h int) *TestSurface
NewTestSurface returns a new TestSurface.
func (*TestSurface) Begin ¶ added in v0.3.0
func (s *TestSurface) Begin()
Begin resets the state of the TestSurface, clearing all cells. It must be called before drawing the Surface.
func (*TestSurface) BgColors ¶ added in v0.3.0
func (s *TestSurface) BgColors() string
BgColors renders the TestSurface's background colors, using the digits 0-7 for painted cells, and the empty character for unpainted cells.
func (*TestSurface) Decorations ¶ added in v0.3.0
func (s *TestSurface) Decorations() string
Decorations renders the TestSurface's decorations (Reverse, Bold, Underline) using a bitmask:
Reverse: 1 Bold: 2 Underline: 4
func (*TestSurface) End ¶ added in v0.3.0
func (s *TestSurface) End()
End indicates the surface has been painted on, and can be rendered. It's a no-op for TestSurface.
func (*TestSurface) FgColors ¶ added in v0.3.0
func (s *TestSurface) FgColors() string
FgColors renders the TestSurface's foreground colors, using the digits 0-7 for painted cells, and the empty character for unpainted cells.
func (*TestSurface) HideCursor ¶ added in v0.3.0
func (s *TestSurface) HideCursor()
HideCursor removes the cursor from the display.
func (*TestSurface) SetCell ¶ added in v0.3.0
func (s *TestSurface) SetCell(x, y int, ch rune, style Style)
SetCell sets the contents of the addressed cell.
func (*TestSurface) SetCursor ¶ added in v0.3.0
func (s *TestSurface) SetCursor(x, y int)
SetCursor moves the Surface's cursor to the specified position.
func (*TestSurface) Size ¶ added in v0.3.0
func (s *TestSurface) Size() image.Point
Size returns the dimensions of the surface.
func (*TestSurface) String ¶ added in v0.3.0
func (s *TestSurface) String() string
String returns the characters written to the TestSurface.
type TextEdit ¶
type TextEdit struct { WidgetBase // contains filtered or unexported fields }
TextEdit is a multi-line text editor.
func (*TextEdit) OnKeyEvent ¶
OnKeyEvent handles key events.
func (*TextEdit) OnTextChanged ¶
OnTextChanged sets a function to be run whenever the text content of the widget has been changed.
func (*TextEdit) SetWordWrap ¶ added in v0.3.0
SetWordWrap sets whether the text should wrap or not.
type Theme ¶
type Theme struct {
// contains filtered or unexported fields
}
Theme defines the styles for a set of identifiers.
type UI ¶
type UI interface { // SetWidget sets the root widget of the UI. SetWidget(w Widget) // SetTheme sets the current theme of the UI. SetTheme(p *Theme) // SetKeybinding sets the callback for when a key sequence is pressed. SetKeybinding(seq string, fn func()) // ClearKeybindings removes all previous set keybindings. ClearKeybindings() // SetFocusChain sets a chain of widgets that determines focus order. SetFocusChain(ch FocusChain) // Run starts the UI goroutine and blocks either Quit was called or an error occurred. Run() error // Update schedules work in the UI thread and await its completion. // Note that calling Update from the UI thread will result in deadlock. Update(fn func()) // Quit shuts down the UI goroutine. Quit() // Repaint the UI Repaint() }
UI defines the operations needed by the underlying engine.
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
}
WidgetBase defines base attributes and operations for all widgets.
func (*WidgetBase) Draw ¶
func (w *WidgetBase) Draw(p *Painter)
Draw is an empty operation to fulfill the Widget interface.
func (*WidgetBase) IsFocused ¶
func (w *WidgetBase) IsFocused() bool
IsFocused returns whether the widget is focused.
func (*WidgetBase) MinSizeHint ¶
func (w *WidgetBase) MinSizeHint() image.Point
MinSizeHint returns the size below which the widget cannot shrink.
func (*WidgetBase) OnKeyEvent ¶
func (w *WidgetBase) OnKeyEvent(ev KeyEvent)
OnKeyEvent is an empty operation to fulfill the Widget interface.
func (*WidgetBase) Resize ¶
func (w *WidgetBase) Resize(size image.Point)
Resize sets the size of the widget.
func (*WidgetBase) SetFocused ¶
func (w *WidgetBase) SetFocused(f bool)
SetFocused focuses the widget.
func (*WidgetBase) SetSizePolicy ¶
func (w *WidgetBase) SetSizePolicy(h, v SizePolicy)
SetSizePolicy sets the size policy for horizontal and vertical directions.
func (*WidgetBase) Size ¶
func (w *WidgetBase) Size() image.Point
Size returns the current size of the widget.
func (*WidgetBase) SizeHint ¶
func (w *WidgetBase) SizeHint() image.Point
SizeHint returns the size hint of the widget.
func (*WidgetBase) SizePolicy ¶
func (w *WidgetBase) SizePolicy() (SizePolicy, SizePolicy)
SizePolicy returns the current size policy.