Draw Drawables in reverse order

This commit is contained in:
Richard Feldman 2022-02-23 08:14:14 -05:00
parent 380f367530
commit e5b4133a8e
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -431,8 +431,8 @@ struct Drawable {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum DrawableContent { enum DrawableContent {
/// This stores an actual Section because an earlier step needs to know /// This stores an actual Section because an earlier step needs to know the bounds of
/// the bounds of the text, and making a Section is a convenient way to compute them. /// the text, and making a Section is a convenient way to compute those bounds.
Text(OwnedSection), Text(OwnedSection),
FillRect, FillRect,
// Row(Vec<(Vector2<f32>, Drawable)>), // Row(Vec<(Vector2<f32>, Drawable)>),
@ -455,7 +455,10 @@ fn process_drawables(
// calling draw and updating boiunding boxes // calling draw and updating boiunding boxes
let pos: Vector2<f32> = (0.0, 0.0).into(); let pos: Vector2<f32> = (0.0, 0.0).into();
for drawable in drawables.into_iter() { // Draw these in reverse order, since when traversing the tree, we added them in the
// opposite order from how they should be rendered. (If we didn't reverse here, then
// for example we would draw children and then their parents, which wouldn't go well.)
for drawable in drawables.into_iter().rev() {
draw( draw(
drawable.bounds, drawable.bounds,
drawable.content, drawable.content,
@ -510,7 +513,7 @@ fn draw(
width: bounds.width, width: bounds.width,
height: bounds.height, height: bounds.height,
}, },
color: (0.2, 0.2, 0.5, 0.5), color: (0.2, 0.2, 0.5, 1.0),
border_width: 10.0, border_width: 10.0,
border_color: (0.2, 0.5, 0.5, 1.0), border_color: (0.2, 0.5, 0.5, 1.0),
}; };