Invalidate TextView cache on content change

This commit is contained in:
Alexandre Bury 2016-07-09 18:26:52 -07:00
parent 2860467f29
commit 455a2a817c

View File

@ -96,6 +96,7 @@ impl TextView {
pub fn set_content(&mut self, content: &str) { pub fn set_content(&mut self, content: &str) {
let content = strip_last_newline(content); let content = strip_last_newline(content);
self.content = content.to_string(); self.content = content.to_string();
self.invalidate();
} }
/// Returns the current text in this view. /// Returns the current text in this view.
@ -153,6 +154,11 @@ impl TextView {
self.last_size = Some(size); self.last_size = Some(size);
} }
} }
// Invalidates the cache, so next call will recompute everything.
fn invalidate(&mut self) {
self.last_size = None;
}
} }
// Given a multiline string, and a given maximum width, // Given a multiline string, and a given maximum width,