2021-03-02 10:24:24 +01:00
|
|
|
use crate::compositor::{Component, Compositor, Context, EventResult};
|
|
|
|
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
|
|
|
use tui::{
|
2021-03-22 04:40:07 +01:00
|
|
|
buffer::Buffer as Surface,
|
2021-03-02 10:24:24 +01:00
|
|
|
layout::Rect,
|
|
|
|
style::{Color, Style},
|
|
|
|
};
|
|
|
|
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
use helix_core::Position;
|
|
|
|
use helix_view::Editor;
|
|
|
|
|
|
|
|
pub struct Text {
|
|
|
|
contents: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Text {
|
|
|
|
pub fn new(contents: String) -> Self {
|
|
|
|
Self { contents }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Component for Text {
|
|
|
|
fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
|
|
|
use tui::widgets::{Paragraph, Widget, Wrap};
|
|
|
|
let contents = tui::text::Text::from(self.contents.clone());
|
|
|
|
|
2021-05-07 10:38:25 +02:00
|
|
|
let style = cx.editor.theme.get("ui.text");
|
2021-03-02 10:24:24 +01:00
|
|
|
|
|
|
|
let par = Paragraph::new(contents).wrap(Wrap { trim: false });
|
|
|
|
// .scroll(x, y) offsets
|
|
|
|
|
|
|
|
par.render(area, surface);
|
|
|
|
}
|
|
|
|
|
2021-03-08 09:00:32 +01:00
|
|
|
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
|
2021-03-02 10:24:24 +01:00
|
|
|
let contents = tui::text::Text::from(self.contents.clone());
|
2021-03-08 09:00:32 +01:00
|
|
|
let width = std::cmp::min(contents.width() as u16, viewport.0);
|
|
|
|
let height = std::cmp::min(contents.height() as u16, viewport.1);
|
|
|
|
Some((width, height))
|
2021-03-02 10:24:24 +01:00
|
|
|
}
|
|
|
|
}
|