示例#1
0
        private void Populate()
        {
            Vector2 stageSize = NUIApplication.GetDefaultWindow().WindowSize;

            mTotalPages = (uint)((mExampleList.Count() + EXAMPLES_PER_PAGE - 1) / EXAMPLES_PER_PAGE);

            // Populate ScrollView.
            if (mExampleList.Count() > 0)
            {
                if (mSortAlphabetically)
                {
                    mExampleList.Sort(Example.CompareByTitle);
                }

                int pageCount = mExampleList.Count / (ROWS_PER_PAGE * EXAMPLES_PER_ROW) + ((0 == mExampleList.Count % (ROWS_PER_PAGE * EXAMPLES_PER_ROW)) ? 0 : 1);
                mPages = new View[pageCount];

                int pageIndex = 0;

                uint exampleCount = 0;

                for (int t = 0; t < mTotalPages; t++)
                {
                    // Create Table
                    TableView page = new TableView(ROWS_PER_PAGE, EXAMPLES_PER_ROW);
                    page.PositionUsesPivotPoint = true;
                    page.PivotPoint             = PivotPoint.Center;
                    page.ParentOrigin           = ParentOrigin.Center;
                    page.WidthResizePolicy      = page.HeightResizePolicy = ResizePolicyType.FillToParent;
                    mScrollView.Add(page);

                    // Calculate the number of images going across (columns) within a page, according to the screen resolution and dpi.
                    const float margin = 2.0f;
                    const float tileParentMultiplier = 1.0f / EXAMPLES_PER_ROW;

                    for (uint row = 0; row < ROWS_PER_PAGE; row++)
                    {
                        for (uint column = 0; column < EXAMPLES_PER_ROW; column++)
                        {
                            Example example = mExampleList.ElementAt((int)exampleCount++);

                            // Calculate the tiles relative position on the page (between 0 & 1 in each dimension).
                            Vector2 position = new Vector2((float)(column) / (EXAMPLES_PER_ROW - 1.0f), (float)(row) / (EXAMPLES_PER_ROW - 1.0f));
                            View    tile     = CreateTile(example.Name, example.Title, new Vector3(tileParentMultiplier, tileParentMultiplier, 1.0f), position);

                            tile.SetPadding(new PaddingType((int)margin, (int)margin, (int)margin, (int)margin));
                            page.AddChild(tile, new TableView.CellPosition(row, column));

                            tiles.Add(tile);

                            if (exampleCount == mExampleList.Count)
                            {
                                break;
                            }
                        }

                        if (exampleCount == mExampleList.Count)
                        {
                            break;
                        }
                    }

                    mPages[pageIndex++] = page;

                    if (exampleCount == mExampleList.Count)
                    {
                        break;
                    }
                }
            }

            // Update Ruler info.
            mScrollRulerX = new RulerPtr(new FixedRuler(mPageWidth));
            mScrollRulerY = new RulerPtr(new DefaultRuler());
            mScrollRulerX.SetDomain(new RulerDomain(0.0f, (mTotalPages + 1) * stageSize.Width * TABLE_RELATIVE_SIZE.X * 0.5f, true));
            mScrollRulerY.Disable();
            mScrollView.SetRulerX(mScrollRulerX);
            mScrollView.SetRulerY(mScrollRulerY);
        }
示例#2
0
 public void AddExample(Example example)
 {
     mExampleList.Add(example);
 }
示例#3
0
 static public int CompareByTitle(Example lhs, Example rhs)
 {
     return(String.Compare(lhs.title, lhs.title));
 }