Ooui-tws-port/Ooui.Forms/Extensions/ElementExtensions.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2017-11-10 00:09:48 +00:00
using System;
using Xamarin.Forms;
namespace Ooui.Forms.Extensions
{
public static class ElementExtensions
{
public static SizeRequest GetSizeRequest (this Ooui.Element self, double widthConstraint, double heightConstraint,
double minimumWidth = -1, double minimumHeight = -1)
{
var rw = 0.0;
var rh = 0.0;
Size s = new Size (0, 0);
var measured = false;
2017-11-10 01:23:41 +00:00
if (self.Style.Width.Equals ("inherit")) {
s = self.Text.MeasureSize (self.Style, widthConstraint, heightConstraint);
measured = true;
rw = double.IsPositiveInfinity (s.Width) ? double.PositiveInfinity : Math.Ceiling (s.Width);
}
else {
rw = self.Style.GetNumberWithUnits ("width", "px", 640);
}
2017-11-10 01:23:41 +00:00
if (self.Style.Height.Equals ("inherit")) {
if (!measured) {
s = self.Text.MeasureSize (self.Style, widthConstraint, heightConstraint);
measured = true;
}
rh = double.IsPositiveInfinity (s.Height) ? double.PositiveInfinity : Math.Ceiling (s.Height * 1.4);
}
else {
rh = self.Style.GetNumberWithUnits ("height", "px", 480);
}
var minimum = new Size (minimumWidth < 0 ? rw : minimumWidth,
minimumHeight < 0 ? rh : minimumHeight);
return new SizeRequest (new Size (rw, rh), minimum);
2017-11-10 00:09:48 +00:00
}
}
}