GradientBlock

Struct GradientBlock 

Source
pub struct GradientBlock<'a> {
    pub fill: Line<'a>,
    pub titles: Vec<T<'a>>,
    pub bg: Option<Color>,
    pub border_segments: BorderSegments,
}
Expand description

A struct that represents a customizable block with gradient text, borders, and other visual elements.

This struct allows you to create and manage blocks that have a gradient color effect for text, customizable borders, and areas with specific alignments and fill styles.

Fields§

§fill: Line<'a>§titles: Vec<T<'a>>§bg: Option<Color>§border_segments: BorderSegments

Implementations§

Source§

impl GradientBlock<'_>

Source

pub fn new() -> Self

Examples found in repository?
examples/basic_gradient.rs (line 29)
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
Hide additional examples
examples/themes/zombie_dreams.rs (line 26)
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}
examples/themes/misty_blue.rs (line 26)
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}
examples/themes/monochrome.rs (line 26)
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}
examples/themes/minty_green.rs (line 26)
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}
examples/themes/rusty_ruins.rs (line 26)
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}
Source

pub fn main(&self, area: &Rect, buf: &mut Buffer)

Renders the Gradientblock widget, including optional fill and custom block rendering, along with titles.

Source§

impl<'a> GradientBlock<'a>

Source

pub fn with_gradient(self, gradient: GradientVariation) -> Self

Examples found in repository?
examples/themes/zombie_dreams.rs (line 27)
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}
More examples
Hide additional examples
examples/themes/misty_blue.rs (line 28)
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}
examples/themes/monochrome.rs (line 28)
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}
examples/themes/minty_green.rs (line 28)
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}
examples/themes/rusty_ruins.rs (line 28)
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}
examples/themes/midnight_blurple.rs (line 28)
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::dark::t_midnight_blurple,
22    };
23    let titles = t_midnight_blurple::titles();
24    let theme = t_midnight_blurple::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}
Source

pub fn right(self, seg: Rule) -> Self

sets the right segment

Source

pub fn left(self, seg: Rule) -> Self

sets the left segment

Source

pub fn top(self, seg: Rule) -> Self

sets the top segment

Source

pub fn bottom(self, seg: Rule) -> Self

sets bottom segment

Source

pub fn right_gradient(self, gradient: G) -> Self

Sets gradient of the right segment of the border.

Examples found in repository?
examples/basic_gradient.rs (lines 42-50)
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}
Source

pub fn left_gradient(self, gradient: G) -> Self

Sets gradient of the left segment of the border.

Examples found in repository?
examples/basic_gradient.rs (line 31)
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}
Source

pub fn top_gradient(self, gradient: G) -> Self

Sets gradient of the top segment of the border.

Examples found in repository?
examples/basic_gradient.rs (lines 33-41)
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}
Source

pub fn bottom_gradient(self, gradient: G) -> Self

Sets gradient of the bottom segment of the border.

Examples found in repository?
examples/basic_gradient.rs (line 32)
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}
Source

pub fn margin(self, horizontal: u16, vertical: u16) -> Self

Source

pub fn horizontal_margin(self, margin: u16) -> Self

Source

pub fn vertical_margin(self, margin: u16) -> Self

Source

pub fn right_padding(self, padding: u16) -> Self

Source

pub fn left_padding(self, padding: u16) -> Self

Source

pub fn top_padding(self, padding: u16) -> Self

Source

pub fn bottom_padding(self, padding: u16) -> Self

Source

pub fn borders(self, borders: Borders, corners: bool) -> Self

Source

pub fn corners(self, corners: Corners) -> Self

Source

pub fn center_symbols(self, symbols: CenterSymbols) -> Self

Source

pub fn title_top<I: Into<Line<'a>>>(self, title: I) -> Self

Examples found in repository?
examples/themes/zombie_dreams.rs (line 29)
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}
Source

pub fn title_bottom<I: Into<Line<'a>>>(self, title: I) -> Self

Source

pub fn with_border_style(self, style: BorderStyle) -> Self

Sets the border style for the block.

If this function is not called, the border will be plain by default.

§Parameters
  • style: A BorderStyle enum value that determines the appearance of the border.
    • BorderStyle::New: Empty to be set manually.
    • BorderStyle::Custom: Custom border from SegmentSet struct
§Example 1: Using a standard border style
let border = GradientBlock::new().border_style(BorderStyle::Double);
§Example 2: Using a miscellaneous border style
let border = GradientBlock::new().with_border_style(BorderStyle::Custom(preset::MISC3));
§Example 3: Using a custom border type
let border = GradientBlock::new()
    .with_border_style(BorderStyle::New)
    .top_left('╔')
    .top_right('╗')
    .bottom_left('╚')
    .bottom_right('╝');

Sets the border style of the block.

This function allows setting a predefined border style or a custom one.

§Parameters
  • style: A BorderStyle enum variant specifying the desired border style.
§Behavior
  • BorderStyle::CustomBorderType: Does not set predefined symbols, allowing manual customization.
  • BorderStyle::MiscBorder(MiscBorderTypes): Uses a predefined miscellaneous border style.
  • BorderStyle::Plain, BorderStyle::Double, BorderStyle::Thick, BorderStyle::Rounded: Sets the block’s borders to one of these predefined styles.
§Example
let block = GradientBlock::new().border_style(BorderStyle::Double);
Source

pub fn titles(self, titles: &'a [(Line<'_>, Position)]) -> Self

Sets the titles that appear at the bottom of the border.

§Parameters
  • titles: A vector of tuples where each tuple contains:
    • A String representing the title text.
    • A Alignment indicating how the title should be aligned (e.g., left, center, right).
    • An optional tuple containing a vector of RGB colors and a gradient factor (f32).
§Example
let border = Border::new().bottom_titles(vec![
    ("Footer", Alignment::Center, Some((vec![(255, 0, 0), (190, 3, 252)], 0.5))),
]);
Source

pub fn title(self, title: Line<'a>, pos: Position) -> Self

Examples found in repository?
examples/themes/misty_blue.rs (line 27)
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}
More examples
Hide additional examples
examples/themes/monochrome.rs (line 27)
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}
examples/themes/minty_green.rs (line 27)
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}
examples/themes/rusty_ruins.rs (line 27)
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}
examples/themes/midnight_blurple.rs (line 27)
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::dark::t_midnight_blurple,
22    };
23    let titles = t_midnight_blurple::titles();
24    let theme = t_midnight_blurple::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}
Source

pub const fn top_right(self, symb: char) -> Self

Sets the symbol for the top-right corner of the border.

§Parameters
  • symb: A char representing the symbol to be used in the top-right corner.
§Example
let border = GradientBlock::new().top_right('#');
Source

pub const fn top_left(self, symb: char) -> Self

Sets the symbol for the top-left corner of the border.

§Parameters
  • symb: A char representing the symbol to be used in the top-left corner.
§Example
let border = GradientBlock::new().top_left('*');
Source

pub const fn bottom_right(self, symb: char) -> Self

Sets the symbol for the bottom-right corner of the border.

§Parameters
  • symb: A char representing the symbol to be used in the bottom-right corner.
§Example
let border = GradientBlock::new().bottom_right('%');
Source

pub const fn bottom_left(self, symb: char) -> Self

Sets the symbol for the bottom-left corner of the border.

§Parameters
  • symb: A char representing the symbol to be used in the bottom-left corner.
§Example
let border = GradientBlock::new().bottom_left('@');
Source

pub const fn bottom_horizontal_symbol(self, symb: char) -> Self

Sets the symbol for the bottom horizontal segment.

§Parameters
  • symb: A char representing the symbol to be used for the bottom horizontal border.
§Example
let border = GradientBlockr::new().bottom_horizontal_symbol('-');
Source

pub const fn top_horizontal_symbol(self, symb: char) -> Self

Sets the symbol for the top horizontal border segment.

§Parameters
  • symb: A char representing the symbol to be used for the top horizontal border.
§Example
let border = Border::new().top_horizontal_symbol('=');
Source

pub const fn right_vertical_symbol(self, symb: char) -> Self

Sets the symbol for the right vertical border segment.

§Parameters
  • symb: A char representing the symbol to be used for the right vertical border.
§Example
let border = GradientBlock::new().right_vertical_symbol('|');
Source

pub const fn left_vertical_symbol(self, symb: char) -> Self

Sets the left vertical border symbol.

§Example
let widget = GradientBlock::new().left_vertical_symbol('|');
Source

pub const fn top_center_symbol(self, symb: char) -> Self

Sets the top center border symbol.

§Example
let widget = GradientBlock::new().top_center_symbol('─');
Source

pub const fn bottom_center_symbol(self, symb: char) -> Self

Sets the bottom center border symbol.

§Example
let widget = GradientBlock::new().bottom_center_symbol('═');
Source

pub const fn left_center_symbol(self, symb: char) -> Self

Sets the left center vertical border symbol.

§Example
let widget = GradientBlock::new().left_center_symbol('+');
Source

pub const fn right_center_symbol(self, symb: char) -> Self

Sets the right center vertical border symbol.

§Example
let widget = GradientBlock::new().right_center_symbol('+');
Source

pub fn top_horizontal_right_symbol(self, symb: char) -> Self

Sets the top right horizontal border symbol.

§Example
let widget = GradientBlock::new().top_horizontal_right_symbol('┐');
Source

pub const fn bottom_horizontal_right_symbol(self, symb: char) -> Self

Sets the symbol used for the repeated section of the bottom horizontal border (right side).

§Example
let block = GradientBlock::new().bottom_horizontal_right_symbol('*');
Source

pub const fn top_horizontal_left_symbol(self, symb: char) -> Self

Sets the symbol for the top horizontal left connector.

§Example
let block = GradientBlock::new().top_horizontal_left_symbol('=');
Source

pub const fn bottom_horizontal_left_symbol(self, symb: char) -> Self

Sets the symbol for the bottom horizontal left connector.

§Example
let block = GradientBlock::new().bottom_horizontal_left_symbol('=');
Source

pub const fn top_vertical_right_symbol(self, symb: char) -> Self

Sets the symbol for the top vertical right connector.

§Example
let block = GradientBlock::new().top_vertical_right_symbol('|');
Source

pub const fn bottom_vertical_right_symbol(self, symb: char) -> Self

Sets the symbol for the bottom vertical right connector.

§Example
let block = GradientBlock::new().bottom_vertical_right_symbol('|');
Source

pub const fn top_vertical_left_symbol(self, symb: char) -> Self

Sets the symbol for the top vertical left connector.

§Example
let block = GradientBlock::new().top_vertical_left_symbol('|');
Source

pub fn with_set(self, set: SS) -> Self

Examples found in repository?
examples/basic_gradient.rs (line 30)
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
Hide additional examples
examples/themes/zombie_dreams.rs (line 28)
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}
examples/themes/misty_blue.rs (line 29)
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}
examples/themes/monochrome.rs (line 29)
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}
examples/themes/minty_green.rs (line 29)
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}
examples/themes/rusty_ruins.rs (line 29)
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}
Source

pub const fn bottom_vertical_left_symbol(self, symb: char) -> Self

Sets the symbol for the bottom vertical left connector.

§Example
let block = GradientBlock::new().bottom_vertical_left_symbol('|');
Source

pub fn fill<L: Into<Line<'a>>>(self, fill: L) -> Self

Source

pub fn fill_gradient<GR: Gradient>(self, gradient: GR) -> Self

Sets the fill gradient

§Example
let block = GradientBlock::new().fill_gradient(colorgrad::preset::warm());

Trait Implementations§

Source§

impl Default for GradientBlock<'_>

Source§

fn default() -> Self

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

impl Widget for GradientBlock<'_>

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Renders the Gradientblock widget using the main function.

Source§

impl WidgetRef for GradientBlock<'_>

Source§

fn render_ref(&self, area: R, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<'a> Freeze for GradientBlock<'a>

§

impl<'a> !RefUnwindSafe for GradientBlock<'a>

§

impl<'a> !Send for GradientBlock<'a>

§

impl<'a> !Sync for GradientBlock<'a>

§

impl<'a> Unpin for GradientBlock<'a>

§

impl<'a> !UnwindSafe for GradientBlock<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.