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 - speed
- make polygon store points and indices efficiently - make polygon store points and indices efficiently
- change ezgui API to allow uploading geometry once - change ezgui API to allow uploading geometry once
- experiment with batching and not passing colors
- measure performance of huge maps - measure performance of huge maps
- quality - quality
- need padding around text - need padding around text

View File

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

View File

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