Skip to content

Commit

Permalink
[NUI] Add size, position getter/setter for UIVector2 type
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor authored and JoogabYun committed Feb 4, 2025
1 parent 338690f commit aff39fb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Tizen.NUI.Extension/Markup/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ public static T Size<T>(this T view, float width, float height) where T : View
return view;
}

/// <summary>
/// Sets the size of the view.
/// </summary>
/// <typeparam name="T">The type of the view.</typeparam>
/// <param name="view">The extension target.</param>
/// <param name="size">The size value.</param>
/// <returns>The view itself.</returns>
public static T Size<T>(this T view, UIVector2 size) where T : View
{
return Size(view, size.Width, size.Height);
}

/// <summary>
/// Sets the size width of the view.
/// </summary>
Expand Down Expand Up @@ -205,6 +217,18 @@ public static T Position<T>(this T view, float x, float y) where T : View
return view;
}

/// <summary>
/// Sets the position of the view.
/// </summary>
/// <typeparam name="T">The type of the view.</typeparam>
/// <param name="view">The extension target.</param>
/// <param name="position">The position value.</param>
/// <returns>The view itself.</returns>
public static T Position<T>(this T view, UIVector2 position) where T : View
{
return Position(view, position.X, position.Y);
}

/// <summary>
/// Sets the position x of the view.
/// </summary>
Expand Down Expand Up @@ -637,6 +661,26 @@ public static UIColor BackgroundColor(this View view)
return Object.InternalRetrievingVisualPropertyColor(view.SwigCPtr, View.Property.BACKGROUND, ColorVisualProperty.MixColor);
}

/// <summary>
/// Experimental getter for size
/// </summary>
/// <param name="view">The extension target.</param>
/// <returns>The size value.</returns>
public static UIVector2 Size(this View view)
{
return new UIVector2(view.SizeWidth, view.SizeHeight);
}

/// <summary>
/// Experimental getter for position
/// </summary>
/// <param name="view">The extension target.</param>
/// <returns>The position value.</returns>
public static UIVector2 Position(this View view)
{
return new UIVector2(view.PositionX, view.PositionY);
}

/// <summary>
/// Gets the corner radius of the view.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Tizen.NUI/src/devel/Lite/UIVector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public float Y
/// </summary>
public float Height => Y;

/// <summary>
/// Converts the UIVector2 to Vector3 class implicitly.
/// </summary>
/// <param name="uiVector2">A UIVector2 to be converted to Vector3</param>
public static implicit operator Vector3(UIVector2 uiVector2)
{
return new Vector3(uiVector2.X, uiVector2.Y, 0f);
}


internal readonly NUI.Vector2 ToReferenceType() => new NUI.Vector2(X, Y);
}
}

0 comments on commit aff39fb

Please sign in to comment.