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); }
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)); }
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); }
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); }
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)); }
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); }
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); } }
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); }
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)); }
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); }
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); }
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)); }
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); }
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); }
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); }
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)); }