Ensure text-controller returns false when it doesn't use key.
[platform/core/uifw/dali-toolkit.git] / plugins / dali-sharp / examples / visuals-example.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 Dali;
20 using Dali.Constants;
21
22 namespace MyCSharpExample
23 {
24     class Example
25     {
26         private Application _application;
27         private TextLabel _title;
28
29         public Example(Application application)
30         {
31             _application = application;
32             _application.Initialized += Initialize;
33         }
34
35         public void Initialize(object source, NUIApplicationInitEventArgs e)
36         {
37             Window window = Window.Instance;
38             window.BackgroundColor = Color.White;
39
40             TableView contentLayout = new TableView(4, 1);
41             contentLayout.Name = ("ContentLayout");
42             contentLayout.WidthResizePolicy = "FILL_TO_PARENT";
43             contentLayout.HeightResizePolicy = "FILL_TO_PARENT";
44             contentLayout.SetCellPadding(new Size2D(0, 5));
45             contentLayout.BackgroundColor = new Color(0.949f, 0.949f, 0.949f, 1.0f);
46
47             window.GetDefaultLayer().Add(contentLayout);
48
49             _title = new TextLabel("Visuals Example");
50             _title.Name = "Title";
51             _title.StyleName = "Title";
52             _title.WidthResizePolicy = "FILL_TO_PARENT";
53             _title.HeightResizePolicy = "USE_NATURAL_SIZE";
54             _title.HorizontalAlignment = "CENTER";
55             _title.BackgroundColor = Color.Yellow;
56             contentLayout.Add(_title);
57             contentLayout.SetFitHeight(0);
58
59             // Color Visual example
60             View colorView = new View();
61             colorView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
62             colorView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
63             Property.Map colorVisual = new Property.Map();
64             colorVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Color ))
65                        .Add( ColorVisualProperty.MixColor, new Property.Value( Color.Green ));
66             colorView.Background = colorVisual;
67             contentLayout.Add(colorView);
68
69             // Image Visual example
70             View imageView = new View();
71             imageView.WidthResizePolicy = "USE_NATURAL_SIZE";
72             imageView.HeightResizePolicy = "USE_NATURAL_SIZE";
73             Property.Map imageVisual = new Property.Map();
74             imageVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Image ))
75                        .Add( ImageVisualProperty.URL, new Property.Value( "./images/gallery-0.jpg" ));
76             imageView.Background = imageVisual;
77             contentLayout.SetCellAlignment(new TableView.CellPosition(2, 0), HorizontalAlignmentType.Center, VerticalAlignmentType.CENTER);
78             contentLayout.Add(imageView);
79
80             // Primitive Visual example
81             View primitiveView = new View();
82             primitiveView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
83             primitiveView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
84             Property.Map primitiveVisual = new Property.Map();
85             primitiveVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Primitive ))
86                            .Add( PrimitiveVisualProperty.Shape, new Property.Value((int)PrimitiveVisualShapeType.BEVELLED_CUBE))
87                            .Add( PrimitiveVisualProperty.BevelPercentage, new Property.Value(0.3f))
88                            .Add( PrimitiveVisualProperty.BevelSmoothness, new Property.Value(0.0f))
89                            .Add( PrimitiveVisualProperty.ScaleDimensions, new Property.Value(new Vector3(1.0f,1.0f,0.3f)))
90                            .Add( PrimitiveVisualProperty.MixColor, new Property.Value(new Vector4(0.7f, 0.5f, 0.05f, 1.0f)));
91             primitiveView.Background = primitiveVisual;
92             Radian rad = new Radian(new Degree(45.0f));
93             primitiveView.Orientation = new Rotation(rad, Vector3.YAXIS);
94             contentLayout.Add(primitiveView);
95
96             // Text Visual example
97             View textView = new View();
98             textView.WidthResizePolicy = "SIZE_RELATIVE_TO_PARENT";
99             textView.HeightResizePolicy = "SIZE_RELATIVE_TO_PARENT";
100             Property.Map textVisual = new Property.Map();
101             textVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Text ))
102                       .Add( TextVisualProperty.Text, new Property.Value("I am text visual"))
103                       .Add( TextVisualProperty.TextColor, new Property.Value(Color.Blue))
104                       .Add( TextVisualProperty.PointSize, new Property.Value(20));
105             textView.Background = textVisual;
106             contentLayout.Add(textView);
107         }
108
109         public void MainLoop()
110         {
111             _application.MainLoop();
112         }
113
114         /// <summary>
115         /// The main entry point for the application.
116         /// </summary>
117         [STAThread]
118         static void Main(string[] args)
119         {
120             Example example = new Example(Application.NewApplication());
121             example.MainLoop();
122         }
123     }
124 }