ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::UI::TreeView Class Reference

Scrollable tree container with selection, expand/collapse, and keyboard navigation. More...

#include <TreeView.hpp>

Inheritance diagram for ZenitUI::UI::TreeView:
[legend]

Public Member Functions

 TreeView (float indent=18.0f)
std::shared_ptr< TreeItem > addItem (std::string label, std::string value="", bool expanded=false)
 Create, attach, and return a root-level TreeItem.
void addRootItem (std::shared_ptr< TreeItem > item)
 Attach an existing TreeItem at root level.
bool removeRootItem (const TreeItem *item)
 Detach a root-level TreeItem.
void clearItems ()
 Remove every item and clear selection.
std::vector< std::shared_ptr< TreeItem > > rootItems () const
 Direct root-level TreeItems in order.
std::vector< std::shared_ptr< TreeItem > > visibleItems () const
 Currently visible TreeItems in depth-first display order.
void setIndent (float px)
float getIndent () const noexcept
void selectItem (const std::shared_ptr< TreeItem > &item, bool notify=false)
 Select item (or clear selection if null).
void clearSelection (bool notify=false)
 Clear the current selection.
std::shared_ptr< TreeItem > getSelectedItem () const
 Currently selected item, or nullptr if none.
void expandAll ()
 Expand every branch item in the tree.
void collapseAll ()
 Collapse every branch item in the tree.
std::shared_ptr< TreeItem > findItemByValue (std::string_view value) const
 Depth-first search for the first item whose getValue() == value.
Vec2 measure (float parent_w, float parent_h) override
Public Member Functions inherited from ZenitUI::TLayout< TreeView, ScrollView >
 TLayout (Args &&...args)
 Forward constructor arguments to Base.
std::shared_ptr< TreeView > cls (const std::string &name)
 Fluent addClass; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > id (const std::string &node_id)
 Fluent setId; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > withRef (const std::string &r)
 Fluent setRef; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > size (Value w, Value h)
 Fluent setSize; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > passThrough (bool p=true)
 Fluent setPassThrough; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > with (std::shared_ptr< Layout > c)
 Fluent addChild; returns typed shared_ptr<Derived>.
std::shared_ptr< TreeView > self ()
 Return shared_from_this() statically cast to Derived.

Public Attributes

bool toggleOnDoubleClick {true}
 Toggle branch expansion on row double-click (default: true).
std::function< void(std::shared_ptr< TreeItem >)> onSelectionChanged
 Fired when the selected item changes (argument may be nullptr on clear).
std::function< void(std::shared_ptr< TreeItem >)> onItemActivated
 Fired on Enter or double-click on an item.
std::function< void(std::shared_ptr< TreeItem >, bool)> onItemToggled
 Fired when a branch item is expanded or collapsed.

Protected Member Functions

void onUpdate (float dt) override
Protected Member Functions inherited from ZenitUI::TLayout< TreeView, ScrollView >
virtual void onBuild ()
 Hook: called once after create() finishes constructing the object.

Friends

class TreeItem

Additional Inherited Members

Static Public Member Functions inherited from ZenitUI::TLayout< TreeView, ScrollView >
static std::shared_ptr< TreeView > create (Args &&...args)
 Construct a shared_ptr<Derived> and call onBuild().

Detailed Description

Scrollable tree container with selection, expand/collapse, and keyboard navigation.

Style tag: "TreeView". Inherits scrolling and clipping from ScrollView.

Keyboard navigation (when the TreeView or any TreeRow holds focus):

  • Up / Down: move selection across visible enabled items.
  • Home / End: jump to first / last visible enabled item.
  • Right: expand a collapsed branch, or move to its first enabled child.
  • Left: collapse an expanded branch, or move to its parent item.
  • Enter: activate the selected item (onItemActivated).
Examples
14_desktop_workspace/main.cpp.

The documentation for this class was generated from the following file: