tree

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

Documentation

Overview

Package tree is a widget that displays a collection of widgets organized in a tree structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWalkerCallback

func AddWalkerCallback(c gowid.ICallbacks, name interface{}, cb IWalkerCallback)

func ConfirmPosition

func ConfirmPosition(tp IPos, tree IModel) bool

ConfirmPosition returns true if there is a tree at position tp of argument tree.

func IsSubPosition

func IsSubPosition(outer IPos, inner IPos) bool

func New

func New(walker list.IWalker) *list.Widget

func RemoveWalkerCallback

func RemoveWalkerCallback(c gowid.ICallbacks, name interface{}, id gowid.IIdentity)

func RunWalkerCallbacks

func RunWalkerCallbacks(c gowid.ICallbacks, name interface{}, app gowid.IApp, data ...interface{})

func WidgetAt

func WidgetAt(walker ITreeWalker, pos IPos) gowid.IWidget

Types

type CacheKey

type CacheKey struct {
	Tree IModel
	Exp  bool
}

CacheKey tracks content for a given tree and its expansion state. Note tree position isn't tracked in case objects are inserted into the tree in such a way that the position moves.

type CachingDecorator

type CachingDecorator struct {
	IDecorator
	// contains filtered or unexported fields
}

func NewCachingDecorator

func NewCachingDecorator(dec IDecorator, opts ...CachingDecoratorOptions) *CachingDecorator

func (*CachingDecorator) MakeDecoration

func (d *CachingDecorator) MakeDecoration(pos IPos, tree IModel, wmaker IWidgetMaker) gowid.IWidget

type CachingDecoratorOptions

type CachingDecoratorOptions struct {
	CacheSize int
}

type CachingMaker

type CachingMaker struct {
	IWidgetMaker
	// contains filtered or unexported fields
}

func NewCachingMaker

func NewCachingMaker(dec IWidgetMaker, opts ...CachingMakerOptions) *CachingMaker

func (*CachingMaker) MakeWidget

func (d *CachingMaker) MakeWidget(pos IPos, tree IModel) gowid.IWidget

type CachingMakerOptions

type CachingMakerOptions struct {
	CacheSize int
}

type Collapsed

type Collapsed struct{}

For callback registration

type CollapsedFunction

type CollapsedFunction func(app gowid.IApp)

func (CollapsedFunction) Collapsed

func (f CollapsedFunction) Collapsed(app gowid.IApp)

type Collapsible

type Collapsible struct {
	*Tree

	Callbacks *gowid.Callbacks
	// contains filtered or unexported fields
}

func NewCollapsible

func NewCollapsible(leaf string, children []IModel) *Collapsible

func (*Collapsible) AddOnCollapsed

func (t *Collapsible) AddOnCollapsed(name interface{}, cb ICollapsedCallback)

func (*Collapsible) AddOnExpanded

func (t *Collapsible) AddOnExpanded(name interface{}, cb IExpandedCallback)

func (*Collapsible) Children

func (t *Collapsible) Children() IIterator

func (*Collapsible) IsCollapsed

func (t *Collapsible) IsCollapsed() bool

func (*Collapsible) RemoveOnCollapsed

func (t *Collapsible) RemoveOnCollapsed(name interface{})

func (*Collapsible) RemoveOnExpanded

func (t *Collapsible) RemoveOnExpanded(name interface{})

func (*Collapsible) SetCollapsed

func (t *Collapsible) SetCollapsed(app gowid.IApp, collapsed bool)

func (*Collapsible) String

func (t *Collapsible) String() string

type DecoratorFunction

type DecoratorFunction func(pos IPos, tree IModel, wmaker IWidgetMaker) gowid.IWidget

func (DecoratorFunction) MakeDecoration

func (f DecoratorFunction) MakeDecoration(pos IPos, tree IModel, wmaker IWidgetMaker) gowid.IWidget

type Expanded

type Expanded struct{}

type ExpandedFunction

type ExpandedFunction func(app gowid.IApp)

func (ExpandedFunction) Expanded

func (f ExpandedFunction) Expanded(app gowid.IApp)

type ICollapsedCallback

type ICollapsedCallback interface {
	Collapsed(app gowid.IApp)
}

type ICollapsible

type ICollapsible interface {
	IModel
	IsCollapsed() bool
	SetCollapsed(gowid.IApp, bool)
}

type IDecorator

type IDecorator interface {
	MakeDecoration(pos IPos, tree IModel, wmaker IWidgetMaker) gowid.IWidget
}

type IExpandedCallback

type IExpandedCallback interface {
	Expanded(app gowid.IApp)
}

type IIterator

type IIterator interface {
	Value() IModel
	Next() bool
}

type IModel

type IModel interface {
	Leaf() string
	Children() IIterator
	fmt.Stringer
}

type IPos

type IPos interface {
	GetSubStructure(IModel) IModel
	Copy() IPos
	Indices() []int
	SetIndices([]int)
	Equal(list.IWalkerPosition) bool
	GreaterThan(list.IWalkerPosition) bool
	fmt.Stringer
}

IPos is the interface of a type that represents the position of a sub-tree or leaf in a tree.

nil means invalid [] means the root of the tree [0] means 0th child of root [3] means 3rd child of root [1,2] means 2nd child of 1st child of root

func DepthFirstSearch added in v1.4.0

func DepthFirstSearch(tree IModel, fn ISearchPred) IPos

func FirstChildPosition

func FirstChildPosition(tp IPos, tree IModel) IPos

FirstChildPosition returns the IPos corresponding to the first child of tp, or nil if there are no children.

func LastChildPosition

func LastChildPosition(tp IPos, tree IModel) IPos

LastChildPosition returns the IPos corresponding to the last child of tp, or nil if there are no children.

func LastDescendant

func LastDescendant(tp IPos, tree IModel) IPos

LastDescendant moves to the last child of the current level, and then to the last child of that node, and onwards until the end is reached.

func LastInDirection

func LastInDirection(tp IPos, tree IModel, f func(IPos, IModel) IPos) IPos

LastInDirection navigates the tree starting at tp and moving in the direction determined by the function f until the end is reached. The function returns the last position that was passed through.

func NextOfKin

func NextOfKin(tp IPos, tree IModel) IPos

NextOfKin returns the position of the sibling of the parent of tp if that position exists, and if not, the sibling of the parent's parent, and on upwards. If the next of kin is not found, nil is returned.

func NextPosition

func NextPosition(tp IPos, tree IModel) IPos

NextPosition is used to navigate the tree in a depth first manner. Starting at the current position, the first child is selected. If there isn't one, then the current node's sibling is selected. If there isn't one, then the "next of kin" is selected.

func NextSiblingPosition

func NextSiblingPosition(tp IPos, tree IModel) IPos

NextSiblingPosition returns the position of the next sibling relative to the position tp.

func ParentPosition

func ParentPosition(tp IPos) IPos

ParentPosition returns the position of the parent of position tp or nil if tp is the root node.

func PreviousPosition

func PreviousPosition(tp IPos, tree IModel) IPos

PreviousPosition is used to navigate the tree backwards in a depth first manner.

func PreviousSiblingPosition

func PreviousSiblingPosition(tp IPos, tree IModel) IPos

PreviousSiblingPosition returns the position of the previous sibling relative to the position tp.

type ISearchPred added in v1.4.0

type ISearchPred interface {
	CheckNode(IModel, IPos) bool
}

type ITreeWalker

type ITreeWalker interface {
	Tree() IModel
	Maker() IWidgetMaker
	Decorator() IDecorator
	Focus() list.IWalkerPosition
}

type IWalkerCallback

type IWalkerCallback interface {
	gowid.IIdentity
	Changed(app gowid.IApp, tree ITreeWalker, data ...interface{})
}

type IWidgetMaker

type IWidgetMaker interface {
	MakeWidget(pos IPos, tree IModel) gowid.IWidget
}

type SearchPred added in v1.4.0

type SearchPred func(IModel, IPos) bool

func (SearchPred) CheckNode added in v1.4.0

func (s SearchPred) CheckNode(tree IModel, pos IPos) bool

type Tree

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

func NewTree

func NewTree(leaf string, children []IModel) *Tree

func (*Tree) Children

func (t *Tree) Children() IIterator

func (*Tree) GetChildren

func (t *Tree) GetChildren() []IModel

func (*Tree) Leaf

func (t *Tree) Leaf() string

func (*Tree) SetChildren

func (t *Tree) SetChildren(c []IModel)

func (*Tree) SetLeaf

func (t *Tree) SetLeaf(s string)

func (*Tree) String

func (t *Tree) String() string

type TreePos

type TreePos struct {
	Pos []int
}

TreePos is a simple implementation of IPos.

func NewPos

func NewPos() *TreePos

func NewPosExt

func NewPosExt(pos []int) *TreePos

func (*TreePos) Copy

func (tp *TreePos) Copy() IPos

func (*TreePos) Equal

func (tp *TreePos) Equal(other list.IWalkerPosition) bool

func (*TreePos) GetSubStructure

func (tp *TreePos) GetSubStructure(tree IModel) IModel

GetSubStructure returns the (sub-)Tree at this position from the tree argument provided.

func (*TreePos) GreaterThan

func (tp *TreePos) GreaterThan(other list.IWalkerPosition) bool

func (*TreePos) Indices

func (tp *TreePos) Indices() []int

func (*TreePos) SetIndices

func (tp *TreePos) SetIndices(indices []int)

func (*TreePos) String

func (tp *TreePos) String() string

type TreeWalker

type TreeWalker struct {
	*gowid.Callbacks
	gowid.FocusCallbacks
	// contains filtered or unexported fields
}

func NewWalker

func NewWalker(tree IModel, pos IPos, maker IWidgetMaker, dec IDecorator) *TreeWalker

func (*TreeWalker) At

list.IWalker

func (*TreeWalker) Decorator

func (f *TreeWalker) Decorator() IDecorator

func (*TreeWalker) Focus

func (f *TreeWalker) Focus() list.IWalkerPosition

list.IWalker

func (*TreeWalker) Maker

func (f *TreeWalker) Maker() IWidgetMaker

func (*TreeWalker) Next

list.IWalker

func (*TreeWalker) OnFocusChanged

func (t *TreeWalker) OnFocusChanged(f IWalkerCallback)

func (*TreeWalker) Previous

list.IWalker

func (*TreeWalker) RemoveOnFocusChanged

func (t *TreeWalker) RemoveOnFocusChanged(f gowid.IIdentity)

func (*TreeWalker) SetFocus

func (f *TreeWalker) SetFocus(pos list.IWalkerPosition, app gowid.IApp)

func (*TreeWalker) Tree

func (f *TreeWalker) Tree() IModel

type WalkerCallback

type WalkerCallback struct {
	Name interface{}
	WalkerFunction
}

WidgetCallback is a simple struct with a name field for IIdentity and that embeds a WidgetChangedFunction to be issued as a callback when a widget property changes.

func MakeCallback

func MakeCallback(name interface{}, fn WalkerFunction) WalkerCallback

func (WalkerCallback) ID

func (f WalkerCallback) ID() interface{}

type WalkerFunction

type WalkerFunction func(app gowid.IApp, tree ITreeWalker)

func (WalkerFunction) Changed

func (f WalkerFunction) Changed(app gowid.IApp, tree ITreeWalker, data ...interface{})

type WidgetMakerFunction

type WidgetMakerFunction func(pos IPos, tree IModel) gowid.IWidget

func (WidgetMakerFunction) MakeWidget

func (f WidgetMakerFunction) MakeWidget(pos IPos, tree IModel) gowid.IWidget

Jump to

Keyboard shortcuts

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