1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! How a row is described for list and tree controls.
//!
//! Implement [`ListItem`] for your item type so [`crate::ui::ListView`] and
//! [`crate::ui::TreeView`] can paint cells, sort, filter, and build the header.
//! [`columns_count`](ListItem::columns_count) and [`column`](ListItem::column)
//! define the [`super::Column`]s. [`render_method`](ListItem::render_method)
//! returns a [`RenderMethod`] for each cell (or [`RenderMethod::Custom`] to use
//! [`paint`](ListItem::paint)). [`compare`](ListItem::compare) sorts;
//! [`matches`](ListItem::matches) filters when `CustomFilter` is set.
//!
//! Alternatively, `#[derive(ListItem)]` with `#[Column(...)]` on each displayed
//! field generates the same implementation.
//!
//! # Cell formats
//!
//! | Type | Typical [`RenderMethod`] |
//! |------|--------------------------|
//! | [`NumericFormat`] | `Int64`, `UInt64` |
//! | [`FloatFormat`] | `Float` |
//! | [`BoolFormat`] | `Bool` |
//! | [`DateFormat`] / [`TimeFormat`] / [`DateTimeFormat`] / [`DurationFormat`] | date and time variants |
//! | [`SizeFormat`] / [`PercentageFormat`] / [`RatingFormat`] | `Size`, `Percentage`, `Rating` |
//! | [`CurrencyFormat`] | `Currency` (`$ 12.50`) |
//! | [`Status`] / [`StatusFormat`] | `Status` (running, queued, …) |
//! | [`TemperatureFormat`] / [`AreaFormat`] / [`DistanceFormat`] / [`VolumeFormat`] / [`WeightFormat`] / [`SpeedFormat`] | unit values |
//!
//! # Examples
//!
//! ```rust
//! use appcui::prelude::*;
//!
//! #[derive(ListItem)]
//! struct Student {
//! #[Column(name: "&Name", width: 20, align: Left)]
//! name: String,
//! #[Column(name: "&Grade", width: 5, align: Center)]
//! grade: u8,
//! }
//! ```
//!
//! A manual implementation can return [`RenderMethod`] values directly:
//!
//! ```rust
//! use appcui::prelude::*;
//! use std::cmp::Ordering;
//!
//! struct Student {
//! name: String,
//! grade: u8,
//! }
//!
//! impl ListItem for Student {
//! fn columns_count() -> u16 {
//! 2
//! }
//! fn column(index: u16) -> Column {
//! match index {
//! 0 => Column::new("&Name", 20, TextAlignment::Left),
//! 1 => Column::new("&Grade", 5, TextAlignment::Center),
//! _ => Column::new("", 10, TextAlignment::Left),
//! }
//! }
//! fn render_method(&self, column_index: u16) -> Option<RenderMethod<'_>> {
//! match column_index {
//! 0 => Some(RenderMethod::Text(&self.name)),
//! 1 => Some(RenderMethod::UInt64(self.grade as u64, NumericFormat::Normal)),
//! _ => None,
//! }
//! }
//! fn compare(&self, other: &Self, column_index: u16) -> Ordering {
//! match column_index {
//! 0 => self.name.cmp(&other.name),
//! 1 => self.grade.cmp(&other.grade),
//! _ => Ordering::Equal,
//! }
//! }
//! }
//! ```
pub
pub
pub
pub use ListItem;
pub use RenderMethod;
pub use AreaFormat;
pub use BoolFormat;
pub use CurrencyFormat;
pub use DateFormat;
pub use DateTimeFormat;
pub use DurationFormat;
pub use TimeFormat;
pub use DistanceFormat;
pub use FloatFormat;
pub use NumericFormat;
pub use PercentageFormat;
pub use RatingFormat;
pub use SizeFormat;
pub use SpeedFormat;
pub use Status;
pub use StatusFormat;
pub use TemperatureFormat;
pub use VolumeFormat;
pub use WeightFormat;