make text entry work when empty

This commit is contained in:
Dustin Carlino 2019-01-24 11:04:56 -08:00
parent 9182a57af5
commit 46c07dc57a
3 changed files with 7 additions and 5 deletions

View File

@ -68,6 +68,7 @@
- speed
- make polygon store points and indices efficiently
- change ezgui API to allow uploading geometry once
- experiment with batching and not passing colors
- measure performance of huge maps
- quality
- need padding around text

View File

@ -128,14 +128,15 @@ impl Text {
so_far.push_str(&span.text);
so_far
});
// Empty lines or whitespace-only lines effectively have 0 width.
glyphs
.pixel_bounds(Section {
text: &full_line,
scale: Scale::uniform(FONT_SIZE),
..Section::default()
})
.expect("can't get text dims of a whitespace-only span")
.width()
.map(|rect| rect.width())
.unwrap_or(0)
})
.max()
.unwrap() as f64;

View File

@ -28,12 +28,12 @@ impl TextBox {
txt.add_line(self.line[0..self.cursor_x].to_string());
if self.cursor_x < self.line.len() {
// TODO This bit was highlighted
// TODO This "cursor" looks awful!
txt.append("|".to_string(), Some(text::SELECTED_COLOR));
txt.append(self.line[self.cursor_x..=self.cursor_x].to_string(), None);
txt.append(self.line[self.cursor_x + 1..].to_string(), None);
} else {
// TODO This bit was highlighted
txt.append(" ".to_string(), None);
txt.append("|".to_string(), Some(text::SELECTED_COLOR));
}
canvas.draw_blocking_text(g, txt, CENTERED);