fltk.tree

FLTK Tree Widget

This module provides tree view widgets for hierarchical data:

  • Tree: Container widget displaying hierarchical items
  • TreeItem: Individual item in a tree

    Authors

    Dejan Lekić

    License

    BSD-3-Clause

Types 6

Sort order options for items added to the tree.

NONE = 0No sorting; items are added in the order defined (default)
ASCENDING = 1Add items in ascending sort order
DESCENDING = 2Add items in descending sort order

Defines the style of connection lines between items.

NONE = 0Use no lines connecting items
DOTTED = 1Use dotted lines connecting items (default)
SOLID = 2Use solid lines connecting items

Tree selection style.

NONE = 0Nothing selected when items are clicked
SINGLE = 1Single item selected when item is clicked (default)
MULTI = 2Multiple items can be selected with SHIFT, CTRL or mouse drags
SINGLE_DRAGGABLE = 3Single items may be selected and reordered by mouse drag

Individual item in a tree widget.

TreeItem represents a single node in the tree hierarchy. Items can have children, forming a hierarchical structure. Items are managed by the Tree widget and should not be created directly.

Fields
TreeItemPtr _itemHandle
Methods
TreeItemPtr itemHandle() @safe nothrow @nogcReturns the underlying item handle.
bool isValid() const @safe nothrow @nogcChecks if this item is valid.
string label() constGets the item's label text.
void label(string text)Sets the item's label text.
TreeItem parent()Gets the parent item.
int childCount() constGets the number of children.
TreeItem child(int index)Gets a child by index.
bool hasChildren() constChecks if this item has children.
int depth() constGets the depth of this item in the tree.
Constructors
this(TreeItemPtr handle)Creates a wrapper around an existing tree item handle.
classTree : Widget

Tree widget for displaying hierarchical data.

Tree displays items in a hierarchical structure with expand/collapse functionality. Items are added using path notation (e.g., "Parent/Child").

Example:

auto tree = new Tree(10, 10, 200, 300, "Files:");
tree.add("Documents/Report.txt");
tree.add("Documents/Notes.txt");
tree.add("Images/Photo.jpg");
tree.add("Images/Logo.png");

Fields
TreePtr _treeHandle
Methods
TreePtr treeHandle() @safe nothrow @nogcReturns the underlying tree handle.
TreeItem add(string path)Adds an item to the tree by path.
bool remove(TreeItem item)Removes an item from the tree.
void clear()Clears all items from the tree.
void clearChildren()Clears all children but keeps the root.
TreeItem root()Gets the root item of the tree.
TreeItem findItem(string path)Finds an item by path.
TreeItem first()Gets the first item in the tree.
TreeItem next(TreeItem item)Gets the next item after the given item.
TreeItem firstSelectedItem()Gets the first selected item.
TreeItem nextSelectedItem(TreeItem item)Gets the next selected item.
bool open(TreeItem item)Opens (expands) an item to show its children.
bool close(TreeItem item)Closes (collapses) an item to hide its children.
bool isOpen(TreeItem item) constChecks if an item is open.
bool select(TreeItem item)Selects an item.
bool deselect(TreeItem item)Deselects an item.
int deselectAll()Deselects all items.
bool isSelected(TreeItem item) constChecks if an item is selected.
void showRoot(bool show) @trustedShows or hides the root item.
int itemLabelFont() const @trustedGets the font used for item labels.
void itemLabelFont(int font) @trustedSets the font used for item labels.
int itemLabelSize() const @trustedGets the font size used for item labels.
void itemLabelSize(int size) @trustedSets the font size used for item labels.
Color itemLabelFgColor() const @trustedGets the foreground color used for item labels.
void itemLabelFgColor(Color color) @trustedSets the foreground color used for item labels.
Color itemLabelBgColor() const @trustedGets the background color used for item labels.
void itemLabelBgColor(Color color) @trustedSets the background color used for item labels.
int marginLeft() const @trustedGets the left margin of the tree.
void marginLeft(int val) @trustedSets the left margin of the tree.
int marginTop() const @trustedGets the top margin of the tree.
void marginTop(int val) @trustedSets the top margin of the tree.
TreeConnector connectorStyle() const @trustedGets the connector line style.
void connectorStyle(TreeConnector style) @trustedSets the connector line style.
Color connectorColor() const @trustedGets the connector line color.
void connectorColor(Color color) @trustedSets the connector line color.
int connectorWidth() const @trustedGets the connector width (space to the right of open/close icon).
void connectorWidth(int val) @trustedSets the connector width.
int lineSpacing() const @trustedGets the vertical spacing between lines.
void lineSpacing(int val) @trustedSets the vertical spacing between lines.
TreeSelect selectMode() const @trustedGets the selection mode.
void selectMode(TreeSelect mode) @trustedSets the selection mode.
TreeSort sortOrder() const @trustedGets the sort order for new items.
void sortOrder(TreeSort order) @trustedSets the sort order for new items.
int openChildMarginBottom() const @trustedGets the margin below an open child in pixels.
void openChildMarginBottom(int val) @trustedSets the margin below an open child in pixels.
int userIconMarginLeft() const @trustedGets the user icon's left margin value in pixels.
void userIconMarginLeft(int val) @trustedSets the user icon's left margin value in pixels.
int labelMarginLeft() const @trustedGets the label's left margin value in pixels.
void labelMarginLeft(int val) @trustedSets the label's left margin value in pixels.
bool showCollapse() const @trustedGets whether collapse icons are shown.
void showCollapse(bool show) @trustedSets whether collapse icons should be shown.
Boxtype selectBox() const @trustedGets the selection box style.
void selectBox(Boxtype box) @trustedSets the selection box style.
Constructors
this(int x, int y, int width, int height, string label = null)Creates a new tree widget.
Destructors

Manages a dynamic array of TreeItem pointers.

This class provides a container for managing collections of tree items, supporting operations like add, insert, remove, swap, and move. It is useful for bulk operations on tree items or maintaining separate collections of items.

Example:

auto arr = new TreeItemArray();
// Add items to the array
// arr.add(someItem);
assert(arr.total() == 0);  // Initially empty

Fields
Methods
int total() const @trustedReturns the total number of items in the array.
TreeItem opIndex(int index) @trustedGets an item at the specified index.
void add(TreeItem item) @trustedAdds an item to the end of the array.
void insert(int pos, TreeItem item) @trustedInserts an item at the specified position.
void replace(int pos, TreeItem item) @trustedReplaces an item at the specified position.
void remove(int index) @trustedRemoves an item at the specified index.
void clear() @trustedClears all items from the array.
void swap(int ax, int bx) @trustedSwaps two items in the array.
bool move(int to, int from) @trustedMoves an item from one position to another.
TreeItemArrayPtr handle() @safe nothrow @nogcReturns the underlying handle for low-level operations.
Constructors
this(int chunksize = 10)Creates a new tree item array.
Destructors