Skip to content

Commit

Permalink
[NUI] UICorner includes the a relative flag
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor committed Jan 31, 2025
1 parent 088e466 commit ad88ea0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/Tizen.NUI.Extension/Markup/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ public static T PositionY<T>(this T view, float y) where T : View
/// <param name="uniform">The uniform corner value.</param>
/// <param name="isRelative">Sets the corner radius policy to relative. The default is false.</param>
/// <returns>The view itself.</returns>
/// <remarks>This sets both <see cref="View.CornerRadius"/> and <see cref="View.CornerRadiusPolicy"/> at once.</remarks>
public static T CornerRadius<T>(this T view, float uniform, bool isRelative = false) where T : View
{
return view.CornerRadius(new UICorner(uniform, uniform, uniform, uniform), isRelative);
return view.CornerRadius(new UICorner(uniform, isRelative));
}

/// <summary>
Expand All @@ -255,9 +256,10 @@ public static T CornerRadius<T>(this T view, float uniform, bool isRelative = fa
/// <param name="bottomLeft">The bottom-left value.</param>
/// <param name="isRelative">Sets the corner radius policy to relative. The default is false.</param>
/// <returns>The view itself.</returns>
/// <remarks>This sets both <see cref="View.CornerRadius"/> and <see cref="View.CornerRadiusPolicy"/> at once.</remarks>
public static T CornerRadius<T>(this T view, float topLeft, float topRight, float bottomRight, float bottomLeft, bool isRelative = false) where T : View
{
return view.CornerRadius(new UICorner(topLeft, topRight, bottomRight, bottomLeft), isRelative);
return view.CornerRadius(new UICorner(topLeft, topRight, bottomRight, bottomLeft, isRelative));
}

/// <summary>
Expand All @@ -266,13 +268,13 @@ public static T CornerRadius<T>(this T view, float topLeft, float topRight, floa
/// <typeparam name="T">The type of the view.</typeparam>
/// <param name="view">The extension target.</param>
/// <param name="corner">The corner value.</param>
/// <param name="isRelative">Sets the corner radius policy to relative. The default is false.</param>
/// <returns>The view itself.</returns>
public static T CornerRadius<T>(this T view, UICorner corner, bool isRelative = false) where T : View
/// <remarks>This sets both <see cref="View.CornerRadius"/> and <see cref="View.CornerRadiusPolicy"/> at once.</remarks>
public static T CornerRadius<T>(this T view, UICorner corner) where T : View
{
// TODO Do not create Vector4 here
view.CornerRadius = corner.ToReferenceType();
view.CornerRadiusPolicy = isRelative ? VisualTransformPolicyType.Relative : VisualTransformPolicyType.Absolute;
view.CornerRadiusPolicy = corner.IsRelative ? VisualTransformPolicyType.Relative : VisualTransformPolicyType.Absolute;
return view;
}

Expand Down Expand Up @@ -644,7 +646,7 @@ public static UICorner CornerRadius(this View view)
{
// TODO Do not use Vector4 here
var corner = view.CornerRadius;
return new UICorner(corner.X, corner.Y, corner.Z, corner.W);
return new UICorner(corner.X, corner.Y, corner.Z, corner.W, view.CornerRadiusPolicy == VisualTransformPolicyType.Relative);
}

/// <summary>
Expand Down
31 changes: 29 additions & 2 deletions src/Tizen.NUI/src/devel/Lite/UICorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,27 @@ public struct UICorner
/// Initializes a new instance of the <see cref="UICorner"/> struct.
/// </summary>
/// <param name="uniform">The uniform corner value.</param>
public UICorner(float uniform) : this(uniform, uniform, uniform, uniform)
public UICorner(float uniform) : this(uniform, false)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UICorner"/> struct.
/// </summary>
/// <param name="uniform">The uniform corner value.</param>
/// <param name="isRelative">Whether the values should be considered as relative to target box size.</param>
public UICorner(float uniform, bool isRelative) : this(uniform, uniform, uniform, uniform, isRelative)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UICorner"/> struct.
/// </summary>
/// <param name="topLeft">The top-left value.</param>
/// <param name="topRight">The top-right value.</param>
/// <param name="bottomRight">The bottom-right value.</param>
/// <param name="bottomLeft">The bottom-left value.</param>
public UICorner(float topLeft, float topRight, float bottomRight, float bottomLeft) : this(topLeft, topRight, bottomRight, bottomLeft, false)
{
}

Expand All @@ -49,12 +69,14 @@ public UICorner(float uniform) : this(uniform, uniform, uniform, uniform)
/// <param name="topRight">The top-right value.</param>
/// <param name="bottomRight">The bottom-right value.</param>
/// <param name="bottomLeft">The bottom-left value.</param>
public UICorner(float topLeft, float topRight, float bottomRight, float bottomLeft)
/// <param name="isRelative">Whether the values should be considered as relative to target box size.</param>
public UICorner(float topLeft, float topRight, float bottomRight, float bottomLeft, bool isRelative)
{
TopLeft = topLeft;
TopRight = topRight;
BottomRight = bottomRight;
BottomLeft = bottomLeft;
IsRelative = isRelative;
}

/// <summary>
Expand Down Expand Up @@ -87,6 +109,11 @@ public UICorner(float topLeft, float topRight, float bottomRight, float bottomLe
/// </summary>
public float BottomLeft { get; }

/// <summary>
/// Gets a value indicating whether the values are relative to target box size.
/// </summary>
public bool IsRelative { get; }

internal readonly NUI.Vector4 ToReferenceType() => new NUI.Vector4(TopLeft, TopRight, BottomRight, BottomLeft);
}
}

0 comments on commit ad88ea0

Please sign in to comment.