termuix

package module
v0.0.0-...-a2c1f9b Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 13 Imported by: 0

README

termuix

termuix

Documentation

Overview

+build !windows

Index

Constants

View Source
const (
	KeyF1         = "<F1>"
	KeyF2         = "<F2>"
	KeyF3         = "<F3>"
	KeyF4         = "<F4>"
	KeyF5         = "<F5>"
	KeyF6         = "<F6>"
	KeyF7         = "<F7>"
	KeyF8         = "<F8>"
	KeyF9         = "<F9>"
	KeyF10        = "<F10>"
	KeyF11        = "<F11>"
	KeyF12        = "<F12>"
	KeyInsert     = "<Insert>"
	KeyDelete     = "<Delete>"
	KeyHome       = "<Home>"
	KeyEnd        = "<End>"
	KeyPgup       = "<PageUp>"
	KeyPgdn       = "<PageDown>"
	KeyArrowUp    = "<Up>"
	KeyArrowDown  = "<Down>"
	KeyArrowLeft  = "<Left>"
	KeyArrowRight = "<Right>"

	KeyCtrlSpace  = "<C-<Space>>" //  KeyCtrl2  KeyCtrlTilde
	KeyCtrlA      = "<C-a>"
	KeyCtrlB      = "<C-b>"
	KeyCtrlC      = "<C-c>"
	KeyCtrlD      = "<C-d>"
	KeyCtrlE      = "<C-e>"
	KeyCtrlF      = "<C-f>"
	KeyCtrlG      = "<C-g>"
	KeyBackspace  = "<C-<Backspace>>" //  KeyCtrlH
	KeyTab        = "<Tab>"           //  KeyCtrlI
	KeyCtrlJ      = "<C-j>"
	KeyCtrlK      = "<C-k>"
	KeyCtrlL      = "<C-l>"
	KeyEnter      = "<Enter>" //  KeyCtrlM
	KeyCtrlN      = "<C-n>"
	KeyCtrlO      = "<C-o>"
	KeyCtrlP      = "<C-p>"
	KeyCtrlQ      = "<C-q>"
	KeyCtrlR      = "<C-r>"
	KeyCtrlS      = "<C-s>"
	KeyCtrlT      = "<C-t>"
	KeyCtrlU      = "<C-u>"
	KeyCtrlV      = "<C-v>"
	KeyCtrlW      = "<C-w>"
	KeyCtrlX      = "<C-x>"
	KeyCtrlY      = "<C-y>"
	KeyCtrlZ      = "<C-z>"
	KeyEsc        = "<Escape>" //  KeyCtrlLsqBracket  KeyCtrl3
	KeyCtrl4      = "<C-4>"    //  KeyCtrlBackslash
	KeyCtrl5      = "<C-5>"    //  KeyCtrlRsqBracket
	KeyCtrl6      = "<C-6>"
	KeyCtrl7      = "<C-7>" //  KeyCtrlSlash  KeyCtrlUnderscore
	KeySpace      = "<Space>"
	KeyBackspace2 = "<Backspace>" //  KeyCtrl8:
)

List of events:

	mouse events:
		<MouseLeft> <MouseRight> <MouseMiddle>
		<MouseWheelUp> <MouseWheelDown>
	keyboard events:
		any uppercase or lowercase letter like j or J
		<C-d> etc
		<M-d> etc
		<Up> <Down> <Left> <Right>
		<Insert> <Delete> <Home> <End> <Previous> <Next>
		<Backspace> <Tab> <Enter> <Escape> <Space>
		<C-<Space>> etc
	terminal events:
        <Resize>

    keyboard events that do not work:
        <C-->
        <C-2> <C-~>
        <C-h>
        <C-i>
        <C-m>
        <C-[> <C-3>
        <C-\\>
        <C-]>
        <C-/> <C-_>
        <C-8>
View Source
const (
	DOT      = '•'
	ELLIPSES = '…'

	UP_ARROW   = '▲'
	DOWN_ARROW = '▼'

	COLLAPSED = '+'
	EXPANDED  = '−'
)
View Source
const (
	TOP_LEFT     = '┌'
	TOP_RIGHT    = '┐'
	BOTTOM_LEFT  = '└'
	BOTTOM_RIGHT = '┘'

	VERTICAL_LINE   = '│'
	HORIZONTAL_LINE = '─'

	VERTICAL_LEFT   = '┤'
	VERTICAL_RIGHT  = '├'
	HORIZONTAL_UP   = '┴'
	HORIZONTAL_DOWN = '┬'

	QUOTA_LEFT  = '«'
	QUOTA_RIGHT = '»'

	VERTICAL_DASH   = '┊'
	HORIZONTAL_DASH = '┈'
)

Variables

View Source
var (
	BARS = [...]rune{' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}

	SHADED_BLOCKS = [...]rune{' ', '░', '▒', '▓', '█'}

	IRREGULAR_BLOCKS = [...]rune{
		' ', '▘', '▝', '▀', '▖', '▌', '▞', '▛',
		'▗', '▚', '▐', '▜', '▄', '▙', '▟', '█',
	}

	BRAILLE_OFFSET = '\u2800'
	BRAILLE        = [4][2]rune{
		{'\u0001', '\u0008'},
		{'\u0002', '\u0010'},
		{'\u0004', '\u0020'},
		{'\u0040', '\u0080'},
	}

	DOUBLE_BRAILLE = map[[2]int]rune{
		[2]int{0, 0}: '⣀',
		[2]int{0, 1}: '⡠',
		[2]int{0, 2}: '⡐',
		[2]int{0, 3}: '⡈',

		[2]int{1, 0}: '⢄',
		[2]int{1, 1}: '⠤',
		[2]int{1, 2}: '⠔',
		[2]int{1, 3}: '⠌',

		[2]int{2, 0}: '⢂',
		[2]int{2, 1}: '⠢',
		[2]int{2, 2}: '⠒',
		[2]int{2, 3}: '⠊',

		[2]int{3, 0}: '⢁',
		[2]int{3, 1}: '⠡',
		[2]int{3, 2}: '⠑',
		[2]int{3, 3}: '⠉',
	}

	SINGLE_BRAILLE_LEFT  = [4]rune{'\u2840', '⠄', '⠂', '⠁'}
	SINGLE_BRAILLE_RIGHT = [4]rune{'\u2880', '⠠', '⠐', '⠈'}
)
View Source
var CellClear = Cell{
	Rune:  ' ',
	Style: StyleClear,
}
View Source
var DefaultFocusChain = &SimpleFocusChain{
	widgets: make([]Widget, 0),
}

DefaultFocusChain is the default focus chain.

View Source
var DefaultTheme = &RootTheme{
	styles: map[string]Style{},
}

DefaultTheme is a theme with reasonable defaults.

View Source
var StyleClear = Style{
	Fg:       ColorClear,
	Bg:       ColorClear,
	Modifier: ModifierClear,
}
View Source
var Theme = RootTheme{
	Default: NewStyle(ColorWhite),

	Block: BlockTheme{
		Title:  NewStyle(ColorWhite),
		Border: NewStyle(ColorWhite),
	},

	BarChart: BarChartTheme{
		Bars:   StandardColors,
		Nums:   StandardStyles,
		Labels: StandardStyles,
	},

	Paragraph: ParagraphTheme{
		Text: NewStyle(ColorWhite),
	},

	PieChart: PieChartTheme{
		Slices: StandardColors,
	},

	List: ListTheme{
		Text: NewStyle(ColorWhite),
	},

	Tree: TreeTheme{
		Text:      NewStyle(ColorWhite),
		Collapsed: COLLAPSED,
		Expanded:  EXPANDED,
	},

	StackedBarChart: StackedBarChartTheme{
		Bars:   StandardColors,
		Nums:   StandardStyles,
		Labels: StandardStyles,
	},

	Gauge: GaugeTheme{
		Bar:   ColorWhite,
		Label: NewStyle(ColorWhite),
	},

	Sparkline: SparklineTheme{
		Title: NewStyle(ColorWhite),
		Line:  ColorWhite,
	},

	Plot: PlotTheme{
		Lines: StandardColors,
		Axes:  ColorWhite,
	},

	Table: TableTheme{
		Text: NewStyle(ColorWhite),
	},

	Tab: TabTheme{
		Active:   NewStyle(ColorRed),
		Inactive: NewStyle(ColorWhite),
	},
}

Theme holds the default Styles and Colors for all widgets. You can set default widget Styles by modifying the Theme before creating the widgets.

Functions

func AbsInt

func AbsInt(x int) int

func CellsToString

func CellsToString(cells []Cell) string

func FloorFloat64

func FloorFloat64(x float64) float64

func GetMaxFloat64From2dSlice

func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error)

func GetMaxFloat64FromSlice

func GetMaxFloat64FromSlice(slice []float64) (float64, error)

func GetMaxIntFromSlice

func GetMaxIntFromSlice(slice []int) (int, error)

func InterfaceSlice

func InterfaceSlice(slice interface{}) []interface{}

InterfaceSlice takes an []interface{} represented as an interface{} and converts it https://stackoverflow.com/questions/12753805/type-converting-slices-of-interfaces-in-go

func MaxFloat64

func MaxFloat64(x, y float64) float64

func MaxInt

func MaxInt(x, y int) int

func MinFloat64

func MinFloat64(x, y float64) float64

func MinInt

func MinInt(x, y int) int

func PollEvents

func PollEvents() <-chan Event

PollEvents gets events from termbox, converts them, then sends them to each of its channels.

func RoundFloat64

func RoundFloat64(x float64) float64

func SetLogger

func SetLogger(l Logger)

SetLogger sets the logger that is used in tui.

func SplitCells

func SplitCells(cells []Cell, r rune) [][]Cell

func SumFloat64Slice

func SumFloat64Slice(data []float64) float64

func SumIntSlice

func SumIntSlice(slice []int) int

func TrimString

func TrimString(s string, w int) string

TrimString trims a string to a max length and adds '…' to the end if it was trimmed.

Types

type BarChartTheme

type BarChartTheme struct {
	Bars   []Color
	Nums   []Style
	Labels []Style
}

type Block

type Block struct {
	WidgetBase
}

Block is the base struct inherited by most widgets. Block manages size, position, border, and title. It implements all 3 of the methods needed for the `Drawable` interface. Custom widgets will override the Draw method.

func NewBlock

func NewBlock() *Block

func (*Block) Draw

func (s *Block) Draw()

Draw implements the Drawable interface.

func (*Block) GetInner

func (s *Block) GetInner() image.Rectangle

GetRect GetInner the Drawable interface.

func (*Block) GetOuter

func (s *Block) GetOuter() image.Rectangle

GetRect implements the Drawable interface.

func (*Block) Resize

func (s *Block) Resize(pos image.Point, size image.Point)

func (*Block) SetBorder

func (s *Block) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

func (*Block) SetRect

func (s *Block) SetRect(x, y, w, h int)

func (*Block) SetTitle

func (s *Block) SetTitle(title string)

SetTitle sets the title of the box.

type BlockTheme

type BlockTheme struct {
	Title  Style
	Border Style
}

type Box

type Box struct {
	Block
}

func NewHBox

func NewHBox(c ...Widget) *Box

func NewVBox

func NewVBox(c ...Widget) *Box

func (*Box) GetInner

func (s *Box) GetInner() image.Rectangle

GetRect GetInner the Drawable interface.

func (*Box) SetRect

func (s *Box) SetRect(x, y, w, h int)

type Cell

type Cell struct {
	Rune  rune
	Style Style
}

Cell represents a viewable terminal cell

func NewCell

func NewCell(rune rune, args ...interface{}) Cell

NewCell takes 1 to 2 arguments 1st argument = rune 2nd argument = optional style

func RunesToStyledCells

func RunesToStyledCells(runes []rune, style Style) []Cell

func TrimCells

func TrimCells(cells []Cell, w int) []Cell

func WrapCells

func WrapCells(cells []Cell, width uint) []Cell

WrapCells takes []Cell and inserts Cells containing '\n' wherever a linebreak should go.

type CellWithX

type CellWithX struct {
	X    int
	Cell Cell
}

func BuildCellWithXArray

func BuildCellWithXArray(cells []Cell) []CellWithX

type Color

type Color int32

Color represents a color.

const (
	ColorDefault Color = iota

	ColorBlack   Color = 0
	ColorRed     Color = 1
	ColorGreen   Color = 2
	ColorYellow  Color = 3
	ColorBlue    Color = 4
	ColorMagenta Color = 5
	ColorCyan    Color = 6
	ColorWhite   Color = 7
)

Common colors.

const ColorClear Color = -1

func SelectColor

func SelectColor(colors []Color, index int) Color

type Decoration

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

type EchoMode int

EchoMode is used to determine the visibility of Input 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 Event

type Event struct {
	Type    EventType
	ID      string
	Payload interface{}
}

type EventType

type EventType uint
const (
	KeyboardEvent EventType = iota
	MouseEvent
	ResizeEvent
	CallbackEvent
	PaintEvent
)

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 GaugeTheme

type GaugeTheme struct {
	Bar   Color
	Label Style
}

type Input

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

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

func NewInput

func NewInput() *Input

NewInput returns a new Input.

func (*Input) DoEvent

func (s *Input) DoEvent(ev Event) bool

func (*Input) DoKeyEvent

func (e *Input) DoKeyEvent(ev Event) bool

OnKeyEvent handles key events.

func (*Input) Draw

func (e *Input) Draw()

func (*Input) GetInner

func (s *Input) GetInner() image.Rectangle

GetRect GetInner the Drawable interface.

func (*Input) MinSizeHint

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

MinSizeHint returns the minimum size hint for the layout.

func (*Input) OnChanged

func (e *Input) OnChanged(fn func(Input *Input))

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

func (*Input) OnSubmit

func (e *Input) OnSubmit(fn func(Input *Input))

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

func (*Input) Resize

func (l *Input) Resize(pos image.Point, size image.Point)

Resize changes the size of the Widget.

func (*Input) SetEchoMode

func (e *Input) SetEchoMode(m EchoMode)

SetEchoMode sets the echo mode of the Input.

func (*Input) SetRect

func (s *Input) SetRect(x, y, w, h int)

func (*Input) SetText

func (e *Input) SetText(text string)

SetText sets the text content of the Input.

func (*Input) SizeHint

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

SizeHint returns the recommended size hint for the Input.

func (*Input) Text

func (e *Input) Text() string

Text returns the text content of the Input.

type Label

type Label struct {
	Block
	// 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()

Draw draws the label.

func (*Label) GetInner

func (s *Label) GetInner() image.Rectangle

GetRect GetInner the Drawable interface.

func (*Label) MinSizeHint

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

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

func (*Label) Resize

func (l *Label) Resize(pos, size image.Point)

Resize changes the size of the Widget.

func (*Label) SetRect

func (s *Label) SetRect(x, y, w, h int)

func (*Label) SetStyleName

func (l *Label) SetStyleName(style string)

SetStyleName sets the identifier used for custom styling.

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.

func (*Label) Text

func (l *Label) Text() string

Text returns the text content of the label.

type LayoutMode

type LayoutMode int

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

const (
	Horizontal LayoutMode = iota
	Vertical
)

Available alignment options.

type ListTheme

type ListTheme struct {
	Text Style
}

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}

Logger provides a interface for the standard logger.

type Modifier

type Modifier uint
const (
	// ModifierClear clears any modifiers
	ModifierClear     Modifier = 0
	ModifierBold      Modifier = 1 << 9
	ModifierUnderline Modifier = 1 << 10
	ModifierReverse   Modifier = 1 << 11
)

type Mouse

type Mouse struct {
	Drag bool
	X    int
	Y    int
}

Mouse payload.

type Painter

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

Painter provides operations to paint on a surface.

func NewPainter

func NewPainter() *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)

DrawCursor draws the cursor at the given position.

func (*Painter) DrawRune

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

DrawRune paints a rune at the given coordinate.

func (*Painter) DrawText

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

DrawText paints a string starting at the given coordinate.

func (*Painter) End

func (p *Painter) End()

End finalizes any painting that has been made.

func (*Painter) Fill

func (self *Painter) Fill(c Cell, rect image.Rectangle)

func (*Painter) GetCell

func (self *Painter) GetCell(p image.Point) Cell

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) SetCell

func (self *Painter) SetCell(c Cell, p image.Point)

func (*Painter) SetString

func (self *Painter) SetString(s string, style Style, p image.Point)

func (*Painter) Translate

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

Translate pushes a new translation transform to the stack.

type ParagraphTheme

type ParagraphTheme struct {
	Text Style
}

type PieChartTheme

type PieChartTheme struct {
	Slices []Color
}

type PlotTheme

type PlotTheme struct {
	Lines []Color
	Axes  Color
}

type Resize

type Resize struct {
	Width  int
	Height int
}

Resize payload.

type RootTheme

type RootTheme struct {
	Default Style

	Block BlockTheme

	BarChart        BarChartTheme
	Gauge           GaugeTheme
	Plot            PlotTheme
	List            ListTheme
	Tree            TreeTheme
	Paragraph       ParagraphTheme
	PieChart        PieChartTheme
	Sparkline       SparklineTheme
	StackedBarChart StackedBarChartTheme
	Tab             TabTheme
	Table           TableTheme
	// contains filtered or unexported fields
}

Theme defines the styles for a set of identifiers.

func NewTheme

func NewTheme() *RootTheme

NewTheme return an empty theme.

func (*RootTheme) HasStyle

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

HasStyle returns whether an identifier is associated with an identifier.

func (*RootTheme) SetStyle

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

SetStyle sets a style for a given identifier.

func (*RootTheme) Style

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

Style returns the style associated with an identifier. If there is no Style associated with the name, it returns a default Style.

type RuneBuffer

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

RuneBuffer provides readline functionality for text widgets.

func (*RuneBuffer) Backspace

func (r *RuneBuffer) Backspace()

Backspace deletes the rune left of the cursor.

func (*RuneBuffer) CursorPos

func (r *RuneBuffer) CursorPos() image.Point

CursorPos returns the coordinate for the cursor for a given width.

func (*RuneBuffer) Delete

func (r *RuneBuffer) Delete()

Delete deletes the rune at the current cursor position.

func (*RuneBuffer) Kill

func (r *RuneBuffer) Kill()

Kill deletes all runes from the cursor until the end of the line.

func (*RuneBuffer) Len

func (r *RuneBuffer) Len() int

Len returns the number of runes in the buffer.

func (*RuneBuffer) MoveBackward

func (r *RuneBuffer) MoveBackward()

MoveBackward moves the cursor back by one rune.

func (*RuneBuffer) MoveForward

func (r *RuneBuffer) MoveForward()

MoveForward moves the cursor forward by one rune.

func (*RuneBuffer) MoveToLineEnd

func (r *RuneBuffer) MoveToLineEnd()

MoveToLineEnd moves the cursor to the end of the current line.

func (*RuneBuffer) MoveToLineStart

func (r *RuneBuffer) MoveToLineStart()

MoveToLineStart moves the cursor to the start of the current line.

func (*RuneBuffer) Pos

func (r *RuneBuffer) Pos() int

Pos returns the current index in the buffer.

func (*RuneBuffer) Runes

func (r *RuneBuffer) Runes() []rune

Runes return the buffer

func (*RuneBuffer) Set

func (r *RuneBuffer) Set(buf []rune)

Set the buffer and the index at the end of the buffer.

func (*RuneBuffer) SetMaxWidth

func (r *RuneBuffer) SetMaxWidth(w int)

SetMaxWidth sets the maximum text width.

func (*RuneBuffer) SetWithIdx

func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)

SetWithIdx set the the buffer with a given index.

func (*RuneBuffer) SplitByLine

func (r *RuneBuffer) SplitByLine() []string

SplitByLine returns the lines for a given width.

func (*RuneBuffer) String

func (r *RuneBuffer) String() string

func (*RuneBuffer) Width

func (r *RuneBuffer) Width() int

Width returns the width of the rune buffer, taking into account for CJK.

func (*RuneBuffer) WriteRune

func (r *RuneBuffer) WriteRune(s rune)

WriteRune appends a rune to the buffer.

func (*RuneBuffer) WriteRunes

func (r *RuneBuffer) WriteRunes(s []rune)

WriteRunes appends runes to the buffer.

type Screen

type Screen struct {
	image.Rectangle
	CellMap map[image.Point]Cell
	sync.Mutex
}

Buffer represents a section of a terminal and is a renderable rectangle of cells.

func NewScreen

func NewScreen(r image.Rectangle) *Screen

func (*Screen) Clear

func (s *Screen) Clear()

func (*Screen) Fill

func (self *Screen) Fill(c Cell, rect image.Rectangle)

func (*Screen) GetCell

func (self *Screen) GetCell(p image.Point) Cell

func (*Screen) HideCursor

func (s *Screen) HideCursor()

func (*Screen) SetCell

func (self *Screen) SetCell(c Cell, p image.Point)

func (*Screen) SetCursor

func (s *Screen) SetCursor(x, y int)

func (*Screen) SetString

func (self *Screen) SetString(s string, style Style, p image.Point)

func (*Screen) Show

func (s *Screen) Show()

func (*Screen) Size

func (self *Screen) Size() image.Point

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 Space

type Space struct {
	W uint
	H uint
}

type SparklineTheme

type SparklineTheme struct {
	Title Style
	Line  Color
}

type StackedBarChartTheme

type StackedBarChartTheme struct {
	Bars   []Color
	Nums   []Style
	Labels []Style
}

type Style

type Style struct {
	Fg Color
	Bg Color

	Modifier Modifier
}

Style determines how a cell should be painted. The zero value uses default from

func NewStyle

func NewStyle(fg Color, args ...interface{}) Style

NewStyle takes 1 to 3 arguments 1st argument = Fg 2nd argument = optional Bg 3rd argument = optional Modifier

func SelectStyle

func SelectStyle(styles []Style, index int) Style

func (*Style) SetModifier

func (s *Style) SetModifier(m Modifier)

type Surface

type Surface interface {
	GetCell(p image.Point) Cell
	SetCell(c Cell, p image.Point)
	Fill(c Cell, rect image.Rectangle)
	SetCursor(x, y int)
	HideCursor()
	Size() image.Point
	Clear()
	Show()
}

Surface defines a surface that can be painted on.

type TabTheme

type TabTheme struct {
	Active   Style
	Inactive Style
}

type TableTheme

type TableTheme struct {
	Text Style
}

type TreeTheme

type TreeTheme struct {
	Text      Style
	Collapsed rune
	Expanded  rune
}

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()
}

func New

func New(root Widget) (UI, error)
func New(root component.Widget) (component.UI, error) {
	return component.NewUi(root)
}

type Widget

type Widget interface {
	GetOuter() image.Rectangle
	GetInner() image.Rectangle
	GetInnerRealPos() image.Rectangle
	SetRect(x, y, w, h int)
	Draw()
	sync.Locker
	SetFocused(bool)
	IsFocused() bool
	SetActive(a bool)
	IsActive() bool
	SetParent(p Widget)
	GetPainter() *Painter
	SetPainter(p *Painter)
	DoEvent(e Event) bool
	OnEvent(fn func(w Widget, e *Event))
	Append(w Widget)
	Prepend(w Widget)
	Insert(i int, w Widget)
	Remove(i int)
	Length() int
	//SetBorder(enabled bool)
	//SetTitle(title string)
	SetText(text string)
	LayoutMode() LayoutMode               //子元素排列布局
	SizePolicy() (SizePolicy, SizePolicy) //显示模式
	MinSizeHint() image.Point
	SizeHint() image.Point
	Resize(pos image.Point, size image.Point)
	ReLayout() //重新布局
	sync.Locker
}

type WidgetBase

type WidgetBase struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*WidgetBase) Append

func (s *WidgetBase) Append(w Widget)

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

func (*WidgetBase) DoEvent

func (s *WidgetBase) DoEvent(e Event) bool

返回ture 消息将不在冒泡

func (*WidgetBase) Draw

func (s *WidgetBase) Draw()

func (*WidgetBase) GetInner

func (s *WidgetBase) GetInner() image.Rectangle

GetRect GetInner the Drawable interface.

func (*WidgetBase) GetInnerRealPos

func (s *WidgetBase) GetInnerRealPos() image.Rectangle

获取打印的真实坐标

func (*WidgetBase) GetOuter

func (s *WidgetBase) GetOuter() image.Rectangle

GetRect implements the Drawable interface.

func (*WidgetBase) GetPainter

func (w *WidgetBase) GetPainter() *Painter

func (*WidgetBase) GetParentMin

func (s *WidgetBase) GetParentMin() image.Point

func (*WidgetBase) Init

func (s *WidgetBase) Init()

func (*WidgetBase) Insert

func (s *WidgetBase) Insert(i int, w Widget)

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

func (*WidgetBase) IsActive

func (w *WidgetBase) IsActive() bool

IsActive returns whether the widget is active.

func (*WidgetBase) IsFocused

func (w *WidgetBase) IsFocused() bool

IsFocused returns whether the widget is focused.

func (*WidgetBase) LayoutMode

func (s *WidgetBase) LayoutMode() LayoutMode

Alignment returns the current alignment of the Box.

func (*WidgetBase) Length

func (s *WidgetBase) Length() int

Length returns the number of items in the box.

func (*WidgetBase) MinSizeHint

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

MinSizeHint returns the minimum size hint for the layout.

func (*WidgetBase) OnEvent

func (s *WidgetBase) OnEvent(fn func(w Widget, e *Event))

func (*WidgetBase) Prepend

func (s *WidgetBase) Prepend(w Widget)

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

func (*WidgetBase) ReLayout

func (s *WidgetBase) ReLayout()

重新布局

func (*WidgetBase) Remove

func (s *WidgetBase) Remove(i int)

Remove deletes the widget from the Box at a given index.

func (*WidgetBase) Resize

func (s *WidgetBase) Resize(pos image.Point, size image.Point)

func (*WidgetBase) SetActive

func (w *WidgetBase) SetActive(a bool)

SetActive active the widget.

func (*WidgetBase) SetFocused

func (w *WidgetBase) SetFocused(f bool)

SetFocused focuses the widget.

func (*WidgetBase) SetHeight

func (w *WidgetBase) SetHeight(height int)

SetHeight returns whether the widget is active.

func (*WidgetBase) SetPainter

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

func (*WidgetBase) SetParent

func (w *WidgetBase) SetParent(p Widget)

SetActive active the widget.

func (*WidgetBase) SetRect

func (s *WidgetBase) SetRect(x, y, w, h int)

func (*WidgetBase) SetStyle

func (w *WidgetBase) SetStyle(style Style)

IsActive returns whether the widget is active.

func (*WidgetBase) SetText

func (w *WidgetBase) SetText(text string)

SetText

func (*WidgetBase) SetWidth

func (w *WidgetBase) SetWidth(width int)

SetWidth returns whether the widget is active.

func (*WidgetBase) SizeHint

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

SizeHint returns the recommended size hint for the layout.

func (*WidgetBase) SizePolicy

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

SizePolicy returns the current size policy.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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