Skip to content

Commit

Permalink
[NUI] UIColor supports token
Browse files Browse the repository at this point in the history
* UIColor supportes token
* Token table is managed by internal TokenManager

Signed-off-by: Jiyun Yang <[email protected]>
  • Loading branch information
rabbitfor committed Feb 13, 2025
1 parent af9b979 commit b0c6bf3
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 31 deletions.
39 changes: 39 additions & 0 deletions src/Tizen.NUI.Extension/Internal/ViewPropertySetters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;

namespace Tizen.NUI.Extension
{
internal static class ViewPropertySetters
{
public static readonly PropertySetter<View, UIColor> BackgroundColor = new ("_background", (view, value) => view.SetBackgroundColor(value));

public static readonly PropertySetter<View, UIColor> BorderlineColor = new (nameof(View.BorderlineColor), (view, value) =>
{
//FIXME: we need to set UI value type directly without converting reference value.
view.BorderlineColor = value.ToReferenceType();
});

public static readonly PropertySetter<View, UIColor> Color = new (nameof(View.Color), (view, value) =>
{
//FIXME: we need to set UI value type directly without converting reference value.
view.Color = value.ToReferenceType();
});
}
}
10 changes: 4 additions & 6 deletions src/Tizen.NUI.Extension/Markup/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public static T Color<T>(this T view, uint value, float alpha) where T : View
/// <returns>The view itself.</returns>
public static T Color<T>(this T view, UIColor color) where T : View
{
//FIXME: we need to set UI value type directly without converting reference value.
view.Color = color.ToReferenceType();
color.Apply(view, ViewPropertySetters.Color);
return view;
}

Expand Down Expand Up @@ -132,7 +131,7 @@ public static T BackgroundColor<T>(this T view, uint value, float alpha) where T
/// <returns>The view itself.</returns>
public static T BackgroundColor<T>(this T view, UIColor color) where T : View
{
view.SetBackgroundColor(color);
color.Apply(view, ViewPropertySetters.BackgroundColor);
return view;
}

Expand Down Expand Up @@ -416,8 +415,7 @@ public static T BorderlineColor<T>(this T view, uint value, float alpha) where T
/// <returns>The view itself.</returns>
public static T BorderlineColor<T>(this T view, UIColor color) where T : View
{
//FIXME: we need to set UI value type directly without converting reference value.
view.BorderlineColor = color.ToReferenceType();
color.Apply(view, ViewPropertySetters.BorderlineColor);
return view;
}

Expand Down Expand Up @@ -447,7 +445,7 @@ public static T Borderline<T>(this T view, float width, UIColor color, float off
{
view.BorderlineWidth = width;
//FIXME: we need to set UI value type directly without converting reference value.
view.BorderlineColor = color.ToReferenceType();
view.BorderlineColor(color);
view.BorderlineOffset = offset;
return view;
}
Expand Down
37 changes: 37 additions & 0 deletions src/Tizen.NUI/src/devel/Common/IPropertySetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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
{
/// <summary>
/// The interface for property setter.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IPropertySetter<TValue>
{
/// <summary>
/// The name of the property.
/// </summary>
string Name { get; }

/// <summary>
/// Invokes property setter.
/// </summary>
void Invoke(object target, TValue value);
}
}
43 changes: 43 additions & 0 deletions src/Tizen.NUI/src/devel/Common/IToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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;
using Tizen.NUI.BaseComponents;

namespace Tizen.NUI
{
/// <summary>
/// Interface for token. Token is a key-value pair that can be applied to the target. It has an id and value. The value type is generic.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IToken<T>
{
/// <summary>
/// The unique identifier of the token.
/// </summary>
string Id { get; }

/// <summary>
/// The value of the token.
/// </summary>
T Value { get; }

/// <summary>
/// Apply the token to target.
/// </summary>
void Apply<TView>(TView view, IPropertySetter<T> propertySetter) where TView : View;
}
}
51 changes: 51 additions & 0 deletions src/Tizen.NUI/src/devel/Common/ITokenTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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;
using System.Collections.Generic;
using System.ComponentModel;
using Tizen.NUI.BaseComponents;

namespace Tizen.NUI
{
/// <summary>
/// The interface for a token table.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface ITokenTable<T>
{
/// <summary>
/// The event which is invoked when the resource table is updated.
/// </summary>
event EventHandler Updated;

/// <summary>
/// The method to get the value from the resource table.
/// </summary>
bool TryGetValue(string id, out T result);

/// <summary>
/// The method to update the resource table.
/// </summary>
void Update(IDictionary<string, T> table);

/// <summary>
/// The method to bind target with token.
/// When table is updated, binded view will be updated.
/// </summary>
void Bind(View target, IPropertySetter<T> setter, IToken<T> token);
}
}
51 changes: 51 additions & 0 deletions src/Tizen.NUI/src/devel/Common/PropertySetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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;
using System.ComponentModel;

namespace Tizen.NUI
{
/// <summary>
/// Describes a property setter.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class PropertySetter<TView, TValue> : IPropertySetter<TValue>
{
private Action<TView, TValue> _setter;

/// <summary>
/// Creates an instance of the PropertySetter class.
/// </summary>
/// <param name="name">The name of the property.</param>
/// <param name="setter">The action to set the property.</param>
public PropertySetter(string name, Action<TView, TValue> setter)
{
Name = name;
_setter = setter;
}

/// <inheritdoc/>
public string Name { get; }

/// <inheritdoc/>
public virtual void Invoke(object target, TValue value)
{
if (target is TView typedTarget)
_setter(typedTarget, value);
}
}
}
39 changes: 39 additions & 0 deletions src/Tizen.NUI/src/devel/Common/TokenType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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
{
/// <summary>
/// The type of token.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public enum TokenType
{
/// <summary> The color token.</summary>
Color,

/// <summary> The shadow token.</summary>
Shadow,

/// <summary> The font family token.</summary>
FontFamily,

/// <summary> The font weight token.</summary>
FontSize
}
}
Loading

0 comments on commit b0c6bf3

Please sign in to comment.