Fix TextView size computation

We weren't counting spaces.
This commit is contained in:
Alexandre Bury 2015-05-23 20:12:11 -07:00
parent 488443081d
commit e79207ac6e
3 changed files with 5 additions and 4 deletions

View File

@ -7,5 +7,3 @@ Praesent iaculis enim id eros consectetur venenatis. Nunc malesuada faucibus luc
Sed consectetur imperdiet augue et consectetur. Aliquam rhoncus nisl et mi lobortis ultricies. Fusce pretium mi nibh, in maximus nunc porta et. Morbi maximus elit vel egestas sagittis. Pellentesque egestas vehicula augue. Quisque ornare placerat ante, non vulputate nisl placerat commodo. Nam sit amet eros placerat, varius diam a, bibendum sem. Mauris orci leo, dapibus nec sapien eu, finibus hendrerit erat. Duis et neque diam. Vivamus nec ultrices ipsum. In hac habitasse platea dictumst. Fusce vel eros sit amet velit sollicitudin eleifend vitae et nunc.
Donec elementum pharetra elit, quis finibus ante dictum et. Vivamus tristique dignissim nulla. Ut dignissim tincidunt elementum. Nullam pellentesque turpis sapien, iaculis sagittis arcu mollis nec. Pellentesque quis vehicula urna. Aenean pretium eget ex vitae interdum. Phasellus pharetra magna id vehicula cursus. Vivamus egestas id nulla et lacinia. Donec congue at eros volutpat tristique. Donec mi tortor, commodo a nisl sed, vulputate malesuada velit. Morbi sed sagittis odio. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia auctor dapibus. Quisque sagittis odio vel urna laoreet ultrices.

View File

@ -24,7 +24,9 @@ impl Printer {
/// Prints some text at the given position relative to the window.
pub fn print<S: ToVec2>(&self, pos: S, text: &str) {
let p = pos.to_vec2() + self.offset;
let mut p = pos.to_vec2();
if p.y >= self.size.y { return; }
p = p + self.offset;
ncurses::mvprintw(p.y as i32, p.x as i32, text);
}

View File

@ -17,10 +17,11 @@ fn get_line_span(line: &str, max_width: usize) -> usize {
let mut length = 0;
for l in line.split(" ").map(|word| word.len()) {
length += l;
if length > max_width {
if length >= max_width {
length = l;
lines += 1;
}
length += 1;
}
lines
}