[Tizen] Update NUISamples to support .netcore 2.0
[platform/core/csapi/nui.git] / NUISamples / examples / hello-world.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 System.Threading.Tasks;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22
23 namespace HelloWorldTest
24 {
25     class Example : NUIApplication
26     {
27         private Animation _animation;
28         private TextLabel _text;
29         private int cnt;
30         private View _view;
31
32         protected override void OnCreate()
33         {
34             base.OnCreate();
35             Initialize();
36         }
37
38         TextLabel pixelLabel;
39         TextLabel pointLabel;
40         public void Initialize()
41         {
42             Window window = Window.Instance;
43             window.BackgroundColor = Color.White;
44             window.TouchEvent += OnWindowTouched;
45             window.KeyEvent += OnWindowKeyEvent;
46             window.Resized += (obj, e) =>
47             {
48                 Tizen.Log.Debug("NUI", "Height: " + e.WindowSize.Height);
49                 Tizen.Log.Debug("NUI", "Width: " + e.WindowSize.Width);
50             };
51
52             pixelLabel = new TextLabel("Test Pixel Size 32.0f");
53             pixelLabel.Position2D = new Position2D(10, 10);
54             pixelLabel.PixelSize = 32.0f;
55             window.Add(pixelLabel);
56
57             pointLabel = new TextLabel("Test Point Size 32.0f");
58             pointLabel.Position2D = new Position2D(10, 100);
59             pointLabel.PointSize = 32.0f;
60             window.Add(pointLabel);
61
62             Task.Factory.StartNew(() =>
63             {
64                 try
65                 {
66             TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
67             ellipsis.Size2D = new Size2D(100, 100);
68             ellipsis.Position2D = new Position2D(10, 250);
69             ellipsis.PointSize = 20.0f;
70             ellipsis.Ellipsis = true;
71             window.Add(ellipsis);
72                 }
73                 catch (Exception e)
74                 {
75                     Tizen.Log.Debug("NUI", $"exception caught! e={e}");
76                 }
77             }).Wait();
78
79             TextLabel autoScrollStopMode = new TextLabel("AutoScrollStopMode is finish-loop.");
80             autoScrollStopMode.Size2D = new Size2D(400, 100);
81             autoScrollStopMode.Position2D = new Position2D(10, 400);
82             autoScrollStopMode.PointSize = 15.0f;
83             autoScrollStopMode.AutoScrollStopMode = AutoScrollStopMode.FinishLoop;
84             autoScrollStopMode.AutoScrollLoopDelay = 10.0f;
85             autoScrollStopMode.EnableAutoScroll = true;
86             window.Add(autoScrollStopMode);
87
88             _text = new TextLabel("Hello NUI World");
89             _text.Position2D = new Position2D(10, 500);
90             _text.HorizontalAlignment = HorizontalAlignment.Center;
91             _text.PointSize = 20.0f;
92             _text.TextColor = Color.Magenta;
93             window.Add(_text);
94
95             _view = new View();
96             _view.Size2D = new Size2D(100, 100);
97             _view.SizeWidth = 50;
98             Tizen.Log.Debug("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
99
100             _animation = new Animation
101             {
102                 Duration = 2000
103             };
104             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
105             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
106             _animation.AnimateBy(_text, "ScaleX", 3, 1000, 1500);
107             _animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
108             _animation.EndAction = Animation.EndActions.Discard;
109             _animation.Finished += AnimationFinished;
110
111             _view.SizeWidth = 50;
112             Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
113
114             TextLabelLineWrapModeTest();
115             ViewLayoutDirectionTest();
116         }
117
118
119         private View view1, view11, view12, view111, view121;
120         public void ViewLayoutDirectionTest()
121         {
122             view1 = new View();
123             view1.Name = "view 1";
124             view1.LayoutDirection = ViewLayoutDirectionType.RTL;
125             Window.Instance.GetDefaultLayer().Add(view1);
126             view1.LayoutDirectionChanged += View1_LayoutDirectionChanged;
127
128             view11 = new View();
129             view11.Name = "view 11";
130             view11.InheritLayoutDirection = true;
131             view1.Add(view11);
132
133             view12 = new View();
134             view12.Name = "view 12";
135             view12.LayoutDirection = ViewLayoutDirectionType.LTR;
136             view1.Add(view12);
137
138             view111 = new View();
139             view111.Name = "view 111";
140             view111.InheritLayoutDirection = true;
141             view11.Add(view111);
142
143             view121 = new View();
144             view121.Name = "view 121";
145             view121.InheritLayoutDirection = true;
146             view12.Add(view121);
147         }
148
149         private void View1_LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
150         {
151             NUILog.Error("View1_LayoutDirectionChanged()! e.Type=" + e.Type);
152         }
153
154         public void AnimationFinished(object sender, EventArgs e)
155         {
156             Tizen.Log.Debug("NUI", "AnimationFinished()! cnt=" + (cnt));
157             if (_animation)
158             {
159                 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
160             }
161             _view.SizeWidth = 50;
162             Tizen.Log.Debug("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
163         }
164
165         int win_test;
166         public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
167         {
168             Tizen.Log.Debug("NUI", "e.Key.KeyPressedName=" + e.Key.KeyPressedName);
169
170             if (e.Key.State == Key.StateType.Down)
171             {
172                 if (e.Key.KeyPressedName == "Up")
173                 {
174                     if (_animation)
175                     {
176                         _animation.Finished += AnimationFinished;
177                         cnt++;
178                         Tizen.Log.Debug("NUI", "AnimationFinished added!");
179                     }
180                     pointLabel.TextColorAnimatable = Color.Blue;
181                     pixelLabel.TextColorAnimatable = Color.Blue;
182
183                     Tizen.Log.Debug("NUI", $"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
184                 }
185                 else if (e.Key.KeyPressedName == "Down")
186                 {
187                     if (_animation)
188                     {
189                         _animation.Finished -= AnimationFinished;
190                         cnt--;
191                         Tizen.Log.Debug("NUI", "AnimationFinished removed!");
192                     }
193                     pointLabel.TextColorAnimatable = Color.Red;
194                     pixelLabel.TextColorAnimatable = Color.Red;
195
196                     Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
197                     Tizen.Log.Debug("NUI", $"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
198                 }
199                 else if (e.Key.KeyPressedName == "Return")
200                 {
201                     _animation.Play();
202                     Tizen.Log.Debug("NUI", "_animation play here!");
203                 }
204             }
205         }
206
207         public void OnWindowTouched(object sender, Window.TouchEventArgs e)
208         {
209             if (e.Touch.GetState(0) == PointStateType.Down)
210             {
211                 _animation.Play();
212             }
213         }
214
215         private TextLabel myTextLabel;
216         private TextLabel myTextLabel2;
217         private TextEditor myTextEditor;
218         private TextEditor myTextEditor2;
219         public void TextLabelLineWrapModeTest()
220         {
221             Tizen.Log.Debug("NUI", "WrapModeTest START!");
222             myTextLabel = new TextLabel();
223             myTextLabel.Position2D = new Position2D(10, 600);
224             myTextLabel.Size2D = new Size2D(400, 90);
225             myTextLabel.BackgroundColor = Color.Blue;
226             myTextLabel.PointSize = 20;
227             myTextLabel.TextColor = Color.White;
228             myTextLabel.MultiLine = true;
229             myTextLabel.LineWrapMode = LineWrapMode.Character;
230             myTextLabel.Text = $"[TextLabel LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
231             Window.Instance.GetDefaultLayer().Add(myTextLabel);
232
233             myTextLabel2 = new TextLabel();
234             myTextLabel2.Position2D = new Position2D(450, 600);
235             myTextLabel2.Size2D = new Size2D(400, 90);
236             myTextLabel2.BackgroundColor = Color.Blue;
237             myTextLabel2.PointSize = 20;
238             myTextLabel2.TextColor = Color.White;
239             myTextLabel2.MultiLine = true;
240             myTextLabel2.LineWrapMode = LineWrapMode.Word;
241             myTextLabel2.Text = $"[TextLabel LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
242             Window.Instance.GetDefaultLayer().Add(myTextLabel2);
243
244             Tizen.Log.Debug("NUI", $"TextLabel LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
245
246             myTextEditor = new TextEditor();
247             myTextEditor.Position2D = new Position2D(10, 700);
248             myTextEditor.Size2D = new Size2D(400, 90);
249             myTextEditor.BackgroundColor = Color.Red;
250             myTextEditor.PointSize = 20;
251             myTextEditor.TextColor = Color.White;
252             //myTextEditor.MultiLine = true;
253             myTextEditor.LineWrapMode = LineWrapMode.Character;
254             myTextEditor.Text = $"[TextEditor LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
255             Window.Instance.GetDefaultLayer().Add(myTextEditor);
256
257             myTextEditor2 = new TextEditor();
258             myTextEditor2.Position2D = new Position2D(450, 700);
259             myTextEditor2.Size2D = new Size2D(400, 90);
260             myTextEditor2.BackgroundColor = Color.Red;
261             myTextEditor2.PointSize = 20;
262             myTextEditor2.TextColor = Color.White;
263             //myTextEditor2.MultiLine = true;
264             myTextEditor2.LineWrapMode = LineWrapMode.Word;
265             myTextEditor2.Text = $"[TextEditor LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
266             Window.Instance.GetDefaultLayer().Add(myTextEditor2);
267
268             Tizen.Log.Debug("NUI", $"TextEditor LineWrapMode 1st={ myTextEditor?.LineWrapMode} 2nd={ myTextEditor2?.LineWrapMode}");
269         }
270
271         [STAThread]
272         static void _Main(string[] args)
273         {
274             Example example = new Example();
275             example.Run(args);
276         }
277     }
278 }