list

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 6 Imported by: 15

Documentation

Overview

Package list provides a widget displaying a vertical list of widgets with one in focus and support for previous and next.

Index

Constants

This section is empty.

Variables

View Source
var BadState = fmt.Errorf("Broken state in list widget")

Functions

func CalculateOnScreen

func CalculateOnScreen(w IListFns, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) (int, int, int, error)

func Render

func Render(w IWidget, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas

func SubWidgetSize

func SubWidgetSize(w IWidget, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderSize

Types

type IBoundedWalker

type IBoundedWalker interface {
	IWalker
	Length() int
}

IBoundedWalker is implemented by an IWalker type that knows the maximum length of its underlying data set. It must return IBoundedWalkerPosition rather than only IWalkerPosition.

type IBoundedWalkerPosition

type IBoundedWalkerPosition interface {
	IWalkerPosition
	ToInt() int
}

For most simple uses

type IListFns added in v1.1.0

type IListFns interface {
	RenderSubwidgets(gowid.IRenderSize, gowid.Selector, gowid.IApp) ([]SubRenders, SubRenders, []SubRenders)
	Walker() IWalker
	SetWalker(IWalker, gowid.IApp)
}

type IWalker

type IWalker interface {
	At(pos IWalkerPosition) gowid.IWidget
	Focus() IWalkerPosition
	SetFocus(pos IWalkerPosition, app gowid.IApp)
	Next(pos IWalkerPosition) IWalkerPosition
	Previous(pos IWalkerPosition) IWalkerPosition
}

Remove HaveFocus because the Next and Previous APIs have to return an gowid.IWidget anyway - so just standardize on assuming a nil interface means invalid

type IWalkerEnd

type IWalkerEnd interface {
	Last() IWalkerPosition // nil possible if empty
}

IWalkerEnd is any type that supports being able to provide a last position. This is used to support the End key on the keyboard.

type IWalkerHome

type IWalkerHome interface {
	First() IWalkerPosition // nil possible if empty
}

IWalkerHome is any type that supports being able to provide a first position.

type IWalkerPosition

type IWalkerPosition interface {
	Equal(IWalkerPosition) bool
	GreaterThan(IWalkerPosition) bool
}

IWalkerPosition is satisfied by any struct with an Equal() method that can determine whether it's at the "same" position as another or is more advanced than another.

type IWidget

type IWidget interface {
	gowid.IWidget
	IListFns
}

type IndexedWidget

type IndexedWidget struct {
	*Widget
	// contains filtered or unexported fields
}

func NewBounded

func NewBounded(walker IBoundedWalker, opts ...Options) *IndexedWidget

func (*IndexedWidget) SetWalker

func (w *IndexedWidget) SetWalker(l IWalker, app gowid.IApp)

func (*IndexedWidget) Walker

func (w *IndexedWidget) Walker() IWalker

type ListPos

type ListPos int

func (ListPos) Equal

func (l ListPos) Equal(other IWalkerPosition) bool

func (ListPos) GreaterThan

func (l ListPos) GreaterThan(other IWalkerPosition) bool

func (ListPos) ToInt

func (l ListPos) ToInt() int

type Options

type Options struct {
	//SelectedStyle gowid.ICellStyler // apply a style to the selected widget - orthogonal to focus styling
	DownKeys         []vim.KeyPress
	UpKeys           []vim.KeyPress
	DoNotSetSelected bool // Whether or not to set the focus.Selected field for the selected child
}

type SimpleListWalker

type SimpleListWalker struct {
	Widgets []gowid.IWidget
	// contains filtered or unexported fields
}

func NewSimpleListWalker

func NewSimpleListWalker(widgets []gowid.IWidget) *SimpleListWalker

func (*SimpleListWalker) At

func (*SimpleListWalker) First

func (w *SimpleListWalker) First() IWalkerPosition

func (*SimpleListWalker) Focus

func (w *SimpleListWalker) Focus() IWalkerPosition

func (*SimpleListWalker) Last

func (*SimpleListWalker) Length

func (w *SimpleListWalker) Length() int

func (*SimpleListWalker) Next

func (*SimpleListWalker) Previous

func (*SimpleListWalker) SetFocus

func (w *SimpleListWalker) SetFocus(focus IWalkerPosition, app gowid.IApp)

type SubRenders

type SubRenders struct {
	Widget          gowid.IWidget
	Position        IWalkerPosition
	Canvas          gowid.ICanvas
	FullCanvasLines int
}

func (*SubRenders) IsChopped

func (r *SubRenders) IsChopped() bool

IsChopped is a utility function for a SubRender struct that returns true if the canvas returned for this widget is smaller than the full size rendered (i.e. that it has been adjusted vertically)

type WalkerIndex

type WalkerIndex struct {
	Widget gowid.IWidget
	Pos    IWalkerPosition
}

WalkerMoved is a simple struct used to hold the result of a Next() or Previous() call on an IWalker. I find its use more convenient than returning multiple values because you can use it inline with other expressions.

type Widget

type Widget struct {
	gowid.AddressProvidesID
	*gowid.Callbacks
	gowid.FocusCallbacks
	gowid.IsSelectable
	// contains filtered or unexported fields
}

func New

func New(walker IWalker, opts ...Options) *Widget

func (*Widget) AtBottom

func (w *Widget) AtBottom() bool

func (*Widget) AtTop

func (w *Widget) AtTop() bool

func (*Widget) CalculateOnScreen

func (w *Widget) CalculateOnScreen(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) (int, int, int, error)

func (*Widget) GoToBottom

func (w *Widget) GoToBottom(app gowid.IApp)

func (*Widget) GoToMiddle

func (w *Widget) GoToMiddle(app gowid.IApp)

func (*Widget) GoToTop

func (w *Widget) GoToTop(app gowid.IApp)

func (*Widget) InMiddle

func (w *Widget) InMiddle() bool

func (*Widget) MoveToNextFocus

func (w *Widget) MoveToNextFocus(subRenderSize gowid.IRenderSize, focus gowid.Selector, screenLines int, app gowid.IApp) (bool, IWalkerPosition)

func (*Widget) MoveToPreviousFocus

func (w *Widget) MoveToPreviousFocus(subRenderSize gowid.IRenderSize, focus gowid.Selector, screenLines int, app gowid.IApp) (bool, IWalkerPosition)

func (*Widget) Render

func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas

func (*Widget) RenderSize

func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox

func (*Widget) RenderSubwidgets

func (w *Widget) RenderSubwidgets(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) (top []SubRenders, middle SubRenders, bottom []SubRenders)

RenderSubWidgets starts at the focus widget, rendering it, and returning the result as middle, a SubRenders struct. This tells the caller information about the widget rendered, including the full number of lines that would've been used if the provided render size had been large enough (this information tells the caller that the whole widget isn't displayed). After rendering the middle widget, the function renders Previous and Next widgets until the space above the middle widget and the space below the middle widget is filled.

func (*Widget) SelectChild added in v1.3.0

func (w *Widget) SelectChild(f gowid.Selector) bool

func (*Widget) SetState added in v1.1.0

func (w *Widget) SetState(st interface{}, app gowid.IApp)

func (*Widget) SetWalker

func (w *Widget) SetWalker(l IWalker, app gowid.IApp)

func (*Widget) State added in v1.1.0

func (w *Widget) State() interface{}

func (*Widget) String

func (w *Widget) String() string

func (*Widget) SubWidgetSize

func (w *Widget) SubWidgetSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderSize

func (*Widget) UserInput

func (w *Widget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool

func (*Widget) Walker

func (w *Widget) Walker() IWalker

type WidgetIsUnboundedError

type WidgetIsUnboundedError struct {
	Type interface{}
}

func (WidgetIsUnboundedError) Error

func (e WidgetIsUnboundedError) Error() string

Jump to

Keyboard shortcuts

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