1pub use crossterm::{
3    cursor,
4    event::{self, Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent},
5    execute, queue, style,
6    style::{Attribute, Attributes, Color, ContentStyle},
7    terminal::{self, ClearType},
8    Command, Result,
9};
10use std::io::{self};
11
12use titik::{
13    Button, Callback, Checkbox, FlexBox, GroupBox, Image, Link, ListBox, Radio,
14    Renderer, Slider, TabBox, TextArea, TextInput, Widget,
15};
16
17fn build_ui() -> Box<dyn Widget<()>> {
18    println!("building the ui");
19    let mut root_node = FlexBox::new();
20    root_node.set_scroll_top(0.0);
21    root_node.vertical();
22
23    let mut slider = Slider::new(0.5);
24    slider.use_thick_track(true);
25    let mut tab1 = TabBox::new();
26    tab1.set_tab_labels(vec![
27        "Tab1".into(),
28        "Tab2".into(),
29        "Tab3".into(),
30        "Tab4".into(),
31        "Tab5".into(),
32        "And more tabs..".into(),
33    ]);
34    tab1.set_active_tab(1);
35    let mut gb1 = GroupBox::new();
38    gb1.set_label("Selection");
39
40    let cb1 = Checkbox::new("Checkbox1");
41    let cb2 = Checkbox::new("Checkbox2");
42    let rb1 = Radio::new("Radio1");
43    let rb2 = Radio::new("Radio2");
44    let mut link1 = Link::new("https://github.com", "Github");
45    link1.set_border(true);
46
47    let mut list_box1 = ListBox::new();
48    list_box1.set_list(vec![
49        "Item1".into(),
50        "Item2".into(),
51        "Item3".into(),
52        "Item4".into(),
53        "Item5".into(),
54        "Item6".into(),
55    ]);
56
57    tab1.add_child_to_tab(0, Box::new(list_box1));
58
59    gb1.add_child(Box::new(cb1));
60    gb1.add_child(Box::new(cb2));
61    gb1.add_child(Box::new(rb1));
62    gb1.add_child(Box::new(rb2));
63    gb1.add_child(Box::new(link1));
64
65    let input1 = TextInput::new("Hello world!");
66
67    let input2 =
68        TextInput::new("The quick brown fox jumps over the lazy dog...");
69
70    let mut text_area1: TextArea<()> = TextArea::new(
71        "This is a text area\
72            \n1. With a line that is a bit long.. but not very long....\
73            \n2. and another line\
74            \n3. With a veryyyyyyy looooooooooooooooooooooooooooooooooooonnnnnnnnnnngggggggg line\
75            \n4. and another line...............\
76            \n5. With a line\
77            \n6. With a line and not too long\
78            \n7. and another line\
79            \n8. With a line\
80            \n9. and another line\
81            \n10. and another line with another pharse\
82            \n11. With a line\
83            \n12. and another line\
84            \n13. With a line\
85            \n14. and another line not so loooooooooooooooooooooooooong\
86            \n15. With a line\
87            \n16. With a line\
88            \n17. and another line\
89            \n18. With a line\
90            \n19. and another line\
91            \n20. This is the last line and also a looooooooooooooooooooong line",
92    );
93    let mut btn2: Button<()> = Button::new("Button2");
96    btn2.set_rounded(true);
97    btn2.set_id("btn2");
98    let mut img: Image<()> =
99        Image::new(include_bytes!("../horse.jpg").to_vec());
100
101    let mut btn1: Button<()> = Button::new("Button 1");
102    btn1.set_id("btn1");
103
104    btn1.add_click_listener(Callback::from(|_| {
105        eprintln!("btn1 is clicked");
106    }));
107
108    root_node.add_child(Box::new(btn1));
109    root_node.add_child(Box::new(slider));
110    root_node.add_child(Box::new(btn2));
111    tab1.add_child(Box::new(gb1));
112    let mut row = FlexBox::new();
113    row.horizontal();
114    row.set_expand_width(true);
115    row.set_expand_height(false);
116    row.add_child(Box::new(img));
117    root_node.add_child(Box::new(row));
118    root_node.add_child(Box::new(tab1));
119    root_node.add_child(Box::new(input1));
121    root_node.add_child(Box::new(input2));
122    root_node.add_child(Box::new(text_area1));
123    Box::new(root_node)
124}
125
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}