/// <summary> /// Gets the width allocated to the right block. /// </summary> /// <param name="width">The total width available.</param> /// <param name="leftPreferredWidth">The width preferred by the left block.</param> /// <param name="centerPreferredWidth">The width preferred by the center block.</param> /// <param name="rightPreferredWidth">The width preferred by the right block.</param> /// <returns>The allocated width.</returns> private double GetWidthAllocatedToRightBlock(double width, double?leftPreferredWidth, double?centerPreferredWidth, double?rightPreferredWidth) { if (this.rightBlock == null) { return(0); } // There is a right block. if (rightPreferredWidth != null) { return(rightPreferredWidth.Value); } // The right block is flexible. if (this.centerBlock == null) { // There is no center block if (this.leftBlock == null) { // There is no left block. return(width); } // There is a left block. if (leftPreferredWidth != null) { // The left block is not flexible. return(width - (leftPreferredWidth.Value + this.Layout.objectSpacing)); } // The left block is flexible return((width - this.Layout.objectSpacing) / 2); } // There is a center block if (centerPreferredWidth != null) { // The center block is fixed. return(((width - centerPreferredWidth.Value) / 2) - this.Layout.objectSpacing); } // The center block is flexible if (this.leftBlock == null) { // There is no left block. // The flexible right block must share the right side with half of the center block. return(((width / 2) - this.Layout.objectSpacing) / 1.5); } // There is a left block. if (leftPreferredWidth != null) { // The left block is not flexible. return(LuaMath.max(leftPreferredWidth.Value, (((width / 2) - this.Layout.objectSpacing) / 3) * 2)); } // The left block is flexible return((width - (this.Layout.objectSpacing * 2)) / 3); }
public override double?GetPreferredWidth() { var innerPreferredWidth = this.Inner.GetPreferredWidth(); if (innerPreferredWidth != null) { return(LuaMath.max((double)innerPreferredWidth, this.textLabel.GetWidth())); } return(null); }
/// <summary> /// Gets the preferred height of the page. /// </summary> /// <returns>The preferred height. Null if it is flexible.</returns> public double?GetPreferredHeight() { var heights = this.Content.Select(line => line.GetPreferredHeight()).ToArray(); if (!heights.Any(h => h == null)) { return(heights.Sum() + (this.Layout.lineSpacing * LuaMath.max(this.Content.Count - 1, 0))); } return(null); }
protected override void SizeChanged() { var obj = this.FirstChild; double width = 0; double height = 0; while (obj != null) { width += obj.Object.GetWidth(); height = LuaMath.max(height, obj.Object.GetHeight()); obj = obj.Next; } this.frame.SetWidth(width); this.frame.SetHeight(height); }
/// <summary> /// Gets the width allocated to the center block. /// </summary> /// <param name="width">The total width available.</param> /// <param name="leftPreferredWidth">The width preferred by the left block.</param> /// <param name="centerPreferredWidth">The width preferred by the center block.</param> /// <param name="rightPreferredWidth">The width preferred by the right block.</param> /// <returns>The allocated width.</returns> private double GetWidthAllocatedToCenterBlock(double width, double?leftPreferredWidth, double?centerPreferredWidth, double?rightPreferredWidth) { if (this.centerBlock == null) { return(0); } // There is a center block. if (centerPreferredWidth != null) { return(centerPreferredWidth.Value); } // The center block is flexible. if (this.leftBlock == null) { // There is no left block if (this.rightBlock == null) { // There is no right block. return(width); } // There is a right block. if (rightPreferredWidth != null) { // The right block is not flexible. return(((width / 2) - (rightPreferredWidth.Value + this.Layout.objectSpacing)) * 2); } // The right block is flexible return((((width / 2) - this.Layout.objectSpacing) / 3) * 2); } // There is a left block var halfWidthMinusOneObjectSpacing = (width / 2) - this.Layout.objectSpacing; if (leftPreferredWidth != null) { // The left block is fixed. if (this.rightBlock != null && rightPreferredWidth != null) { // There is a fixed right block. return((((width / 2) - LuaMath.max(leftPreferredWidth.Value, rightPreferredWidth.Value)) - this.Layout.objectSpacing) * 2); } if (this.rightBlock != null) { // There is a flexible right block. return(LuaMath.min((halfWidthMinusOneObjectSpacing / 3) * 2, (halfWidthMinusOneObjectSpacing - leftPreferredWidth.Value) * 2)); } // There is no right block. return((halfWidthMinusOneObjectSpacing - leftPreferredWidth.Value) * 2); } // The left block is flexible if (this.rightBlock == null) { // There is no right block. // The flexible center block must share the center side with half of the left block. return((halfWidthMinusOneObjectSpacing / 3) * 2); } // There is a right block. if (rightPreferredWidth != null) { // The right block is not flexible. return(LuaMath.min((halfWidthMinusOneObjectSpacing / 3) * 2, (halfWidthMinusOneObjectSpacing - rightPreferredWidth.Value) * 2)); } // The right block is flexible return((width - (this.Layout.objectSpacing * 2)) / 3); }