component

package
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: 10 Imported by: 0

Documentation

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Box

type Box struct {
	WidgetBase
}

func NewHBox

func NewHBox() *Box

func NewVBox

func NewVBox() *Box

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 Input

type Input struct {
	WidgetBase
	// 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)

func (*Input) DoKeyEvent

func (e *Input) DoKeyEvent(ev Event)

OnKeyEvent handles key events.

func (*Input) Draw

func (e *Input) Draw(buf *Buffer)

Draw draws the Input.

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) 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 {
	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(buf *Buffer)

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

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

Resize changes the size of the Widget.

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

	Close()
}

UI defines the operations needed by the underlying engine.

func NewUi

func NewUi(root Widget) (UI, error)

type Widget

type Widget interface {
	Drawable
	SetFocused(bool)
	IsFocused() bool
	SetActive(a bool)
	IsActive() bool
	SetParent(p Widget)
	DoEvent(e Event)
	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 {
	Block
	// 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)

func (*WidgetBase) Draw

func (s *WidgetBase) Draw(buf *Buffer)

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

func (s *WidgetBase) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

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

func (w *WidgetBase) SetParent(p Widget)

SetActive active the widget.

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

func (s *WidgetBase) SetTitle(title string)

SetTitle sets the title of the box.

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.

Jump to

Keyboard shortcuts

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