Esempio n. 1
0
        Widget _buildToolbar(BuildContext context)
        {
            if (this.selectionControls == null)
            {
                return(new Container());
            }

            // Find the horizontal midpoint, just above the selected text.
            List <TextSelectionPoint> endpoints = this.renderObject.getEndpointsForSelection(this._selection);
            Offset midpoint = new Offset(
                (endpoints.Count == 1) ? endpoints[0].point.dx : (endpoints[0].point.dx + endpoints[1].point.dx) / 2.0f,
                endpoints[0].point.dy - this.renderObject.preferredLineHeight
                );

            Rect editingRegion = Rect.fromPoints(this.renderObject.localToGlobal(Offset.zero),
                                                 this.renderObject.localToGlobal(this.renderObject.size.bottomRight(Offset.zero))
                                                 );

            return(new FadeTransition(
                       opacity: this._toolbarOpacity,
                       child: new CompositedTransformFollower(
                           link: this.layerLink,
                           showWhenUnlinked: false,
                           offset: -editingRegion.topLeft,
                           child: this.selectionControls.buildToolbar(context, editingRegion, midpoint, this.selectionDelegate)
                           )
                       ));
        }
Esempio n. 2
0
        public override void performLayout(Size size)
        {
            float  columnCardX      = size.width / 5.0f;
            float  columnCardWidth  = size.width - columnCardX;
            float  columnCardHeight = size.height / this.cardCount;
            float  rowCardWidth     = size.width;
            Offset offset           = this.translation.alongSize(size);
            float  columnCardY      = 0.0f;
            float  rowCardX         = -(this.selectedIndex * rowCardWidth);

            float columnTitleX  = size.width / 10.0f;
            float rowTitleWidth = size.width * ((1 + this.tCollapsed) / 2.25f);
            float rowTitleX     = (size.width - rowTitleWidth) / 2.0f - this.selectedIndex * rowTitleWidth;

            const float paddedSectionIndicatorWidth = AnimationWidgetsUtils.kSectionIndicatorWidth + 8.0f;
            float       rowIndicatorWidth           = paddedSectionIndicatorWidth +
                                                      (1.0f - this.tCollapsed) * (rowTitleWidth - paddedSectionIndicatorWidth);
            float rowIndicatorX = (size.width - rowIndicatorWidth) / 2.0f - this.selectedIndex * rowIndicatorWidth;

            for (int index = 0; index < this.cardCount; index++)
            {
                Rect   columnCardRect = Rect.fromLTWH(columnCardX, columnCardY, columnCardWidth, columnCardHeight);
                Rect   rowCardRect    = Rect.fromLTWH(rowCardX, 0.0f, rowCardWidth, size.height);
                Rect   cardRect       = this._interpolateRect(columnCardRect, rowCardRect).shift(offset);
                string cardId         = $"card{index}";
                if (this.hasChild(cardId))
                {
                    this.layoutChild(cardId, BoxConstraints.tight(cardRect.size));
                    this.positionChild(cardId, cardRect.topLeft);
                }

                Size   titleSize         = this.layoutChild($"title{index}", BoxConstraints.loose(cardRect.size));
                float  columnTitleY      = columnCardRect.centerLeft.dy - titleSize.height / 2.0f;
                float  rowTitleY         = rowCardRect.centerLeft.dy - titleSize.height / 2.0f;
                float  centeredRowTitleX = rowTitleX + (rowTitleWidth - titleSize.width) / 2.0f;
                Offset columnTitleOrigin = new Offset(columnTitleX, columnTitleY);
                Offset rowTitleOrigin    = new Offset(centeredRowTitleX, rowTitleY);
                Offset titleOrigin       = this._interpolatePoint(columnTitleOrigin, rowTitleOrigin);
                this.positionChild($"title{index}", titleOrigin + offset);

                Size   indicatorSize         = this.layoutChild($"indicator{index}", BoxConstraints.loose(cardRect.size));
                float  columnIndicatorX      = cardRect.centerRight.dx - indicatorSize.width - 16.0f;
                float  columnIndicatorY      = cardRect.bottomRight.dy - indicatorSize.height - 16.0f;
                Offset columnIndicatorOrigin = new Offset(columnIndicatorX, columnIndicatorY);
                Rect   titleRect             = Rect.fromPoints(titleOrigin, titleSize.bottomRight(titleOrigin));
                float  centeredRowIndicatorX = rowIndicatorX + (rowIndicatorWidth - indicatorSize.width) / 2.0f;
                float  rowIndicatorY         = titleRect.bottomCenter.dy + 16.0f;
                Offset rowIndicatorOrigin    = new Offset(centeredRowIndicatorX, rowIndicatorY);
                Offset indicatorOrigin       = this._interpolatePoint(columnIndicatorOrigin, rowIndicatorOrigin);
                this.positionChild($"indicator{index}", indicatorOrigin + offset);

                columnCardY   += columnCardHeight;
                rowCardX      += rowCardWidth;
                rowTitleX     += rowTitleWidth;
                rowIndicatorX += rowIndicatorWidth;
            }
        }
Esempio n. 3
0
        void showButtonMenu()
        {
            PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
            RenderBox          button         = (RenderBox)context.findRenderObject();
            RenderBox          overlay        = (RenderBox)Overlay.of(context).context.findRenderObject();
            RelativeRect       position       = RelativeRect.fromRect(
                Rect.fromPoints(
                    button.localToGlobal(widget.offset, ancestor: overlay),
                    button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay)
                    ),
                Offset.zero & overlay.size
                );
            List <PopupMenuEntry <T> > items = widget.itemBuilder(context);

            if (items.isNotEmpty())
            {
                material_.showMenu <T>(
                    context: context,
                    elevation: widget.elevation ?? popupMenuTheme.elevation,
                    items: items,
                    initialValue: widget.initialValue,
                    position: position,
                    shape: widget.shape ?? popupMenuTheme.shape,
                    color: widget.color ?? popupMenuTheme.color,
                    captureInheritedThemes: widget.captureInheritedThemes
                    )
                .then(newValue => {
                    if (!mounted)
                    {
                        return;
                    }
                    if (newValue == null)
                    {
                        if (widget.onCanceled != null)
                        {
                            widget.onCanceled();
                        }
                        return;
                    }

                    if (widget.onSelected != null)
                    {
                        widget.onSelected((T)newValue);
                    }
                });
            }
        }
Esempio n. 4
0
        public override Rect lerp(float t)
        {
            if (this._dirty)
            {
                this._initialize();
            }

            if (t == 0.0)
            {
                return(this.begin);
            }

            if (t == 1.0)
            {
                return(this.end);
            }

            return(Rect.fromPoints(this._beginArc.lerp(t), this._endArc.lerp(t)));
        }
Esempio n. 5
0
        public override Rect lerp(float t)
        {
            if (_dirty)
            {
                _initialize();
            }

            if (t == 0.0)
            {
                return(begin);
            }

            if (t == 1.0)
            {
                return(end);
            }

            return(Rect.fromPoints(_beginArc.lerp(t), _endArc.lerp(t)));
        }
Esempio n. 6
0
        Widget _buildToolbar(BuildContext context)
        {
            if (selectionControls == null)
            {
                return(new Container());
            }

            // Find the horizontal midpoint, just above the selected text.
            List <TextSelectionPoint> endpoints = renderObject.getEndpointsForSelection(_selection);

            Rect editingRegion = Rect.fromPoints(renderObject.localToGlobal(Offset.zero),
                                                 renderObject.localToGlobal(renderObject.size.bottomRight(Offset.zero))
                                                 );

            bool isMultiline = endpoints.last().point.dy - endpoints.first().point.dy >
                               renderObject.preferredLineHeight / 2;

            float midX = isMultiline
                ? editingRegion.width / 2
                : (endpoints.first().point.dx + endpoints.last().point.dx) / 2;

            Offset midpoint = new Offset(
                midX,
                endpoints[0].point.dy - renderObject.preferredLineHeight
                );

            return(new FadeTransition(
                       opacity: _toolbarOpacity,
                       child: new CompositedTransformFollower(
                           link: toolbarLayerLink,
                           showWhenUnlinked: false,
                           offset: -editingRegion.topLeft,
                           child: selectionControls.buildToolbar(
                               context,
                               editingRegion,
                               renderObject.preferredLineHeight,
                               midpoint,
                               endpoints,
                               selectionDelegate)
                           )
                       ));
        }
Esempio n. 7
0
        void showButtonMenu()
        {
            RenderBox    button   = (RenderBox)this.context.findRenderObject();
            RenderBox    overlay  = (RenderBox)Overlay.of(this.context).context.findRenderObject();
            RelativeRect position = RelativeRect.fromRect(
                Rect.fromPoints(
                    button.localToGlobal(this.widget.offset, ancestor: overlay),
                    button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay)
                    ),
                Offset.zero & overlay.size
                );

            PopupMenuUtils.showMenu(
                context: this.context,
                elevation: this.widget.elevation,
                items: this.widget.itemBuilder(this.context),
                initialValue: this.widget.initialValue,
                position: position
                )
            .Then(newValue => {
                if (!this.mounted)
                {
                    return;
                }

                if (newValue == null)
                {
                    if (this.widget.onCanceled != null)
                    {
                        this.widget.onCanceled();
                    }

                    return;
                }

                if (this.widget.onSelected != null)
                {
                    this.widget.onSelected((T)newValue);
                }
            });
        }
Esempio n. 8
0
        public override void paint(Canvas canvas, Size size)
        {
            float halfStrokeWidth = 1.0f;
            Paint paint           = new Paint();

            paint.color = color;
            Rect circle = Rect.fromCircle(
                center: new Offset(CupertinoTextSelectionUtils._kSelectionHandleRadius, CupertinoTextSelectionUtils._kSelectionHandleRadius),
                radius: CupertinoTextSelectionUtils._kSelectionHandleRadius
                );
            Rect line = Rect.fromPoints(
                new Offset(
                    CupertinoTextSelectionUtils._kSelectionHandleRadius - halfStrokeWidth,
                    2 * CupertinoTextSelectionUtils._kSelectionHandleRadius - CupertinoTextSelectionUtils._kSelectionHandleOverlap
                    ),
                new Offset(CupertinoTextSelectionUtils._kSelectionHandleRadius + halfStrokeWidth, size.height)
                );
            Path path = new Path();

            path.addOval(circle);
            // Draw line so it slightly overlaps the circle.
            path.addRect(line);
            canvas.drawPath(path, paint);
        }