pub struct Frame<'a> { /* private fields */ }Expand description
A consistent view into the terminal state for rendering a single frame.
This is obtained via the closure argument of Terminal::draw. It is used to render widgets
to the terminal and control the cursor position.
The changes drawn to the frame are applied only to the current Buffer. After the closure
returns, the current buffer is compared to the previous buffer and only the changes are applied
to the terminal. This avoids drawing redundant cells.
Implementations§
Source§impl Frame<'_>
impl Frame<'_>
Sourcepub const fn area(&self) -> Rect
pub const fn area(&self) -> Rect
The area of the current frame
This is guaranteed not to change during rendering, so may be called multiple times.
If your app listens for a resize event from the backend, it should ignore the values from the event for any calculations that are used to render the current frame and use this value instead as this is the area of the buffer that is used to render the current frame.
Examples found in repository?
24fn run(
25 terminal: &mut ratatui::DefaultTerminal,
26 set: SegmentSet,
27) -> io::Result<()> {
28 use tui_gradient_block::gradient_block::GradientBlock;
29 let block = GradientBlock::new()
30 .with_set(set)
31 .left_gradient(solid((48, 174, 209)))
32 .bottom_gradient(solid((48, 174, 209)))
33 .top_gradient(Box::new(
34 GradientBuilder::new()
35 .colors(&[
36 Color::from_rgba8(48, 174, 209, 1),
37 Color::from_rgba8(225, 22, 247, 1),
38 ])
39 .build::<colorgrad::LinearGradient>()
40 .unwrap(),
41 ))
42 .right_gradient(Box::new(
43 GradientBuilder::new()
44 .colors(&[
45 Color::from_rgba8(225, 22, 247, 1),
46 Color::from_rgba8(48, 174, 209, 1),
47 ])
48 .build::<colorgrad::LinearGradient>()
49 .unwrap(),
50 ));
51
52 loop {
53 terminal.draw(|f| f.render_widget(&block, f.area()))?;
54 let event = event::read()?;
55
56 if let Event::Key(key_event) = event {
57 if key_event.kind == KeyEventKind::Press {
58 if let KeyCode::Char('q') = key_event.code {
59 break Ok(());
60 }
61 }
62 }
63 }
64}More examples
15fn run(
16 terminal: &mut ratatui::DefaultTerminal,
17 set: SegmentSet,
18) -> io::Result<()> {
19 use ratatui::{text::Line, layout::{Constraint, Direction, Layout}};
20 use tui_gradient_block::{
21 gradient_block::GradientBlock,
22 theme_presets::cool::t_zombie_dreams,
23 };
24 let theme = t_zombie_dreams::full();
25 let blocks = vec![
26 GradientBlock::new()
27 .with_gradient(theme.double_corners_left)
28 .with_set(set.clone()),
29 GradientBlock::new().title_top(Line::from(tui_rule::generate_gradient_text!("Zombie Dreams", theme.right.top)).centered())
30 .with_gradient(theme.misc1)
31 .with_set(set.clone()),
32 GradientBlock::new()
33 .with_gradient(theme.double_corners_right)
34 .with_set(set.clone()),
35 ];
36
37 loop {
38 terminal.draw(|f| {
39 let base = Layout::new(
40 Direction::Horizontal,
41 [
42 Constraint::Percentage(33),
43 Constraint::Percentage(33),
44 Constraint::Percentage(34),
45 ],
46 )
47 .vertical_margin(1)
48 .horizontal_margin(1)
49 .spacing(3)
50 .split(f.area());
51 for (block, area) in blocks.iter().zip(base.iter()) {
52 f.render_widget(block, *area);
53 }
54 })?;
55 let event = event::read()?;
56
57 if let Event::Key(key_event) = event {
58 if key_event.kind == KeyEventKind::Press {
59 if let KeyCode::Char('q') = key_event.code {
60 break Ok(());
61 }
62 }
63 }
64 }
65}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::cool::t_misty_blue,
22 };
23 let titles = t_misty_blue::titles();
24 let theme = t_misty_blue::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::misc::t_monochrome,
22 };
23 let titles = t_monochrome::titles();
24 let theme = t_monochrome::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::cool::t_minty_green,
22 };
23 let titles = t_minty_green::titles();
24 let theme = t_minty_green::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::warm::t_rusty_ruins,
22 };
23 let titles = t_rusty_ruins::titles();
24 let theme = t_rusty_ruins::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}Sourcepub const fn size(&self) -> Rect
👎Deprecated: use .area() as it’s the more correct name
pub const fn size(&self) -> Rect
The area of the current frame
This is guaranteed not to change during rendering, so may be called multiple times.
If your app listens for a resize event from the backend, it should ignore the values from the event for any calculations that are used to render the current frame and use this value instead as this is the area of the buffer that is used to render the current frame.
Sourcepub fn render_widget<W>(&mut self, widget: W, area: Rect)where
W: Widget,
pub fn render_widget<W>(&mut self, widget: W, area: Rect)where
W: Widget,
Render a Widget to the current buffer using Widget::render.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using Layout to split the total area).
§Example
use ratatui::{layout::Rect, widgets::Block};
let block = Block::new();
let area = Rect::new(0, 0, 5, 5);
frame.render_widget(block, area);Examples found in repository?
24fn run(
25 terminal: &mut ratatui::DefaultTerminal,
26 set: SegmentSet,
27) -> io::Result<()> {
28 use tui_gradient_block::gradient_block::GradientBlock;
29 let block = GradientBlock::new()
30 .with_set(set)
31 .left_gradient(solid((48, 174, 209)))
32 .bottom_gradient(solid((48, 174, 209)))
33 .top_gradient(Box::new(
34 GradientBuilder::new()
35 .colors(&[
36 Color::from_rgba8(48, 174, 209, 1),
37 Color::from_rgba8(225, 22, 247, 1),
38 ])
39 .build::<colorgrad::LinearGradient>()
40 .unwrap(),
41 ))
42 .right_gradient(Box::new(
43 GradientBuilder::new()
44 .colors(&[
45 Color::from_rgba8(225, 22, 247, 1),
46 Color::from_rgba8(48, 174, 209, 1),
47 ])
48 .build::<colorgrad::LinearGradient>()
49 .unwrap(),
50 ));
51
52 loop {
53 terminal.draw(|f| f.render_widget(&block, f.area()))?;
54 let event = event::read()?;
55
56 if let Event::Key(key_event) = event {
57 if key_event.kind == KeyEventKind::Press {
58 if let KeyCode::Char('q') = key_event.code {
59 break Ok(());
60 }
61 }
62 }
63 }
64}More examples
15fn run(
16 terminal: &mut ratatui::DefaultTerminal,
17 set: SegmentSet,
18) -> io::Result<()> {
19 use ratatui::{text::Line, layout::{Constraint, Direction, Layout}};
20 use tui_gradient_block::{
21 gradient_block::GradientBlock,
22 theme_presets::cool::t_zombie_dreams,
23 };
24 let theme = t_zombie_dreams::full();
25 let blocks = vec![
26 GradientBlock::new()
27 .with_gradient(theme.double_corners_left)
28 .with_set(set.clone()),
29 GradientBlock::new().title_top(Line::from(tui_rule::generate_gradient_text!("Zombie Dreams", theme.right.top)).centered())
30 .with_gradient(theme.misc1)
31 .with_set(set.clone()),
32 GradientBlock::new()
33 .with_gradient(theme.double_corners_right)
34 .with_set(set.clone()),
35 ];
36
37 loop {
38 terminal.draw(|f| {
39 let base = Layout::new(
40 Direction::Horizontal,
41 [
42 Constraint::Percentage(33),
43 Constraint::Percentage(33),
44 Constraint::Percentage(34),
45 ],
46 )
47 .vertical_margin(1)
48 .horizontal_margin(1)
49 .spacing(3)
50 .split(f.area());
51 for (block, area) in blocks.iter().zip(base.iter()) {
52 f.render_widget(block, *area);
53 }
54 })?;
55 let event = event::read()?;
56
57 if let Event::Key(key_event) = event {
58 if key_event.kind == KeyEventKind::Press {
59 if let KeyCode::Char('q') = key_event.code {
60 break Ok(());
61 }
62 }
63 }
64 }
65}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::cool::t_misty_blue,
22 };
23 let titles = t_misty_blue::titles();
24 let theme = t_misty_blue::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::misc::t_monochrome,
22 };
23 let titles = t_monochrome::titles();
24 let theme = t_monochrome::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::cool::t_minty_green,
22 };
23 let titles = t_minty_green::titles();
24 let theme = t_minty_green::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}14fn run(
15 terminal: &mut ratatui::DefaultTerminal,
16 set: SegmentSet,
17) -> io::Result<()> {
18 use ratatui::layout::{Constraint, Direction, Layout};
19 use tui_gradient_block::{
20 gradient_block::GradientBlock,
21 theme_presets::warm::t_rusty_ruins,
22 };
23 let titles = t_rusty_ruins::titles();
24 let theme = t_rusty_ruins::full();
25 let blocks_top = vec![
26 GradientBlock::new()
27 .title(titles.up.0, titles.up.1)
28 .with_gradient(theme.up)
29 .with_set(set.clone()),
30 GradientBlock::new()
31 .title(titles.down.0, titles.down.1)
32 .with_gradient(theme.down)
33 .with_set(set.clone()),
34 GradientBlock::new()
35 .title(titles.left.0, titles.left.1)
36 .with_gradient(theme.left)
37 .with_set(set.clone()),
38 GradientBlock::new()
39 .title(titles.right.0, titles.right.1)
40 .with_gradient(theme.right)
41 .with_set(set.clone()),
42 GradientBlock::new()
43 .title(titles.top_left.0, titles.top_left.1)
44 .with_gradient(theme.top_left)
45 .with_set(set.clone()),
46 GradientBlock::new()
47 .title(titles.top_right.0, titles.top_right.1)
48 .with_gradient(theme.top_right)
49 .with_set(set.clone()),
50 GradientBlock::new()
51 .title(titles.bottom_left.0, titles.bottom_left.1)
52 .with_gradient(theme.bottom_left)
53 .with_set(set.clone()),
54 ];
55 let blocks_bottom = vec![
56 GradientBlock::new()
57 .title(titles.bottom_right.0, titles.bottom_right.1)
58 .with_gradient(theme.bottom_right)
59 .with_set(set.clone()),
60 GradientBlock::new()
61 .title(
62 titles.double_corners_left.0,
63 titles.double_corners_left.1,
64 )
65 .with_gradient(theme.double_corners_left)
66 .with_set(set.clone()),
67 GradientBlock::new()
68 .title(
69 titles.double_corners_right.0,
70 titles.double_corners_right.1,
71 )
72 .with_gradient(theme.double_corners_right)
73 .with_set(set.clone()),
74 GradientBlock::new()
75 .title(titles.vertical.0, titles.vertical.1)
76 .with_gradient(theme.vertical)
77 .with_set(set.clone()),
78 GradientBlock::new()
79 .title(titles.horizontal.0, titles.horizontal.1)
80 .with_gradient(theme.horizontal)
81 .with_set(set.clone()),
82 GradientBlock::new()
83 .title(titles.misc1.0, titles.misc1.1)
84 .with_gradient(theme.misc1)
85 .with_set(set.clone()),
86 GradientBlock::new()
87 .title(titles.misc2.0, titles.misc2.1)
88 .with_gradient(theme.misc2)
89 .with_set(set.clone()),
90 ];
91
92 loop {
93 terminal.draw(|f| {
94 let base = Layout::new(
95 Direction::Vertical,
96 [
97 Constraint::Percentage(50),
98 Constraint::Percentage(50),
99 ],
100 )
101 .split(f.area());
102 let top = Layout::new(
103 Direction::Horizontal,
104 [
105 Constraint::Percentage(14),
106 Constraint::Percentage(14),
107 Constraint::Percentage(14),
108 Constraint::Percentage(14),
109 Constraint::Percentage(14),
110 Constraint::Percentage(15),
111 Constraint::Percentage(15),
112 ],
113 )
114 .split(base[0]);
115 let bottom = Layout::new(
116 Direction::Horizontal,
117 [
118 Constraint::Percentage(14),
119 Constraint::Percentage(14),
120 Constraint::Percentage(14),
121 Constraint::Percentage(14),
122 Constraint::Percentage(14),
123 Constraint::Percentage(15),
124 Constraint::Percentage(15),
125 ],
126 )
127 .split(base[1]);
128 for (block, area) in blocks_top.iter().zip(top.iter()) {
129 f.render_widget(block, *area);
130 }
131 for (block, area) in
132 blocks_bottom.iter().zip(bottom.iter())
133 {
134 f.render_widget(block, *area);
135 }
136 })?;
137 let event = event::read()?;
138
139 if let Event::Key(key_event) = event {
140 if key_event.kind == KeyEventKind::Press {
141 if let KeyCode::Char('q') = key_event.code {
142 break Ok(());
143 }
144 }
145 }
146 }
147}Sourcepub fn render_widget_ref<W>(&mut self, widget: W, area: Rect)where
W: WidgetRef,
pub fn render_widget_ref<W>(&mut self, widget: W, area: Rect)where
W: WidgetRef,
Render a WidgetRef to the current buffer using WidgetRef::render_ref.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using [Layout] to split the total area).
§Example
use ratatui::{layout::Rect, widgets::Block};
let block = Block::new();
let area = Rect::new(0, 0, 5, 5);
frame.render_widget_ref(block, area);§Stability
This API is marked as unstable and is only available when the unstable-widget-ref
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn render_stateful_widget<W>(
&mut self,
widget: W,
area: Rect,
state: &mut <W as StatefulWidget>::State,
)where
W: StatefulWidget,
pub fn render_stateful_widget<W>(
&mut self,
widget: W,
area: Rect,
state: &mut <W as StatefulWidget>::State,
)where
W: StatefulWidget,
Render a StatefulWidget to the current buffer using StatefulWidget::render.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using Layout to split the total area).
The last argument should be an instance of the StatefulWidget::State associated to the
given StatefulWidget.
§Example
use ratatui::{
layout::Rect,
widgets::{List, ListItem, ListState},
};
let mut state = ListState::default().with_selected(Some(1));
let list = List::new(vec![ListItem::new("Item 1"), ListItem::new("Item 2")]);
let area = Rect::new(0, 0, 5, 5);
frame.render_stateful_widget(list, area, &mut state);Sourcepub fn render_stateful_widget_ref<W>(
&mut self,
widget: W,
area: Rect,
state: &mut <W as StatefulWidgetRef>::State,
)where
W: StatefulWidgetRef,
pub fn render_stateful_widget_ref<W>(
&mut self,
widget: W,
area: Rect,
state: &mut <W as StatefulWidgetRef>::State,
)where
W: StatefulWidgetRef,
Render a StatefulWidgetRef to the current buffer using
StatefulWidgetRef::render_ref.
Usually the area argument is the size of the current frame or a sub-area of the current
frame (which can be obtained using [Layout] to split the total area).
The last argument should be an instance of the StatefulWidgetRef::State associated to
the given StatefulWidgetRef.
§Example
use ratatui::{
layout::Rect,
widgets::{List, ListItem, ListState},
};
let mut state = ListState::default().with_selected(Some(1));
let list = List::new(vec![ListItem::new("Item 1"), ListItem::new("Item 2")]);
let area = Rect::new(0, 0, 5, 5);
frame.render_stateful_widget_ref(list, area, &mut state);§Stability
This API is marked as unstable and is only available when the unstable-widget-ref
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn set_cursor_position<P>(&mut self, position: P)
pub fn set_cursor_position<P>(&mut self, position: P)
After drawing this frame, make the cursor visible and put it at the specified (x, y) coordinates. If this method is not called, the cursor will be hidden.
Note that this will interfere with calls to Terminal::hide_cursor,
Terminal::show_cursor, and Terminal::set_cursor_position. Pick one of the APIs and
stick with it.
Sourcepub fn set_cursor(&mut self, x: u16, y: u16)
👎Deprecated: the method set_cursor_position indicates more clearly what about the cursor to set
pub fn set_cursor(&mut self, x: u16, y: u16)
After drawing this frame, make the cursor visible and put it at the specified (x, y) coordinates. If this method is not called, the cursor will be hidden.
Note that this will interfere with calls to Terminal::hide_cursor,
Terminal::show_cursor, and Terminal::set_cursor_position. Pick one of the APIs and
stick with it.
Sourcepub fn buffer_mut(&mut self) -> &mut Buffer
pub fn buffer_mut(&mut self) -> &mut Buffer
Gets the buffer that this Frame draws into as a mutable reference.
Sourcepub const fn count(&self) -> usize
pub const fn count(&self) -> usize
Returns the current frame count.
This method provides access to the frame count, which is a sequence number indicating how many frames have been rendered up to (but not including) this one. It can be used for purposes such as animation, performance tracking, or debugging.
Each time a frame has been rendered, this count is incremented,
providing a consistent way to reference the order and number of frames processed by the
terminal. When count reaches its maximum value (usize::MAX), it wraps around to zero.
This count is particularly useful when dealing with dynamic content or animations where the state of the display changes over time. By tracking the frame count, developers can synchronize updates or changes to the content with the rendering process.
§Examples
let current_count = frame.count();
println!("Current frame count: {}", current_count);Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Frame<'a>
impl<'a> RefUnwindSafe for Frame<'a>
impl<'a> Send for Frame<'a>
impl<'a> Sync for Frame<'a>
impl<'a> Unpin for Frame<'a>
impl<'a> !UnwindSafe for Frame<'a>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more