#![cfg(feature = "testing")]
mod common;
use guido::prelude::*;
const SHAPES: usize = 600;
const CELL: f32 = 8.0;
const ACROSS: usize = 30;
fn grid() -> Container {
let mut rows = container().layout(Flex::column().spacing(0.0));
for r in 0..SHAPES.div_ceil(ACROSS) {
let mut row = container().layout(Flex::row().spacing(0.0));
for c in 0..ACROSS {
let i = r * ACROSS + c;
if i >= SHAPES {
break;
}
let last = i == SHAPES - 1;
row = row.child(container().width(CELL).height(CELL).background(if last {
Color::rgb(1.0, 0.0, 1.0)
} else {
Color::rgb(0.0, 0.3, 0.6)
}));
}
rows = rows.child(row);
}
rows
}
#[test]
fn the_shapes_past_the_buffers_first_size_are_still_drawn() {
let Some(mut app) = common::headless() else {
return;
};
let width = (ACROSS as f32 * CELL) as u32;
let height = (SHAPES.div_ceil(ACROSS) as f32 * CELL) as u32;
let config = SurfaceConfig::new()
.height(height)
.anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT);
let surface = app.surface(config, || {
container().width(fill()).height(fill()).child(grid())
});
app.configure(surface, width, height, 1.0);
app.step();
let last = SHAPES - 1;
let x = ((last % ACROSS) as f32 * CELL + CELL / 2.0) as u32;
let y = ((last / ACROSS) as f32 * CELL + CELL / 2.0) as u32;
let [r, g, b, _] = app.read_pixel(surface, x, y);
assert!(
r > 200 && g < 60 && b > 200,
"instance {last} of {SHAPES} is the magenta cell at ({x}, {y}) and it \
reads as ({r}, {g}, {b}) — the instance buffer grew past its first \
size and something is still reading the old one"
);
let [er, eg, eb, _] = app.read_pixel(surface, (CELL / 2.0) as u32, (CELL / 2.0) as u32);
assert!(
er < 60 && eg > 40 && eb > 100,
"the first cell should still be the ordinary blue, got ({er}, {eg}, {eb})"
);
}