[NUI.Components] Fix Background Image not works issue (#1246) (#1248)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ImageControlStyle.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System.Collections.Generic;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// ImageControlStyle is a class which saves Button's ux data.
26     /// </summary>
27     /// <since_tizen> 6 </since_tizen>
28     /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public class ImageControlStyle : ControlStyle
31     {
32         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create("ImageControlResourceUrl", typeof(Selector<string>), typeof(ImageControlStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var imageControlStyle = (ImageControlStyle)bindable;
37             if (null == imageControlStyle.resourceUrlSelector) imageControlStyle.resourceUrlSelector = new Selector<string>();
38             imageControlStyle.resourceUrlSelector.Clone((Selector<string>)newValue);
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var imageControlStyle = (ImageControlStyle)bindable;
43             return imageControlStyle.resourceUrlSelector;
44         });
45         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
46         [EditorBrowsable(EditorBrowsableState.Never)]
47         public static readonly BindableProperty BorderProperty = BindableProperty.Create("ImageControlBorder", typeof(Selector<Rectangle>), typeof(ImageControlStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
48         {
49             var imageControlStyle = (ImageControlStyle)bindable;
50             if (null == imageControlStyle.borderSelector) imageControlStyle.borderSelector = new Selector<Rectangle>();
51             imageControlStyle.borderSelector.Clone((Selector<Rectangle>)newValue);
52         },
53         defaultValueCreator: (bindable) =>
54         {
55             var imageControlStyle = (ImageControlStyle)bindable;
56             return imageControlStyle.borderSelector;
57         });
58
59         private Selector<string> resourceUrlSelector;
60         private Selector<Rectangle> borderSelector;
61
62         static ImageControlStyle() { }
63
64         /// <summary>
65         /// Creates a new instance of a ImageControlStyle.
66         /// </summary>
67         /// <since_tizen> 6 </since_tizen>
68         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public ImageControlStyle() : base()
71         {
72         }
73
74         /// <summary>
75         /// Creates a new instance of a ImageControlStyle with style.
76         /// </summary>
77         /// <param name="style">Create ImageControlStyle by style customized by user.</param>
78         /// <since_tizen> 6 </since_tizen>
79         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
80         [EditorBrowsable(EditorBrowsableState.Never)]
81         public ImageControlStyle(ImageControlStyle style) : base(style)
82         {
83             if(null == style) return;
84
85             this.CopyFrom(style);
86         }
87
88         /// <summary>
89         /// Image URL.
90         /// </summary>
91         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
92         [EditorBrowsable(EditorBrowsableState.Never)]
93         public Selector<string> ResourceUrl
94         {
95             get
96             {
97                 Selector<string> url = (Selector<string>)GetValue(ResourceUrlProperty);
98                 return (null != url) ? url : resourceUrlSelector = new Selector<string>();
99             }
100             set => SetValue(ResourceUrlProperty, value);
101         }
102
103         /// <summary>
104         /// Image border.
105         /// </summary>
106         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
107         [EditorBrowsable(EditorBrowsableState.Never)]
108         public Selector<Rectangle> Border
109         {
110             get
111             {
112                 Selector<Rectangle> border = (Selector<Rectangle>)GetValue(BorderProperty);
113                 return (null != border) ? border : borderSelector = new Selector<Rectangle>();
114             }
115             set => SetValue(BorderProperty, value);
116         }
117
118         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public override void CopyFrom(BindableObject bindableObject)
121         {
122             base.CopyFrom(bindableObject);
123
124             ImageControlStyle imageControlStyle = bindableObject as ImageControlStyle;
125
126             if (null != imageControlStyle)
127             {
128                 if (null != imageControlStyle.ResourceUrl)
129                 {
130                     if (null == ResourceUrl) ResourceUrl = new Selector<string>();
131                     ResourceUrl.Clone(imageControlStyle.ResourceUrl);
132                 }
133                 if (null != imageControlStyle.Border)
134                 {
135                     if (null == Border) Border = new Selector<Rectangle>();
136                     Border.Clone(imageControlStyle.Border);
137                 }
138             }
139         }
140     }
141 }