| 1 |
use crate::compositor::{Component, Context}; |
| 2 |
use helix_view::graphics::{Margin, Rect}; |
| 3 |
use helix_view::info::Info; |
| 4 |
use tui::buffer::Buffer as Surface; |
| 5 |
use tui::text::Text; |
| 6 |
use tui::widgets::{Block, Paragraph, Widget}; |
| 7 |
|
| 8 |
impl Component for Info { |
| 9 |
fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { |
| 10 |
let text_style = cx.editor.theme.get("ui.text.info"); |
| 11 |
let popup_style = cx.editor.theme.get("ui.popup.info"); |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
let width = self.width + 2 + 2; |
| 17 |
let height = self.height + 2; |
| 18 |
let area = viewport.intersection(Rect::new( |
| 19 |
viewport.width.saturating_sub(width), |
| 20 |
viewport.height.saturating_sub(height + 2), |
| 21 |
width, |
| 22 |
height, |
| 23 |
)); |
| 24 |
surface.clear_with(area, popup_style); |
| 25 |
|
| 26 |
let block = Block::bordered() |
| 27 |
.title(self.title.as_ref()) |
| 28 |
.border_style(popup_style); |
| 29 |
|
| 30 |
let margin = Margin::horizontal(1); |
| 31 |
let inner = block.inner(area).inner(margin); |
| 32 |
block.render(area, surface); |
| 33 |
|
| 34 |
Paragraph::new(&Text::from(self.text.as_str())) |
| 35 |
.style(text_style) |
| 36 |
.render(inner, surface); |
| 37 |
} |
| 38 |
} |