summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Forms.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Forms.cs')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Forms.cs90
1 files changed, 89 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Forms.cs b/Xamarin.Forms.Platform.Tizen/Forms.cs
index 892faf58..1a2d7bd6 100644
--- a/Xamarin.Forms.Platform.Tizen/Forms.cs
+++ b/Xamarin.Forms.Platform.Tizen/Forms.cs
@@ -17,6 +17,13 @@ namespace Xamarin.Forms.Platform.Tizen
TSystemInfo.TryGetValue<int>("http://tizen.org/feature/screen.dpi", out dpi);
return dpi;
});
+
+ static Lazy<double> s_elmScale = new Lazy<double>(() =>
+ {
+ // 72.0 is from EFL which is using fixed DPI value (72.0) to determine font size internally. Thus, we are restoring the size by deviding the DPI by 72.0 here.
+ return s_dpi.Value / 72.0 / Elementary.GetScale();
+ });
+
class TizenDeviceInfo : DeviceInfo
{
readonly Size pixelScreenSize;
@@ -68,6 +75,11 @@ namespace Xamarin.Forms.Platform.Tizen
TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out height);
scalingFactor = 1.0; // scaling is disabled, we're using pixels as Xamarin's geometry units
+ if (_useDeviceIndependentPixel)
+ {
+ scalingFactor = s_dpi.Value / 160.0;
+ }
+
pixelScreenSize = new Size(width, height);
scaledScreenSize = new Size(width / scalingFactor, height / scalingFactor);
@@ -76,6 +88,8 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
+ static bool _useDeviceIndependentPixel = false;
+
public static event EventHandler<ViewInitializedEventArgs> ViewInitialized;
public static FormsApplication Context
@@ -116,6 +130,12 @@ namespace Xamarin.Forms.Platform.Tizen
public static void Init(FormsApplication application)
{
+ Init(application, false);
+ }
+
+ public static void Init(FormsApplication application, bool useDeviceIndependentPixel)
+ {
+ _useDeviceIndependentPixel = useDeviceIndependentPixel;
SetupInit(application);
}
@@ -186,7 +206,7 @@ namespace Xamarin.Forms.Platform.Tizen
{
Device.Idiom = TargetIdiom.TV;
}
- else if ( profile == "desktop")
+ else if (profile == "desktop")
{
Device.Idiom = TargetIdiom.Desktop;
}
@@ -210,10 +230,78 @@ namespace Xamarin.Forms.Platform.Tizen
return Color.Black;
}
+ /// <summary>
+ /// Converts the dp into pixel considering current DPI value.
+ /// </summary>
+ /// <remarks>
+ /// Use this API if you want to get pixel size without scaling factor.
+ /// </remarks>
+ /// <param name="dp"></param>
+ /// <returns></returns>
internal static int ConvertToPixel(double dp)
{
return (int)Math.Round(dp * s_dpi.Value / 160.0);
}
+
+ /// <summary>
+ /// Converts the dp into pixel by using scaling factor.
+ /// </summary>
+ /// <remarks>
+ /// Use this API if you want to get pixel size from dp by using scaling factor.
+ /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
+ /// </remarks>
+ /// <param name="dp"></param>
+ /// <returns></returns>
+ internal static int ConvertToScaledPixel(double dp)
+ {
+ return (int)Math.Round(dp * Device.Info.ScalingFactor);
+ }
+
+ /// <summary>
+ /// Converts the pixel into dp value by using scaling factor.
+ /// </summary>
+ /// <remarks>
+ /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
+ /// </remarks>
+ /// <param name="pixel"></param>
+ /// <returns></returns>
+ internal static double ConvertToScaledDP(int pixel)
+ {
+ return pixel / Device.Info.ScalingFactor;
+ }
+
+ /// <summary>
+ /// Converts the pixel into dp value by using scaling factor.
+ /// </summary>
+ /// <remarks>
+ /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
+ /// </remarks>
+ /// <param name="pixel"></param>
+ /// <returns></returns>
+ internal static double ConvertToScaledDP(double pixel)
+ {
+ return pixel / Device.Info.ScalingFactor;
+ }
+
+ /// <summary>
+ /// Converts the sp into EFL's font size metric (EFL point).
+ /// </summary>
+ /// <param name="sp"></param>
+ /// <returns></returns>
+ internal static int ConvertToEflFontPoint(double sp)
+ {
+ return (int)Math.Round(sp * s_elmScale.Value);
+ }
+
+ /// <summary>
+ /// Convert the EFL's point into sp.
+ /// </summary>
+ /// <param name="eflPt"></param>
+ /// <returns></returns>
+ internal static double ConvertToDPFont(int eflPt)
+ {
+ return eflPt / s_elmScale.Value;
+ }
}
class TizenExpressionSearch : ExpressionVisitor, IExpressionSearch