예제 #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, 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));
        }
예제 #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)
                {
                    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);
        }
예제 #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, 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);
        }
예제 #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, 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);
        }
예제 #5
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));
        }