Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/display_multiple_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
18 changes: 14 additions & 4 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use sdl2::{
surface::Surface,
video::{Window, WindowContext},
};
use std::cmp::min;

/// Displays the provided RGBA image in a new window.
///
Expand All @@ -23,15 +24,19 @@ pub fn display_image<I>(title: &str, image: &I, window_width: u32, window_height
where
I: GenericImageView + ConvertBuffer<RgbaImage>,
{
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<I>(title: &str, images: &[&I], window_width: u32, window_height: u32)
where
pub fn display_multiple_images<I>(
titles: &[&str],
images: &[&I],
window_width: u32,
window_height: u32,
) where
I: GenericImageView + ConvertBuffer<RgbaImage>,
{
if images.is_empty() {
Expand All @@ -49,7 +54,12 @@ where

let mut windows: Vec<Window> = Vec::with_capacity(images.len());
let mut window_visibility: Vec<bool> = 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()
Expand Down
Loading