c67da0892992863c380d3777516468f32d4c3a28
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewSelectorData.cs
1 /*
2  * Copyright(c) 2020 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
18 namespace Tizen.NUI.BaseComponents
19 {
20     /// <summary>
21     /// The class storing extra data for a View to optimize size of it.
22     /// </summary>
23     internal class ViewSelectorData
24     {
25         public TriggerableSelector<Color> BackgroundColor { get; } = new TriggerableSelector<Color>(View.BackgroundColorProperty, delegate (View view)
26         {
27             var background = view.Background;
28             int visualType = 0;
29             background.Find(Visual.Property.Type)?.Get(out visualType);
30
31             if (visualType == (int)Visual.Type.Color)
32             {
33                 Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
34                 background.Find(ColorVisualProperty.MixColor)?.Get(backgroundColor);
35                 return backgroundColor;
36             }
37             return null;
38         });
39         public TriggerableSelector<string> BackgroundImage { get; } = new TriggerableSelector<string>(View.BackgroundImageProperty, delegate (View view)
40         {
41             string backgroundImage = null;
42             view.Background.Find(ImageVisualProperty.URL)?.Get(out backgroundImage);
43             return backgroundImage;
44         });
45         public TriggerableSelector<Rectangle> BackgroundImageBorder { get; } = new TriggerableSelector<Rectangle>(View.BackgroundImageBorderProperty);
46         public TriggerableSelector<Color> Color { get; } = new TriggerableSelector<Color>(View.ColorProperty, delegate (View view)
47         {
48             Color color = new Color();
49             if (view.GetProperty(Interop.ActorProperty.ColorGet()).Get(color))
50             {
51                 return color;
52             }
53             return null;
54         });
55         public TriggerableSelector<float?> Opacity { get; } = new TriggerableSelector<float?>(View.OpacityProperty);
56         public TriggerableSelector<ImageShadow> ImageShadow { get; } = new TriggerableSelector<ImageShadow>(View.ImageShadowProperty);
57         public TriggerableSelector<Shadow> BoxShadow { get; } = new TriggerableSelector<Shadow>(View.BoxShadowProperty);
58         public TriggerableSelector<float?> CornerRadius { get; } = new TriggerableSelector<float?>(View.CornerRadiusProperty);
59
60         public void Reset(View view)
61         {
62             BackgroundColor.Reset(view);
63             BackgroundImage.Reset(view);
64             BackgroundImageBorder.Reset(view);
65             Color.Reset(view);
66             Opacity.Reset(view);
67             ImageShadow.Reset(view);
68             BoxShadow.Reset(view);
69             CornerRadius.Reset(view);
70         }
71     }
72 }