libnotcurses_sys/widgets/tree/mod.rs
1//! `NcTree` widget
2
3// functions already exported by bindgen : 11
4// ------------------------------------------
5// (#) test: 0
6// (W) wrap: 10
7// ------------------------------------------
8//W nctree_add
9//W nctree_create
10//W nctree_destroy
11//W nctree_del
12//W nctree_focused
13//~ nctree_goto
14//W nctree_next
15//W nctree_offer_input
16//W nctree_plane
17//W nctree_prev
18//W nctree_redraw
19
20use core::ffi::{c_int, c_void};
21
22use crate::{c_api::ffi, NcPlane};
23
24mod methods;
25
26/// High-level hierarchical line-based data.
27///
28/// `NcTree`s organize static hierarchical items, and allow them to be browsed.
29///
30/// An NcTree cannot be empty, count must be non-zero.
31///
32/// - Each item can have arbitrary subitems.
33/// - Items can be collapsed and expanded.
34/// - The display supports scrolling and searching.
35/// - Items cannot be added or removed, however; they must be provided in their
36/// entirety at creation time.
37///
38/// NOTE: `NcTree` shares many properties with `NcReel`. Unlike the latter,
39/// `NcTree`s support arbitrary hierarchical levels, but they do not allow
40/// elements to come and go across the lifetime of the widget.
41///
42/// `type in C: nctree (struct)`
43pub type NcTree = ffi::nctree;
44
45/// Item for [`NcTree`].
46///
47/// each item has a curry, and zero or more subitems.
48pub type NcTreeItem = ffi::nctree_item;
49
50/// Options struct for [`NcTree`].
51pub type NcTreeOptions = ffi::nctree_options;
52
53// e.g.:
54//
55// ```c
56// int treecb(struct ncplane* n, void* curry, int pos){
57// ncplane_printf_yx(n, 0, 0, "item: %s pos: %d",
58// static_cast<const char*>(curry), pos);
59// return 0;
60// }
61// ```
62
63/// An [NcTreeItem] callback function (unsafe).
64pub type NcTreeItemCbUnsafe = unsafe extern "C" fn(*mut NcPlane, *mut c_void, c_int) -> c_int;
65
66/// An [NcTreeItem] callback function.
67pub type NcTreeItemCb = fn(&mut NcPlane, &str, i32);
68
69// WIP TODO: create callback type and conversion functions
70//
71// /// Converts [NcTreeItemCbUnsafe] to [NcTreeItemCb].
72// pub fn nctreeitemcb_to_rust(resizecb: Option<NcTreeItemCbUnsafe>) -> Option<NcTreeItemCb> {
73// if let Some(cb) = resizecb {
74// return Some(unsafe { core::mem::transmute(cb) });
75// } else {
76// None
77// }
78// }
79//
80// /// Converts [NcTreeItemCb] to [NcTreeItemCbUnsafe].
81// ///
82// // waiting for https://github.com/rust-lang/rust/issues/53605
83// // to make this function const, and then NcPlaneOptions constructors.
84// pub fn nctreeitemcb_to_c(resizecb: Option<NcTreeItemCb>) -> Option<NcTreeItemCbUnsafe> {
85// if let Some(cb) = resizecb {
86// return Some(unsafe { core::mem::transmute(cb) });
87// } else {
88// None
89// }
90// }