summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/text.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-12-09 02:28:53 +0000
committerBlaž Hrastnik2021-12-09 02:28:53 +0000
commitdf3b88387b311e16b3af3771c3870b2ea0235c95 (patch)
treec6096da01150ede81dc652eb4458f2a6319861ea /helix-term/src/ui/text.rs
parentdac317e620f227611e8c572125b0572ece4043c4 (diff)
dap: Improve variables UI
Diffstat (limited to 'helix-term/src/ui/text.rs')
-rw-r--r--helix-term/src/ui/text.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs
index 4641fae1..caece049 100644
--- a/helix-term/src/ui/text.rs
+++ b/helix-term/src/ui/text.rs
@@ -4,7 +4,7 @@ use tui::buffer::Buffer as Surface;
use helix_view::graphics::Rect;
pub struct Text {
- contents: String,
+ contents: tui::text::Text<'static>,
size: (u16, u16),
viewport: (u16, u16),
}
@@ -12,18 +12,28 @@ pub struct Text {
impl Text {
pub fn new(contents: String) -> Self {
Self {
+ contents: tui::text::Text::from(contents),
+ size: (0, 0),
+ viewport: (0, 0),
+ }
+ }
+}
+
+impl From<tui::text::Text<'static>> for Text {
+ fn from(contents: tui::text::Text<'static>) -> Self {
+ Self {
contents,
size: (0, 0),
viewport: (0, 0),
}
}
}
+
impl Component for Text {
fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
use tui::widgets::{Paragraph, Widget, Wrap};
- let contents = tui::text::Text::from(self.contents.clone());
- let par = Paragraph::new(contents).wrap(Wrap { trim: false });
+ let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false });
// .scroll(x, y) offsets
par.render(area, surface);
@@ -31,9 +41,8 @@ impl Component for Text {
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
if viewport != self.viewport {
- let contents = tui::text::Text::from(self.contents.clone());
- let width = std::cmp::min(contents.width() as u16, viewport.0);
- let height = std::cmp::min(contents.height() as u16, viewport.1);
+ let width = std::cmp::min(self.contents.width() as u16, viewport.0);
+ let height = std::cmp::min(self.contents.height() as u16, viewport.1);
self.size = (width, height);
self.viewport = viewport;
}