Documentation
¶
Index ¶
- func SelectNodeWithCallback(state *TreeState, id any, opts *TreeOptions)
- func Tree(state *TreeState, content func(TreeScope), options ...TreeOption) api.Composable
- func TreeFromData(state *TreeState, roots []any, childUIDs func(any) []any, ...) api.Composable
- type TreeBranchIcons
- type TreeOption
- func WithBranchCloseIcon(closed api.Composable) TreeOption
- func WithBranchIcons(icons *TreeBranchIcons) TreeOption
- func WithBranchOpenIcon(open api.Composable) TreeOption
- func WithHideSeparators(hide bool) TreeOption
- func WithIndentSize(size int) TreeOption
- func WithModifier(m ui.Modifier) TreeOption
- func WithOnBranchClosed(callback func(id any)) TreeOption
- func WithOnBranchOpened(callback func(id any)) TreeOption
- func WithOnSelected(callback func(id any)) TreeOption
- func WithOnUnselected(callback func(id any)) TreeOption
- func WithTextStyle(style *text.TextStyle) TreeOption
- func WithTextStyleOption(textStyleOption text.TextStyleOption) TreeOption
- type TreeOptions
- type TreeScope
- type TreeState
- func (s *TreeState) ClearSelection()
- func (s *TreeState) CloseAllBranches()
- func (s *TreeState) Collapse(id any)
- func (s *TreeState) Expand(id any)
- func (s *TreeState) ExpandToNode(id any, parentLookup func(any) any)
- func (s *TreeState) GetFirstSelected() any
- func (s *TreeState) GetSelectedItems() []any
- func (s *TreeState) IsExpanded(id any) bool
- func (s *TreeState) IsSelected(id any) bool
- func (s *TreeState) OpenAllBranches(roots []any, childUIDs func(any) []any, isBranch func(any) bool)
- func (s *TreeState) Select(id any, singleSelection bool)
- func (s *TreeState) Toggle(id any)
- func (s *TreeState) Unselect(id any)
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 ¶
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) ExpandToNode ¶
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 ¶
GetFirstSelected returns the first selected item ID, or nil if none selected. Useful for single-selection mode.
func (*TreeState) GetSelectedItems ¶
GetSelectedItems returns a slice of all selected item IDs.
func (*TreeState) IsExpanded ¶
IsExpanded checks if the given node ID is expanded.
func (*TreeState) IsSelected ¶
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 ¶
Select marks the given node ID as selected. If singleSelection is true, all other nodes are unselected.