# tui-realm-treeview
~ Treeview component for tui-realm ~
orange trees ยท tui-realm ยท Documentation
Developed by @veeso
Current version: 1.1.0 (22/11/2021)
--- - [tui-realm-treeview](#tui-realm-treeview) - [About tui-realm-treeview ๐ฒ](#about-tui-realm-treeview-) - [Get started ๐](#get-started-) - [Add tui-realm-treeview to your Cargo.toml ๐ฆ](#add-tui-realm-treeview-to-your-cargotoml-) - [Examples ๐](#examples-) - [About performance](#about-performance) - [Component API](#component-api) - [Updating the tree](#updating-the-tree) - [Remounting the component](#remounting-the-component) - [Updating the tree from the "on" method](#updating-the-tree-from-the-on-method) - [Documentation ๐](#documentation-) - [Contributing and issues ๐ค๐ป](#contributing-and-issues-) - [Changelog โณ](#changelog-) - [Support the developer โ](#support-the-developer-) - [License ๐](#license-) --- ## About tui-realm-treeview ๐ฒ tui-realm-treeview is an implementation of a **treeview component** for [tui-realm](https://github.com/veeso/tui-realm). It uses the [Orange trees](https://github.com/veeso/orange-trees) engine for implementing trees. ![Demo](docs/images/demo.gif) --- ## Get started ๐ ### Add tui-realm-treeview to your Cargo.toml ๐ฆ ```toml tui-realm-treeview = "^1.1.0" ``` Or if you don't use **Crossterm**, define the backend as you do with tui-realm: ```toml tui-realm-treeview = { version = "^1.1.0", default-features = false, features = [ "with-termion" ] } ``` ### Examples ๐ View how to use the treeview-component following the [example](examples/demo.rs). The example contains a simple file explorer using a tree view, the depth is set to 3. ```sh cargo run --example demo ``` - Press `ENTER` to expand the selected directory - Press `BACKSPACE` to go to upper directory - Move up and down with `UP/DOWN` arrow keys - Advance by up to 6 entries with `PGUP/PGDOWN` - Open directories with `RIGHT` - Close directories with `LEFT` - Change window between input field and treeview with `TAB` - Press `ESC` to quit ### About performance โ If you were a tui-realm-treeview 0.x user, I'm glad to announce that this new version of the library is much more faster and reliable than the older version. That's because now I'm using a new engine for trees and I'm no more relying on the tui_tree_widget, which required me to convert the tree into another kind of structure which wasn't really compatible with the tree data structure. For this new library I've re-implemented everything, including the widget, to be 100% compatible with the orange-trees engine. In this library there is a consistent use of recursion, and since rust is not functional, this might lead to stack overflows when dealing with huge trees. --- ## Component API **Commands**: | Cmd | Result | Behaviour | |---------------------------|------------------|------------------------------------------------------| | `Custom($TREE_CMD_CLOSE)` | `None` | Close selected node | | `Custom($TREE_CMD_OPEN)` | `None` | Open selected node | | `GoTo(Begin)` | `Changed | None` | Move cursor to the top of the current tree node | | `GoTo(End)` | `Changed | None` | Move cursor to the bottom of the current tree node | | `Move(Down)` | `Changed | None` | Go to next element | | `Move(Up)` | `Changed | None` | Go to previous element | | `Scroll(Down)` | `Changed | None` | Move cursor down by defined max steps or end of node | | `Scroll(Up)` | `Changed | None` | Move cursor up by defined max steps or begin of node | | `Submit` | `Submit` | Just returns submit result with current state | **State**: the state returned is a `One(String)` containing the id of the selected node. If no node is selected `None` is returned. **Properties**: - `Background(Color)`: background color. The background color will be used as background for unselected entry, but will be used as foreground for the selected entry when focus is true - `Borders(Borders)`: set borders properties for component - `Custom($TREE_IDENT_SIZE, Size)`: Set space to render for each each depth level - `Custom($TREE_INITIAL_NODE, String)`: Select initial node in the tree. This option has priority over `keep_state` - `Custom($TREE_PRESERVE_STATE, Flag)`: If true, the selected entry will be kept after an update of the tree (obviously if the entry still exists in the tree). - `FocusStyle(Style)`: inactive style - `Foreground(Color)`: foreground color. The foreground will be used as foreground for the selected item, when focus is false, otherwise as background - `HighlightedColor(Color)`: The provided color will be used to highlight the selected node. `Foreground` will be used if unset. - `HighlightedStr(String)`: The provided string will be displayed on the left side of the selected entry in the tree - `ScrollStep(Length)`: Defines the maximum amount of rows to scroll - `TextProps(TextModifiers)`: set text modifiers - `Title(Title)`: Set box title ### Updating the tree The tree in this component is not inside the `props`, but is a member of the `TreeView` mock component structure. In order to update and work with the tree you've got basically two ways to do this. #### Remounting the component In situation where you need to update the tree on the update routine (as happens in the example), the best way to update the tree is to remount the component from scratch. If you follow the example, you'll see I've implemented the constructor for my treeview component as follows: ```rust impl FsTree { pub fn new(tree: Tree, initial_node: Option