use cranpose_ui_graphics::{
GraphicsLayer, Point, RUNTIME_SHADER_PRELUDE_WGSL, RenderEffect, RuntimeShader,
};
use support::clip_band::{self, FRAME};
use crate::support;
const SHOWN: Point = Point { x: 40.0, y: 10.0 };
const SCROLLED_OUT: Point = Point { x: 40.0, y: -140.0 };
fn red_backdrop() -> RenderEffect {
RenderEffect::runtime_shader(RuntimeShader::new(&format!(
"{RUNTIME_SHADER_PRELUDE_WGSL}
@fragment fn effect_fs(input: VertexOutput) -> @location(0) vec4<f32> {{
return vec4<f32>(0.86, 0.12, 0.12, 1.0);
}}"
)))
}
fn glass() -> GraphicsLayer {
GraphicsLayer {
clip: true,
backdrop_effect: Some(red_backdrop()),
..GraphicsLayer::default()
}
}
#[test]
fn a_glass_control_scrolled_out_of_its_list_paints_nothing() {
let mut renderer = match support::headless_renderer() {
Ok(renderer) => renderer,
Err(err) => {
eprintln!("skipping clipped out layer: {err}");
return;
}
};
let shown = support::capture_graph(
&mut renderer,
clip_band::page(glass(), SHOWN, vec![]),
FRAME,
FRAME,
);
let (_, inside) = clip_band::red_pixels(&shown.pixels);
assert!(
inside > 1000,
"the glass control must paint inside the band when it is on show for this to test \
anything, painted {inside} pixels"
);
let scrolled = support::capture_graph(
&mut renderer,
clip_band::page(glass(), SCROLLED_OUT, vec![]),
FRAME,
FRAME,
);
let (above, inside) = clip_band::red_pixels(&scrolled.pixels);
assert_eq!(
(above, inside),
(0, 0),
"a glass control scrolled out of its list painted {above} pixels above the list and \
{inside} inside it"
);
}