/// <summary>
/// Unit Size for current screen
/// </summary>
- public const UnitSize PixelsPerUnit = UnitSize.MediumUnit;
-
- /// <summary>
- /// Number of units per pixel
- /// </summary>
- public const float UnitsPerPixel = 1.0f / (int)PixelsPerUnit;
+ public const UnitSize PixelsPerUnit = UnitSize.Medium;
}
}
/// <summary>
/// Number of pixels per unit for very large size displays with very small dpi.
/// </summary>
- ExtraSmallUnit = 1,
+ ExtraSmall = 1,
/// <summary>
/// Number of pixels per unit for large size displays with small dpi.
/// </summary>
- SmallUnit = 2,
+ Small = 2,
/// <summary>
/// Number of pixels per unit for average size displays with average dpi.
/// </summary>
- MediumUnit = 4,
+ Medium = 4,
/// <summary>
/// Number of pixels per unit for small size displays with high dpi.
/// </summary>
- LargeUnit = 6,
+ Large = 6,
/// <summary>
/// Number of pixels per unit for very small size displays with very high dpi.
/// </summary>
- ExtraLargUnit = 8,
+ ExtraLarge = 8,
}
}
--- /dev/null
+using System;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using Tizen.NUI.Xaml;
+
+namespace Fitness.Views
+{
+ public class SizeInUnitsMarkup : IMarkupExtension
+ {
+ /// <summary>
+ /// Width in units
+ /// </summary>
+ public int Width { get; set; }
+
+ /// <summary>
+ /// Height in units
+ /// </summary>
+ public int Height { get; set; }
+
+ public object ProvideValue(IServiceProvider provider)
+ {
+ return new Size2D(UnitsUtils.UnitsToPixels(Width), UnitsUtils.UnitsToPixels(Height));
+ }
+ }
+}
public static class UnitsUtils
{
/// <summary>
+ /// Number of units per pixel
+ /// </summary>
+ private const float UnitsPerPixel = 1.0f / (int)Config.PixelsPerUnit;
+
+ /// <summary>
/// Converts units into pixels using current UnitSize settings
/// </summary>
public static int UnitsToPixels(int units)
/// </summary>
public static int PixelsToUnits(int pixels)
{
- return (int)(pixels * Config.UnitsPerPixel);
+ return (int)(pixels * UnitsPerPixel);
}
/// <summary>
+++ /dev/null
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
-using Tizen.NUI.Binding;
-
-namespace Fitness.Views
-{
- public static class XamlExtensions
- {
- /// <summary>
- /// SizeInUnits Xaml property extension.
- /// Use this property to define Size of view int Units system.
- /// </summary>
- public static readonly BindableProperty SizeInUnitsProperty =
- BindableProperty.CreateAttached("SizeInUnits", typeof(Size2D), typeof(XamlExtensions), default(Size2D), propertyChanged: OnSizeInUnitsChanged);
-
- public static void OnSizeInUnitsChanged(BindableObject view, object oldValue, object newValue)
- {
- if (view is View nuiView)
- {
- nuiView.Size = UnitsUtils.UnitsToPixels(newValue as Size2D);
- }
- }
- }
-}
<View.Layout>
<LinearLayout LinearOrientation="Vertical" CellPadding="50,50" LinearAlignment="Center"/>
</View.Layout>
- <TextLabel Text="Title" HorizontalAlignment="Center" VerticalAlignment="Center" views:XamlExtensions.SizeInUnits="75, 12" BackgroundColor="Cyan"/>
+ <TextLabel Text="Title" HorizontalAlignment="Center" VerticalAlignment="Center" Size="{views:SizeInUnitsMarkup Width=75, Height=12}" BackgroundColor="Cyan"/>
</View>