on 2158366 help sign in
32 lines 955 B history raw
1use crate::compositor::{Component, Context};
2use tui::buffer::Buffer as Surface;
4use helix_view::graphics::Rect;
6pub struct Text {
7 contents: String,
8}
10impl Text {
11 pub fn new(contents: String) -> Self {
12 Self { contents }
13 }
15impl Component for Text {
16 fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
17 use tui::widgets::{Paragraph, Widget, Wrap};
18 let contents = tui::text::Text::from(self.contents.clone());
20 let par = Paragraph::new(contents).wrap(Wrap { trim: false });
21 // .scroll(x, y) offsets
23 par.render(area, surface);
24 }
26 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
27 let contents = tui::text::Text::from(self.contents.clone());
28 let width = std::cmp::min(contents.width() as u16, viewport.0);
29 let height = std::cmp::min(contents.height() as u16, viewport.1);
30 Some((width, height))
31 }