Struct Renderer

Source
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>

Source

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?
examples/demo.rs (line 129)
126fn main() -> Result<()> {
127    let mut stdout = io::stdout();
128    let mut root_node = build_ui();
129    let mut renderer = Renderer::new(&mut stdout, None, root_node.as_mut());
130    renderer.run()?;
131    Ok(())
132}
More examples
Hide additional 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}
Source

pub fn run(&mut self) -> Result<()>

run the event loop of the renderer

Examples found in repository?
examples/demo.rs (line 130)
126fn main() -> Result<()> {
127    let mut stdout = io::stdout();
128    let mut root_node = build_ui();
129    let mut renderer = Renderer::new(&mut stdout, None, root_node.as_mut());
130    renderer.run()?;
131    Ok(())
132}
More examples
Hide additional 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.