void OnInnerLayoutUpdate()
        {
            if (_layoutBound == _innerContainer.Geometry.Size)
            {
                return;
            }

            _layoutBound = _innerContainer.Geometry.Size;

            int  baseX = _innerContainer.Geometry.X;
            Rect bound = _scroller.Geometry;
            int  index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Platform.GetRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                index++;
            }
            _innerContainer.MinimumWidth = Element.Children.Count * bound.Width;

            if (_scroller.HorizontalPageIndex != _pageIndex)
            {
                _scroller.ScrollTo(_pageIndex, 0, false);
            }
        }
Esempio n. 2
0
        public void ItemRemoved(int removed)
        {
            if (_realizedItem.ContainsKey(removed))
            {
                CollectionView.UnrealizeView(_realizedItem[removed].View);
                _realizedItem.Remove(removed);
            }

            var items = _realizedItem.Keys.OrderBy(key => key);

            foreach (var index in items)
            {
                if (index > removed)
                {
                    _realizedItem[index - 1] = _realizedItem[index];
                }
            }

            var last = items.LastOrDefault();

            if (last > removed)
            {
                _realizedItem.Remove(last);
            }

            UpdateRemovedSize(removed);
            _scrollCanvasSize = new ESize(0, 0);
        }
Esempio n. 3
0
        private void OnInnerLayoutUpdate()
        {
            if (!_isInitalized || (_layoutBound == _innerContainer.Geometry.Size && _childCount == Element.Children.Count))
            {
                return;
            }

            _layoutBound = _innerContainer.Geometry.Size;
            _childCount  = Element.Children.Count;
            int  baseX = _innerContainer.Geometry.X;
            Rect bound = _scroller.Geometry;
            int  index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Xamarin.Forms.Platform.Tizen.Platform.GetRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                (nativeView as ElmSharp.Widget)?.AllowFocus(true);
                index++;
            }
            _innerContainer.MinimumWidth = Element.Children.Count * bound.Width;

            if (_scroller.HorizontalPageIndex != _pageIndex)
            {
                _scroller.ScrollTo(_pageIndex, 0, false);
            }
        }
Esempio n. 4
0
        public ESize GetScrollCanvasSize()
        {
            if (CollectionView.Count == 0 || _allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return(_allocatedSize);
            }


            if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0)
            {
                return(_scrollCanvasSize);
            }

            int totalItemSize = 0;

            if (_hasUnevenRows)
            {
                totalItemSize = _accumulatedItemSizes[_accumulatedItemSizes.Count - 1];
            }
            else
            {
                totalItemSize = BaseItemSize * CollectionView.Count;
            }

            if (IsHorizontal)
            {
                _scrollCanvasSize = new ESize(totalItemSize, _allocatedSize.Height);
            }
            else
            {
                _scrollCanvasSize = new ESize(_allocatedSize.Width, totalItemSize);
            }

            return(_scrollCanvasSize);
        }
Esempio n. 5
0
        public void ItemInserted(int inserted)
        {
            var items = _realizedItem.Keys.OrderByDescending(key => key);

            foreach (var index in items)
            {
                if (index >= inserted)
                {
                    _realizedItem[index + 1] = _realizedItem[index];
                }
            }
            if (_realizedItem.ContainsKey(inserted))
            {
                _realizedItem.Remove(inserted);
            }
            else
            {
                var last = items.LastOrDefault();
                if (last >= inserted)
                {
                    _realizedItem.Remove(last);
                }
            }

            UpdateInsertedSize(inserted);

            _scrollCanvasSize = new ESize(0, 0);
        }
Esempio n. 6
0
        void InitializeMeasureCache()
        {
            _baseItemSize     = 0;
            _scrollCanvasSize = new ESize(0, 0);
            _last             = new ERect(0, 0, 0, 0);

            if (!_hasUnevenRows)
            {
                return;
            }

            if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return;
            }

            int n = CollectionView.Count;

            _itemSizes            = new List <int>();
            _cached               = new List <bool>();
            _accumulatedItemSizes = new List <int>();

            for (int i = 0; i < n; i++)
            {
                _cached.Add(false);
                _itemSizes.Add(BaseItemSize);
                if (i % Span == 0)
                {
                    int accIndex = i / Span;
                    _accumulatedItemSizes.Add((accIndex > 0 ? (_accumulatedItemSizes[accIndex - 1] + ItemSpacing) : ItemStartPoint) + _itemSizes[i]);
                }
            }
        }
Esempio n. 7
0
        void InitializeMeasureCache()
        {
            _baseItemSize     = 0;
            _scrollCanvasSize = new ESize(0, 0);

            if (!_hasUnevenRows)
            {
                return;
            }

            if (_allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return;
            }

            int n = CollectionView.Count;

            _itemSizes            = new List <int>();
            _cached               = new List <bool>();
            _accumulatedItemSizes = new List <int>();

            for (int i = 0; i < n; i++)
            {
                _cached.Add(false);
                _itemSizes.Add(BaseItemSize);
                _accumulatedItemSizes.Add((i > 0 ? _accumulatedItemSizes[i - 1] : 0) + _itemSizes[i]);
            }
        }
Esempio n. 8
0
        public ESize GetScrollCanvasSize()
        {
            if (CollectionView.Count == 0 || _allocatedSize.Width <= 0 || _allocatedSize.Height <= 0)
            {
                return(_allocatedSize);
            }

            if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0)
            {
                return(_scrollCanvasSize);
            }

            int totalItemSize = 0;

            if (_hasUnevenRows)
            {
                totalItemSize = _accumulatedItemSizes[_accumulatedItemSizes.Count - 1] + FooterSizeWithSpacing;
            }
            else
            {
                totalItemSize = (int)Math.Ceiling(CollectionView.Count / (double)Span) * (BaseItemSize + ItemSpacing) - ItemSpacing + ItemStartPoint + FooterSizeWithSpacing;
            }

            if (IsHorizontal)
            {
                _scrollCanvasSize = new ESize(totalItemSize, _allocatedSize.Height);
            }
            else
            {
                _scrollCanvasSize = new ESize(_allocatedSize.Width, totalItemSize);
            }

            return(_scrollCanvasSize);
        }
Esempio n. 9
0
        void OnInnerLayoutUpdate()
        {
            if (!_isInitalized || _layoutBound == _innerContainer.Geometry.Size)
            {
                return;
            }

            _layoutBound = _innerContainer.Geometry.Size;

            int  baseX = _innerContainer.Geometry.X;
            Rect bound = _scroller.Geometry;
            int  index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Platform.GetRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                index++;
            }
            _innerContainer.MinimumWidth = Element.Children.Count * bound.Width;

            if (_scroller.HorizontalPageIndex != _pageIndex)
            {
                // If you change the orientation of the device and the Animation is set to false, it will not work.
                _scroller.ScrollTo(_pageIndex, 0, true);
            }
        }
Esempio n. 10
0
        void OnInnerLayoutUpdate()
        {
            if (!_isInitalized || (_layoutBound == _innerContainer.Geometry.Size && _childCount == Element.Children.Count))
            {
                return;
            }

            _layoutBound = _innerContainer.Geometry.Size;
            _childCount  = Element.Children.Count;

            int   baseX = _innerContainer.Geometry.X;
            ERect bound = _scroller.Geometry;
            int   index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Platform.GetRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                index++;
            }

            var widthRequest = _childCount * bound.Width;

            _innerContainer.MinimumWidth = widthRequest;
            if (_innerContainer.Geometry.Width == widthRequest && _scroller.HorizontalPageIndex != _pageIndex)
            {
                _scroller.ScrollTo(_pageIndex, 0, true);
            }
        }
Esempio n. 11
0
        public void SetFooter(EvasObject footer, ESize size)
        {
            bool contentSizeChanged = false;

            if (IsHorizontal)
            {
                if (_footerSize.Width != size.Width)
                {
                    contentSizeChanged = true;
                }
            }
            else
            {
                if (_footerSize.Height != size.Height)
                {
                    contentSizeChanged = true;
                }
            }

            _footer     = footer;
            _footerSize = size;

            if (contentSizeChanged)
            {
                InitializeMeasureCache();
                CollectionView.ContentSizeUpdated();
            }

            UpdateFooterPosition();
        }
Esempio n. 12
0
        /// <summary>
        /// Implementation of the IMeasurable.Measure() method.
        /// </summary>
        public ESize Measure(int availableWidth, int availableHeight)
        {
            ESize entrySize = _entry.Measure(availableWidth, availableHeight);
            int   width     = entrySize.Width + (CancelButtonPaddingHorizontal * 2) + CancelButtonSize;

            return(new ESize(width, BackgroundHeight));
        }
Esempio n. 13
0
 public void Reset()
 {
     foreach (var realizedItem in _realizedItem.Values.ToList())
     {
         CollectionView.UnrealizeView(realizedItem.View);
     }
     _realizedItem.Clear();
     _scrollCanvasSize = new ESize(0, 0);
 }
Esempio n. 14
0
 /// <summary>
 /// Updates the content of the carousel.
 /// </summary>
 void UpdateCarouselContent()
 {
     _innerContainer.UnPackAll();
     _layoutBound = new ESize(0, 0);
     foreach (var page in Element.Children)
     {
         EvasObject nativeView = Platform.GetOrCreateRenderer(page).NativeView;
         _innerContainer.PackEnd(nativeView);
     }
     _pageIndex = Element.Children.IndexOf(Element.CurrentPage);
     _scroller.ScrollTo(_pageIndex, 0, false);
     Element.UpdateFocusTreePolicy();
 }
Esempio n. 15
0
        private static Size GetScreenSize()
        {
            var screenSize = new Size();

            if (!Information.TryGetValue("http://tizen.org/feature/screen.width", out int width))
            {
                return(screenSize);
            }
            if (!Information.TryGetValue("http://tizen.org/feature/screen.height", out int height))
            {
                return(screenSize);
            }

            screenSize.Width  = width;
            screenSize.Height = height;
            return(screenSize);
        }
Esempio n. 16
0
        public void SetHeader(EvasObject header, ESize size)
        {
            bool contentSizeChanged = false;

            if (IsHorizontal)
            {
                if (_headerSize.Width != size.Width)
                {
                    contentSizeChanged = true;
                }
            }
            else
            {
                if (_headerSize.Height != size.Height)
                {
                    contentSizeChanged = true;
                }
            }

            _header     = header;
            _headerSize = size;

            if (contentSizeChanged)
            {
                InitializeMeasureCache();
                CollectionView.ContentSizeUpdated();
            }

            var position = CollectionView.ParentPosition;

            if (_header != null)
            {
                var bound = new ERect(position.X, position.Y, _headerSize.Width, _headerSize.Height);
                if (IsHorizontal)
                {
                    bound.Height = _allocatedSize.Height;
                }
                else
                {
                    bound.Width = _allocatedSize.Width;
                }
                _header.Geometry = bound;
            }
        }
Esempio n. 17
0
        public ESize GetScrollCanvasSize()
        {
            if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0)
            {
                return(_scrollCanvasSize);
            }

            var itemCount = CollectionView.Count;
            var itemSize  = CollectionView.GetItemSize();

            if (IsHorizontal)
            {
                return(_scrollCanvasSize = new ESize((int)Math.Ceiling(itemCount / (double)Span) * itemSize.Width, _allocatedSize.Height));
            }
            else
            {
                return(_scrollCanvasSize = new ESize(_allocatedSize.Width, (int)Math.Ceiling(itemCount / (double)Span) * itemSize.Height));
            }
        }
        public ESize GetScrollCanvasSize()
        {
            if (_scrollCanvasSize.Width > 0 && _scrollCanvasSize.Height > 0)
            {
                return(_scrollCanvasSize);
            }

            var itemCount = CollectionView.Count;
            var itemSize  = CollectionView.GetItemSize();

            if (IsHorizontal)
            {
                return(_scrollCanvasSize = new ESize(itemCount * itemSize.Width, _allocatedSize.Height));
            }
            else
            {
                return(_scrollCanvasSize = new ESize(_allocatedSize.Width, itemCount * itemSize.Height));
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Implements the <see cref="Xamarin.Forms.Platform.Tizen.Native.IMeasurable"/> interface.
        /// </summary>
        /// <param name="availableWidth">Available width.</param>
        /// <param name="availableHeight">Available height.</param>
        public ESize Measure(int availableWidth, int availableHeight)
        {
            var imageSize = ObjectSize;
            var size      = new ESize()
            {
                Width  = imageSize.Width,
                Height = imageSize.Height,
            };

            if (0 != availableWidth && 0 != availableHeight &&
                (imageSize.Width > availableWidth || imageSize.Height > availableHeight))
            {
                // when available size is limited and insufficient for the image ...
                double imageRatio     = (double)imageSize.Width / (double)imageSize.Height;
                double availableRatio = (double)availableWidth / (double)availableHeight;
                // depending on the relation between availableRatio and imageRatio, copy the availableWidth or availableHeight
                // and calculate the size which preserves the image ratio, but does not exceed the available size
                size.Width  = availableRatio > imageRatio ? imageSize.Width * availableHeight / imageSize.Height : availableWidth;
                size.Height = availableRatio > imageRatio ? availableHeight : imageSize.Height * availableWidth / imageSize.Width;
            }

            return(size);
        }
Esempio n. 20
0
        private void OnInnerLayoutUpdate()
        {
            if (_layoutBound == _innerContainer.Geometry.Size)
            {
                return;
            }

            _layoutBound = _innerContainer.Geometry.Size;
            int  baseX = _innerContainer.Geometry.X;
            Rect bound = _scroller.Geometry;
            int  index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Xamarin.Forms.Platform.Tizen.Platform.GetRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                (nativeView as ElmSharp.Widget)?.AllowFocus(true);
                index++;
            }
            _innerContainer.MinimumWidth = Element.Children.Count * bound.Width;

            if (_scroller.HorizontalPageIndex != _pageIndex)
            {
                _scroller.ScrollTo(_pageIndex, 0, false);
            }

            //Below code is workaround code.
            //there is no way to call after Platform.GetRenderer(page) is ready.
            if (!_isUpdateContent && _innerContainer.MinimumWidth == _layoutBound.Width)
            {
                UpdateCarouselContent();
                UpdateIndexItem();
                _isUpdateContent = true;
            }
        }
Esempio n. 21
0
 public void SizeAllocated(ESize size)
 {
     _scrollCanvasSize = new ESize(0, 0);
     _allocatedSize    = size;
     InitializeMeasureCache();
 }
Esempio n. 22
0
 public void UpdateSpan(int span)
 {
     Span = span;
     _scrollCanvasSize = new ESize(0, 0);
     CollectionView.RequestLayoutItems();
 }
Esempio n. 23
0
 public void SizeAllocated(ESize size)
 {
     Reset();
     _allocatedSize    = size;
     _scrollCanvasSize = new ESize(0, 0);
 }
Esempio n. 24
0
 public void SizeAllocated(ESize size)
 {
     Reset();
     _allocatedSize = size;
     InitializeMeasureCache();
 }