protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background color, background image, borders _backgroundImage = stylesheet.SetBackgroundSettings(this); if (_backgroundImage == null) { _backgroundColor = _view.BackgroundColor; } // selected-color _selectedColor = style.SelectedColor(this).ToNullableColor(); if (_selectedColor != null && _backgroundImage != null) { _selectedImage = GetFilteredImage(_backgroundImage, _selectedColor); } // size to content by background IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage); return(LayoutChildren(stylesheet, bound, maxBound)); }
private IBound SizeToContent(IBound styleBound, IBound maxBound, IStyleSheetHelper style) { IBound bound = GetBoundByBackgroud(styleBound, maxBound); bool sizeByWith = style.SizeToContentWidth(this); bool sizeByHeight = style.SizeToContentHeight(this); if (sizeByWith || sizeByHeight) { float measureWidth = sizeByWith ? maxBound.Width : styleBound.Width; float measureHeight = sizeByHeight ? maxBound.Height : styleBound.Height; // RedundantNameQualifier to fix compile error // ReSharper disable RedundantNameQualifier int wspec = Android.Views.View.MeasureSpec.MakeMeasureSpec(Java.Lang.Math.Round(measureWidth), MeasureSpecMode.AtMost); int hspec = Android.Views.View.MeasureSpec.MakeMeasureSpec(Java.Lang.Math.Round(measureHeight), MeasureSpecMode.AtMost); // ReSharper restore RedundantNameQualifier _view.Measure(wspec, hspec); float w = sizeByWith ? _view.MeasuredWidth : styleBound.Width; float h = sizeByHeight ? _view.MeasuredHeight : styleBound.Height; // choose max bound: from image resizing or from size to content by text bool safeProportion = !bound.Equals(styleBound) && sizeByWith && sizeByHeight; bound = StyleSheetContext.Current.MergeBound(bound, w, h, maxBound, safeProportion); } return(bound); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { IStyleSheetHelper style = stylesheet.Helper; base.Apply(stylesheet, styleBound, maxBound); // background color, borders stylesheet.SetBackgroundSettings(this); // text color _view.TextColor = style.Color(this).ToColorOrClear(); // placeholder color _placeholderColor = style.PlaceholderColor(this).ToNullableColor(); SetupPlaceholder(_placeholder); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // padding _view.PaddingLeft = style.PaddingLeft(this, styleBound.Width); _view.PaddingTop = style.PaddingTop(this, styleBound.Height); _view.PaddingRight = style.PaddingRight(this, styleBound.Width); _view.PaddingBottom = style.PaddingBottom(this, styleBound.Height); // text align switch (style.TextAlign(this)) { case TextAlignValues.Left: _view.TextAlignment = UITextAlignment.Left; break; case TextAlignValues.Center: _view.TextAlignment = UITextAlignment.Center; break; case TextAlignValues.Right: _view.TextAlignment = UITextAlignment.Right; break; } _view.RightView = CreateValidationIcon(_view.Font.LineHeight); _view.Text = _text; // size to content by background return(styleBound); }
public static UIFont Font(this IStyleSheet styleSheet, Control control, float parentHeight) { IStyleSheetHelper style = styleSheet.Helper; string fontName = style.FontName(control); if (fontName != null) { float size = style.FontSize(control, parentHeight); return(UIFont.FromName(fontName, size)); } return(null); }
public static Bound Screen(StyleSheet.StyleSheet stylesheet , ILayoutable parent , ILayoutable control , Bound screenBound) { IStyleSheetHelper style = stylesheet.Helper; float parentW = screenBound.Width; float parentH = screenBound.Height; float paddingL = style.Padding <PaddingLeft>(parent, parentW); float paddingT = style.Padding <PaddingTop>(parent, parentH); float paddingR = style.Padding <PaddingRight>(parent, parentW); float paddingB = style.Padding <PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin <MarginLeft>(control, parentW); float marginT = style.Margin <MarginTop>(control, parentH); float marginR = style.Margin <MarginRight>(control, parentW); float marginB = style.Margin <MarginBottom>(control, parentH); InitializeImageContainer(stylesheet, control, ref w, ref h); float maxW = parentW - (marginL + marginR) - (paddingL + paddingR) - 2 * borderWidth; if (parentW < paddingL + marginL + w + marginR + paddingR + 2 * borderWidth) { w = maxW; } float maxH = parentH - (marginT + marginB) - (paddingT + paddingB) - 2 * borderWidth; if (parentH < paddingT + marginT + h + marginB + paddingB + 2 * borderWidth) { h = maxH; } float l = borderWidth + paddingL + marginL; float t = borderWidth + paddingT + marginT; Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width > maxW ? maxW : bound.Width; h = bound.Height > maxH ? maxH : bound.Height; control.Frame = new Rectangle(l, t, w, h); return(screenBound); }
private void ApplyChild(Control control, IBound rootBound) { float parentWidth = rootBound.Width; float parentHeight = rootBound.Height; IStyleSheetHelper style = _stylesheet.Helper; float w = style.Width(control, parentWidth); float h = style.Height(control, parentHeight); IStyleSheetContext context = StyleSheetContext.Current; IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h), context.CreateBound(parentWidth, float.MaxValue)); control.Frame = ControlsContext.Current.CreateRectangle(0, 0, bound); }
private void ApplyChild(Control control, IBound rootBound) { float parentWidth = rootBound.Width; float parentHeight = rootBound.Height; IStyleSheetHelper style = CurrentStyleSheet.Helper; float width = style.Width(control, parentWidth); float height = style.Height(control, parentHeight); IBound bound = control.ApplyStyles(CurrentStyleSheet, StyleSheetContext.Current.CreateBound(width, height), StyleSheetContext.Current.CreateBound(parentWidth, float.PositiveInfinity)); control.Frame = ControlsContext.Current.CreateRectangle(0, 0, bound); control.View.LayoutParameters = new AbsListView.LayoutParams(control.Frame.Width.Round(), control.Frame.Height.Round()); }
public IBound Screen(ILayoutable control, IBound screenBound) { IStyleSheetHelper style = _stylesheet.Helper; IStyleSheetContext context = StyleSheetContext.Current; float parentW = screenBound.Width; float parentH = screenBound.Height; float paddingL = style.PaddingLeft(_container, parentW); float paddingT = style.PaddingTop(_container, parentH); float paddingR = style.PaddingRight(_container, parentW); float paddingB = style.PaddingBottom(_container, parentH); float borderWidth = style.BorderWidth(_container); float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.MarginLeft(control, parentW); float marginT = style.MarginTop(control, parentH); float marginR = style.MarginRight(control, parentW); float marginB = style.MarginBottom(control, parentH); float maxW = parentW - (marginL + marginR) - (paddingL + paddingR) - 2 * borderWidth; if (parentW < paddingL + marginL + w + marginR + paddingR + 2 * borderWidth) { w = maxW; } float maxH = parentH - (marginT + marginB) - (paddingT + paddingB) - 2 * borderWidth; if (parentH < paddingT + marginT + h + marginB + paddingB + 2 * borderWidth) { h = maxH; } float l = borderWidth + paddingL + marginL; float t = borderWidth + paddingT + marginT; IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h), context.CreateBound(maxW, maxH)); w = bound.Width > maxW ? maxW : bound.Width; h = bound.Height > maxH ? maxH : bound.Height; control.Frame = new Rectangle(l, t, w, h); return(screenBound); }
void Dispose(bool disposing) { if (!_disposed) { if (disposing) { Helper = null; } if (_cache != null) { _cache.Dispose(); } _cache = null; _disposed = true; } }
private void Relayout() { IStyleSheetHelper helper = CurrentStyleSheet.Helper; bool changed = _disposed || _siblingsChanged || helper.SizeToContentWidth(this) || helper.SizeToContentHeight(this) || StylesChanged(); if (Parent != null && changed) { var parent = (CustomControl <T>)Parent; parent.Relayout(); _siblingsChanged = false; } else { ApplyStyles(CurrentStyleSheet, Frame.Bound, Frame.Bound); } }
protected IBound MergeBoundByContent(IStyleSheetHelper style, IBound bound, IBound maxBound, UIEdgeInsets insets, bool safeProportion) { bool sizeByWidth = style.SizeToContentWidth(this); bool sizeByHeight = style.SizeToContentHeight(this); if (sizeByWidth || sizeByHeight) { float measureWidth = sizeByWidth ? maxBound.Width : bound.Width; float measureHeight = sizeByHeight ? maxBound.Height : bound.Height; SizeF size = _view.SizeThatFits(new SizeF(measureWidth, measureHeight)); float w = sizeByWidth ? size.Width + insets.Left + insets.Right : bound.Width; float h = sizeByHeight ? size.Height + insets.Top + insets.Bottom : bound.Height; bound = StyleSheetContext.Current.MergeBound(bound, w, h, maxBound, safeProportion && sizeByWidth && sizeByHeight); } return(bound); }
public static UIImage SetBackgroundSettings(this IStyleSheet styleSheet, Control control) { IStyleSheetHelper style = styleSheet.Helper; UIImage image = styleSheet.GetBackgroundImage(control); if (image != null) { return(image); } control.View.BackgroundColor = style.BackgroundColor(control).ToColorOrClear(); if (style.HasBorder(control)) { control.View.ClipsToBounds = true; control.View.Layer.BorderWidth = style.BorderWidth(control); control.View.Layer.BorderColor = style.BorderColor(control).ToColorOrClear().CGColor; control.View.Layer.CornerRadius = style.BorderRadius(control); } return(null); }
public static Drawable ColorWithBorders(this IStyleSheet styleSheet, IStyledObject control, Color color) { IStyleSheetHelper helper = styleSheet.Helper; Drawable drawable; if (styleSheet.Helper.HasBorder(control)) { var shape = new GradientDrawable(); var borderWidth = (int)Math.Round(helper.BorderWidth(control)); Color borderColor = ToColorOrTransparent(helper.BorderColor(control)); shape.SetShape(ShapeType.Rectangle); shape.SetColor(color); shape.SetCornerRadius(helper.BorderRadius(control)); shape.SetStroke(borderWidth, borderColor); drawable = shape; } else { drawable = new ColorDrawable(color); } return(drawable); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background image _backgroundImage = FromSource() ?? stylesheet.GetBackgroundImage(this); if (_backgroundImage != null) { _view.Image = _backgroundImage; // selected-color UIColor selectedColor = style.SelectedColor(this).ToNullableColor(); if (selectedColor != null) { _selectedImage = GetFilteredImage(_backgroundImage, selectedColor); } } // size to content by background return(GetBoundByImage(styleBound, maxBound, _backgroundImage)); }
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)); }
public IBound Dock(IEnumerable <ILayoutable> controls, IBound styleBound, IBound maxBound) { IStyleSheetHelper style = _stylesheet.Helper; IStyleSheetContext context = StyleSheetContext.Current; float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.PaddingLeft(_container, parentW); float paddingT = style.PaddingTop(_container, parentH); float paddingR = style.PaddingRight(_container, parentW); float paddingB = style.PaddingBottom(_container, parentH); float borderWidth = style.BorderWidth(_container); float left = borderWidth + paddingL; float top = borderWidth + paddingT; float right = parentW - (paddingR + borderWidth); float bottom = parentH - (paddingB + borderWidth); float resizedWidth = parentW; float resizedHeight = parentH; float freeW = style.SizeToContentWidth(_container) ? maxBound.Width - parentW : 0; float freeH = style.SizeToContentHeight(_container) ? maxBound.Height - parentH : 0; IList <ILayoutable> controlsList = controls as IList <ILayoutable> ?? controls.ToList(); var frames = new Rectangle[controlsList.Count]; for (int i = 0; i < controlsList.Count; i++) { ILayoutable control = controlsList[i]; float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.MarginLeft(control, parentW); float marginT = style.MarginTop(control, parentH); float marginR = style.MarginRight(control, parentW); float marginB = style.MarginBottom(control, parentH); float maxW = right - left - (marginL + marginR); float maxH = bottom - top - (marginT + marginB); resizedWidth += SizeTo(false, ref w, ref maxW, ref freeW, ref right); resizedHeight += SizeTo(false, ref h, ref maxH, ref freeH, ref bottom); IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h) , context.CreateBound(maxW + freeW, maxH + freeH)); w = bound.Width; h = bound.Height; resizedWidth += SizeTo(false, ref w, ref maxW, ref freeW, ref right); resizedHeight += SizeTo(false, ref h, ref maxH, ref freeH, ref bottom); float x = left + marginL; float y = top + marginT; DockAlignValues align = style.DockAlign(control); switch (align) { case DockAlignValues.Left: left += marginL + w + marginR; break; case DockAlignValues.Top: top += marginT + h + marginB; break; case DockAlignValues.Right: x = right - (marginR + w); right -= marginL + w + marginR; // reverse reference system, for size to content x = -(resizedWidth - x); break; case DockAlignValues.Bottom: y = bottom - (marginB + h); bottom -= marginT + h + marginB; // reverse reference system, for size to content y = -(resizedHeight - y); break; default: throw new Exception("Unknown align: " + align); } frames[i] = new Rectangle(x, y, w, h); } // restore reference system for (int i = 0; i < controlsList.Count; i++) { Rectangle f = frames[i]; float x = f.Left >= 0 ? f.Left : resizedWidth + f.Left; float y = f.Top >= 0 ? f.Top : resizedHeight + f.Top; controlsList[i].Frame = new Rectangle(x, y, f.Width, f.Height); } return(context.CreateBound(resizedWidth, resizedHeight)); }
private IBound Queue(IEnumerable <ILayoutable> controls, IBound styleBound, IBound maxBound, out float[] borders, bool horizontal, bool extensible) { if (styleBound.Width > maxBound.Width || styleBound.Height > maxBound.Height) { throw new ArgumentException("maxBoud lesser than styleBound"); } IStyleSheetHelper style = _stylesheet.Helper; IStyleSheetContext context = StyleSheetContext.Current; var bordersList = new List <float>(); float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.PaddingLeft(_container, parentW); float paddingT = style.PaddingTop(_container, parentH); float paddingR = style.PaddingRight(_container, parentW); float paddingB = style.PaddingBottom(_container, parentH); float borderWidth = style.BorderWidth(_container); float left = paddingL + borderWidth; float top = paddingT + borderWidth; float right = parentW - (borderWidth + paddingR); float bottom = parentH - (borderWidth + paddingB); float resizedWidth = parentW; float resizedHeight = parentH; bool sizeToContentWidth = style.SizeToContentWidth(_container); bool sizeToContentHeight = style.SizeToContentHeight(_container); float freeW = sizeToContentWidth ? maxBound.Width - parentW : 0; float freeH = sizeToContentHeight ? maxBound.Height - parentH : 0; bordersList.Add(horizontal ? left : top); IList <ILayoutable> controlsList = controls as IList <ILayoutable> ?? controls.ToList(); var dirtyFrames = new LayoutParams[controlsList.Count]; for (int i = 0; i < controlsList.Count; i++) { ILayoutable control = controlsList[i]; float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.MarginLeft(control, parentW); float marginT = style.MarginTop(control, parentH); float marginR = style.MarginRight(control, parentW); float marginB = style.MarginBottom(control, parentH); float maxW = right - left - (marginL + marginR); float maxH = bottom - top - (marginT + marginB); resizedWidth += SizeTo(horizontal && extensible, ref w, ref maxW, ref freeW, ref right); resizedHeight += SizeTo(!horizontal && extensible, ref h, ref maxH, ref freeH, ref bottom); float childMaxW = horizontal && extensible ? float.MaxValue : maxW + freeW; float childMaxH = !horizontal && extensible ? float.MaxValue : maxH + freeH; IBound bound = control.ApplyStyles(_stylesheet, context.CreateBound(w, h), context.CreateBound(childMaxW, childMaxH)); w = bound.Width; h = bound.Height; resizedWidth += SizeTo(horizontal && extensible, ref w, ref maxW, ref freeW, ref right); resizedHeight += SizeTo(!horizontal && extensible, ref h, ref maxH, ref freeH, ref bottom); dirtyFrames[i] = new LayoutParams(left, top, w, h, marginL, marginT, marginR, marginB); // new Rectangle(left + leftOffset, top + topOffset, w, h); if (horizontal) { left += marginL + w + marginR; } else { top += marginT + h + marginB; } bordersList.Add(horizontal ? left : top); } borders = bordersList.ToArray(); for (int i = 0; i < controlsList.Count; i++) { ILayoutable control = controlsList[i]; LayoutParams layoutParams = dirtyFrames[i]; float topOffset = layoutParams.MarginTop; float leftOffset = layoutParams.MarginLeft; if (horizontal) { float maxH = bottom - top - (layoutParams.MarginTop + layoutParams.MarginBottom); if (layoutParams.Height < maxH) { VerticalAlignValues align = style.VerticalAlign(control); switch (align) { case VerticalAlignValues.Top: break; case VerticalAlignValues.Center: case VerticalAlignValues.Central: topOffset += (maxH - layoutParams.Height) / 2; break; case VerticalAlignValues.Bottom: topOffset = (bottom - layoutParams.MarginBottom - layoutParams.Height) - top; break; } } } else { float maxW = right - left - (layoutParams.MarginLeft + layoutParams.MarginRight); if (layoutParams.Width < maxW) { HorizontalAlignValues align = style.HorizontalAlign(control); switch (align) { case HorizontalAlignValues.Left: break; case HorizontalAlignValues.Center: case HorizontalAlignValues.Central: leftOffset += (maxW - layoutParams.Width) / 2; break; case HorizontalAlignValues.Right: leftOffset = (right - layoutParams.MarginRight - layoutParams.Width) - left; break; } } } control.Frame = new Rectangle(layoutParams.Left + leftOffset, layoutParams.Top + topOffset , layoutParams.Width, layoutParams.Height); } float contentW = horizontal ? left + paddingR + borderWidth : resizedWidth; float contentH = !horizontal ? top + paddingB + borderWidth : resizedHeight; return(context.CreateBound(resizedWidth, resizedHeight, contentW, contentH)); }
public static Bound Dock(StyleSheet.StyleSheet stylesheet , ILayoutable parent , IEnumerable <ILayoutable> controls , Bound styleBound , Bound maxBound) { IStyleSheetHelper style = stylesheet.Helper; float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.Padding <PaddingLeft>(parent, parentW); float paddingT = style.Padding <PaddingTop>(parent, parentH); float paddingR = style.Padding <PaddingRight>(parent, parentW); float paddingB = style.Padding <PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float layoutL = borderWidth + paddingL; float layoutT = borderWidth + paddingT; float layoutW = parentW - (paddingL + paddingR) - 2 * borderWidth; float layoutH = parentH - (paddingT + paddingB) - 2 * borderWidth; foreach (ILayoutable control in controls) { float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin <MarginLeft>(control, parentW); float marginT = style.Margin <MarginTop>(control, parentH); float marginR = style.Margin <MarginRight>(control, parentW); float marginB = style.Margin <MarginBottom>(control, parentH); float maxW = layoutW - (marginL + marginR); maxW = maxW > 0 ? maxW : 0; float maxH = layoutH - (marginT + marginB); maxH = maxH > 0 ? maxH : 0; if (layoutW < marginL + w + marginR) { w = maxW; } if (layoutH < marginT + h + marginB) { h = maxH; } Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width; h = bound.Height; InitializeImageContainer(stylesheet, control, ref w, ref h); if (layoutW < marginL + w + marginR) { w = maxW; } if (layoutH < marginT + h + marginB) { h = maxH; } float offsetL = layoutL; float offsetT = layoutT; DockAlign.Align align = style.DockAlign(control); switch (align) { case DockAlign.Align.Left: offsetL += marginL; offsetT += marginT; layoutL = offsetL + w + marginR; layoutW -= marginL + w + marginR; break; case DockAlign.Align.Top: offsetL += marginL; offsetT += marginT; layoutT = offsetT + h + marginB; layoutH -= marginT + h + marginB; break; case DockAlign.Align.Right: offsetL += layoutW - (w + marginR); offsetT += marginT; layoutW -= marginL + w + marginR; break; case DockAlign.Align.Bottom: offsetL += marginL; offsetT += layoutH - (h + marginB); layoutH -= marginT + h + marginB; break; } control.Frame = new Rectangle(offsetL, offsetT, w, h); } return(styleBound); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background color, borders stylesheet.SetBackgroundSettings(this); // text color _textColor = style.Color(this).ToColorOrClear(); _view.TextColor = _textColor; // placeholder color _placeholderColor = style.PlaceholderColor(this).ToColorOrClear(); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); if (IOSApplicationContext.OSVersion.Major >= 7) { _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr); } // text align switch (style.TextAlign(this)) { case TextAlignValues.Left: _view.TextAlignment = UITextAlignment.Left; break; case TextAlignValues.Center: _view.TextAlignment = UITextAlignment.Center; break; case TextAlignValues.Right: _view.TextAlignment = UITextAlignment.Right; break; } RefreshPlaceholder(); float size = _view.Font.LineHeight; _errorSubview = CreateValidationIcon(size); _errorSubview.Frame = new RectangleF(styleBound.Width - size, pt, size, size); _errorSubview.Hidden = true; _view.AddSubview(_errorSubview); // size to content by background return(styleBound); }
public static Bound Vertical(StyleSheet.StyleSheet stylesheet , ILayoutable parent , IEnumerable <ILayoutable> controls , Bound styleBound , Bound maxBound , bool extensible = false) { IStyleSheetHelper style = stylesheet.Helper; float parentW = styleBound.Width; float parentH = styleBound.Height; float paddingL = style.Padding <PaddingLeft>(parent, parentW); float paddingT = style.Padding <PaddingTop>(parent, parentH); float paddingR = style.Padding <PaddingRight>(parent, parentW); float paddingB = style.Padding <PaddingBottom>(parent, parentH); float borderWidth = style.BorderWidth(parent); float off = paddingT + borderWidth; foreach (ILayoutable control in controls) { float w = style.Width(control, parentW); float h = style.Height(control, parentH); float marginL = style.Margin <MarginLeft>(control, parentW); float marginT = style.Margin <MarginTop>(control, parentH); float marginR = style.Margin <MarginRight>(control, parentW); float marginB = style.Margin <MarginBottom>(control, parentH); off += marginT; float left = borderWidth + paddingL + marginL; float top = off; float right = parentW - (paddingR + marginR) - borderWidth; float bottom = parentH - (paddingB + marginB) - borderWidth; float maxW = right - left; maxW = maxW > 0 ? maxW : 0; float maxH = extensible ? float.MaxValue : bottom - top; maxH = maxH > 0 ? maxH : 0; if (!extensible && maxH < h) { h = maxH; } w = w > maxW ? maxW : w; Bound bound = control.Apply(stylesheet, new Bound(w, h), new Bound(maxW, maxH)); w = bound.Width; h = bound.Height; InitializeImageContainer(stylesheet, control, ref w, ref h); if (!extensible && maxH < h) { h = maxH; } if (w < maxW) { HorizontalAlign.Align align = style.HorizontalAlign(control); switch (align) { case HorizontalAlign.Align.Left: break; case HorizontalAlign.Align.Central: float delta = (right - left - w) / 2; left += delta; break; case HorizontalAlign.Align.Right: left = right - w; break; } } control.Frame = new Rectangle(left, top, w, h); off += h + marginB; } return(new Bound(styleBound.Width, styleBound.Height, parentW, off + paddingB + borderWidth)); }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); IStyleSheetHelper style = stylesheet.Helper; // background color, borders, background image UIImage backgroundImage = stylesheet.SetBackgroundSettings(this); if (backgroundImage != null) { _view.SetBackgroundImage(backgroundImage, UIControlState.Normal); } // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } // word wrap bool nowrap = style.WhiteSpace(this) == WhiteSpaceKind.Nowrap; _view.TitleLabel.LineBreakMode = !nowrap ? UILineBreakMode.WordWrap : UILineBreakMode.TailTruncation; // text-format _textFormat = style.TextFormat(this); switch (_textFormat) { case TextFormatValues.Text: SetText(); // text color _textColor = style.Color(this).ToColorOrClear(); _view.SetTitleColor(_textColor, UIControlState.Normal); // selected-color using (UIColor selectedColor = style.SelectedColor(this).ToNullableColor()) if (selectedColor != null) { _view.SetTitleColor(selectedColor, UIControlState.Highlighted); } break; case TextFormatValues.Html: string whitespace = nowrap ? "nowrap" : "normal"; string span = string.Format( "<span style=\"font-family: {0}; font-size: {1:F0}; color: {2}; white-space: {3}\">{4}</span>" , _view.Font.FamilyName, _view.Font.PointSize, "{0}", whitespace, "{1}"); // text color _textHtmlSpan = string.Format(span, style.Color(this).Hex, "{0}"); // selected-color IColorInfo selectedColorInfo = style.SelectedColor(this); if (selectedColorInfo != null) { _selectedHtmlSpan = string.Format(span, selectedColorInfo.Hex, "{0}"); } SetSpannedText(_textHtmlSpan); break; default: throw new NotImplementedException("Text format not found: " + _textFormat); } // selected-background UIColor selectedBackground = style.SelectedBackground(this).ToNullableColor(); if (selectedBackground != null) { if (backgroundImage != null) { using (UIImage selectedImage = GetFilteredImage(backgroundImage, selectedBackground)) _view.SetBackgroundImage(selectedImage, UIControlState.Highlighted); selectedBackground.Dispose(); } else { _selectedBackground = selectedBackground; } } // text align SetTextAlign(style.TextAlign(this, TextAlignValues.Center), nowrap); { // text padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); _view.ContentEdgeInsets = new UIEdgeInsets(pt, pl, pb, pr); // resize by background image IBound bound = GetBoundByImage(styleBound, maxBound, backgroundImage); // size to content bound = MergeBoundByContent(style, bound, maxBound, _view.ContentEdgeInsets, backgroundImage != null); _view.TitleLabel.PreferredMaxLayoutWidth = bound.Width - pl - pr; return(bound); } }
protected override IBound Apply(IStyleSheet stylesheet, IBound styleBound, IBound maxBound) { base.Apply(stylesheet, styleBound, maxBound); _view.Text = _text; IStyleSheetHelper style = stylesheet.Helper; // background color, borders, background image _backgroundImage = stylesheet.SetBackgroundSettings(this); if (_backgroundImage != null) { _view.Layer.Contents = _backgroundImage.CGImage; _view.BackgroundColor = UIColor.Clear; } // text-format _textFormat = style.TextFormat(this); // font UIFont f = stylesheet.Font(this, styleBound.Height); if (f != null) { _view.Font = f; } switch (_textFormat) { case TextFormatValues.Text: _view.Text = _text; // text color _view.TextColor = _textColor = style.Color(this).ToColorOrClear(); // selected-color _selectedColor = style.SelectedColor(this).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}"); // text color _textHtmlSpan = string.Format(span, style.Color(this).Hex, "{0}"); // selected-color IColorInfo selectedColor = style.SelectedColor(this); if (selectedColor != null) { _selectedHtmlSpan = string.Format(span, selectedColor.Hex, "{0}"); } SetSpannedText(_textHtmlSpan); break; default: throw new NotImplementedException("Text format not found: " + _textFormat); } // selected-background UIColor selectedBackground = style.SelectedBackground(this).ToNullableColor(); if (selectedBackground != null) { if (_backgroundImage != null) { _selectedBackgroundImage = GetFilteredImage(_backgroundImage, selectedBackground).CGImage; selectedBackground.Dispose(); } else { _selectedBackground = selectedBackground; } } // word wrap bool nowrap = style.WhiteSpace(this) == WhiteSpaceKind.Nowrap; if (!nowrap) { _view.TextContainer.LineBreakMode = UILineBreakMode.WordWrap; _view.TextContainer.MaximumNumberOfLines = 0; } else { _view.TextContainer.LineBreakMode = UILineBreakMode.TailTruncation; _view.TextContainer.MaximumNumberOfLines = 1; } // text align SetTextAlign(style.TextAlign(this), nowrap); // text padding float pl = style.PaddingLeft(this, styleBound.Width); float pt = style.PaddingTop(this, styleBound.Height); float pr = style.PaddingRight(this, styleBound.Width); float pb = style.PaddingBottom(this, styleBound.Height); _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr); // resize by background image IBound bound = GetBoundByImage(styleBound, maxBound, _backgroundImage); // size to content return(MergeBoundByContent(style, bound, maxBound, _view.TextContainerInset, _backgroundImage != null)); }