Пример #1
0
        protected override void Update(float time)
        {
            base.Update(time);
            bool recalcLayout = false;

            for (int idx = 0; idx < _items.Count; ++idx)
            {
                if (!_bindingToElement.ContainsKey(_items.ElementAt(idx)))
                {
                    InsertItem(_items.ElementAt(idx), idx);
                    recalcLayout = true;
                }
            }

            if (recalcLayout)
            {
                //RecalculateAll();

                if (Parent != null)
                {
                    SetForceRecalcFlag();
                    Parent.RecalcLayout();
                }
            }
        }
Пример #2
0
        void Recalculate()
        {
            lock (_items)
            {
                int count = _items.Count;

                int added = 0;

                _updateScrollPosition = new Point((int)_scrollingService.ScrollPositionX, (int)_scrollingService.ScrollPositionY);
                Point position = new Point(-_updateScrollPosition.X, -_updateScrollPosition.Y);

                for (int idx = 0; idx < count; ++idx)
                {
                    object bind = _items.ElementAt(_reverse ? count - idx - 1 : idx);

                    UiView view;
                    _bindingToElement.TryGetValue(bind, out view);

                    if (view == null)
                    {
                        if (added < _maxAddOneTime)
                        {
                            DefinitionFile template;

                            if (_additionalTemplates == null || !_additionalTemplates.TryGetValue(bind.GetType(), out template))
                            {
                                template = _template;
                            }

                            view = (UiView)template.CreateInstance(Controller, bind);

                            lock (_childrenLock)
                            {
                                _bindingToElement.Add(bind, view);
                                _children.Add(view);
                            }

                            view.Parent = this;
                            view.RegisterView();
                            view.ViewAdded();
                            added++;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    Rectangle bounds = CalculateItemBounds(view);
                    Point     size   = view.ComputeSize(Bounds.Width, Bounds.Height);

                    if (_vertical)
                    {
                        bounds.Height = size.Y;
                        bounds.Y      = position.Y + view.PositionParameters.Margin.Top;

                        position.Y = bounds.Bottom + view.PositionParameters.Margin.Bottom;
                    }
                    else
                    {
                        bounds.Width = size.X;
                        bounds.X     = position.X + view.PositionParameters.Margin.Left;

                        position.X = bounds.Right + view.PositionParameters.Margin.Right;
                    }

                    view.Bounds = bounds;
                }

                _maxScroll = new Point(_updateScrollPosition.X + position.X, _updateScrollPosition.Y + position.Y);
            }
        }
Пример #3
0
        void Recalculate()
        {
            _newItems.Clear();

            lock (_items)
            {
                int count = _items.Count;

                int added = 0;

                int numberOfElements = 0;

                int maxAdd = count == 0 ? _maxAddFirstTime : _maxAddOneTime;

                for (int idx = 0; idx < count; ++idx)
                {
                    object bind = _items.ElementAt(_reverse ? count - idx - 1 : idx);

                    UiView view;
                    _bindingToElement.TryGetValue(bind, out view);

                    if (view == null)
                    {
                        if (added < maxAdd)
                        {
                            DefinitionFile template;

                            if (_additionalTemplates == null || !_additionalTemplates.TryGetValue(bind.GetType(), out template))
                            {
                                template = _template;
                            }

                            view = (UiView)template.CreateInstance(Controller, bind);

                            _newItems.Add(view);
                            added++;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (numberOfElements < _itemViews.Count)
                    {
                        _itemViews[numberOfElements] = view;
                    }
                    else
                    {
                        _itemViews.Add(view);
                    }
                    numberOfElements++;
                }

                if (_itemViews.Count > numberOfElements)
                {
                    _itemViews.RemoveRange(numberOfElements, _itemViews.Count - numberOfElements);
                }
            }

            for (int idx = 0; idx < _newItems.Count; ++idx)
            {
                UiView view = _newItems[idx];

                lock (_childrenLock)
                {
                    _bindingToElement.Add(view.Binding, view);
                    _children.Add(view);
                }

                view.Parent = this;
                view.RegisterView();
                view.ViewAdded();
                view.ViewUpdate(0);
            }

            RecalculatePositionsAndScroll();
        }
Пример #4
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            int position      = 0;
            int startPosition = ScreenBounds.Top;

            int separatorHeight = _separator != null?Math.Max(1, _separatorHeight.Compute(Bounds.Height)) : 0;

            int rowHeight = _rowHeight.Compute(Bounds.Height);

            Rectangle target = new Rectangle();


            float startIndexF = _scrollingService.ScrollPositionY / (float)(rowHeight + separatorHeight);

            int startIndex = (int)startIndexF;

            startPosition -= (int)_scrollingService.ScrollPositionY % (rowHeight + separatorHeight);

            if (_reversed)
            {
                startIndex = _items.Count - startIndex - 1;
            }

            Rectangle textTarget = new Rectangle();
            int       maxY       = ScreenBounds.Bottom;

            parameters.DrawBatch.PushClip(ScreenBounds);

            target        = ScreenBounds;
            target.Y      = startPosition;
            target.Height = separatorHeight;

            if (separatorHeight > 0)
            {
                for (int dataIndex = startIndex; dataIndex < _items.Count && dataIndex >= 0;)
                {
                    _separator.Draw(parameters.DrawBatch, target, parameters.Opacity);

                    target.Y += rowHeight + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }
            }

            startPosition += separatorHeight;

            for (int columnIndex = 0; columnIndex < _columns.Count; ++columnIndex)
            {
                var column = _columns[columnIndex];
                int width  = column.Width.Compute(Bounds.Width);

                UniversalFont font        = column.Font.Font;
                float         fontScale   = column.Font.Scale;
                float         fontSpacing = column.Font.Spacing;

                int lineHeight = column.LineHeight;

                TextAlign textAlign = column.TextAlign;

                target.X     = position + column.TextMargin.Left + ScreenBounds.Left;
                target.Width = width - column.TextMargin.Width;

                target.Y      = startPosition;
                target.Height = rowHeight;

                Margin textMargin = column.TextMargin;

                int dataIndex = startIndex;
                int count     = _items.Count;

                for (int idx = 0; idx < count; idx++)
                {
                    textTarget.X     = target.X;
                    textTarget.Width = target.Width;

                    textTarget.Y      = target.Y + textMargin.Top;
                    textTarget.Height = target.Height - textMargin.Height;

                    if (dataIndex >= 0 && dataIndex < count)
                    {
                        QuickDataRow row = (QuickDataRow)(_items.ElementAt(dataIndex));

                        Color  color = row.Colors[columnIndex].Value;
                        string text  = row.Labels[columnIndex];

                        parameters.DrawBatch.DrawText(font, text, textTarget, textAlign, color, fontSpacing, lineHeight, fontScale);
                    }

                    target.Y += target.Height + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }

                position += width;
            }

            parameters.DrawBatch.PopClip();
        }