示例#1
0
 static IRenderable CreatePanel(string name, BoxBorder border)
 {
     return(new Panel($"This is a panel with\nthe [yellow]{name}[/] border.")
            .Header($" [blue]{name}[/] ", Justify.Center)
            .Border(border)
            .BorderStyle(Style.Parse("grey")));
 }
示例#2
0
    /// <summary>
    /// Sets the border.
    /// </summary>
    /// <typeparam name="T">An object type with a border.</typeparam>
    /// <param name="obj">The object to set the border for.</param>
    /// <param name="border">The border to use.</param>
    /// <returns>The same instance so that multiple calls can be chained.</returns>
    public static T Border <T>(this T obj, BoxBorder border)
        where T : class, IHasBoxBorder
    {
        if (obj is null)
        {
            throw new ArgumentNullException(nameof(obj));
        }

        obj.Border = border;
        return(obj);
    }
示例#3
0
    /// <summary>
    /// Gets the safe border for a border.
    /// </summary>
    /// <param name="border">The border to get the safe border for.</param>
    /// <param name="safe">Whether or not to return the safe border.</param>
    /// <returns>The safe border if one exist, otherwise the original border.</returns>
    public static BoxBorder GetSafeBorder(this BoxBorder border, bool safe)
    {
        if (border is null)
        {
            throw new ArgumentNullException(nameof(border));
        }

        if (safe && border.SafeBorder != null)
        {
            border = border.SafeBorder;
        }

        return(border);
    }
示例#4
0
    private void AddTopBorder(
        List <Segment> result, RenderContext context, BoxBorder border,
        Style borderStyle, int panelWidth)
    {
        var rule = new Rule
        {
            Style        = borderStyle,
            Border       = border,
            TitlePadding = 1,
            TitleSpacing = 0,
            Title        = Header?.Text,
            Alignment    = Header?.Alignment ?? Justify.Left,
        };

        // Top left border
        result.Add(new Segment(border.GetPart(BoxBorderPart.TopLeft), borderStyle));

        // Top border (and header text if specified)
        result.AddRange(((IRenderable)rule).Render(context, panelWidth - 2).Where(x => !x.IsLineBreak));

        // Top right border
        result.Add(new Segment(border.GetPart(BoxBorderPart.TopRight), borderStyle));
        result.Add(Segment.LineBreak);
    }
示例#5
0
        public override Widget build(BuildContext context)
        {
            base.build(context);
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            TextEditingController     controller = _effectiveController;
            List <TextInputFormatter> formatters = widget.inputFormatters ?? new List <TextInputFormatter>();
            bool   enabled      = widget.enabled ?? true;
            Offset cursorOffset =
                new Offset(
                    CupertinoTextFieldUtils._iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio,
                    0);

            if (widget.maxLength != null && widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(widget.maxLength));
            }

            CupertinoThemeData themeData     = CupertinoTheme.of(context);
            TextStyle          resolvedStyle = widget.style?.copyWith(
                color: CupertinoDynamicColor.resolve(widget.style?.color, context),
                backgroundColor: CupertinoDynamicColor.resolve(widget.style?.backgroundColor, context)
                );
            TextStyle textStyle = themeData.textTheme.textStyle.merge(resolvedStyle);
            TextStyle resolvedPlaceholderStyle = widget.placeholderStyle?.copyWith(
                color: CupertinoDynamicColor.resolve(widget.placeholderStyle?.color, context),
                backgroundColor: CupertinoDynamicColor.resolve(widget.placeholderStyle?.backgroundColor, context)
                );
            TextStyle  placeholderStyle   = textStyle.merge(resolvedPlaceholderStyle);
            Brightness?keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context);

            Color cursorColor   = CupertinoDynamicColor.resolve(widget.cursorColor, context) ?? themeData.primaryColor;
            Color disabledColor = CupertinoDynamicColor.resolve(CupertinoTextFieldUtils._kDisabledBackground, context);

            Color     decorationColor = CupertinoDynamicColor.resolve(widget.decoration?.color, context);
            BoxBorder border          = widget.decoration?.border;
            Border    resolvedBorder  = border as Border;

            if (border is Border)
            {
                BorderSide resolveBorderSide(BorderSide side)
                {
                    return(side == BorderSide.none
                        ? side
                        : side.copyWith(color: CupertinoDynamicColor.resolve(side.color, context)));
                }

                resolvedBorder = (Border)(border == null || border.GetType() != typeof(Border)
                    ? border
                    : new Border(
                                              top: resolveBorderSide(((Border)border).top),
                                              left: resolveBorderSide(((Border)border).left),
                                              bottom: resolveBorderSide(((Border)border).bottom),
                                              right: resolveBorderSide(((Border)border).right)
                                              ));
            }

            BoxDecoration effectiveDecoration = widget.decoration?.copyWith(
                border: resolvedBorder,
                color: enabled ? decorationColor : (decorationColor == null ? disabledColor : decorationColor)
                );

            Widget paddedEditable = new Padding(
                padding: widget.padding,
                child: new RepaintBoundary(
                    child: new EditableText(
                        key: editableTextKey,
                        controller: controller,
                        readOnly: widget.readOnly,
                        toolbarOptions: widget.toolbarOptions,
                        showCursor: widget.showCursor,
                        showSelectionHandles: _showSelectionHandles,
                        focusNode: _effectiveFocusNode,
                        keyboardType: widget.keyboardType,
                        textInputAction: widget.textInputAction,
                        textCapitalization: widget.textCapitalization,
                        style: textStyle,
                        strutStyle: widget.strutStyle,
                        textAlign: widget.textAlign,
                        autofocus: widget.autofocus,
                        obscureText: widget.obscureText,
                        autocorrect: widget.autocorrect,
                        smartDashesType: widget.smartDashesType,
                        smartQuotesType: widget.smartQuotesType,
                        enableSuggestions: widget.enableSuggestions,
                        maxLines: widget.maxLines,
                        minLines: widget.minLines,
                        expands: widget.expands,
                        selectionColor: CupertinoTheme.of(context).primaryColor.withOpacity(0.2f),
                        selectionControls: widget.selectionEnabled
                        ? CupertinoTextFieldUtils.cupertinoTextSelectionControls : null,
                        onChanged: widget.onChanged,
                        onSelectionChanged: _handleSelectionChanged,
                        onEditingComplete: widget.onEditingComplete,
                        onSubmitted: widget.onSubmitted,
                        inputFormatters: formatters,
                        rendererIgnoresPointer: true,
                        cursorWidth: widget.cursorWidth,
                        cursorRadius: widget.cursorRadius,
                        cursorColor: cursorColor,
                        cursorOpacityAnimates: true,
                        cursorOffset: cursorOffset,
                        paintCursorAboveText: true,
                        backgroundCursorColor: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context),
                        selectionHeightStyle: widget.selectionHeightStyle,
                        selectionWidthStyle: widget.selectionWidthStyle,
                        scrollPadding: widget.scrollPadding,
                        keyboardAppearance: keyboardAppearance,
                        dragStartBehavior: widget.dragStartBehavior,
                        scrollController: widget.scrollController,
                        scrollPhysics: widget.scrollPhysics,
                        enableInteractiveSelection: widget.enableInteractiveSelection
                        )
                    )
                );

            return(new IgnorePointer(
                       ignoring: !enabled,
                       child: new Container(
                           decoration: effectiveDecoration,
                           child: _selectionGestureDetectorBuilder.buildGestureDetector(
                               behavior: HitTestBehavior.translucent,
                               child: new Align(
                                   alignment: new Alignment(-1.0f, _textAlignVertical.y),
                                   widthFactor: 1.0f,
                                   heightFactor: 1.0f,
                                   child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle)
                                   )
                               )
                           )

                       ));
        }