use super::oneshot;
use super::test_application::{run, run_async, PER_ASSEMBLY};
use crate::HeadlessWindowExtensions;
use ferroui_base::input::{MouseButton, RawInputModifiers};
use ferroui_base::layout::{HorizontalAlignment, VerticalAlignment};
use ferroui_base::media::Brushes;
use ferroui_base::rendering::composition::ElementComposition;
use ferroui_base::threading::Dispatcher;
use ferroui_base::Point;
use ferroui_controls::{Button, ContentControl, Control, SizeToContent, Window};
fn show_use_and_close_a_window() {
let window = Window::new();
let button = Button::new();
window.set_content(Some(Control::boxed(button.clone())));
window.show();
button.focus();
window.mouse_down(Point::new(1.0, 1.0), MouseButton::Left, RawInputModifiers::NONE);
window.close();
}
async fn show_a_window_and_take_a_snapshot() {
let content_control = ContentControl::new();
content_control.set_horizontal_alignment(HorizontalAlignment::Stretch);
content_control.set_vertical_alignment(VerticalAlignment::Stretch);
content_control.set_width(100.0);
content_control.set_height(100.0);
content_control.set_background(Some(Brushes::green()));
let window = Window::new();
window.set_content(Some(Control::boxed(content_control)));
window.set_size_to_content(SizeToContent::WIDTH_AND_HEIGHT);
window.show();
Dispatcher::ui_thread().run_jobs(None);
let composition_visual = ElementComposition::get_element_visual(&window).unwrap();
assert!(composition_visual.root().is_some(), "the composition visual of the window is attached to its target");
let task = composition_visual.compositor().create_composition_visual_snapshot(&composition_visual, 1.0);
let (completed, completion) = oneshot();
task.on_completed(move || completed.send(()));
completion.await;
let snapshot = task.take_result().expect("the outcome of the snapshot").expect("the snapshot");
assert_eq!(100.0, snapshot.size().width);
assert_eq!(100.0, snapshot.size().height);
}
#[test]
fn a_test_after_one_that_closed_a_window_composes_its_own_window() {
for _ in 0..5 {
run(&PER_ASSEMBLY, show_use_and_close_a_window);
run_async(&PER_ASSEMBLY, show_a_window_and_take_a_snapshot);
}
}