fynetree

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package fynetree contains a type that makes using Fyne tree widgets easier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FyneTree

type FyneTree[T any] struct {
	// contains filtered or unexported fields
}

FyneTree is a type that holds all data needed to render a Fyne tree widget.

It is designed to make it easier to construct the data for tree widgets and it's method are supposed to be used directly inside the functions for creating and updating a fyne tree.

It is not recommended to update an existing tree, while it is being used by a tree widget. This can lead to data races. Instead, create and update a new object and then replace the old object once the update is complete.

Nodes can be of any type.

Nodes that have child nodes are reported as branches. This means there can not be any empty branch nodes.

func New

func New[T any]() *FyneTree[T]

New returns a new FyneTree object.

func (*FyneTree[T]) Add

func (t *FyneTree[T]) Add(parentUID widget.TreeNodeID, uid widget.TreeNodeID, value T) (widget.TreeNodeID, error)

Add adds a node safely. It returns it's UID or an error if the node can not be added.

Use "" as parentUID for adding nodes at the top level. Nodes will be rendered in the same order as they are added.

func (*FyneTree[T]) ChildUIDs

func (t *FyneTree[T]) ChildUIDs(uid widget.TreeNodeID) []widget.TreeNodeID

ChildUIDs returns the child UIDs of a node.

func (*FyneTree[T]) IsBranch

func (t *FyneTree[T]) IsBranch(uid widget.TreeNodeID) bool

IsBranch reports wether a node is a branch.

func (*FyneTree[T]) MustAdd

func (t *FyneTree[T]) MustAdd(parentUID widget.TreeNodeID, uid widget.TreeNodeID, value T) widget.TreeNodeID

MustAdd is like Add, but panics if adding fails.

func (*FyneTree[T]) MustValue

func (t *FyneTree[T]) MustValue(uid widget.TreeNodeID) T

MustValue returns the value of a node or panics if the node does not exist. This method mainly exists to simplify test code and should not be used in production code.

func (*FyneTree[T]) Parent

func (t *FyneTree[T]) Parent(uid widget.TreeNodeID) (parent widget.TreeNodeID, ok bool)

Parent returns the UID of the parent node.

func (*FyneTree[T]) Path

func (t *FyneTree[T]) Path(uid widget.TreeNodeID) []widget.TreeNodeID

Path returns the UIDs of nodes between a given node and the root.

func (*FyneTree[T]) Size

func (t *FyneTree[T]) Size() int

Size returns the number of nodes in the tree

func (*FyneTree[T]) Value

func (t *FyneTree[T]) Value(uid widget.TreeNodeID) (value T, ok bool)

Value returns the value of a node and reports wether the node exists

Note that when using this method with a Fyne widget it is possible, that a UID forwarded by the widget no longer exists due to race conditions. It is therefore recommended to always check the ok value.

func (*FyneTree[T]) ValueWithFallback

func (t *FyneTree[T]) ValueWithFallback(uid widget.TreeNodeID, fallback T) T

Value returns the value of a node or a fallback value.

Jump to

Keyboard shortcuts

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