Added TreeNode.GetLevel(). Resolves #502

pull/503/merge
Oliver 4 years ago
parent f007e9ad38
commit efed17a61c

@ -1,6 +1,6 @@
# Rich Interactive Widgets for Terminal UIs
[![Godoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/rivo/tview)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/rivo/tview)](https://pkg.go.dev/github.com/rivo/tview)
[![Go Report](https://img.shields.io/badge/go%20report-A%2B-brightgreen.svg)](https://goreportcard.com/report/github.com/rivo/tview)
This Go package provides commonly needed components for terminal based user interfaces.

@ -41,9 +41,13 @@ type TreeNode struct {
// An optional function which is called when the user selects this node.
selected func()
// The hierarchy level (0 for the root, 1 for its children, and so on). This
// is only up to date immediately after a call to process() (e.g. via
// Draw()).
level int
// Temporary member variables.
parent *TreeNode // The parent node (nil for the root).
level int // The hierarchy level (0 for the root, 1 for its children, and so on).
graphicsX int // The x-coordinate of the left-most graphics rune.
textX int // The x-coordinate of the first rune of the text.
}
@ -207,6 +211,14 @@ func (n *TreeNode) SetIndent(indent int) *TreeNode {
return n
}
// GetLevel returns the node's level within the hierarchy, where 0 corresponds
// to the root node, 1 corresponds to its children, and so on. This is only
// guaranteed to be up to date immediately after the tree that contains this
// node is drawn.
func (n *TreeNode) GetLevel() int {
return n.level
}
// TreeView displays tree structures. A tree consists of nodes (TreeNode
// objects) where each node has zero or more child nodes and exactly one parent
// node (except for the root node which has no parent node).

Loading…
Cancel
Save