Skip to content

Commit

Permalink
Simplify method
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Jan 2, 2024
1 parent 1990a8a commit 41ff565
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions CommonControls/Thumbnails.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,37 +356,7 @@ private void LoadImages()
ChkBox = new Dictionary<int, CheckBox>(pics.Count);
}

//Handle some special cases
if (ThumbCellSize == 0)
{
ThumbCellSize = 100;
}

if (ThumbHeight == 0 && ThumbWidth == 0)
{
ThumbHeight = 1;
}

//here we are especial clever, if we add the Height in the Designer we can generate a custom Length
//catch on reload
if (ThumbHeight * ThumbWidth < pics.Count)
{
if (ThumbWidth == 1)
{
ThumbHeight = pics.Count;
}

if (ThumbHeight == 1)
{
ThumbWidth = pics.Count;
}

if (ThumbHeight != 1 && ThumbWidth != 1 && pics.Count > 1)
{
var fraction = new ExtendedMath.Fraction(pics.Count, ThumbHeight);
ThumbWidth = (int)Math.Ceiling(fraction.Decimal);
}
}
CalculateGrid(pics.Count);

var exGrid = ExtendedGrid.ExtendGrid(ThumbWidth, ThumbHeight, ThumbGrid);
Thb.Children.Clear();
Expand Down Expand Up @@ -490,6 +460,40 @@ private void LoadImages()
Trace.WriteLine("End: " + timer.Elapsed);
}

/// <summary>
/// Calculates the grid.
/// </summary>
/// <param name="count">The count.</param>
private void CalculateGrid(int count)
{
//Handle some special cases
if (ThumbCellSize == 0) ThumbCellSize = 100;
if (ThumbHeight == 0 && ThumbWidth == 0) ThumbHeight = 1;

//here we are especial clever, if we add the Height in the Designer we can generate a custom Length
//catch on reload
if (ThumbHeight * ThumbWidth >= count)
{
return;
}

if (ThumbWidth == 1)
{
ThumbHeight = count;
}

if (ThumbHeight == 1)
{
ThumbWidth = count;
}

if (ThumbHeight != 1 && ThumbWidth != 1 && count > 1)
{
var fraction = new ExtendedMath.Fraction(count, ThumbHeight);
ThumbWidth = (int)Math.Ceiling(fraction.Decimal);
}
}

/// <summary>
/// Just some Method to Delegate click
/// </summary>
Expand Down

0 comments on commit 41ff565

Please sign in to comment.