예제 #1
0
파일: UiListBox.cs 프로젝트: prepare/Sitana
        void RecalculatePositionsAndScroll()
        {
            _updateScrollPosition = new Point((int)_scrollingService.ScrollPositionX, (int)_scrollingService.ScrollPositionY);
            Point position = new Point(-_updateScrollPosition.X, -_updateScrollPosition.Y);

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

                bool      shouldRecalc = view.ShouldRecalc(false, false);
                Rectangle bounds       = shouldRecalc ? CalculateItemBounds(view) : view.Bounds;

                Point size = bounds.Size;

                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;
                }

                if (shouldRecalc)
                {
                    view.Bounds = bounds;
                    view.ViewUpdate(0);
                }
                else
                {
                    Point offset = bounds.Location - view.Bounds.Location;
                    view.Move(offset);
                }

                _maxScroll = new Point(_updateScrollPosition.X + position.X, _updateScrollPosition.Y + position.Y);
            }
        }
예제 #2
0
파일: UiListBox.cs 프로젝트: prepare/Sitana
        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();
        }