pub struct Renderer<'a, MSG> { /* private fields */ }
Expand description
This provides the render loop of the terminal UI
Implementations§
Source§impl<'a, MSG> Renderer<'a, MSG>
impl<'a, MSG> Renderer<'a, MSG>
Sourcepub fn new(
write: &'a mut dyn Write,
program: Option<&'a dyn Dispatch<MSG>>,
root_node: &'a mut dyn Widget<MSG>,
) -> Self
pub fn new( write: &'a mut dyn Write, program: Option<&'a dyn Dispatch<MSG>>, root_node: &'a mut dyn Widget<MSG>, ) -> Self
create a new renderer with the supplied root_node
Examples found in repository?
More examples
examples/simple.rs (line 119)
8fn main() -> Result<()> {
9 let mut stdout = io::stdout();
10 let mut root_node = FlexBox::<()>::new();
11 root_node.set_border(false);
12 root_node.set_thick_border(true);
13 let mut column = FlexBox::new();
14 column.vertical();
15 column.set_border(false);
16 column.set_thick_border(false);
17 let mut row = FlexBox::<()>::new();
18 row.horizontal();
19 row.set_border(false);
20 row.set_thick_border(false);
21 row.set_rounded(true);
22 let btn1 = Button::<()>::new("btn 1");
23 let btn2 = Button::<()>::new("btn 2");
24 let cb1 = Checkbox::<()>::new("cb 1");
25 let cb2 = Checkbox::<()>::new("cb 2");
26 let label1 = TextLabel::new("label1");
27
28 let rb1 = Radio::<()>::new("Radio1");
29 let rb2 = Radio::<()>::new("Radio2");
30
31 let input1 = TextInput::new("Hello");
32
33 let mut list_box1 = ListBox::<()>::new();
34 list_box1.set_use_divider(true);
35 list_box1.set_list(vec![
36 "Item1".into(),
37 "Item2".into(),
38 "Item3".into(),
39 "Item4".into(),
40 "Item5".into(),
41 "Item6".into(),
42 "Item7".into(),
43 "Item8".into(),
44 "Item9".into(),
45 "Item10".into(),
46 "Item11".into(),
47 "Item12".into(),
48 "Item13".into(),
49 "Item14".into(),
50 "Item15".into(),
51 "Item16".into(),
52 "Item17".into(),
53 "Item18".into(),
54 "Item19".into(),
55 "Item20".into(),
56 "Item21".into(),
57 "Item22".into(),
58 "Item23".into(),
59 "Item24".into(),
60 "Item25".into(),
61 "Item26".into(),
62 "Item27".into(),
63 "Item28".into(),
64 "Item29".into(),
65 "Item30".into(),
66 ]);
67
68 let mut tab1 = TabBox::new();
69 tab1.set_tab_labels(vec![
70 "Tab1".into(),
71 "Tab2".into(),
72 "Tab3".into(),
73 "Tab4".into(),
74 "Tab5".into(),
75 "And more tabs..".into(),
76 ]);
77
78 let cb11 = Checkbox::new("Checkbox1");
79 let cb12 = Checkbox::new("Checkbox2");
80 let rb11 = Radio::new("Radio1");
81 let rb12 = Radio::new("Radio2");
82
83 let mut gb1 = GroupBox::new();
84 gb1.set_label("Selection");
85 gb1.add_child(Box::new(cb11));
86 gb1.add_child(Box::new(cb12));
87 gb1.add_child(Box::new(rb11));
88 gb1.add_child(Box::new(rb12));
89
90 let mut tab_row = FlexBox::new();
91 tab_row.vertical();
92
93 tab1.set_active_tab(2);
94 tab1.add_child_to_tab(1, Box::new(list_box1));
95 tab_row.add_child(Box::new(Checkbox::new("checkbox1 in first tab")));
96 tab_row.add_child(Box::new(Checkbox::new("checkbox2 in first tab")));
97 tab_row.add_child(Box::new(Radio::new("radio1 in first tab")));
98 tab_row.add_child(Box::new(TextInput::new("Hello input in first tab")));
99 tab1.add_child_to_tab(0, Box::new(tab_row));
100 tab1.add_child_to_tab(2, Box::new(gb1));
101 tab1.add_child_to_tab(
102 3,
103 Box::new(TextArea::new("This is a good textarea view")),
104 );
105
106 column.add_child(Box::new(cb1));
107 column.add_child(Box::new(cb2));
108 column.add_child(Box::new(rb1));
109 column.add_child(Box::new(rb2));
110 column.add_child(Box::new(input1));
111 column.add_child(Box::new(label1));
112
113 row.add_child(Box::new(btn1));
114 row.add_child(Box::new(btn2));
115 row.add_child(Box::new(tab1));
116 //row.add_child(Box::new(list_box1));
117 column.add_child(Box::new(row));
118 root_node.add_child(Box::new(column));
119 let mut renderer = Renderer::<()>::new(&mut stdout, None, &mut root_node);
120 renderer.run()?;
121 Ok(())
122}
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
run the event loop of the renderer
Examples found in repository?
More examples
examples/simple.rs (line 120)
8fn main() -> Result<()> {
9 let mut stdout = io::stdout();
10 let mut root_node = FlexBox::<()>::new();
11 root_node.set_border(false);
12 root_node.set_thick_border(true);
13 let mut column = FlexBox::new();
14 column.vertical();
15 column.set_border(false);
16 column.set_thick_border(false);
17 let mut row = FlexBox::<()>::new();
18 row.horizontal();
19 row.set_border(false);
20 row.set_thick_border(false);
21 row.set_rounded(true);
22 let btn1 = Button::<()>::new("btn 1");
23 let btn2 = Button::<()>::new("btn 2");
24 let cb1 = Checkbox::<()>::new("cb 1");
25 let cb2 = Checkbox::<()>::new("cb 2");
26 let label1 = TextLabel::new("label1");
27
28 let rb1 = Radio::<()>::new("Radio1");
29 let rb2 = Radio::<()>::new("Radio2");
30
31 let input1 = TextInput::new("Hello");
32
33 let mut list_box1 = ListBox::<()>::new();
34 list_box1.set_use_divider(true);
35 list_box1.set_list(vec![
36 "Item1".into(),
37 "Item2".into(),
38 "Item3".into(),
39 "Item4".into(),
40 "Item5".into(),
41 "Item6".into(),
42 "Item7".into(),
43 "Item8".into(),
44 "Item9".into(),
45 "Item10".into(),
46 "Item11".into(),
47 "Item12".into(),
48 "Item13".into(),
49 "Item14".into(),
50 "Item15".into(),
51 "Item16".into(),
52 "Item17".into(),
53 "Item18".into(),
54 "Item19".into(),
55 "Item20".into(),
56 "Item21".into(),
57 "Item22".into(),
58 "Item23".into(),
59 "Item24".into(),
60 "Item25".into(),
61 "Item26".into(),
62 "Item27".into(),
63 "Item28".into(),
64 "Item29".into(),
65 "Item30".into(),
66 ]);
67
68 let mut tab1 = TabBox::new();
69 tab1.set_tab_labels(vec![
70 "Tab1".into(),
71 "Tab2".into(),
72 "Tab3".into(),
73 "Tab4".into(),
74 "Tab5".into(),
75 "And more tabs..".into(),
76 ]);
77
78 let cb11 = Checkbox::new("Checkbox1");
79 let cb12 = Checkbox::new("Checkbox2");
80 let rb11 = Radio::new("Radio1");
81 let rb12 = Radio::new("Radio2");
82
83 let mut gb1 = GroupBox::new();
84 gb1.set_label("Selection");
85 gb1.add_child(Box::new(cb11));
86 gb1.add_child(Box::new(cb12));
87 gb1.add_child(Box::new(rb11));
88 gb1.add_child(Box::new(rb12));
89
90 let mut tab_row = FlexBox::new();
91 tab_row.vertical();
92
93 tab1.set_active_tab(2);
94 tab1.add_child_to_tab(1, Box::new(list_box1));
95 tab_row.add_child(Box::new(Checkbox::new("checkbox1 in first tab")));
96 tab_row.add_child(Box::new(Checkbox::new("checkbox2 in first tab")));
97 tab_row.add_child(Box::new(Radio::new("radio1 in first tab")));
98 tab_row.add_child(Box::new(TextInput::new("Hello input in first tab")));
99 tab1.add_child_to_tab(0, Box::new(tab_row));
100 tab1.add_child_to_tab(2, Box::new(gb1));
101 tab1.add_child_to_tab(
102 3,
103 Box::new(TextArea::new("This is a good textarea view")),
104 );
105
106 column.add_child(Box::new(cb1));
107 column.add_child(Box::new(cb2));
108 column.add_child(Box::new(rb1));
109 column.add_child(Box::new(rb2));
110 column.add_child(Box::new(input1));
111 column.add_child(Box::new(label1));
112
113 row.add_child(Box::new(btn1));
114 row.add_child(Box::new(btn2));
115 row.add_child(Box::new(tab1));
116 //row.add_child(Box::new(list_box1));
117 column.add_child(Box::new(row));
118 root_node.add_child(Box::new(column));
119 let mut renderer = Renderer::<()>::new(&mut stdout, None, &mut root_node);
120 renderer.run()?;
121 Ok(())
122}
Auto Trait Implementations§
impl<'a, MSG> Freeze for Renderer<'a, MSG>
impl<'a, MSG> !RefUnwindSafe for Renderer<'a, MSG>
impl<'a, MSG> !Send for Renderer<'a, MSG>
impl<'a, MSG> !Sync for Renderer<'a, MSG>
impl<'a, MSG> Unpin for Renderer<'a, MSG>
impl<'a, MSG> !UnwindSafe for Renderer<'a, MSG>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more