Skip to content

Commit

Permalink
[NUI] Update dp and sp extension methods and sp converting.
Browse files Browse the repository at this point in the history
  • Loading branch information
everLEEst committed Jan 6, 2025
1 parent 19d0c1b commit c415d26
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
79 changes: 76 additions & 3 deletions src/Tizen.NUI/src/public/Utility/GraphicsTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

using System;
using System.ComponentModel;

namespace Tizen.NUI
Expand Down Expand Up @@ -43,9 +44,21 @@ public static float DpToPx(this float dp)
}

/// <summary>
/// Converter float sp to pixel.
/// Converter float dp to pixel.
/// </summary>
/// <param name="sp">The float sp unit value to be converted pixel unit.</param>
/// <param name="dp">The float dp unit value to be converted pixel unit.</param>
/// <returns>The float pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static float Dp(this float dp)
{
return GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp);
}

/// <summary>
/// Converter float scaled dp to pixel.
/// </summary>
/// <param name="sp">The float scaled dp unit value to be converted pixel unit.</param>
/// <returns>The float pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
Expand All @@ -54,6 +67,18 @@ public static float SpToPx(this float sp)
return GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
}

/// <summary>
/// Converter float scaled dp to pixel.
/// </summary>
/// <param name="sp">The float scaled dp unit value to be converted pixel unit.</param>
/// <returns>The float pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static float Sp(this float sp)
{
return GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
}

/// <summary>
/// Converter float pixel to dp.
/// </summary>
Expand Down Expand Up @@ -90,6 +115,18 @@ public static int DpToPx(this int dp)
return (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp);
}

/// <summary>
/// Converter int dp to pixel.
/// </summary>
/// <param name="dp">The int dp unit value to be converted pixel unit.</param>
/// <returns>The int pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static int Dp(this int dp)
{
return (int)GraphicsTypeManager.Instance.Dp.ConvertToPixel(dp);
}

/// <summary>
/// Converter int dp to pixel.
/// </summary>
Expand All @@ -102,6 +139,18 @@ public static int SpToPx(this int sp)
return (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
}

/// <summary>
/// Converter int dp to pixel.
/// </summary>
/// <param name="sp">The int sp unit value to be converted pixel unit.</param>
/// <returns>The int pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static int Sp(this int sp)
{
return (int)GraphicsTypeManager.Instance.Sp.ConvertToPixel(sp);
}

/// <summary>
/// Converter int pixel to dp.
/// </summary>
Expand All @@ -126,7 +175,6 @@ public static int PxToSp(this int pixel)
return (int)GraphicsTypeManager.Instance.Sp.ConvertFromPixel(pixel);
}


/// <summary>
/// Converter Size pixel to dp.
/// </summary>
Expand Down Expand Up @@ -552,5 +600,30 @@ public static float PtToSp(this float pt)
{
return GraphicsTypeManager.Instance.Point.ConvertPointToSp(pt);
}

/// <summary>
/// Converter float pixel to scaled pixel.
/// </summary>
/// <param name="px">The float pixel value to be scaled.</param>
/// <returns>The float scaled pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static float Scale(this float px)
{
return px * GraphicsTypeManager.Instance.ScalingFactor;
}

/// <summary>
/// Converter int pixel to scaled pixel.
/// </summary>
/// <param name="px">The int pixel value to be scaled.</param>
/// <returns>The int scaled pixel unit value.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public static int Scale(this int px)
{
return (int)(px * GraphicsTypeManager.Instance.ScalingFactor);
}

}
}
4 changes: 2 additions & 2 deletions src/Tizen.NUI/src/public/Utility/SpTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override float ConvertScriptToPixel(string scriptValue)
[EditorBrowsable(EditorBrowsableState.Never)]
public override float ConvertToPixel(float value)
{
return value * (GraphicsTypeManager.Instance.ScaledDpi / (float)GraphicsTypeManager.Instance.BaselineDpi);
return value * ((float)(GraphicsTypeManager.Instance.Dpi * GraphicsTypeManager.Instance.ScalingFactor) / GraphicsTypeManager.Instance.BaselineDpi);
}

/// <summary>
Expand All @@ -94,7 +94,7 @@ public override float ConvertToPixel(float value)
[EditorBrowsable(EditorBrowsableState.Never)]
public override float ConvertFromPixel(float value)
{
return value * (GraphicsTypeManager.Instance.BaselineDpi / (float)GraphicsTypeManager.Instance.ScaledDpi);
return value * (GraphicsTypeManager.Instance.BaselineDpi / (float)(GraphicsTypeManager.Instance.Dpi * GraphicsTypeManager.Instance.ScalingFactor));
}
}
}

0 comments on commit c415d26

Please sign in to comment.