public void Add(View view, Expression <Func <Rectangle> > bounds) { if (bounds == null) { throw new ArgumentNullException(nameof(bounds)); } SetBoundsConstraint(view, BoundsConstraint.FromExpression(bounds)); base.Add(view); }
public static BoundsConstraint FromExpression(Expression <Func <Rectangle> > expression, IEnumerable <View> parents = null) { Func <Rectangle> compiled = expression.Compile(); var result = new BoundsConstraint { _measureFunc = compiled, RelativeTo = parents ?? ExpressionSearch.Default.FindObjects <View>(expression).ToArray() // make sure we have our own copy }; return(result); }
static Rectangle SolveView(View view) { BoundsConstraint boundsConstraint = GetBoundsConstraint(view); if (boundsConstraint == null) { throw new Exception("BoundsConstraint should not be null at this point"); } var result = boundsConstraint.Compute(); return(result); }
protected override void OnAdded(View view) { BoundsConstraint boundsConstraint = GetBoundsConstraint(view); if (boundsConstraint == null) { // user probably added the view through the strict Add method. CreateBoundsFromConstraints(view, GetXConstraint(view), GetYConstraint(view), GetWidthConstraint(view), GetHeightConstraint(view)); } _childrenInSolveOrder = null; base.OnAdded(view); }
bool CanSolveView(View view, Dictionary <View, bool> solveTable) { BoundsConstraint boundsConstraint = GetBoundsConstraint(view); var parents = new List <View>(); if (boundsConstraint == null) { throw new Exception("BoundsConstraint should not be null at this point"); } parents.AddRange(boundsConstraint.RelativeTo); // expressions probably referenced the base layout somewhere while (parents.Remove(this)) // because winphone does not have RemoveAll... { ; } if (!parents.Any()) { return(true); } for (var i = 0; i < parents.Count; i++) { View p = parents[i]; bool solvable; if (!solveTable.TryGetValue(p, out solvable)) { throw new InvalidOperationException("Views that have relationships to or from them must be kept in the RelativeLayout."); } if (!solvable) { return(false); } } return(true); }
public void Add(View view, Expression <Func <double> > x = null, Expression <Func <double> > y = null, Expression <Func <double> > width = null, Expression <Func <double> > height = null) { Func <double> xCompiled = x != null?x.Compile() : () => 0; Func <double> yCompiled = y != null?y.Compile() : () => 0; Func <double> widthCompiled = width != null?width.Compile() : () => view.Measure(Parent.Width, Parent.Height, MeasureFlags.IncludeMargins).Request.Width; Func <double> heightCompiled = height != null?height.Compile() : () => view.Measure(Parent.Width, Parent.Height, MeasureFlags.IncludeMargins).Request.Height; var parents = new List <View>(); parents.AddRange(ExpressionSearch.Default.FindObjects <View>(x)); parents.AddRange(ExpressionSearch.Default.FindObjects <View>(y)); parents.AddRange(ExpressionSearch.Default.FindObjects <View>(width)); parents.AddRange(ExpressionSearch.Default.FindObjects <View>(height)); BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(xCompiled(), yCompiled(), widthCompiled(), heightCompiled()), parents.Distinct().ToArray()); SetBoundsConstraint(view, bounds); base.Add(view); }
void CreateBoundsFromConstraints(View view, Constraint xConstraint, Constraint yConstraint, Constraint widthConstraint, Constraint heightConstraint) { var parents = new List <View>(); Func <double> x; if (xConstraint != null) { x = () => xConstraint.Compute(this); if (xConstraint.RelativeTo != null) { parents.AddRange(xConstraint.RelativeTo); } } else { x = () => 0; } Func <double> y; if (yConstraint != null) { y = () => yConstraint.Compute(this); if (yConstraint.RelativeTo != null) { parents.AddRange(yConstraint.RelativeTo); } } else { y = () => 0; } Func <double> width; if (widthConstraint != null) { width = () => widthConstraint.Compute(this); if (widthConstraint.RelativeTo != null) { parents.AddRange(widthConstraint.RelativeTo); } } else { width = () => view.Measure(Width, Height, MeasureFlags.IncludeMargins).Request.Width; } Func <double> height; if (heightConstraint != null) { height = () => heightConstraint.Compute(this); if (heightConstraint.RelativeTo != null) { parents.AddRange(heightConstraint.RelativeTo); } } else { height = () => view.Measure(Width, Height, MeasureFlags.IncludeMargins).Request.Height; } BoundsConstraint bounds = BoundsConstraint.FromExpression(() => new Rectangle(x(), y(), width(), height()), parents.Distinct().ToArray()); SetBoundsConstraint(view, bounds); }
public static void SetBoundsConstraint(BindableObject bindable, BoundsConstraint value) { bindable.SetValue(BoundsConstraintProperty, value); }