public bool Equals(Rectangle obj) { bool result = true; result &= _valid.Equals(obj._valid); result &= Left.Equals(obj.Left); result &= Top.Equals(obj.Top); result &= Width.Equals(obj.Width); result &= Height.Equals(obj.Height); return result; }
public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound) { var bound = new Bound(BitBrowserApp.Current.Width, BitBrowserApp.Current.Height); base.Apply(stylesheet, bound, bound); //background color _view.SetBackgroundColor(Android.Graphics.Color.White); if (OnLoad != null) OnLoad.Execute(); Frame = new Rectangle(0, 0, bound); return bound; }
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); }