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
//! Custom widget trait for user-defined character-cell rendering.
//!
//! The `Widget` trait allows users to create custom views that render
//! directly to the terminal buffer. This is an escape hatch for UIs
//! that can't be composed from built-in widgets.
//!
//! # Example
//! ```rust,ignore
//! use telex::prelude::*;
//! use telex::widget::Widget;
//! use telex::buffer::{Buffer, Rect};
//!
//! struct PianoRoll { notes: Vec<u8> }
//!
//! impl Widget for PianoRoll {
//! fn render(&self, area: Rect, buf: &mut Buffer) {
//! for (i, ¬e) in self.notes.iter().enumerate() {
//! if i as u16 >= area.width { break; }
//! let ch = if note > 0 { '█' } else { '░' };
//! buf.set(area.x + i as u16, area.y, ch,
//! crossterm::style::Color::White,
//! crossterm::style::Color::Black);
//! }
//! }
//! }
//! ```
use crate;
/// Trait for custom character-cell widgets.
///
/// Implement this trait to create widgets that render directly to the
/// terminal buffer. Use `View::custom()` to wrap your widget in a View.