Exemplo n.º 1
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)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.BackgroundColor = backgroundColor.ToColorOrClear();
                }
            }

            foreach (Control control in _containerBehaviour.Childrens)
            {
                if (control.View != null)
                {
                    ApplyChild(control, styleBound);
                }
            }

            Index = ScrollIndex;
            _view.ReloadData();

            return(styleBound);
        }
Exemplo 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)
            {
                // background color, background image, borders
                _backgroundImage = helper.SetBackgroundSettings(this);
                if (_backgroundImage == null)
                {
                    _backgroundColor = _view.BackgroundColor;
                }
                else
                {
                    DrawBackgroundImage(_backgroundImage);
                }
                // selected-color
                _selectedColor = helper.Get <ISelectedColor>().ToNullableColor();
                if (_selectedColor != null && _backgroundImage != null)
                {
                    _selectedImage = GetFilteredImage(_backgroundImage, _selectedColor);
                }
            }
            // size to content by background
            IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage);

            return(LayoutChildren(CurrentStyleSheet, bound, maxBound));
        }
Exemplo n.º 3
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)
            {
                // background color, background image, borders
                Drawable background;
                if (helper.BackgroundChanged(CurrentStyleSheet, Frame.Bound, out background))
                {
                    using (background)
                        SetBackground(background);
                }

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

            IBound bound = GetBoundByBackgroud(styleBound, maxBound);

            return(LayoutChildren(CurrentStyleSheet, bound, maxBound));
        }
Exemplo n.º 4
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)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.SetBackgroundColor(backgroundColor.ToColorOrTransparent());
                }
            }

            foreach (Control control in _containerBehaviour.Childrens)
            {
                if (control.View != null)
                {
                    ApplyChild(control, styleBound);
                }
            }

            _view.InvalidateViews();
            _view.Invalidate();

            return(styleBound);
        }
Exemplo n.º 5
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            // background image
            _backgroundImage = FromSource() ?? helper.Get <IBackgroundImage>().GetImage();

            if (_backgroundImage != null)
            {
                _view.Image = _backgroundImage;

                // selected-color
                ISelectedColor selectedColor;
                if (helper.TryGet(out selectedColor))
                {
                    UIColor color = selectedColor.ToNullableColor();
                    if (color != null)
                    {
                        _selectedImage = GetFilteredImage(_backgroundImage, selectedColor.ToNullableColor());
                    }
                }
            }

            // size to content by background
            return(GetBoundByImage(styleBound, maxBound, _backgroundImage));
        }
Exemplo n.º 6
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)
            {
                // background color
                _view.BackgroundColor = helper.Get <IBackgroundColor>().ToColorOrClear();
            }
            return(styleBound);
        }
Exemplo n.º 7
0
        public static void ReloadBackgroundImage(this IStyleHelper helper, IStyleSheet styleSheet, IBound bound, Control control)
        {
            IBackgroundImage image;

            if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
            {
                var imageCache = styleSheet.GetCache <ImageCache>();
                using (BitmapDrawable background = imageCache.GetImage(image.Path, bound.Width, bound.Height))
                    control.SetBackground(background);
            }
        }
Exemplo n.º 8
0
        public static bool BackgroundChanged(this IStyleHelper helper
                                             , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache <ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return(true);
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return(false);
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle     borderStyle;
            IBorderWidth     borderWidth;
            IBorderColor     borderColor;
            IBorderRadius    borderRadius;

            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var   shape = new GradientDrawable();
                    var   width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                {
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                }
                return(true);
            }

            background = null;
            return(false);
        }
Exemplo n.º 9
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)
            {
                IColor color;
                if (helper.TryGet(out color))
                {
                    _view.Color = color.ToColorOrClear();
                }
            }
            return(styleBound);
        }
Exemplo n.º 10
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)
            {
                IColor color;
                if (helper.TryGet(out color))
                {
                    _view.IndeterminateDrawable.SetColorFilter(color.ToColorOrTransparent(), PorterDuff.Mode.Multiply);
                }
            }

            return(StyleSheetContext.Current.StrechBoundInProportion(styleBound, maxBound, 1, 1));
        }
Exemplo n.º 11
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)
            {
                // background color, background image, borders
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.SetBackgroundColor(backgroundColor.ToColorOrTransparent());
                }
            }

            return(styleBound);
        }
Exemplo n.º 12
0
        public static void SetFontSettings(this IStyleHelper helper, TextView view, float parentHeight)
        {
            string fontFamily;

            if (helper.TryGetFontFamily(out fontFamily))
            {
                view.SetTypeface(Typeface.Create(fontFamily, TypefaceStyle.Normal), TypefaceStyle.Normal);
            }

            float fontSize;

            if (helper.TryGetFontSize(parentHeight, out fontSize))
            {
                view.SetTextSize(ComplexUnitType.Px, fontSize);
            }
        }
Exemplo n.º 13
0
        public static UIImage SetBackgroundSettings(this IStyleHelper helper, Control control)
        {
            IBackgroundImage backgroundImage;

            if (helper.TryGet(out backgroundImage) && !string.IsNullOrWhiteSpace(backgroundImage.Path))
            {
                UIImage image = backgroundImage.GetImage();
                if (image != null)
                {
                    return(image);
                }
            }
            // if control has background image, we have to ignore background color
            if (!string.IsNullOrEmpty(backgroundImage.Path))
            {
                return(null);
            }

            IBackgroundColor backgroundColor;
            IBorderStyle     borderStyle;
            IBorderWidth     borderWidth;
            IBorderColor     borderColor;
            IBorderRadius    borderRadius;

            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                control.View.BackgroundColor = backgroundColor.ToColorOrClear();
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    control.View.ClipsToBounds      = true;
                    control.View.Layer.BorderWidth  = borderWidth.Value;
                    control.View.Layer.BorderColor  = borderColor.ToColorOrClear().CGColor;
                    control.View.Layer.CornerRadius = borderRadius.Radius;
                }
                else
                {
                    // hide bounds
                    control.View.ClipsToBounds      = false;
                    control.View.Layer.BorderWidth  = 0;
                    control.View.Layer.BorderColor  = UIColor.Clear.CGColor;
                    control.View.Layer.CornerRadius = 0;
                }
            }
            return(null);
        }
Exemplo n.º 14
0
        public static bool FontChanged(this IStyleHelper helper, float parentHeight, out UIFont font)
        {
            string fontFamily;
            float  fontSize;
            bool   changed = helper.TryGetFontFamily(out fontFamily);

            changed |= helper.TryGetFontSize(parentHeight, out fontSize);

            if (changed)
            {
                font = UIFont.FromName(fontFamily, fontSize);
                return(true);
            }

            font = null;
            return(false);
        }
Exemplo n.º 15
0
 public StyleKeeper(IStyleHelper styleHelper)
 {
     if (styleHelper == null)
     {
         throw new ArgumentNullException("styleHelper");
     }
     _Helper = styleHelper;
     _Local  = new LocalStyleGroup {
         Name = "Local", Helper = _Helper.Local
     };
     _Remote = new RemoteStyleGroup {
         Name = "Remote"
     };
     _Embedded = new EmbeddedStyleGroup {
         Name = "Embedded"
     };
 }
Exemplo n.º 16
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            var bound = StyleSheetContext.Current.CreateBound(BitBrowserApp.Current.Width, BitBrowserApp.Current.Height);

            base.ReApply(styles, bound, bound);

            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                // background color
                IBackgroundColor backgroundColor;
                if (helper.TryGet(out backgroundColor))
                {
                    _view.SetBackgroundColor(backgroundColor.ToColorOrTransparent());
                }
            }

            return(bound);
        }
Exemplo n.º 17
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)
            {
                // background color, background image, borders
                _backgroundImage = helper.SetBackgroundSettings(this);
                if (_backgroundImage != null)
                {
                    DrawBackgroundImage();
                }
            }

            // size to content by background
            IBound boundByBackground = GetBoundByImage(styleBound, maxBound, _backgroundImage);
            IBound bound             = LayoutChildren(CurrentStyleSheet, boundByBackground, maxBound);

            SetupAlignOffset(bound);
            _view.ContentOffset = GetContentOffset(Behaviour.OffsetByIndex);

            return(bound);
        }
Exemplo n.º 18
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)
            {
                // background color, borders
                helper.SetBackgroundSettings(this);

                // text color
                ITextColor textColor;
                if (helper.TryGet(out textColor))
                {
                    _view.TextColor = textColor.ToColorOrClear();
                }

                // placeholder color
                IPlaceholderColor placeholderColor;
                if (helper.TryGet(out placeholderColor))
                {
                    _placeholderColor = placeholderColor.ToNullableColor();
                    SetupPlaceholder(_placeholder);
                }

                // font
                UIFont f;
                if (helper.FontChanged(styleBound.Height, out f))
                {
                    _view.Font = f;
                }

                // padding
                float screenWidth  = ApplicationContext.Current.DisplayProvider.Width;
                float screenHeight = ApplicationContext.Current.DisplayProvider.Height;
                _view.PaddingLeft   = helper.Get <IPaddingLeft>().CalcSize(styleBound.Width, screenWidth);
                _view.PaddingTop    = helper.Get <IPaddingTop>().CalcSize(styleBound.Height, screenHeight);
                _view.PaddingRight  = helper.Get <IPaddingRight>().CalcSize(styleBound.Width, screenWidth);
                _view.PaddingBottom = helper.Get <IPaddingBottom>().CalcSize(styleBound.Height, screenHeight);

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

                    case TextAlignValues.Center:
                        _view.TextAlignment = UITextAlignment.Center;
                        break;

                    case TextAlignValues.Right:
                        _view.TextAlignment = UITextAlignment.Right;
                        break;
                    }
                }

                DisposeField(ref _placeholderColor);

                DisposeField(ref _placeholderColor);

                // for padding :)
                _view.RightView = CreateValidationIcon(_view.Font.LineHeight);
            }

            return(styleBound);
        }
Exemplo n.º 19
0
        protected override IBound ReApply(IDictionary <Type, IStyle> styles, IBound styleBound, IBound maxBound)
        {
            // we forbid execution of SetSpannedString()
            _blinkAllowed = false;

            IStyleHelper helper = StyleSheetContext.Current.CreateHelper(styles, CurrentStyleSheet, this);

            if (styles.Count > 0)
            {
                _view.Text = _text;

                // background color, borders, background image
                UIImage image = helper.SetBackgroundSettings(this);
                if (image != null && image != _backgroundImage)
                {
                    _backgroundImage.Dispose();
                    _backgroundImage      = image;
                    _view.Layer.Contents  = _backgroundImage.CGImage;
                    _view.BackgroundColor = UIColor.Clear;
                }

                // font
                UIFont f;
                if (helper.FontChanged(styleBound.Height, out f))
                {
                    _view.Font = f;
                }

                // word wrap
                IWhiteSpace whiteSpace;
                bool        whiteSpaceChanged = helper.TryGet(out whiteSpace);
                bool        nowrap            = whiteSpace.Kind == WhiteSpaceKind.Nowrap;
                if (whiteSpaceChanged)
                {
                    if (!nowrap)
                    {
                        _view.TextContainer.LineBreakMode        = UILineBreakMode.WordWrap;
                        _view.TextContainer.MaximumNumberOfLines = 0;
                    }
                    else
                    {
                        _view.TextContainer.LineBreakMode        = UILineBreakMode.TailTruncation;
                        _view.TextContainer.MaximumNumberOfLines = 1;
                    }
                }

                // text-format
                ITextFormat textFormat;
                bool        formatChanged = helper.TryGet(out textFormat);
                _textFormat = textFormat.Format;

                switch (_textFormat)
                {
                case TextFormatValues.Text:
                {
                    _view.AttributedText = new NSAttributedString();
                    _view.Text           = _text;

                    // text color
                    ITextColor textColor;
                    if (helper.TryGet(out textColor) || formatChanged)
                    {
                        _view.TextColor = _textColor = textColor.ToColorOrClear();
                    }

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

                case TextFormatValues.Html:
                {
                    string span =
                        string.Format("<span style=\"font-family: {0}; font-size: {1:F0}; color: {2}\">{3}</span>",
                                      _view.Font.FamilyName, _view.Font.PointSize, "{0}", "{1}");

                    ITextColor textColor;
                    formatChanged |= helper.TryGet(out textColor);
                    _textHtmlSpan  = string.Format(span, textColor.Value.Hex, "{0}");

                    // selected-color
                    ISelectedColor selectedColor;
                    formatChanged |= helper.TryGet(out selectedColor);
                    if (selectedColor.ToNullableColor() != null)
                    {
                        _selectedHtmlSpan = string.Format(span, selectedColor.Value.Hex, "{0}");
                    }

                    if (formatChanged)
                    {
                        SetSpannedText(_textHtmlSpan);
                    }
                }
                break;

                default:
                    throw new NotImplementedException("Text format not found: " + _textFormat);
                }

                // selected-background
                ISelectedBackground selectedBackground;
                if (helper.TryGet(out selectedBackground))
                {
                    UIColor color = selectedBackground.ToNullableColor();
                    if (_backgroundImage != null && color != null)
                    {
                        _selectedBackgroundImage = GetFilteredImage(_backgroundImage, color).CGImage;
                        color.Dispose();
                    }
                    else
                    {
                        _selectedBackground = color;
                    }
                }

                // text align
                ITextAlign textAlign;
                if (helper.TryGet(out textAlign))
                {
                    SetTextAlign(textAlign.Align, nowrap);
                }

                // text padding
                float screenWidth  = ApplicationContext.Current.DisplayProvider.Width;
                float screenHeight = ApplicationContext.Current.DisplayProvider.Height;
                float pl           = helper.Get <IPaddingLeft>().CalcSize(styleBound.Width, screenWidth);
                float pt           = helper.Get <IPaddingTop>().CalcSize(styleBound.Height, screenHeight);
                float pr           = helper.Get <IPaddingRight>().CalcSize(styleBound.Width, screenWidth);
                float pb           = helper.Get <IPaddingBottom>().CalcSize(styleBound.Height, screenHeight);
                _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr);
            }
            _blinkAllowed = true;

            // resize by background image
            IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage);

            // size to content
            return(MergeBoundByContent(CurrentStyleSheet.Helper, bound, maxBound, _view.TextContainerInset,
                                       _backgroundImage != null));
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
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)
            {
                // background color, borders
                helper.SetBackgroundSettings(this);

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

                // placeholder color
                IPlaceholderColor placeholderColor;
                if (helper.TryGet(out placeholderColor))
                {
                    _placeholderColor = placeholderColor.ToColorOrClear();
                    if (!string.IsNullOrEmpty(_placeholder) && _placeholderVisible)
                    {
                        _view.TextColor = _placeholderColor;
                    }
                }

                // font
                UIFont f;
                if (helper.FontChanged(styleBound.Height, out f))
                {
                    _view.Font = f;
                }

                // padding
                float screenWidth  = ApplicationContext.Current.DisplayProvider.Width;
                float screenHeight = ApplicationContext.Current.DisplayProvider.Height;
                float pl           = helper.Get <IPaddingLeft>().CalcSize(styleBound.Width, screenWidth);
                float pt           = helper.Get <IPaddingTop>().CalcSize(styleBound.Height, screenHeight);
                float pr           = helper.Get <IPaddingRight>().CalcSize(styleBound.Width, screenWidth);
                float pb           = helper.Get <IPaddingBottom>().CalcSize(styleBound.Height, screenHeight);
                if (IOSApplicationContext.OSVersion.Major >= 7)
                {
                    _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr);
                }

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

                    case TextAlignValues.Center:
                        _view.TextAlignment = UITextAlignment.Center;
                        break;

                    case TextAlignValues.Right:
                        _view.TextAlignment = UITextAlignment.Right;
                        break;
                    }
                }

                float size = _view.Font.LineHeight;
                _errorSubview.Frame  = new RectangleF(styleBound.Width - size, pt, size, size);
                _errorSubview.Hidden = true;
            }

            return(styleBound);
        }
Exemplo n.º 22
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);
        }