use waft_embedder::Image;
use waft_foundation::App;
use crate::AnyElement;
pub fn capture_image(app: &mut App, element: AnyElement) -> Option<Image> {
let mut boundary = element
.render_object(app)
.expect("the element has a render object");
while !boundary.is_repaint_boundary(app) {
boundary = boundary
.parent(app)
.expect("a repaint boundary at or above the element");
}
debug_assert!(!boundary.debug_needs_paint(app), "the element is painted");
let layer = boundary
.layer(app)
.and_then(|layer| layer.as_offset_layer())
.expect("a repaint boundary's layer is an offset layer");
let bounds = boundary.paint_bounds(app);
let picture = layer.to_picture(app, bounds, 1.0);
let width = bounds.width().ceil() as u32;
let height = bounds.height().ceil() as u32;
app.platform()
.picture_to_image_sync(&picture, width, height)
}