diff --git a/examples/display_multiple_images.rs b/examples/display_multiple_images.rs index 32dd7d61..70862d3d 100644 --- a/examples/display_multiple_images.rs +++ b/examples/display_multiple_images.rs @@ -31,7 +31,12 @@ fn main() { .expect("No image found at provided path") .to_rgba8(); - display_multiple_images("", &[&first_image, &second_image], 500, 500); + display_multiple_images( + &["first_image", "second_image"], + &[&first_image, &second_image], + 500, + 500, + ); } #[cfg(not(feature = "display-window"))] diff --git a/src/window.rs b/src/window.rs index 0b6119d3..bc22254c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -14,6 +14,7 @@ use sdl2::{ surface::Surface, video::{Window, WindowContext}, }; +use std::cmp::min; /// Displays the provided RGBA image in a new window. /// @@ -23,15 +24,19 @@ pub fn display_image(title: &str, image: &I, window_width: u32, window_height where I: GenericImageView + ConvertBuffer, { - display_multiple_images(title, &[image], window_width, window_height); + display_multiple_images(&[title], &[image], window_width, window_height); } /// Displays the provided RGBA images in new windows. /// /// The minimum window width or height is 150 pixels - input values less than this /// will be rounded up to the minimum. -pub fn display_multiple_images(title: &str, images: &[&I], window_width: u32, window_height: u32) -where +pub fn display_multiple_images( + titles: &[&str], + images: &[&I], + window_width: u32, + window_height: u32, +) where I: GenericImageView + ConvertBuffer, { if images.is_empty() { @@ -49,7 +54,12 @@ where let mut windows: Vec = Vec::with_capacity(images.len()); let mut window_visibility: Vec = Vec::with_capacity(images.len()); - for _ in 0..images.len() { + for i in 0..images.len() { + let title = if titles.is_empty() { + "" + } else { + titles[min(i, titles.len() - 1)] + }; let mut window = video_subsystem .window(title, window_width, window_height) .resizable()