Added SupportWrap property

This commit is contained in:
Jaex 2022-03-17 10:52:44 +03:00
parent 0c035baf0e
commit 3c68d36b1c

View file

@ -35,6 +35,7 @@ public class ImageViewer : Form
public Image CurrentImage { get; private set; }
public string CurrentImageFilePath { get; private set; }
public bool SupportImageNavigation => Images != null && Images.Length > 0;
public bool SupportWrap { get; set; }
public string[] Images { get; private set; }
public int CurrentImageIndex { get; private set; }
@ -81,15 +82,20 @@ private void NavigateImage(int position)
int nextImageIndex = CurrentImageIndex + position;
if (nextImageIndex > Images.Length - 1)
if (SupportWrap)
{
nextImageIndex = 0;
}
else if (nextImageIndex < 0)
{
nextImageIndex = Images.Length - 1;
if (nextImageIndex > Images.Length - 1)
{
nextImageIndex = 0;
}
else if (nextImageIndex < 0)
{
nextImageIndex = Images.Length - 1;
}
}
nextImageIndex = nextImageIndex.Clamp(0, Images.Length - 1);
if (CurrentImageIndex != nextImageIndex)
{
CurrentImageIndex = nextImageIndex;