Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/treeview.h

A tree you can open, close and walk.

#include <sonore/gfx/treeview.h>
On this page

Design notes

What it is for

Presets in folders. Samples in a library. Anything with a hierarchy, which a ListBox flattens into a list that is either enormous or wrong.

Lazy, because the alternative is unusable

A sample library is a hundred thousand files. Building the whole tree to draw twelve rows means walking a drive before the editor appears, and on a network share it means an editor that does not appear. So a node's children are built the first time it is OPENED, through a callback the owner supplies -- and a node can say it MIGHT have children before anyone knows whether it does, which is what lets a folder show a twisty without being read first.

Virtual, like ListBox

The open nodes are flattened into a row list, and only the rows on screen are drawn. A tree with four hundred visible rows paints the twelve you can see. The flattening is recomputed when something opens or closes, not per frame.

Types 2

One node.

Owns its children, which is the arrangement that makes closing a folder free -- the subtree goes with it -- and the one place a caller has to be careful: a pointer to a node is only valid while its parent stays open.

class TreeView : public Widget

A tree of TreeNodes that opens, closes and scrolls, built lazily as the user opens it -- the reference's TreeView, over plain nodes rather than an item class to derive. The file comment says why it is lazy and virtual.

The tree belongs to the caller: setRoot() takes a root that is NOT owned and must outlive the view (or be replaced first), and each node owns its children. Set onNeedChildren before setRoot(); it is called once per node, on first opening, and may read the disk. After changing nodes from outside, call rebuild(). Message thread only.

↑↓ to move↵ to openEvery public name in the headers, and every guide