public override bool Layout(List <IDataRogueControlRenderer> controlRenderers, ISystemContainer systemContainer, object handle, List <MapCoordinate> playerFov, Rectangle boundingBox) { if (!Initialised) { InitialiseControls(); } Controls = new List <IDataRogueControl> { LeftSelector, RightSelector }; var internalBoundingBox = boundingBox.PadIn(Margin).PadIn(Padding); // First assign space for the paging text, if it turns out to be necessary. PagingText.Layout(controlRenderers, systemContainer, handle, playerFov, internalBoundingBox); var spaceForMenuItems = new Rectangle(internalBoundingBox.Location, new Size(internalBoundingBox.Width, internalBoundingBox.Height - PagingText.LayoutPosition.Height)); // Find the size of a test menu item. Use this to work out how many pages you need. We assume we're always laying this out vertically. var testMenuItem = MenuItems.First(); testMenuItem.Layout(controlRenderers, systemContainer, handle, playerFov, spaceForMenuItems); var itemHeight = testMenuItem.LayoutPosition.Height; var itemCount = MenuItems.Count(); var itemsPerPage = spaceForMenuItems.Height / itemHeight; var totalPages = (+itemsPerPage - 1) / itemsPerPage; var selectedItemIndex = MenuItems.IndexOf(SelectedItem); var page = selectedItemIndex / itemsPerPage; // Find what page the selected item is on, and layout those items. for (int i = 0; i < itemsPerPage; i++) { var displayIndex = page * itemsPerPage + i; if (displayIndex < itemCount) { MenuItem item = MenuItems[displayIndex]; item.Layout(controlRenderers, systemContainer, handle, playerFov, spaceForMenuItems); Controls.Add(item); spaceForMenuItems = spaceForMenuItems.ShrinkFromTop(item.LayoutPosition.Height); } } // If page count > 1, add the page text. Otherwise make sure it's not in Controls. if (totalPages > 1) { var pageTextPosition = new Rectangle(internalBoundingBox.Left, spaceForMenuItems.Bottom, internalBoundingBox.Width, internalBoundingBox.Bottom - spaceForMenuItems.Bottom); PagingText.Layout(controlRenderers, systemContainer, handle, playerFov, pageTextPosition); Controls.Add(PagingText); } if (ShrinkToContents) { CalculateOwnPosition(boundingBox); } ApplyAlignmentToContents(internalBoundingBox); if (ShrinkToContents) { CalculateOwnPosition(boundingBox); } // Place the MenuSelectorControls arond the selected item. PlaceSelectorControls(controlRenderers, systemContainer, handle, playerFov, boundingBox); return(false); }