Skip to main content

SplitBuilder

Struct SplitBuilder 

Source
pub struct SplitBuilder { /* private fields */ }
Expand description

Builder for Split pane views.

Implementations§

Source§

impl SplitBuilder

Source

pub fn new() -> Self

Source

pub fn horizontal(self) -> Self

Set the orientation to horizontal (side by side).

Examples found in repository?
examples/15_markdown.rs (line 77)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }
More examples
Hide additional examples
examples/13_split_panes.rs (line 61)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }
Source

pub fn vertical(self) -> Self

Set the orientation to vertical (stacked).

Source

pub fn first(self, view: View) -> Self

Set the first pane content.

Examples found in repository?
examples/15_markdown.rs (lines 79-91)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }
More examples
Hide additional examples
examples/13_split_panes.rs (lines 64-81)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }
Source

pub fn second(self, view: View) -> Self

Set the second pane content.

Examples found in repository?
examples/15_markdown.rs (lines 92-104)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }
More examples
Hide additional examples
examples/13_split_panes.rs (lines 82-98)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }
Source

pub fn ratio(self, ratio: f32) -> Self

Set the split ratio (0.0 to 1.0, where 0.5 is equal split).

Examples found in repository?
examples/15_markdown.rs (line 78)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }
More examples
Hide additional examples
examples/13_split_panes.rs (line 62)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }
Source

pub fn min_first(self, min: u16) -> Self

Set the minimum size for the first pane (in cells).

Examples found in repository?
examples/13_split_panes.rs (line 63)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }
Source

pub fn min_second(self, min: u16) -> Self

Set the minimum size for the second pane (in cells).

Source

pub fn show_divider(self, show: bool) -> Self

Set whether to show a divider line between panes.

Source

pub fn build(self) -> View

Examples found in repository?
examples/15_markdown.rs (line 105)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }
More examples
Hide additional examples
examples/13_split_panes.rs (line 99)
20    fn render(&self, cx: Scope) -> View {
21        let show_help = state!(cx, || false);
22
23        // F1 toggles help
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let selected_item = state!(cx, || 0usize);
30
31        let items = vec![
32            "README.md".to_string(),
33            "Cargo.toml".to_string(),
34            "src/".to_string(),
35            "src/main.rs".to_string(),
36            "src/lib.rs".to_string(),
37            "tests/".to_string(),
38        ];
39
40        let on_select = with!(selected_item => move |idx: usize| {
41            selected_item.set(idx);
42        });
43
44        let detail_text = match selected_item.get() {
45            0 => "# README\n\nThis is a demo of split panes.\n\nThe left panel shows a file list,\nthe right panel shows details.",
46            1 => "[package]\nname = \"demo\"\nversion = \"0.1.0\"\nedition = \"2021\"",
47            2 => "Directory: src/\n\nContains the main source files.",
48            3 => "fn main() {\n    println!(\"Hello, world!\");\n}",
49            4 => "pub mod utils;\npub mod widgets;",
50            5 => "Directory: tests/\n\nContains integration tests.",
51            _ => "Select an item to see details.",
52        };
53
54        // Horizontal split: file list on left, details on right
55        View::vstack()
56            .child(
57                View::boxed()
58                    .flex(1)
59                    .child(
60                        View::split()
61                            .horizontal()
62                            .ratio(0.3)
63                            .min_first(15)
64                            .first(
65                                View::vstack()
66                                    .child(
67                                        View::styled_text("Files")
68                                            .color(Color::Cyan)
69                                            .bold()
70                                            .build(),
71                                    )
72                                    .child(
73                                        View::list()
74                                            .items(items)
75                                            .selected(selected_item.get())
76                                            .on_select(on_select)
77                                            .build(),
78                                    )
79                                    .child(View::gap(1))
80                                    .build(),
81                            )
82                            .second(
83                                View::vstack()
84                                    .child(
85                                        View::styled_text("Details")
86                                            .color(Color::Green)
87                                            .bold()
88                                            .build(),
89                                    )
90                                    .child(
91                                        View::boxed()
92                                            .border(true)
93                                            .flex(1)
94                                            .child(View::text(detail_text))
95                                            .build(),
96                                    )
97                                    .build(),
98                            )
99                            .build(),
100                    )
101                    .build(),
102            )
103            .child(
104                View::styled_text("↑↓: select file | F1 help | Ctrl+Q: quit")
105                    .dim()
106                    .build(),
107            )
108            .child(
109                View::modal()
110                    .visible(show_help.get())
111                    .title("Example 13: Split Panes")
112                    .on_dismiss(with!(show_help => move || show_help.set(false)))
113                    .child(
114                        View::vstack()
115                            .child(View::styled_text("What you're seeing").bold().build())
116                            .child(View::text("• Horizontal split: file list / details"))
117                            .child(View::text("• ratio(0.3) = 30% left, 70% right"))
118                            .child(View::text("• min_first(15) sets minimum pane width"))
119                            .child(View::gap(1))
120                            .child(View::styled_text("Key concepts").bold().build())
121                            .child(View::text("• View::split() creates resizable panes"))
122                            .child(View::text("• .horizontal() or .vertical() orientation"))
123                            .child(View::text("• .first() and .second() set pane content"))
124                            .child(View::text("• Splits can be nested"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Try this").bold().build())
127                            .child(View::text("• Select different files to see details"))
128                            .child(View::text("• Resize terminal to see layout adapt"))
129                            .child(View::gap(1))
130                            .child(View::styled_text("Next up").bold().build())
131                            .child(View::text("→ 14_tabs: tabbed interfaces"))
132                            .child(View::gap(1))
133                            .child(View::styled_text("Press Escape to close").dim().build())
134                            .build(),
135                    )
136                    .build(),
137            )
138            .build()
139    }

Trait Implementations§

Source§

impl Default for SplitBuilder

Source§

fn default() -> SplitBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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, 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.