2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Threading.Tasks;
21 using Tizen.NUI.BaseComponents;
23 namespace HelloWorldTest
25 class Example : NUIApplication
27 private Animation _animation;
28 private TextLabel _text;
32 protected override void OnCreate()
40 public void Initialize()
42 Window window = Window.Instance;
43 window.BackgroundColor = Color.White;
44 window.TouchEvent += OnWindowTouched;
45 window.KeyEvent += OnWindowKeyEvent;
46 window.Resized += (obj, e) =>
48 Tizen.Log.Debug("NUI", "Height: " + e.WindowSize.Height);
49 Tizen.Log.Debug("NUI", "Width: " + e.WindowSize.Width);
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);
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);
62 Task.Factory.StartNew(() =>
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;
75 Tizen.Log.Debug("NUI", $"exception caught! e={e}");
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);
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;
96 _view.Size2D = new Size2D(100, 100);
98 Tizen.Log.Debug("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
100 _animation = new Animation
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;
111 _view.SizeWidth = 50;
112 Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
114 TextLabelLineWrapModeTest();
115 //ViewLayoutDirectionTest();
119 private View view1, view11, view12, view111, view121;
120 public void ViewLayoutDirectionTest()
123 view1.Name = "view 1";
124 view1.LayoutDirection = ViewLayoutDirectionType.RTL;
125 Window.Instance.GetDefaultLayer().Add(view1);
126 view1.LayoutDirectionChanged += View1_LayoutDirectionChanged;
129 view11.Name = "view 11";
130 view11.InheritLayoutDirection = true;
134 view12.Name = "view 12";
135 view12.LayoutDirection = ViewLayoutDirectionType.LTR;
138 view111 = new View();
139 view111.Name = "view 111";
140 view111.InheritLayoutDirection = true;
143 view121 = new View();
144 view121.Name = "view 121";
145 view121.InheritLayoutDirection = true;
149 private void View1_LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
151 NUILog.Error("View1_LayoutDirectionChanged()! e.Type=" + e.Type);
155 public void AnimationFinished(object sender, EventArgs e)
157 Tizen.Log.Debug("NUI", "AnimationFinished()! cnt=" + (cnt));
160 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
162 _view.SizeWidth = 50;
163 Tizen.Log.Debug("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
167 public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
169 Tizen.Log.Debug("NUI", "e.Key.KeyPressedName=" + e.Key.KeyPressedName);
171 if (e.Key.State == Key.StateType.Down)
173 if (e.Key.KeyPressedName == "Up")
177 _animation.Finished += AnimationFinished;
179 Tizen.Log.Debug("NUI", "AnimationFinished added!");
181 pointLabel.TextColorAnimatable = Color.Blue;
182 pixelLabel.TextColorAnimatable = Color.Blue;
184 Tizen.Log.Debug("NUI", $"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
186 else if (e.Key.KeyPressedName == "Down")
190 _animation.Finished -= AnimationFinished;
192 Tizen.Log.Debug("NUI", "AnimationFinished removed!");
194 pointLabel.TextColorAnimatable = Color.Red;
195 pixelLabel.TextColorAnimatable = Color.Red;
197 Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
198 Tizen.Log.Debug("NUI", $"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
200 else if (e.Key.KeyPressedName == "Return")
203 Tizen.Log.Debug("NUI", "_animation play here!");
208 public void OnWindowTouched(object sender, Window.TouchEventArgs e)
210 if (e.Touch.GetState(0) == PointStateType.Down)
216 private TextLabel myTextLabel;
217 private TextLabel myTextLabel2;
218 private TextEditor myTextEditor;
219 private TextEditor myTextEditor2;
220 public void TextLabelLineWrapModeTest()
222 Tizen.Log.Debug("NUI", "WrapModeTest START!");
223 myTextLabel = new TextLabel();
224 myTextLabel.Position2D = new Position2D(10, 600);
225 myTextLabel.Size2D = new Size2D(400, 90);
226 myTextLabel.BackgroundColor = Color.Blue;
227 myTextLabel.PointSize = 20;
228 myTextLabel.TextColor = Color.White;
229 myTextLabel.MultiLine = true;
230 myTextLabel.LineWrapMode = LineWrapMode.Character;
231 myTextLabel.Text = $"[TextLabel LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
232 Window.Instance.GetDefaultLayer().Add(myTextLabel);
234 myTextLabel2 = new TextLabel();
235 myTextLabel2.Position2D = new Position2D(450, 600);
236 myTextLabel2.Size2D = new Size2D(400, 90);
237 myTextLabel2.BackgroundColor = Color.Blue;
238 myTextLabel2.PointSize = 20;
239 myTextLabel2.TextColor = Color.White;
240 myTextLabel2.MultiLine = true;
241 myTextLabel2.LineWrapMode = LineWrapMode.Word;
242 myTextLabel2.Text = $"[TextLabel LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
243 Window.Instance.GetDefaultLayer().Add(myTextLabel2);
245 Tizen.Log.Debug("NUI", $"TextLabel LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
247 myTextEditor = new TextEditor();
248 myTextEditor.Position2D = new Position2D(10, 700);
249 myTextEditor.Size2D = new Size2D(400, 90);
250 myTextEditor.BackgroundColor = Color.Red;
251 myTextEditor.PointSize = 20;
252 myTextEditor.TextColor = Color.White;
253 //myTextEditor.MultiLine = true;
254 myTextEditor.LineWrapMode = LineWrapMode.Character;
255 myTextEditor.Text = $"[TextEditor LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
256 Window.Instance.GetDefaultLayer().Add(myTextEditor);
258 myTextEditor2 = new TextEditor();
259 myTextEditor2.Position2D = new Position2D(450, 700);
260 myTextEditor2.Size2D = new Size2D(400, 90);
261 myTextEditor2.BackgroundColor = Color.Red;
262 myTextEditor2.PointSize = 20;
263 myTextEditor2.TextColor = Color.White;
264 //myTextEditor2.MultiLine = true;
265 myTextEditor2.LineWrapMode = LineWrapMode.Word;
266 myTextEditor2.Text = $"[TextEditor LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
267 Window.Instance.GetDefaultLayer().Add(myTextEditor2);
269 Tizen.Log.Debug("NUI", $"TextEditor LineWrapMode 1st={ myTextEditor?.LineWrapMode} 2nd={ myTextEditor2?.LineWrapMode}");
273 static void _Main(string[] args)
275 Example example = new Example();