tuirealm_orx_tree/lib.rs
1//! ## TUIRealm Tree via `orx-tree`
2//!
3//! Example usage:
4//!
5//! ```no_run
6//! # use tuirealm::component::{Component, AppComponent};
7//! # use tuirealm::event::{
8//! # NoUserEvent, Event,
9//! # Key,
10//! # KeyEvent,
11//! # KeyModifiers,
12//! # };
13//! # use tuirealm::command::{
14//! # Cmd,
15//! # CmdResult,
16//! # Direction,
17//! # };
18//! # use tuirealm::props::{HorizontalAlignment, Color, BorderType, Borders, Title, TextModifiers, Style};
19//! # use std::num::NonZeroUsize;
20//! #
21//! # #[derive(Debug, Clone, PartialEq)]
22//! # enum Msg {
23//! # ForceRedraw
24//! # }
25//! type TreeView = tuirealm_orx_tree::component::TreeView<String>;
26//!
27//! #[derive(Debug, Component)]
28//! struct OurComponent {
29//! component: TreeView
30//! }
31//!
32//! impl OurComponent {
33//! fn new() -> Self {
34//! Self {
35//! component: TreeView::default()
36//! .background(Color::Reset)
37//! .foreground(Color::White)
38//! .border(
39//! Borders::default()
40//! .color(Color::LightBlue)
41//! .modifiers(BorderType::Rounded),
42//! )
43//! .indent_size(2)
44//! .scroll_step_horizontal(NonZeroUsize::new(2).unwrap())
45//! .empty_tree_text("Loading...")
46//! .title(Title::from(" Library ").alignment(HorizontalAlignment::Left))
47//! .highlight_style(Style::new().fg(Color::Yellow).add_modifier(TextModifiers::REVERSED))
48//! .highlight_symbol(">"),
49//! }
50//! }
51//! }
52//!
53//! impl AppComponent<Msg, NoUserEvent> for OurComponent {
54//! fn on(&mut self, ev: &Event<NoUserEvent>) -> Option<Msg> {
55//! let result = match ev {
56//! // selection
57//! Event::Keyboard(KeyEvent {
58//! code: Key::Left,
59//! modifiers: KeyModifiers::NONE,
60//! }) => self.perform(Cmd::Move(Direction::Left)),
61//! Event::Keyboard(KeyEvent {
62//! code: Key::Right,
63//! modifiers: KeyModifiers::NONE,
64//! }) => self.perform(Cmd::Move(Direction::Right)),
65//! Event::Keyboard(KeyEvent {
66//! code: Key::Down,
67//! modifiers: KeyModifiers::NONE,
68//! }) => self.perform(Cmd::Move(Direction::Down)),
69//! Event::Keyboard(KeyEvent {
70//! code: Key::Up,
71//! modifiers: KeyModifiers::NONE,
72//! }) => self.perform(Cmd::Move(Direction::Up)),
73//!
74//! // etc...
75//!
76//! _ => CmdResult::NoChange,
77//! };
78//!
79//! match result {
80//! CmdResult::NoChange => None,
81//! _ => Some(Msg::ForceRedraw)
82//! }
83//! }
84//! }
85//! ```
86
87pub mod component;
88mod state;
89pub mod types;
90pub mod widget;
91
92// re-exports
93/// Fully re-export the backing storage, in case something extra is necessary
94pub use orx_tree;
95// re-export commonly used types for smaller imports
96pub use orx_tree::{
97 NodeRef,
98 Side,
99 traversal,
100};
101
102// TODO: tests