Esempio n. 1
0
        protected sealed override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color, borders
                Drawable background;
                if (helper.BackgroundChanged(CurrentStyleSheet, Frame.Bound, out background))
                {
                    using (background)
                        SetBackground(background);
                }

                // text color
                ITextColor textColor;
                if (helper.TryGet(out textColor))
                {
                    _view.SetTextColor(textColor.ToColorOrTransparent());
                }


                // placeholder color
                IPlaceholderColor placeholderColor;
                if (helper.TryGet(out placeholderColor))
                {
                    var color = placeholderColor.ToNullableColor();
                    if (color != null)
                    {
                        string text = _view.Text;
                        _view.Text = null;
                        _view.SetHintTextColor(color.Value);
                        _view.Text = text;
                    }
                }

                // font
                helper.SetFontSettings(_view, styleBound.Height);

                // text padding
                int pl = helper.GetSizeOrDefault <IPaddingLeft>(styleBound.Width, _view.PaddingLeft).Round();
                int pt = helper.GetSizeOrDefault <IPaddingTop>(styleBound.Height, _view.PaddingTop).Round();
                int pr = helper.GetSizeOrDefault <IPaddingRight>(styleBound.Width, _view.PaddingRight).Round();
                int pb = helper.GetSizeOrDefault <IPaddingBottom>(styleBound.Height, _view.PaddingBottom).Round();
                _view.SetPadding(pl, pt, pr, pb);

                // text align
                ITextAlign textAlign;
                if (helper.TryGet(out textAlign))
                {
                    switch (textAlign.Align)
                    {
                    case TextAlignValues.Left:
                        _view.Gravity = GravityFlags.Left;
                        break;

                    case TextAlignValues.Center:
                        _view.Gravity = GravityFlags.Center;
                        break;

                    case TextAlignValues.Right:
                        _view.Gravity = 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));
        }
Esempio n. 2
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // text-format
                ITextFormat textFormat;
                if (helper.TryGet(out textFormat))
                {
                    _textFormat = textFormat.Format;
                    SetText();
                }

                // background color, background image, borders
                Drawable background;
                if (helper.BackgroundChanged(CurrentStyleSheet, Frame.Bound, out background))
                {
                    using (background)
                        SetBackground(background);
                }

                // font
                helper.SetFontSettings(_view, styleBound.Height);

                // text color
                ITextColor textColor;
                if (helper.TryGet(out textColor))
                {
                    _textColor = textColor.ToColorOrTransparent();
                    _view.SetTextColor(_textColor);
                }

                //selected color
                ISelectedColor selectedColor;
                if (helper.TryGet(out selectedColor))
                {
                    _selectedColor = selectedColor.ToNullableColor();
                }

                //selected background
                ISelectedBackground selectedBackground;
                if (helper.TryGet(out selectedBackground))
                {
                    _selectionBehaviour.SelectedColor = selectedBackground.ToNullableColor();
                }

                // word wrap
                IWhiteSpace whiteSpace;
                if (helper.TryGet(out whiteSpace))
                {
                    _singleLine = whiteSpace.Kind == WhiteSpaceKind.Nowrap;
                    _view.SetSingleLine(_singleLine);
                }

                // text align
                ITextAlign textAlign;
                if (helper.TryGet(out textAlign))
                {
                    ApplyTextAlign(textAlign.Align);
                    if (_singleLine)
                    {
                        _view.Ellipsize = textAlign.Align == TextAlignValues.Right
                            ? TextUtils.TruncateAt.Start
                            : TextUtils.TruncateAt.End;
                    }
                }

                // text padding
                int pl = helper.GetSizeOrDefault <IPaddingLeft>(styleBound.Width, _view.PaddingLeft).Round();
                int pt = helper.GetSizeOrDefault <IPaddingTop>(styleBound.Height, _view.PaddingTop).Round();
                int pr = helper.GetSizeOrDefault <IPaddingRight>(styleBound.Width, _view.PaddingRight).Round();
                int pb = helper.GetSizeOrDefault <IPaddingBottom>(styleBound.Height, _view.PaddingBottom).Round();
                _view.SetPadding(pl, pt, pr, pb);
            }

            IBound bound = SizeToContent(styleBound, maxBound, CurrentStyleSheet.Helper);

            // reload image with new size
            helper.ReloadBackgroundImage(CurrentStyleSheet, bound, this);

            return(bound);
        }