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

23 lines
822 B
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)
{
2017-11-10 02:12:02 +00:00
var s = self.Text.MeasureSize (self.Style);
2017-11-10 01:23:41 +00:00
var request = new Size (
double.IsPositiveInfinity (s.Width) ? double.PositiveInfinity : s.Width,
double.IsPositiveInfinity (s.Height) ? double.PositiveInfinity : s.Height);
var minimum = new Size (minimumWidth < 0 ? request.Width : minimumWidth,
minimumHeight < 0 ? request.Height : minimumHeight);
2017-11-10 00:09:48 +00:00
return new SizeRequest (request, minimum);
}
}
}