fuck it, center it

pull/6/head
dvkt 5 years ago
parent c273c67087
commit f79fd90b81

@ -56,7 +56,7 @@ impl MenuView {
self.menu.links()
}
fn render_lines(&self, _cols: u16, rows: u16) -> String {
fn render_lines(&self, cols: u16, rows: u16) -> String {
let mut out = String::new();
macro_rules! push {
@ -75,7 +75,14 @@ impl MenuView {
.skip(self.scroll as usize)
.take(rows as usize - 1);
let indent = if self.menu.longest > cols as usize {
String::from("")
} else {
" ".repeat(((cols as usize - self.menu.longest) / 2) - 6)
};
for line in iter {
out.push_str(&indent);
if line.typ == Type::Info {
out.push_str(" ");
} else {
@ -318,8 +325,8 @@ impl Menu {
}
let link = if typ == Type::Info { 0 } else { link };
if line.len() > longest {
longest = line.len();
if name.len() > longest {
longest = name.len();
}
lines.push(Line {

@ -67,15 +67,21 @@ impl View for TextView {
}
}
fn render(&self, _cols: u16, rows: u16) -> String {
fn render(&self, cols: u16, rows: u16) -> String {
let mut out = String::new();
for (i, line) in self.raw.split_terminator('\n').enumerate() {
if i as isize > (self.scroll + rows as isize) - 2 {
break;
}
if i < self.scroll as usize {
continue;
}
let indent = if self.longest > cols as usize {
String::from("")
} else {
" ".repeat((cols as usize - self.longest) / 2)
};
let iter = self
.raw
.split_terminator('\n')
.skip(self.scroll as usize)
.take(rows as usize - 1);
for line in iter {
out.push_str(&indent);
out.push_str(line);
out.push('\n');
}

Loading…
Cancel
Save