Last Updated: February 25, 2016
·
202
· cpsing

pager

private static int[] CalculatePagerInfo(int currentPage, int totalPages)
{
var right = totalPages - currentPage;

    var left = currentPage - 1;

    int rightx =0 , leftx = 0;


    if (right >= 4)
    {
        if (left >= 4)
        {
            rightx = leftx = 4;
        }
        else
        {
            leftx = left;
            rightx = leftx == 0 ? Math.Min(right, 8 - leftx) : Math.Min(right, 9 - leftx);
        }
    }
    else
    {
        rightx = right;
        leftx = rightx == 0 ? Math.Min(8 - rightx, left) : Math.Min(9 - rightx, left);
    }

    return new int[] { leftx, rightx };
}