summaryrefslogtreecommitdiffstats
path: root/src/canvas.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-08-16 01:25:59 -0700
committerGitHub <noreply@github.com>2020-08-16 04:25:59 -0400
commit08e49b63c162f16cb35262cd48da324c779c1a1c (patch)
tree446d654cb60cbd0475b193b6e28900bad46c88e8 /src/canvas.rs
parent9068108d0fe977ec6fc01dc7d8d29674a88c2f6a (diff)
refactor: Revert tui upgrade to 0.10
Reverts tui upgrade, there are some bugs and issues - namely, issues with rendering text. We can revert this commit when those bugs are dealt with (should be fine after 0.10.1, tested building from the repo).
Diffstat (limited to 'src/canvas.rs')
-rw-r--r--src/canvas.rs79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/canvas.rs b/src/canvas.rs
index 8ff9c31b..563651b8 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -4,7 +4,7 @@ use std::collections::HashMap;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
- text::{Span, Spans},
+ widgets::Text,
Frame, Terminal,
};
@@ -55,7 +55,7 @@ pub struct Painter {
pub colours: CanvasColours,
height: u16,
width: u16,
- styled_help_text: Vec<Spans<'static>>,
+ styled_help_text: Vec<Text<'static>>,
is_mac_os: bool,
row_constraints: Vec<Constraint>,
col_constraints: Vec<Vec<Constraint>>,
@@ -163,27 +163,28 @@ impl Painter {
styled_help_spans.extend(
section
.iter()
- .map(|&text| Span::styled(text, self.colours.text_style))
+ .map(|&text| Text::styled(text, self.colours.text_style))
.collect::<Vec<_>>(),
);
} else {
// Not required check but it runs only a few times... so whatever ig, prevents me from
// being dumb and leaving a help text section only one line long.
if section.len() > 1 {
- styled_help_spans.push(Span::from(""));
+ styled_help_spans.push(Text::raw("\n\n"));
styled_help_spans
- .push(Span::styled(section[0], self.colours.table_header_style));
+ .push(Text::styled(section[0], self.colours.table_header_style));
styled_help_spans.extend(
section[1..]
.iter()
- .map(|&text| Span::styled(text, self.colours.text_style))
+ .map(|&text| Text::styled(text, self.colours.text_style))
.collect::<Vec<_>>(),
);
}
}
});
- self.styled_help_text = styled_help_spans.into_iter().map(Spans::from).collect();
+ // self.styled_help_text = styled_help_spans.into_iter().map(Spans::from).collect();
+ self.styled_help_text = styled_help_spans;
}
pub fn draw_data<B: Backend>(
@@ -251,36 +252,44 @@ impl Painter {
let dd_text = self.get_dd_spans(app_state);
- let (text_width, text_height) = if let Some(dd_text) = &dd_text {
- let width = if f.size().width < 100 {
+ let (text_width, text_height) = (
+ if f.size().width < 100 {
f.size().width * 90 / 100
} else {
- let min_possible_width = (f.size().width * 50 / 100) as usize;
- let mut width = dd_text.width();
-
- // This should theoretically never allow width to be 0... we can be safe and do an extra check though.
- while width > (f.size().width as usize) && width / 2 > min_possible_width {
- width /= 2;
- }
-
- std::cmp::max(width, min_possible_width) as u16
- };
-
- (
- width,
- (dd_text.height() + 2 + (dd_text.width() / width as usize)) as u16,
- )
- } else {
- // AFAIK this shouldn't happen, unless something went wrong...
- (
- if f.size().width < 100 {
- f.size().width * 90 / 100
- } else {
- f.size().width * 50 / 100
- },
- 7,
- )
- };
+ f.size().width * 50 / 100
+ },
+ 7,
+ );
+ // let (text_width, text_height) = if let Some(dd_text) = &dd_text {
+ // let width = if f.size().width < 100 {
+ // f.size().width * 90 / 100
+ // } else {
+ // let min_possible_width = (f.size().width * 50 / 100) as usize;
+ // let mut width = dd_text.width();
+
+ // // This should theoretically never allow width to be 0... we can be safe and do an extra check though.
+ // while width > (f.size().width as usize) && width / 2 > min_possible_width {
+ // width /= 2;
+ // }
+
+ // std::cmp::max(width, min_possible_width) as u16
+ // };
+
+ // (
+ // width,
+ // (dd_text.height() + 2 + (dd_text.width() / width as usize)) as u16,
+ // )
+ // } else {
+ // // AFAIK this shouldn't happen, unless something went wrong...
+ // (
+ // if f.size().width < 100 {
+ // f.size().width * 90 / 100
+ // } else {
+ // f.size().width * 50 / 100
+ // },
+ // 7,
+ // )
+ // };
let vertical_bordering = f.size().height.saturating_sub(text_height) / 2;
let vertical_dialog_chunk = Layout::default()