tree

package
v0.1.122 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SelectNodeWithCallback

func SelectNodeWithCallback(state *TreeState, id any, opts *TreeOptions)

SelectNodeWithCallback selects a node and invokes the appropriate callbacks. This is a helper function for use in node click handlers.

func Tree

func Tree(
	state *TreeState,
	content func(TreeScope),
	options ...TreeOption,
) api.Composable

Tree creates a tree component that efficiently renders hierarchical data using LazyColumn. It supports expanding and collapsing branches.

func TreeFromData

func TreeFromData(
	state *TreeState,
	roots []any,
	childUIDs func(any) []any,
	isBranch func(any) bool,
	createNode func(any) api.Composable,
	options ...TreeOption,
) api.Composable

TreeFromData creates a Tree from a data structure, similar to fyne's data-driven Tree. roots: List of root IDs. childUIDs: Function to get children IDs for a given ID. isBranch: Function to strict check if a node is a branch (optional, if nil, checks if children > 0). createNode: Composable factory for a node ID.

Types

type TreeBranchIcons added in v0.1.120

type TreeBranchIcons struct {
	OpenIcon   api.Composable
	ClosedIcon api.Composable
}

type TreeOption

type TreeOption func(*TreeOptions)

TreeOption configures a Tree component.

func WithBranchCloseIcon added in v0.1.120

func WithBranchCloseIcon(closed api.Composable) TreeOption

func WithBranchIcons added in v0.1.120

func WithBranchIcons(icons *TreeBranchIcons) TreeOption

func WithBranchOpenIcon added in v0.1.120

func WithBranchOpenIcon(open api.Composable) TreeOption

func WithHideSeparators

func WithHideSeparators(hide bool) TreeOption

WithHideSeparators hides separators between tree nodes.

func WithIndentSize

func WithIndentSize(size int) TreeOption

WithIndentSize sets the indentation size per depth level.

func WithModifier

func WithModifier(m ui.Modifier) TreeOption

WithModifier sets a modifier for the tree container.

func WithOnBranchClosed

func WithOnBranchClosed(callback func(id any)) TreeOption

WithOnBranchClosed sets the callback for when a branch is collapsed.

func WithOnBranchOpened

func WithOnBranchOpened(callback func(id any)) TreeOption

WithOnBranchOpened sets the callback for when a branch is expanded.

func WithOnSelected

func WithOnSelected(callback func(id any)) TreeOption

WithOnSelected sets the callback for when a node is selected.

func WithOnUnselected

func WithOnUnselected(callback func(id any)) TreeOption

WithOnUnselected sets the callback for when a node is unselected.

func WithTextStyle added in v0.1.120

func WithTextStyle(style *text.TextStyle) TreeOption

func WithTextStyleOption added in v0.1.120

func WithTextStyleOption(textStyleOption text.TextStyleOption) TreeOption

type TreeOptions

type TreeOptions struct {
	// Modifier applies styling to the tree container.
	Modifier ui.Modifier

	// IndentSize is the horizontal indentation per depth level (default: 24).
	IndentSize int

	// HideSeparators hides the visual separators between tree nodes.
	HideSeparators bool

	//will be in SP
	TextStyle *text.TextStyle

	// OnSelected is called when a node is selected.
	OnSelected func(id any)

	// OnUnselected is called when a node is unselected.
	OnUnselected func(id any)

	// OnBranchOpened is called when a branch is expanded.
	OnBranchOpened func(id any)

	// OnBranchClosed is called when a branch is collapsed.
	OnBranchClosed func(id any)

	BranchIcons *TreeBranchIcons
}

TreeOptions holds configuration for a Tree component.

func DefaultTreeOptions

func DefaultTreeOptions() TreeOptions

DefaultTreeOptions returns the default TreeOptions.

type TreeScope

type TreeScope interface {
	// Node adds a leaf node to the tree.
	Node(key any, content api.Composable)

	// Branch adds a collapsible branch node to the tree.
	// header is the content displayed for the branch itself.
	// children is a function that defines the children of this branch.
	Branch(key any, header api.Composable, children func(TreeScope))
}

TreeScope defines the operations available within a Tree.

type TreeState

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

TreeState controls the state of a Tree component, such as which branches are expanded.

func RememberTreeState

func RememberTreeState(c api.Composer) *TreeState

RememberTreeState creates a TreeState that is remembered across compositions.

func (*TreeState) ClearSelection

func (s *TreeState) ClearSelection()

ClearSelection removes all selections.

func (*TreeState) CloseAllBranches

func (s *TreeState) CloseAllBranches()

CloseAllBranches collapses all branches in the tree.

func (*TreeState) Collapse

func (s *TreeState) Collapse(id any)

Collapse marks the given node ID as collapsed.

func (*TreeState) Expand

func (s *TreeState) Expand(id any)

Expand marks the given node ID as expanded.

func (*TreeState) ExpandToNode

func (s *TreeState) ExpandToNode(id any, parentLookup func(any) any)

ExpandToNode opens all ancestors of the given node to make it visible. parentLookup: function to get the parent ID for a given ID, returns nil if no parent.

func (*TreeState) GetFirstSelected

func (s *TreeState) GetFirstSelected() any

GetFirstSelected returns the first selected item ID, or nil if none selected. Useful for single-selection mode.

func (*TreeState) GetSelectedItems

func (s *TreeState) GetSelectedItems() []any

GetSelectedItems returns a slice of all selected item IDs.

func (*TreeState) IsExpanded

func (s *TreeState) IsExpanded(id any) bool

IsExpanded checks if the given node ID is expanded.

func (*TreeState) IsSelected

func (s *TreeState) IsSelected(id any) bool

IsSelected checks if the given node ID is selected.

func (*TreeState) OpenAllBranches

func (s *TreeState) OpenAllBranches(roots []any, childUIDs func(any) []any, isBranch func(any) bool)

OpenAllBranches expands all branches in the tree. roots: the root node IDs. childUIDs: function to get children IDs for a given ID. isBranch: function to check if a node is a branch (optional, if nil, checks children > 0).

func (*TreeState) Select

func (s *TreeState) Select(id any, singleSelection bool)

Select marks the given node ID as selected. If singleSelection is true, all other nodes are unselected.

func (*TreeState) Toggle

func (s *TreeState) Toggle(id any)

Toggle flips the expansion state of the given node ID.

func (*TreeState) Unselect

func (s *TreeState) Unselect(id any)

Unselect marks the given node ID as unselected.

Jump to

Keyboard shortcuts

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