Revert "[Tizen] fix LineWrap GET error"
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.Tizen / 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 Tizen.NUI;
20 using Tizen.NUI.BaseComponents;
21
22 namespace HelloWorldTest
23 {
24     class Example : NUIApplication
25     {
26         private Animation _animation;
27         private TextLabel _text;
28         private int cnt;
29         private View _view;
30
31         protected override void OnCreate()
32         {
33             base.OnCreate();
34             Initialize();
35         }
36
37         TextLabel pixelLabel;
38         TextLabel pointLabel;
39         public void Initialize()
40         {
41             Window window = Window.Instance;
42             window.BackgroundColor = Color.White;
43             window.TouchEvent += OnWindowTouched;
44             window.KeyEvent += OnWindowKeyEvent;
45             window.Resized += (obj, e) =>
46             {
47                 NUILog.Debug("Height: " + e.WindowSize.Height);
48                 NUILog.Debug("Width: " + e.WindowSize.Width);
49             };
50
51             pixelLabel = new TextLabel("Test Pixel Size 32.0f");
52             pixelLabel.Position2D = new Position2D(10, 10);
53             pixelLabel.PixelSize = 32.0f;
54             window.Add(pixelLabel);
55
56             pointLabel = new TextLabel("Test Point Size 32.0f");
57             pointLabel.Position2D = new Position2D(10, 100);
58             pointLabel.PointSize = 32.0f;
59             window.Add(pointLabel);
60
61             TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
62             ellipsis.Size2D = new Size2D(100, 100);
63             ellipsis.Position2D = new Position2D(10, 250);
64             ellipsis.PointSize = 20.0f;
65             ellipsis.Ellipsis = true;
66             window.Add(ellipsis);
67
68             TextLabel autoScrollStopMode = new TextLabel("AutoScrollStopMode is finish-loop.");
69             autoScrollStopMode.Size2D = new Size2D(400, 100);
70             autoScrollStopMode.Position2D = new Position2D(10, 400);
71             autoScrollStopMode.PointSize = 15.0f;
72             autoScrollStopMode.AutoScrollStopMode = AutoScrollStopMode.FinishLoop;
73             autoScrollStopMode.AutoScrollLoopDelay = 10.0f;
74             autoScrollStopMode.EnableAutoScroll = true;
75             window.Add(autoScrollStopMode);
76
77             _text = new TextLabel("Hello NUI World");
78             _text.Position2D = new Position2D(10, 500);
79             _text.HorizontalAlignment = HorizontalAlignment.Center;
80             _text.PointSize = 20.0f;
81             _text.TextColor = Color.Magenta;
82             window.Add(_text);
83
84             _view = new View();
85             _view.Size2D = new Size2D(100, 100);
86             _view.SizeWidth = 50;
87             NUILog.Debug("[1]_view SizeWidth=" + _view.SizeWidth);
88
89             _animation = new Animation
90             {
91                 Duration = 2000
92             };
93             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
94             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
95             _animation.AnimateBy(_text, "ScaleX", 3, 1000, 1500);
96             _animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
97             _animation.EndAction = Animation.EndActions.Discard;
98             _animation.Finished += AnimationFinished;
99
100             _view.SizeWidth = 50;
101             NUILog.Debug("[2]_view SizeWidth=" + _view.SizeWidth);\r
102 \r
103             TextLabelLineWrapModeTest();\r
104         }
105
106         public void AnimationFinished(object sender, EventArgs e)
107         {
108             NUILog.Debug("AnimationFinished()! cnt=" + (cnt));
109             if (_animation)
110             {
111                 NUILog.Debug("Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
112             }
113             _view.SizeWidth = 50;
114             NUILog.Debug("[3]_view SizeWidth=" + _view.SizeWidth);
115         }
116
117         int win_test;
118         public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
119         {
120             NUILog.Debug("e.Key.KeyPressedName=" + e.Key.KeyPressedName);\r
121
122             if (e.Key.State == Key.StateType.Down)
123             {
124                 if (e.Key.KeyPressedName == "Up")
125                 {
126                     if (_animation)
127                     {
128                         _animation.Finished += AnimationFinished;
129                         cnt++;
130                         NUILog.Debug("AnimationFinished added!");
131                     }\r
132                     pointLabel.TextColorAnimatable = Color.Blue;\r
133                     pixelLabel.TextColorAnimatable = Color.Blue;\r
134 \r
135                     NUILog.Debug($"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
136                 }
137                 else if (e.Key.KeyPressedName == "Down")
138                 {
139                     if (_animation)
140                     {
141                         _animation.Finished -= AnimationFinished;
142                         cnt--;
143                         NUILog.Debug("AnimationFinished removed!");
144                     }\r
145                     pointLabel.TextColorAnimatable = Color.Red;\r
146                     pixelLabel.TextColorAnimatable = Color.Red;\r
147 \r
148                     Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
149                     NUILog.Debug($"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
150                 }
151                 else if (e.Key.KeyPressedName == "Return")
152                 {
153                     _animation.Play();
154                     NUILog.Debug("_animation play here!");\r
155                 }\r
156             }
157         }
158
159         public void OnWindowTouched(object sender, Window.TouchEventArgs e)
160         {
161             if (e.Touch.GetState(0) == PointStateType.Down)
162             {
163                 _animation.Play();
164             }
165         }
166
167         private TextLabel myTextLabel;\r
168         private TextLabel myTextLabel2;\r
169         public void TextLabelLineWrapModeTest()\r
170         {\r
171             NUILog.Debug("WrapModeTest START!");\r
172             myTextLabel = new TextLabel();\r
173             myTextLabel.Position2D = new Position2D(10, 600);\r
174             myTextLabel.Size2D = new Size2D(400, 100);\r
175             myTextLabel.BackgroundColor = Color.Blue;\r
176             myTextLabel.PointSize = 20;\r
177             myTextLabel.TextColor = Color.White;\r
178             myTextLabel.MultiLine = true;\r
179             myTextLabel.LineWrapMode = LineWrapMode.Character;\r
180             myTextLabel.Text = $"[LineWrapMode.Character] hello my name is ABCDEFGHI, it is very very long beautiful hansome awesome name.";\r
181             Window.Instance.GetDefaultLayer().Add(myTextLabel);\r
182 \r
183             myTextLabel2 = new TextLabel();\r
184             myTextLabel2.Position2D = new Position2D(10, 800);\r
185             myTextLabel2.Size2D = new Size2D(400, 100);\r
186             myTextLabel2.BackgroundColor = Color.Blue;\r
187             myTextLabel2.PointSize = 20;\r
188             myTextLabel2.TextColor = Color.White;\r
189             myTextLabel2.MultiLine = true;\r
190             myTextLabel2.LineWrapMode = LineWrapMode.Word;\r
191             myTextLabel2.Text = $"[LineWrapMode.Word] hello my name is ABCDEFGHI, it is very very long beautiful hansome awesome name.";\r
192             Window.Instance.GetDefaultLayer().Add(myTextLabel2);\r
193 \r
194             NUILog.Debug($"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");\r
195         }
196
197         [STAThread]
198         static void _Main(string[] args)
199         {
200             Example example = new Example();
201             example.Run(args);
202         }
203     }
204 }