Esempio n. 1
0
        public override Widget build(BuildContext context)
        {
            List <Widget> items = new List <Widget>();
            Widget        onePhysicalPixelVerticalDivider =
                new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio);
            CupertinoLocalizations localizations = CupertinoLocalizations.of(context);

            if (this.handleCut != null)
            {
                items.Add(this._buildToolbarButton(localizations.cutButtonLabel, this.handleCut));
            }

            if (this.handleCopy != null)
            {
                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(this._buildToolbarButton(localizations.copyButtonLabel, this.handleCopy));
            }

            if (this.handlePaste != null)
            {
                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(this._buildToolbarButton(localizations.pasteButtonLabel, this.handlePaste));
            }

            if (this.handleSelectAll != null)
            {
                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(this._buildToolbarButton(localizations.selectAllButtonLabel, this.handleSelectAll));
            }

            Widget triangle = SizedBox.fromSize(
                size: CupertinoTextSelectionUtils._kToolbarTriangleSize,
                child: new CustomPaint(
                    painter: new _TextSelectionToolbarNotchPainter()
                    )
                );

            return(new Column(
                       mainAxisSize: MainAxisSize.min,
                       children: new List <Widget> {
                new ClipRRect(
                    borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius,
                    child: new DecoratedBox(
                        decoration: new BoxDecoration(
                            color: CupertinoTextSelectionUtils._kToolbarDividerColor,
                            borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius,
                            border: Border.all(color: CupertinoTextSelectionUtils._kToolbarBackgroundColor,
                                               width: 0)
                            ),
                        child: new Row(mainAxisSize: MainAxisSize.min, children: items)
                        )
                    ),
                triangle,
                new Padding(padding: EdgeInsets.only(bottom: 10.0f))
            }
                       ));
        }
Esempio n. 2
0
        public override Widget buildToolbar(
            BuildContext context,
            Rect globalEditableRegion,
            float textLineHeight,
            Offset position,
            List <TextSelectionPoint> endpoints,
            TextSelectionDelegate _delegate
            )
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            MediaQueryData mediaQuery = MediaQuery.of(context);

            float toolbarHeightNeeded = mediaQuery.padding.top
                                        + CupertinoTextSelectionUtils._kToolbarScreenPadding
                                        + CupertinoTextSelectionUtils._kToolbarHeight
                                        + CupertinoTextSelectionUtils._kToolbarContentDistance;
            float availableHeight     = globalEditableRegion.top + endpoints.first().point.dy - textLineHeight;
            bool  isArrowPointingDown = toolbarHeightNeeded <= availableHeight;

            float arrowTipX = (position.dx + globalEditableRegion.left).clamp(
                CupertinoTextSelectionUtils._kArrowScreenPadding + mediaQuery.padding.left,
                mediaQuery.size.width - mediaQuery.padding.right - CupertinoTextSelectionUtils._kArrowScreenPadding
                );
            float localBarTopY = isArrowPointingDown
                  ? endpoints.first().point.dy - textLineHeight - CupertinoTextSelectionUtils._kToolbarContentDistance - CupertinoTextSelectionUtils._kToolbarHeight
                  : endpoints.last().point.dy + CupertinoTextSelectionUtils._kToolbarContentDistance;

            List <Widget> items = new List <Widget> {
            };
            Widget onePhysicalPixelVerticalDivider = new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio);
            CupertinoLocalizations localizations   = CupertinoLocalizations.of(context);
            EdgeInsets             arrowPadding    = isArrowPointingDown
                  ? EdgeInsets.only(bottom: CupertinoTextSelectionUtils._kToolbarArrowSize.height)
                  : EdgeInsets.only(top: CupertinoTextSelectionUtils._kToolbarArrowSize.height);

            void addToolbarButtonIfNeeded(
                string text,
                Predicate predicate,
                OnPressed onPressed)
            {
                if (!predicate(_delegate))
                {
                    return;
                }

                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(new CupertinoButton(
                              child: new Text(text, style: CupertinoTextSelectionUtils._kToolbarButtonFontStyle),
                              color: CupertinoTextSelectionUtils._kToolbarBackgroundColor,
                              minSize: CupertinoTextSelectionUtils._kToolbarHeight,
                              padding: CupertinoTextSelectionUtils._kToolbarButtonPadding.add(arrowPadding),
                              borderRadius: null,
                              pressedOpacity: 0.7f,
                              onPressed: () => onPressed(_delegate)
                              ));
            }

            addToolbarButtonIfNeeded(localizations.cutButtonLabel, canCut, handleCut);
            addToolbarButtonIfNeeded(localizations.copyButtonLabel, canCopy, handleCopy);
            addToolbarButtonIfNeeded(localizations.pasteButtonLabel, canPaste, handlePaste);
            addToolbarButtonIfNeeded(localizations.selectAllButtonLabel, canSelectAll, handleSelectAll);
            return(new CupertinoTextSelectionToolbar(
                       barTopY: localBarTopY + globalEditableRegion.top,
                       arrowTipX: arrowTipX,
                       isArrowPointingDown: isArrowPointingDown,
                       child: items.isEmpty() ? null : new DecoratedBox(
                           decoration: new BoxDecoration(color: CupertinoTextSelectionUtils._kToolbarDividerColor),
                           child: new Row(mainAxisSize: MainAxisSize.min, children: items)
                           )
                       ));
        }