Пример #1
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            // Sync child elements to the current group items
            SyncChildrenToRibbonGroupItems();

            // Clear down the cache of item sizes
            _sizeList.Clear();
            _viewList.Clear();
            _viewToGap.Clear();

            int      totalWidth    = 0;
            ViewBase previousChild = null;

            // Find the size of each individual visible child item
            for (int i = 0; i < this.Count; i++)
            {
                ViewBase child = this[i];

                // Only interested in visible items
                if (child.Visible)
                {
                    // Are we positioning a cluster?
                    if (child is ViewLayoutRibbonGroupCluster)
                    {
                        // Inform cluster if it is immediatley after another cluster (and so potentially needs a separator)
                        ViewLayoutRibbonGroupCluster clusterChild = (ViewLayoutRibbonGroupCluster)child;
                        clusterChild.StartSeparator = (previousChild != null) && !(previousChild is ViewLayoutRibbonGroupCluster);
                        clusterChild.EndSeparator   = true;
                    }

                    // Can we calculate the spacing gap between the previous and this item
                    if (previousChild != null)
                    {
                        if (_viewToItem.ContainsKey(child) &&
                            _viewToItem.ContainsKey(previousChild))
                        {
                            // Cast to correct type
                            IRibbonGroupItem childItem    = _viewToItem[child] as IRibbonGroupItem;
                            IRibbonGroupItem previousItem = _viewToItem[previousChild] as IRibbonGroupItem;

                            // Find the requested gap between them
                            _viewToGap.Add(child, childItem.ItemGap(previousItem));
                        }
                        else
                        {
                            // Default the gap
                            _viewToGap.Add(child, DEFAULT_GAP);
                        }
                    }

                    // Get requested size of the child
                    Size childSize = child.GetPreferredSize(context);

                    // Add to list of visible child sizes
                    _sizeList.Add(childSize);
                    _viewList.Add(child);

                    // Cache total visible width for later
                    totalWidth += childSize.Width;

                    // This is now the previous child
                    previousChild = child;
                }
            }

            // Find the item size specific preferred calculation
            switch (_currentSize)
            {
            case GroupItemSize.Large:
                return(LargeMediumPreferredSize(totalWidth, ref _split1Large));

            case GroupItemSize.Medium:
                return(LargeMediumPreferredSize(totalWidth, ref _split1Medium));

            case GroupItemSize.Small:
                return(SmallPreferredSize(totalWidth));

            default:
                // Should never happen!
                Debug.Assert(false);
                return(Size.Empty);
            }
        }
Пример #2
0
        protected void CreateViewList(IList <Type> viewTypes)
        {
            var frame = new RectangleF(0, 0, ContentView.Bounds.Width, ContentView.Bounds.Height);

            if (ViewList != null)
            {
                foreach (var view in ViewList)
                {
                    view.Dispose();
                }

                ViewList.Clear();
                ViewList = null;
            }

            ViewList = new List <UIView>();

            if (viewTypes != null)
            {
                foreach (var viewType in viewTypes)
                {
                    if (viewType == null)
                    {
                        continue;
                    }

                    UIView view         = null;
                    var    hasFrameCtor = viewType.GetConstructor(new Type[] { typeof(RectangleF) }) != null;
                    if (hasFrameCtor)
                    {
                        view = Activator.CreateInstance(viewType, new object[] { frame }) as UIView;

                        if (ListSource.RowHeights[ListSource.BaseIndexPath] != view.Frame.Height)
                        {
                            if (ListSource.RowHeights.ContainsKey(IndexPath))
                            {
                                ListSource.RowHeights[IndexPath] = view.Frame.Height;
                            }
                            else
                            {
                                ListSource.RowHeights.Add(IndexPath, view.Frame.Height);
                            }
                        }
                    }
                    else
                    {
                        view = Activator.CreateInstance(viewType) as UIView;
                    }

                    var dc = view as IDataContext <object>;
                    if (dc != null)
                    {
                        var item = ListSource.GetSectionData(0)[IndexPath.Row];
                        dc.DataContext = item;
                    }

                    var initializeCell = view as IInitializeCell;
                    if (initializeCell != null)
                    {
                        initializeCell.Cell       = this;
                        initializeCell.Controller = ListSource.Controller;

                        var newCellStyle = initializeCell.CellStyle;
                        if (newCellStyle != Style)
                        {
                            Style = newCellStyle;
                            break;
                        }
                    }

                    var themeable = view as IThemeable;
                    if (themeable != null)
                    {
                        if (themeable.Theme == null)
                        {
                            var theme = view.GetType().GetCustomAttribute <ThemeAttribute>();
                            if (theme != null)
                            {
                                var cellViewTheme = Theme.CreateTheme(theme.ThemeType);
                                if (cellViewTheme != null)
                                {
                                    if (Theme != null)
                                    {
                                        Theme.MergeTheme(cellViewTheme);
                                    }
                                    else
                                    {
                                        Theme = cellViewTheme;
                                    }

                                    themeable.Theme = Theme;
                                }
                            }
                        }

                        themeable.InitializeTheme(this);
                    }

                    var cellContent = view as ICellContent;
                    if (cellContent != null)
                    {
                        if (cellContent.CellContentView != null)
                        {
                            _CompositeView.AddSubview(cellContent.CellContentView);
                        }
                    }

                    ViewList.Add(view);
                }
            }
        }