Add TreeView.Transform

This commit is contained in:
Trevor Slocum 2020-04-19 09:49:01 -07:00
parent 57ef7437e3
commit e00b7a3984
3 changed files with 37 additions and 0 deletions

View File

@ -1,6 +1,7 @@
v1.4.5 (WIP)
- Add multithreading support
- Add ContextMenu (initially supported by List)
- Add TreeView.Transform
- Merge upstream mouse support
v1.4.4 (2020-02-24)

View File

@ -551,6 +551,29 @@ func (t *TreeView) GetRowCount() int {
return len(t.nodes)
}
// Transform modifies the current selection.
func (t *TreeView) Transform(tr Transformation) {
t.Lock()
defer t.Unlock()
switch tr {
case TransformFirstItem:
t.movement = treeHome
case TransformLastItem:
t.movement = treeEnd
case TransformPreviousItem:
t.movement = treeUp
case TransformNextItem:
t.movement = treeDown
case TransformPreviousPage:
t.movement = treePageUp
case TransformNextPage:
t.movement = treePageDown
}
t.process()
}
// process builds the visible tree, populates the "nodes" slice, and processes
// pending selection actions.
func (t *TreeView) process() {

13
util.go
View File

@ -50,6 +50,19 @@ var (
InputFieldMaxLength func(maxLength int) func(text string, ch rune) bool
)
// Transformation describes a widget modification.
type Transformation int
// Widget transformations.
const (
TransformFirstItem Transformation = 1
TransformLastItem Transformation = 2
TransformPreviousItem Transformation = 3
TransformNextItem Transformation = 4
TransformPreviousPage Transformation = 5
TransformNextPage Transformation = 6
)
// Package initialization.
func init() {
runewidth.EastAsianWidth = true