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)
|
|
|
|
|
{
|
2017-11-19 20:19:44 +00:00
|
|
|
|
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
|
|
|
|
|
2017-11-19 20:19:44 +00:00
|
|
|
|
if (self.Style.Width.Equals ("inherit")) {
|
2018-02-03 01:15:38 +00:00
|
|
|
|
s = self.Text.MeasureSize (self.Style, widthConstraint, heightConstraint);
|
2017-11-19 20:19:44 +00:00
|
|
|
|
measured = true;
|
2017-12-10 03:34:36 +00:00
|
|
|
|
rw = double.IsPositiveInfinity (s.Width) ? double.PositiveInfinity : Math.Ceiling (s.Width);
|
2017-11-19 20:19:44 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rw = self.Style.GetNumberWithUnits ("width", "px", 640);
|
|
|
|
|
}
|
2017-11-10 01:23:41 +00:00
|
|
|
|
|
2017-11-19 20:19:44 +00:00
|
|
|
|
if (self.Style.Height.Equals ("inherit")) {
|
|
|
|
|
if (!measured) {
|
2018-02-03 01:15:38 +00:00
|
|
|
|
s = self.Text.MeasureSize (self.Style, widthConstraint, heightConstraint);
|
2017-11-19 20:19:44 +00:00
|
|
|
|
measured = true;
|
|
|
|
|
}
|
2017-12-10 03:34:36 +00:00
|
|
|
|
rh = double.IsPositiveInfinity (s.Height) ? double.PositiveInfinity : Math.Ceiling (s.Height * 1.4);
|
2017-11-19 20:19:44 +00:00
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|