on 2158366 help sign in
41 lines 1.5 kB history raw
1use crate::compositor::{Component, Context};
2use helix_view::graphics::{Margin, Rect};
3use helix_view::info::Info;
4use tui::buffer::Buffer as Surface;
5use tui::widgets::{Block, Borders, Paragraph, Widget};
7impl Component for Info {
8 fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
9 let text_style = cx.editor.theme.get("ui.text.focus");
10 let popup_style = text_style.patch(cx.editor.theme.get("ui.popup"));
12 // Calculate the area of the terminal to modify. Because we want to
13 // render at the bottom right, we use the viewport's width and height
14 // which evaluate to the most bottom right coordinate.
15 let width = self.width + 2 + 2; // +2 for border, +2 for margin
16 let height = self.height + 2; // +2 for border
17 let area = viewport.intersection(Rect::new(
18 viewport.width.saturating_sub(width),
19 viewport.height.saturating_sub(height + 2), // +2 for statusline
20 width,
21 height,
22 ));
23 surface.clear_with(area, popup_style);
25 let block = Block::default()
26 .title(self.title.as_str())
27 .borders(Borders::ALL)
28 .border_style(popup_style);
30 let margin = Margin {
31 vertical: 0,
32 horizontal: 1,
33 };
34 let inner = block.inner(area).inner(&margin);
35 block.render(area, surface);
37 Paragraph::new(self.text.as_str())
38 .style(text_style)
39 .render(inner, surface);
40 }