diff --git a/Ooui.Forms/Extensions/FontExtensions.cs b/Ooui.Forms/Extensions/FontExtensions.cs
index 765ee02..310ece6 100644
--- a/Ooui.Forms/Extensions/FontExtensions.cs
+++ b/Ooui.Forms/Extensions/FontExtensions.cs
@@ -5,8 +5,55 @@ namespace Ooui.Forms.Extensions
{
public static class FontExtensions
{
- public static void SetStyleFont (this View view, Style style)
+ public static void SetStyleFont (this View view, string family, double size, FontAttributes attrs, Style style)
{
+#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
+ if (size == 14.0) {
+ style.FontSize = null;
+ }
+ else {
+ style.FontSize = size;
+ }
+#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
+
+ if (string.IsNullOrEmpty (family)) {
+ style.FontFamily = null;
+ }
+ else {
+ style.FontFamily = family;
+ }
+
+ if (attrs.HasFlag (FontAttributes.Bold)) {
+ style.FontWeight = "bold";
+ }
+ else {
+ style.FontWeight = null;
+ }
+
+ if (attrs.HasFlag (FontAttributes.Italic)) {
+ style.FontStyle = "italic";
+ }
+ else {
+ style.FontStyle = null;
+ }
+ }
+
+ public static Size MeasureSize (this string text, string fontFamily, double fontSize, FontAttributes fontAttrs)
+ {
+ if (string.IsNullOrEmpty (text))
+ return Size.Zero;
+
+ var fontHeight = fontSize;
+ var charWidth = fontSize * 0.5;
+
+ var width = text.Length * charWidth;
+
+ return new Size (width, fontHeight);
+ }
+
+ public static Size MeasureSize (this string text, Style style)
+ {
+ return MeasureSize (text, "", 14, FontAttributes.None);
}
public static string ToOouiTextAlign (this TextAlignment align)
@@ -22,17 +69,5 @@ namespace Ooui.Forms.Extensions
}
}
- public static Size MeasureSize (this string text, Style style)
- {
- if (string.IsNullOrEmpty (text))
- return Size.Zero;
-
- var fontHeight = 16.0;
- var charWidth = 8.0;
-
- var width = text.Length * charWidth;
-
- return new Size (width, fontHeight);
- }
}
}
diff --git a/Ooui.Forms/Renderers/ButtonRenderer.cs b/Ooui.Forms/Renderers/ButtonRenderer.cs
index 751e6c7..727d835 100644
--- a/Ooui.Forms/Renderers/ButtonRenderer.cs
+++ b/Ooui.Forms/Renderers/ButtonRenderer.cs
@@ -12,6 +12,13 @@ namespace Ooui.Forms.Renderers
Ooui.Color _buttonTextColorDefaultHighlighted;
Ooui.Color _buttonTextColorDefaultNormal;
+ public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
+ {
+ var size = Element.Text.MeasureSize (Element.FontFamily, Element.FontSize, Element.FontAttributes);
+ size = new Size (size.Width, size.Height * 1.428 + 14);
+ return new SizeRequest (size, size);
+ }
+
protected override void Dispose (bool disposing)
{
if (Control != null) {
@@ -31,6 +38,8 @@ namespace Ooui.Forms.Renderers
Debug.Assert (Control != null, "Control != null");
+ Control.ClassName = "btn btn-primary";
+
_buttonTextColorDefaultNormal = Ooui.Colors.Black;
_buttonTextColorDefaultHighlighted = Ooui.Colors.Black;
_buttonTextColorDefaultDisabled = Ooui.Colors.Black;
@@ -98,7 +107,7 @@ namespace Ooui.Forms.Renderers
void UpdateFont ()
{
- Element.SetStyleFont (Control.Style);
+ Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
}
void UpdateImage ()
@@ -141,14 +150,10 @@ namespace Ooui.Forms.Renderers
void UpdateTextColor ()
{
if (Element.TextColor == Xamarin.Forms.Color.Default) {
- Control.Style.Color = _buttonTextColorDefaultNormal;
- Control.Style.Color = _buttonTextColorDefaultHighlighted;
- Control.Style.Color = _buttonTextColorDefaultDisabled;
+ Control.Style.Color = null;
}
else {
Control.Style.Color = Element.TextColor.ToOouiColor ();
- Control.Style.Color = Element.TextColor.ToOouiColor ();
- Control.Style.Color = _buttonTextColorDefaultDisabled;
}
}
}
diff --git a/Ooui.Forms/Renderers/EntryRenderer.cs b/Ooui.Forms/Renderers/EntryRenderer.cs
index d48f78e..e72843d 100644
--- a/Ooui.Forms/Renderers/EntryRenderer.cs
+++ b/Ooui.Forms/Renderers/EntryRenderer.cs
@@ -140,7 +140,7 @@ namespace Ooui.Forms.Renderers
initialSize = testString.MeasureSize (Control.Style);
}
- Element.SetStyleFont (Control.Style);
+ Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
}
void UpdateKeyboard ()
diff --git a/Ooui.Forms/Renderers/LabelRenderer.cs b/Ooui.Forms/Renderers/LabelRenderer.cs
index 402563e..6a6104d 100644
--- a/Ooui.Forms/Renderers/LabelRenderer.cs
+++ b/Ooui.Forms/Renderers/LabelRenderer.cs
@@ -17,8 +17,8 @@ namespace Ooui.Forms.Renderers
public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
{
if (!_perfectSizeValid) {
- _perfectSize = base.GetDesiredSize (double.PositiveInfinity, double.PositiveInfinity);
- _perfectSize.Minimum = new Size (Math.Min (10, _perfectSize.Request.Width), _perfectSize.Request.Height);
+ var size = Element.Text.MeasureSize (Element.FontFamily, Element.FontSize, Element.FontAttributes);
+ _perfectSize = new SizeRequest (size, size);
_perfectSizeValid = true;
}
@@ -157,7 +157,7 @@ namespace Ooui.Forms.Renderers
return;
_perfectSizeValid = false;
- Element.SetStyleFont (Control.Style);
+ Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
}
void UpdateTextColor ()
diff --git a/Ooui/Style.cs b/Ooui/Style.cs
index cec8577..06b6149 100644
--- a/Ooui/Style.cs
+++ b/Ooui/Style.cs
@@ -180,7 +180,7 @@ namespace Ooui
public Value FontSize {
get => this["font-size"];
- set => this["font-size"] = value;
+ set => this["font-size"] = AddNumberUnits (value, "px");
}
public Value FontStyle {
diff --git a/Samples/ButtonXamlPage.xaml b/Samples/ButtonXamlPage.xaml
old mode 100755
new mode 100644
index 02012d6..9fafa5f
--- a/Samples/ButtonXamlPage.xaml
+++ b/Samples/ButtonXamlPage.xaml
@@ -1,4 +1,4 @@
-
+
@@ -7,7 +7,6 @@
diff --git a/Samples/DisplayAlertPage.xaml b/Samples/DisplayAlertPage.xaml
index 039fe09..8f3c57f 100644
--- a/Samples/DisplayAlertPage.xaml
+++ b/Samples/DisplayAlertPage.xaml
@@ -6,7 +6,6 @@