mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
handle empty lines
This commit is contained in:
parent
ec08a9177e
commit
a9ef443c17
@ -373,7 +373,14 @@ impl GeomBatch {
|
||||
ctx.prerender.upload(self)
|
||||
}
|
||||
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.list.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn get_dims(&self) -> ScreenDims {
|
||||
if self.is_empty() {
|
||||
panic!("Can't get_dims of empty GeomBatch");
|
||||
}
|
||||
let mut bounds = Bounds::new();
|
||||
for (_, poly) in &self.list {
|
||||
bounds.union(poly.get_bounds());
|
||||
|
@ -364,6 +364,9 @@ impl Text {
|
||||
);
|
||||
}*/
|
||||
|
||||
// TODO Bad guess
|
||||
let empty_line_height = 30.0;
|
||||
|
||||
let mut y = top_left.y;
|
||||
let mut max_width = 0.0_f64;
|
||||
for (line_color, line) in self.lines {
|
||||
@ -371,13 +374,21 @@ impl Text {
|
||||
let mut line_batch = GeomBatch::new();
|
||||
for piece in line {
|
||||
let mini_batch = render_text(piece);
|
||||
let dims = mini_batch.get_dims();
|
||||
let dims = if mini_batch.is_empty() {
|
||||
ScreenDims::new(0.0, empty_line_height)
|
||||
} else {
|
||||
mini_batch.get_dims()
|
||||
};
|
||||
for (color, poly) in mini_batch.consume() {
|
||||
line_batch.push(color, poly.translate(x, y));
|
||||
}
|
||||
x += dims.width;
|
||||
}
|
||||
let line_dims = line_batch.get_dims();
|
||||
let line_dims = if line_batch.is_empty() {
|
||||
ScreenDims::new(0.0, empty_line_height)
|
||||
} else {
|
||||
line_batch.get_dims()
|
||||
};
|
||||
|
||||
if let Some(c) = line_color {
|
||||
master_batch.push(
|
||||
|
@ -34,7 +34,12 @@ impl Slider {
|
||||
main_bg_len: width,
|
||||
dragger_len,
|
||||
|
||||
draw: DrawBoth::new(ctx, GeomBatch::new(), Vec::new()),
|
||||
// Dummy value; empty GeomBatches can't be measured.
|
||||
draw: DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(Color::BLACK, Polygon::rectangle(1.0, 1.0))]),
|
||||
Vec::new(),
|
||||
),
|
||||
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
dims: ScreenDims::new(0.0, 0.0),
|
||||
@ -53,7 +58,12 @@ impl Slider {
|
||||
main_bg_len: height,
|
||||
dragger_len,
|
||||
|
||||
draw: DrawBoth::new(ctx, GeomBatch::new(), Vec::new()),
|
||||
// Dummy value; empty GeomBatches can't be measured.
|
||||
draw: DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(Color::BLACK, Polygon::rectangle(1.0, 1.0))]),
|
||||
Vec::new(),
|
||||
),
|
||||
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
dims: ScreenDims::new(0.0, 0.0),
|
||||
|
Loading…
Reference in New Issue
Block a user