be327fe06386e1fe5d567b30e90a91faf8b6366e
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.Tizen / examples / visuals-using-custom-view / visuals-using-custom-view.cs
1 /*
2  * Copyright (c) 2017 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 using System;
19 using Tizen.NUI;
20 using Tizen.NUI.UIComponents;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Constants;
23
24 namespace VisualsUsingCustomView
25 {
26     class VisualsExample : NUIApplication
27     {
28         public VisualsExample() : base()
29         {
30         }
31
32         public VisualsExample(string stylesheet) : base(stylesheet)
33         {
34         }
35
36         public VisualsExample(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
37         {
38         }
39
40         protected override void OnCreate()
41         {
42             base.OnCreate();
43             Initialize();
44         }
45
46         private void Initialize()
47         {
48             Window window = Window.Instance;
49             window.BackgroundColor = Color.White;
50
51             TableView contentLayout = new TableView(14, 1);
52             contentLayout.Name = "ContentLayout";
53             //contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
54             //contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
55             contentLayout.PivotPoint = PivotPoint.TopLeft;
56             contentLayout.ParentOrigin = ParentOrigin.TopLeft;
57             contentLayout.Size2D = new Vector2(window.Size.Width, window.Size.Height);
58             contentLayout.SetCellPadding(new Size2D(5, 5));
59             contentLayout.BackgroundColor = new Color(0.949f, 0.949f, 0.949f, 1.0f);
60
61             window.Add(contentLayout);
62
63             TextLabel title = new TextLabel("Contacts List with Visuals");
64             title.Name = "Title";
65             title.StyleName = "Title";
66             title.WidthResizePolicy = ResizePolicyType.FillToParent;
67             title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
68             title.HorizontalAlignment = HorizontalAlignment.Center;
69             contentLayout.Add(title);
70             contentLayout.SetFitHeight(0);
71
72             // Create ContactView(s) from ContactItem(s) in ContactsList and add them to TableView
73             ContactView contactView;
74             foreach (ContactItem contact in ContactsList.s_contactData)
75             {
76                 contactView = new ContactView();
77                 contactView.WidthResizePolicy = ResizePolicyType.FillToParent;
78                 contactView.HeightResizePolicy = ResizePolicyType.FillToParent;
79
80                 // Configure visuals of ContactView via properties
81                 contactView.NameField = contact.Name;
82                 contactView.MaskURL = contact.MaskURL;
83                 contactView.ImageURL = contact.ImageURL;
84                 contactView.Color = contact.Color;
85                 contactView.Shape = contact.Shape;
86                 contentLayout.Add(contactView);
87             }
88         }
89
90         /// <summary>
91         /// The main entry point for the application.
92         /// </summary>
93         [STAThread]
94         static void _Main(string[] args)
95         {
96             VisualsExample visualsExample = new VisualsExample();
97             visualsExample.Run(args);
98         }
99     }
100 }