Beispiel #1
0
        protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.Helper;

            // text-format
            _textFormat = style.TextFormat(this);
            SetText();

            // background color, background image, borders
            using (var background = stylesheet.Background(this, styleBound))
                SetBackground(background);

            // font
            stylesheet.SetFontSettings(this, _view, styleBound.Height);

            // text color
            _textColor = style.Color(this).ToColorOrTransparent();
            _view.SetTextColor(_textColor);

            //selected color
            _selectedColor = style.SelectedColor(this).ToNullableColor();

            //selected background
            _selectionBehaviour = new SelectionBehaviour(style.SelectedBackground(this).ToNullableColor(), this, stylesheet);

            // word wrap
            _singleLine = style.WhiteSpace(this) == WhiteSpaceKind.Nowrap;
            if (_singleLine)
            {
                _view.SetSingleLine();
            }

            // text align
            TextAlignValues align = style.TextAlign(this, DefaultAlignValues);

            ApplyTextAlign(align);
            if (_singleLine)
            {
                _view.Ellipsize = align == TextAlignValues.Right ? TextUtils.TruncateAt.Start : TextUtils.TruncateAt.End;
            }

            // text padding
            int pl = style.PaddingLeft(this, styleBound.Width).Round();
            int pt = style.PaddingTop(this, styleBound.Height).Round();
            int pr = style.PaddingRight(this, styleBound.Width).Round();
            int pb = style.PaddingBottom(this, styleBound.Height).Round();

            _view.SetPadding(pl, pt, pr, pb);

            return(SizeToContent(styleBound, maxBound, style));
        }
Beispiel #2
0
        protected sealed override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            IStyleSheetHelper style = stylesheet.Helper;

            // background color, borders
            using (var background = stylesheet.Background(this, styleBound, true))
                SetBackground(background);

            // text color
            Color textColor = style.Color(this).ToColorOrTransparent();

            _view.SetTextColor(textColor);

            SetCursor();

            // placeholder color
            var hintColor = style.PlaceholderColor(this).ToNullableColor();

            if (hintColor != null)
            {
                string text = _view.Text;
                _view.Text = null;
                _view.SetHintTextColor(hintColor.Value);
                _view.Text = text;
            }

            // font
            stylesheet.SetFontSettings(this, _view, styleBound.Height);

            // padding
            int pl = style.PaddingLeft(this, styleBound.Width).Round();
            int pt = style.PaddingTop(this, styleBound.Height).Round();
            int pr = style.PaddingRight(this, styleBound.Width).Round();
            int pb = style.PaddingBottom(this, styleBound.Height).Round();

            View.SetPadding(pl, pt, pr, pb);

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlignValues.Left:
                _view.Gravity = GravityFlags.Top | GravityFlags.Left;
                break;

            case TextAlignValues.Center:
                _view.Gravity = GravityFlags.Top | GravityFlags.CenterHorizontal;
                break;

            case TextAlignValues.Right:
                _view.Gravity = GravityFlags.Top | GravityFlags.Right;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
                _view.SetSingleLine(IsMultiline()); // fix disappearing text in android 5.0+
            }

            return(GetBoundByBackgroud(styleBound, maxBound));
        }