Esempio n. 1
0
        Widget _buildTabIndicator(
            int tabIndex,
            TabController tabController,
            ColorTween selectedColorTween,
            ColorTween previousColorTween)
        {
            Color background = null;

            if (tabController.indexIsChanging)
            {
                float t = 1.0f - TabsUtils._indexChangeProgress(tabController);
                if (tabController.index == tabIndex)
                {
                    background = selectedColorTween.lerp(t);
                }
                else if (tabController.previousIndex == tabIndex)
                {
                    background = previousColorTween.lerp(t);
                }
                else
                {
                    background = selectedColorTween.begin;
                }
            }
            else
            {
                float offset = tabController.offset;
                if (tabController.index == tabIndex)
                {
                    background = selectedColorTween.lerp(1.0f - offset.abs());
                }
                else if (tabController.index == tabIndex - 1 && offset > 0.0)
                {
                    background = selectedColorTween.lerp(offset);
                }
                else if (tabController.index == tabIndex + 1 && offset < 0.0)
                {
                    background = selectedColorTween.lerp(-offset);
                }
                else
                {
                    background = selectedColorTween.begin;
                }
            }

            return(new TabPageSelectorIndicator(
                       backgroundColor: background,
                       borderColor: selectedColorTween.end,
                       size: this.indicatorSize
                       ));
        }
Esempio n. 2
0
        public override void paint(Canvas canvas, Size size)
        {
            this._needsPaint = false;
            this._painter    = this._painter ?? this.indicator.createBoxPainter(this.markNeedsPaint);

            if (this.controller.indexIsChanging)
            {
                Rect targetRect = this.indicatorRect(size, this.controller.index);
                this._currentRect = Rect.lerp(targetRect, this._currentRect ?? targetRect,
                                              TabsUtils._indexChangeProgress(this.controller));
            }
            else
            {
                int   currentIndex = this.controller.index;
                Rect  previous     = currentIndex > 0 ? this.indicatorRect(size, currentIndex - 1) : null;
                Rect  middle       = this.indicatorRect(size, currentIndex);
                Rect  next         = currentIndex < this.maxTabIndex ? this.indicatorRect(size, currentIndex + 1) : null;
                float index        = this.controller.index;
                float value        = this.controller.animation.value;
                if (value == index - 1.0f)
                {
                    this._currentRect = previous ?? middle;
                }
                else if (value == index + 1.0f)
                {
                    this._currentRect = next ?? middle;
                }
                else if (value == index)
                {
                    this._currentRect = middle;
                }
                else if (value < index)
                {
                    this._currentRect = previous == null ? middle : Rect.lerp(middle, previous, index - value);
                }
                else
                {
                    this._currentRect = next == null ? middle : Rect.lerp(middle, next, value - index);
                }
            }

            D.assert(this._currentRect != null);

            ImageConfiguration configuration = new ImageConfiguration(
                size: this._currentRect.size
                );

            this._painter.paint(canvas, this._currentRect.topLeft, configuration);
        }