rab/tui/components/
dynamic_lines.rs1use std::cell::RefCell;
2use std::rc::Rc;
3
4use crate::tui::Component;
5
6pub struct DynamicLines {
9 lines: RefCell<Vec<String>>,
10}
11
12pub struct RcDynamicLines(pub Rc<DynamicLines>);
14
15impl Component for RcDynamicLines {
16 fn render(&self, width: usize) -> Vec<String> {
17 self.0.render(width)
18 }
19
20 fn invalidate(&mut self) {
21 self.0.clear_cache();
23 }
24}
25
26impl Clone for RcDynamicLines {
27 fn clone(&self) -> Self {
28 Self(self.0.clone())
29 }
30}
31
32impl DynamicLines {
33 pub fn new() -> Self {
34 Self {
35 lines: RefCell::new(Vec::new()),
36 }
37 }
38
39 pub fn set_lines(&self, new_lines: Vec<String>) {
41 *self.lines.borrow_mut() = new_lines;
42 }
43
44 pub fn clear(&self) {
46 self.lines.borrow_mut().clear();
47 }
48
49 pub fn clear_cache(&self) {
51 }
53}
54
55impl Default for DynamicLines {
56 fn default() -> Self {
57 Self::new()
58 }
59}
60
61impl Component for DynamicLines {
62 fn render(&self, _width: usize) -> Vec<String> {
63 self.lines.borrow().clone()
64 }
65
66 fn invalidate(&mut self) {
67 }
69}