Skip to content

Commit

Permalink
[NUI] Add value type: color, vector2, shadow
Browse files Browse the repository at this point in the history
Introduce the value type of color, vector2 and shadow.
They will replace existing reference types gradually.

Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor committed Jan 7, 2025
1 parent 168de42 commit 26739b8
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/Tizen.NUI/src/devel/Lite/L.Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright(c) 2025 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.ComponentModel;

namespace Tizen.NUI.L
{
/// <summary>
/// Defines a value type of color.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public struct Color
{
public static readonly Color Transparent = new Color(0, 0, 0, 0);
public static readonly Color Black = new Color(0, 0, 0, 1);
public static readonly Color White = new Color(1, 1, 1, 1);
public static readonly Color Red = new Color(1, 0, 0, 1);
public static readonly Color Green = new Color(0, 1, 0, 1);
public static readonly Color Blue = new Color(0, 0, 1, 1);

/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Color(float r, float g, float b, float a)
{
R = r;
G = g;
B = b;
A = a;
}

/// <summary>
/// Gets the red component of the color.
/// </summary>
public float R
{
get;
}

/// <summary>
/// Gets the green component of the color.
/// </summary>
public float G
{
get;
}

/// <summary>
/// Gets the blue component of the color.
/// </summary>
public float B
{
get;
}

/// <summary>
/// Gets the alpha component of the color.
/// </summary>
public float A
{
get;
}

/// <summary>
/// Multiplies the alpha component of the color by the specified value.
/// </summary>
/// <param name="alpha">The value to multiply the alpha component by.</param>
/// <returns>The new color.</returns>
public readonly Color MultiplyAlpha(float alpha) => new Color(R, G, B, A * alpha);

/// <summary>
/// Returns a new color object with the specified alpha value.
/// </summary>
/// <param name="alpha">The new alpha value.</param>
/// <returns>A new color object with the specified alpha value.</returns>
public readonly Color WithAlpha(float alpha) => new Color(R, G, B, alpha);

internal readonly NUI.Color ToReferenceType() => new NUI.Color(R, G, B, A);
}
}
94 changes: 94 additions & 0 deletions src/Tizen.NUI/src/devel/Lite/L.Shadow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright(c) 2025 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.ComponentModel;

namespace Tizen.NUI.L
{
/// <summary>
/// Defines a value type of shadow.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public struct Shadow
{
/// <summary>
/// Create a Shadow.
/// </summary>
/// <param name="blurRadius">The blur radius value for the shadow. Bigger value, much blurry.</param>
public Shadow(float blurRadius) : this(blurRadius, L.Color.Black, Vector2.Zero, Vector2.Zero)
{
}

/// <summary>
/// Create a Shadow.
/// </summary>
/// <param name="blurRadius">The blur radius value for the shadow. Bigger value, much blurry.</param>
/// <param name="color">The color for the shadow.</param>
/// <param name="offset">Optional. The position offset value (x, y) from the top left corner.</param>
/// <param name="extents">Optional. The shadow will extend its size by specified amount of length.</param>
public Shadow(float blurRadius, L.Color color, Vector2 offset, Vector2 extents)
{
BlurRadius = blurRadius;
Color = color;
Offset = offset;
Extents = extents;
}

/// <summary>
/// The blur radius value for the shadow. Bigger value, much blurry.
/// </summary>
/// <remarks>
/// Negative value is ignored. (no blur)
/// </remarks>
public float BlurRadius
{
get;
set;
}

/// <summary>
/// The color for the shadow.
/// </summary>
public L.Color Color
{
get;
set;
}

/// <summary>
/// The position offset value (x, y) from the top left corner.
/// </summary>
public Vector2 Offset
{
get;
set;
}

/// <summary>
/// The shadow will extend its size by specified amount of length.<br />
/// If the value is negative then the shadow will shrink.
/// For example, when View's size is (100, 100) and the Shadow's Extents is (5, -5),
/// the output shadow will have size (105, 95).
/// </summary>
public Vector2 Extents
{
get;
set;
}

internal readonly NUI.Shadow ToShadow() => new NUI.Shadow(BlurRadius, Color.ToReferenceType(), Offset.ToReferenceType(), Extents.ToReferenceType());
}
}
68 changes: 68 additions & 0 deletions src/Tizen.NUI/src/devel/Lite/L.Vector2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright(c) 2025 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.ComponentModel;

namespace Tizen.NUI.L
{
/// <summary>
/// Defines a value type of vector2.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public readonly struct Vector2
{
public static readonly Vector2 Zero = new Vector2(0.0f, 0.0f);

/// <summary>
/// Initializes a new instance of the <see cref="Vector2"/> struct.
/// </summary>
/// <param name="x">The x value.</param>
/// <param name="y">The y value.</param>
public Vector2(float x, float y)
{
X = x;
Y = y;
}

/// <summary>
/// Gets the x component of the vector2.
/// </summary>
public float X
{
get;
}

/// <summary>
/// Gets the y component of the vector2.
/// </summary>
public float Y
{
get;
}

/// <summary>
/// Gets the width component of the vector2.
/// </summary>
public float Width => X;

/// <summary>
/// Gets the height component of the vector2.
/// </summary>
public float Height => Y;

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

0 comments on commit 26739b8

Please sign in to comment.