mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-09 10:50:40 +00:00
Fix text view size with multiline content
This commit is contained in:
parent
74f0fee9b6
commit
0302e74063
@ -1,3 +1,5 @@
|
||||
use std::cmp;
|
||||
|
||||
use vec2::Vec2;
|
||||
use view::{View,DimensionRequest,SizeRequest};
|
||||
use div::*;
|
||||
@ -44,6 +46,18 @@ impl TextView {
|
||||
.find(|w| self.get_num_lines(*w) <= max_height)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_ideal_size(&self) -> Vec2 {
|
||||
let mut maxWidth = 0;
|
||||
let mut height = 0;
|
||||
|
||||
for line in self.content.split("\n") {
|
||||
height += 1;
|
||||
maxWidth = cmp::max(maxWidth, line.len() as u32);
|
||||
}
|
||||
|
||||
Vec2::new(maxWidth, height)
|
||||
}
|
||||
}
|
||||
|
||||
struct LinesIterator<'a> {
|
||||
@ -119,8 +133,10 @@ impl View for TextView {
|
||||
Vec2::new(w, h)
|
||||
},
|
||||
(DimensionRequest::AtMost(w),_) => {
|
||||
if w >= self.content.len() as u32 {
|
||||
Vec2::new(self.content.len() as u32, 1)
|
||||
let ideal = self.get_ideal_size();
|
||||
|
||||
if w >= ideal.x {
|
||||
ideal
|
||||
} else {
|
||||
let h = self.get_num_lines(w as usize) as u32;
|
||||
Vec2::new(w, h)
|
||||
|
Loading…
Reference in New Issue
Block a user