From 77ee0d9b043b4ce92c431a891173aa505e8d0a24 Mon Sep 17 00:00:00 2001 From: "everLEEst(SangHyeon Lee)" Date: Tue, 21 Jan 2025 21:44:02 +0900 Subject: [PATCH] [NUI] Add markup extension methods for view properties Add C# MarkUp Extension methods for View Properties. e.g) View myView = new ().Size(10f, 10f) .Position(10f, 10f) .Layout(new LienarLayout) .Padding(5f, 5f, 5f, 5f) .BackgroundColor(1f, 1f, 1f, 1f) Added Properties - Color - ImageShadow - Borderline - Opacity - Scale - Visibility - Sensitive - IsEnabled - ClippingMode - Layout - Focusable - FocusableChildren - FocusableInTouch - VoiceInteractionName - OffScreenRendering and few getters for UI struct types. - Color - BorderlineColor --- .../Markup/ViewExtensions.cs | 438 +++++++++++++++++- 1 file changed, 413 insertions(+), 25 deletions(-) diff --git a/src/Tizen.NUI.Extension/Markup/ViewExtensions.cs b/src/Tizen.NUI.Extension/Markup/ViewExtensions.cs index 6405f630037..ca46f480a5f 100644 --- a/src/Tizen.NUI.Extension/Markup/ViewExtensions.cs +++ b/src/Tizen.NUI.Extension/Markup/ViewExtensions.cs @@ -15,6 +15,7 @@ * */ using System.ComponentModel; +using Tizen.NUI; using Tizen.NUI.BaseComponents; namespace Tizen.NUI.Extension @@ -38,6 +39,56 @@ public static T Self(this T view, out T self) where T : View return view; } + /// + /// Sets the color of the view. + /// + /// The type of the view. + /// The extension target. + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + /// The view itself. + public static T Color(this T view, float r, float g, float b, float a = 1f) where T : View + { + view.Color = new (r, g, b, a); + return view; + } + + /// + /// Sets the color of the view. + /// + /// The type of the view. + /// The extension target. + /// The value of 0xRRGGBB format. + /// The alpha value between 0.0 and 1.0. + /// + /// + /// new UIColor(0xFF0000, 1f); // Solid red + /// new UIColor(0x00FF00, 0.5f) // Half transparent green + /// + /// + /// The view itself. + public static T Color(this T view, uint value, float alpha) where T : View + { + view.Color = (new UIColor(value, alpha)).ToReferenceType(); + return view; + } + + /// + /// Sets the color of the view. + /// + /// The type of the view. + /// The extension target. + /// The color value. + /// The view itself. + public static T Color(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(); + return view; + } + /// /// Sets the background color of the view. /// @@ -60,6 +111,12 @@ public static T BackgroundColor(this T view, float r, float g, float b, float /// The extension target. /// The value of 0xRRGGBB format. /// The alpha value between 0.0 and 1.0. + /// + /// + /// new UIColor(0xFF0000, 1f); // Solid red + /// new UIColor(0x00FF00, 0.5f) // Half transparent green + /// + /// /// The view itself. public static T BackgroundColor(this T view, uint value, float alpha) where T : View { @@ -79,16 +136,6 @@ public static T BackgroundColor(this T view, UIColor color) where T : View return view; } - /// - /// Experimental getter for background color - /// - /// The extension target. - /// The background color value. - public static UIColor BackgroundColor(this View view) - { - return Object.InternalRetrievingVisualPropertyColor(view.SwigCPtr, View.Property.BACKGROUND, ColorVisualProperty.MixColor); - } - /// /// Sets the background image of the view. /// @@ -96,7 +143,7 @@ public static UIColor BackgroundColor(this View view) /// The extension target. /// The resource url. /// The view itself. - public static TView BackgroundImage(this TView view, string url) where TView : View + public static T BackgroundImage(this T view, string url) where T : View { view.BackgroundImage = url; return view; @@ -229,19 +276,6 @@ public static T CornerRadius(this T view, UICorner corner, bool isRelative = return view; } - /// - /// Gets the corner radius of the view. - /// - /// The type of the view. - /// The extension target. - /// The corner radius value. - 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); - } - /// /// Sets the box shadow of the view. /// @@ -253,7 +287,7 @@ public static UICorner CornerRadius(this View view) /// The view itself. public static T BoxShadow(this T view, float blurRadius, float offsetX = 0, float offsetY = 0) where T : View { - return view.BoxShadow(new UIShadow(blurRadius)); + return view.BoxShadow(new UIShadow(blurRadius, offsetX, offsetY)); } /// @@ -283,5 +317,359 @@ public static T BoxShadow(this T view, UIShadow shadow) where T : View view.SetBoxShadow(shadow); return view; } + + /// + /// Sets the image shadow of the view. + /// + /// The type of the view. + /// The extension target. + /// The image shadow value. + /// The view itself. + public static T ImageShadow(this T view, ImageShadow shadow) where T : View + { + view.ImageShadow = shadow; + return view; + } + + /// + /// Sets the width for the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The width value. + /// The view itself. + public static T BorderlineWidth(this T view, float width) where T : View + { + view.BorderlineWidth = width; + return view; + } + + /// + /// Sets the color for the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + /// The view itself. + public static T BorderlineColor(this T view, float r, float g, float b, float a = 1f) where T : View + { + view.BorderlineColor = new (r, g, b, a); + return view; + } + + /// + /// Sets the color for the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The value of 0xRRGGBB format. + /// The alpha value between 0.0 and 1.0. + /// + /// + /// new UIColor(0xFF0000, 1f); // Solid red + /// new UIColor(0x00FF00, 0.5f) // Half transparent green + /// + /// + /// The view itself. + public static T BorderlineColor(this T view, uint value, float alpha) where T : View + { + view.BorderlineColor = (new UIColor(value, alpha)).ToReferenceType(); + return view; + } + + + /// + /// Sets the color for the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The color value. + /// The view itself. + public static T BorderlineColor(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(); + return view; + } + + /// + /// Sets the offset for the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The offset value. + /// The view itself. + public static T BorderlineOffset(this T view, float offset) where T : View + { + view.BorderlineOffset = offset; + return view; + } + + /// + /// Sets the borderline of the View. + /// + /// The type of the view. + /// The extension target. + /// The width value. + /// The color value. + /// The offset value. + /// The view itself. + public static T Borderline(this T view, float width, UIColor color, float offset) where T : View + { + view.BorderlineWidth = width; + //FIXME: we need to set UI value type directly without converting reference value. + view.BorderlineColor = color.ToReferenceType(); + view.BorderlineOffset = offset; + return view; + } + + /// + /// Sets the view's opacity + /// + /// The type of the view. + /// The extension target. + /// The opacity value. + /// The view itself. + public static T Opacity(this T view, float opacity) where T : View + { + view.Opacity = opacity; + return view; + } + + /// + /// Sets the scale X factor applied to the view. + /// + /// The type of the view. + /// The extension target. + /// The scale value. + /// The view itself. + public static T ScaleX(this T view, float scale) where T : View + { + view.ScaleX = scale; + return view; + } + + /// + /// Sets the scale Y factor applied to the view. + /// + /// The type of the view. + /// The extension target. + /// The scale value. + /// The view itself. + public static T ScaleY(this T view, float scale) where T : View + { + view.ScaleY = scale; + return view; + } + + /// + /// Sets the scale factor applied to the view. + /// + /// The type of the view. + /// The extension target. + /// The scale x value. + /// The scale y value. + /// The view itself. + public static T Scale(this T view, float scaleX, float scaleY) where T : View + { + view.ScaleX = scaleX; + view.ScaleY = scaleY; + return view; + } + + /// + /// Sets the visibility of the view. + /// + /// + /// + /// + /// The type of the view. + /// The extension target. + /// The visibility value. + /// The view itself. + public static T Visibility(this T view, bool visiblity) where T : View + { + if (view.Visibility != visiblity) + { + if (visiblity) + { + view.Show(); + } + else + { + view.Hide(); + } + } + return view; + } + + /// + /// Sets the status of whether the view should emit touch or hover signals. + /// If a View is made insensitive, then the View and its children are not hittable. + /// + /// The type of the view. + /// The extension target. + /// The sensitive value. + /// The view itself. + public static T Sensitive(this T view, bool sensitive) where T : View + { + view.Sensitive = sensitive; + return view; + } + + /// + /// Sets the status of whether the view should be enabled user interactions. + /// If a View is made disabled, then user interactions including touch, focus, and actiavation is disabled. + /// + /// The type of the view. + /// The extension target. + /// The enable value. + /// The view itself. + public static T IsEnabled(this T view, bool enable) where T : View + { + view.IsEnabled = enable; + return view; + } + + /// + /// Sets the clipping behavior (mode) of it's children. + /// + /// The type of the view. + /// The extension target. + /// The clipping mode type value. + /// The view itself. + public static T ClippingMode(this T view, ClippingModeType type) where T : View + { + view.ClippingMode = type; + return view; + } + + /// + /// Set the layout on this View. Replaces any existing Layout. + /// + /// The type of the view. + /// The extension target. + /// The layout for the view. + /// The view itself. + public static T Layout(this T view, LayoutItem layout) where T : View + { + view.Layout = layout; + return view; + } + + /// + /// Sets focusable of the view + /// + /// The type of the view. + /// The extension target. + /// The focusable value. + /// The view itself. + public static T Focusable(this T view, bool focusable) where T : View + { + view.Focusable = focusable; + return view; + } + + /// + /// Sets whether the children of this view can be focusable by keyboard navigation. + /// + /// The type of the view. + /// The extension target. + /// The focusable value. + /// The view itself. + public static T FocusableChildren(this T view, bool focusable) where T : View + { + view.FocusableChildren = focusable; + return view; + } + + /// + /// Sets whether the view can focus by touch. + /// + /// The type of the view. + /// The extension target. + /// The focusable value. + /// The view itself. + public static T FocusableInTouch(this T view, bool focusable) where T : View + { + view.FocusableInTouch = focusable; + return view; + } + + /// + /// Set voice interaction name for Voice Touch. + /// + /// The type of the view. + /// The extension target. + /// The name value. + /// The view itself. + public static T VoiceInteractionName(this T view, string name) where T : View + { + view.VoiceInteractionName = name; + return view; + } + + /// + /// Set the current offscreen rendering type of the view. + /// + /// The type of the view. + /// The extension target. + /// The offscreen type value. + /// The view itself. + public static T OffScreenRendering(this T view, View.OffScreenRenderingType type) where T : View + { + view.OffScreenRendering = type; + return view; + } + +/* Getters */ + + /// + /// Gets the color for the View. + /// + /// The extension target. + /// The color value. + public static UIColor Color(this View view) + { + //FIXME: we need to set UI value type directly without converting reference value. + return new UIColor(view.Color); + } + + /// + /// Experimental getter for background color + /// + /// The extension target. + /// The background color value. + public static UIColor BackgroundColor(this View view) + { + return Object.InternalRetrievingVisualPropertyColor(view.SwigCPtr, View.Property.BACKGROUND, ColorVisualProperty.MixColor); + } + + /// + /// Gets the corner radius of the view. + /// + /// The extension target. + /// The corner radius value. + 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); + } + + /// + /// Gets the color for the borderline of the View. + /// + /// The extension target. + /// The borderline color value. + public static UIColor BorderlineColor(this View view) + { + //FIXME: we need to set UI value type directly without converting reference value. + return new UIColor(view.BorderlineColor); + } + } }