forked from dalihub/nui-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-text.cs
352 lines (305 loc) · 14.4 KB
/
simple-text.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
* Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Threading.Tasks;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
namespace HelloWorldTest
{
class Example : NUIApplication
{
private Animation _animation;
private TextLabel _text;
private int cnt;
private View _view;
TextField textFieldPlaceholderTest;
TextLabel keySubclassTest;
protected override void OnCreate()
{
base.OnCreate();
Initialize();
}
TextLabel pixelLabel;
TextLabel pointLabel;
public void Initialize()
{
Window window = Window.Instance;
window.BackgroundColor = Color.White;
window.TouchEvent += OnWindowTouched;
window.KeyEvent += OnWindowKeyEvent;
window.Resized += (obj, e) =>
{
Tizen.Log.Fatal("NUI", "Height: " + e.WindowSize.Height);
Tizen.Log.Fatal("NUI", "Width: " + e.WindowSize.Width);
};
pixelLabel = new TextLabel("NUI Ubuntu Test! Click with mouse!");
pixelLabel.Position2D = new Position2D(10, 10);
pixelLabel.BackgroundColor = Color.Yellow;
pixelLabel.PointSize = 20;
pixelLabel.TextColor = Color.Blue;
window.Add(pixelLabel);
pointLabel = new TextLabel("Test Point Size 32.0f");
pointLabel.Position2D = new Position2D(10, 70);
pointLabel.PointSize = 32.0f;
window.Add(pointLabel);
/*
Timer timer = new Timer(1000);
Task.Factory.StartNew(() =>
{
try
{
Timer timer_in_another_thread = new Timer(1000);
TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
ellipsis.Size2D = new Size2D(100, 100);
ellipsis.Position2D = new Position2D(10, 250);
ellipsis.PointSize = 20.0f;
ellipsis.Ellipsis = true;
window.Add(ellipsis);
}
catch (Exception e)
{
Tizen.Log.Fatal("NUI", $"exception caught! e={e}");
}
}).Wait();
*/
TextField textFieldEllipsisTest = new TextField();
textFieldEllipsisTest.Text = "TextField Ellipsis Test, ABCDEFGHIJKLMNOPQRSTUVWXYZ";
textFieldEllipsisTest.Size2D = new Size2D(200, 100);
textFieldEllipsisTest.Position2D = new Position2D(10, 150);
textFieldEllipsisTest.PointSize = 30.0f;
textFieldEllipsisTest.Ellipsis = false;
window.Add(textFieldEllipsisTest);
TextField textFieldEllipsisTest2 = new TextField();
textFieldEllipsisTest2.Text = "TextField Ellipsis Test, ABCDEFGHIJKLMNOPQRSTUVWXYZ";
textFieldEllipsisTest2.Size2D = new Size2D(200, 100);
textFieldEllipsisTest2.Position2D = new Position2D(300, 150);
textFieldEllipsisTest2.PointSize = 30.0f;
textFieldEllipsisTest2.Ellipsis = true;
window.Add(textFieldEllipsisTest2);
textFieldPlaceholderTest = new TextField();
PropertyMap propertyMap = new PropertyMap();
propertyMap.Add("placeholderText", new PropertyValue("TextField Placeholder Test"));
propertyMap.Add("placeholderTextFocused", new PropertyValue("Placeholder Text Focused"));
propertyMap.Add("placeholderColor", new PropertyValue(Color.Blue));
propertyMap.Add("placeholderPointSize", new PropertyValue(20.0f));
PropertyMap fontStyleMap = new PropertyMap();
fontStyleMap.Add("weight", new PropertyValue("bold"));
fontStyleMap.Add("width", new PropertyValue("condensed"));
fontStyleMap.Add("slant", new PropertyValue("italic"));
propertyMap.Add("placeholderFontStyle", new PropertyValue(fontStyleMap));
textFieldPlaceholderTest.Size2D = new Size2D(300, 50);
textFieldPlaceholderTest.Position2D = new Position2D(10, 230);
textFieldPlaceholderTest.BackgroundColor = Color.Magenta;
textFieldPlaceholderTest.Placeholder = propertyMap;
textFieldPlaceholderTest.Focusable = true;
window.Add(textFieldPlaceholderTest);
keySubclassTest = new TextLabel();
keySubclassTest.Text = "Key Subclass Test!";
keySubclassTest.Size2D = new Size2D(900, 50);
keySubclassTest.Position2D = new Position2D(10, 300);
keySubclassTest.BackgroundColor = Color.Cyan;
keySubclassTest.PointSize = 20;
keySubclassTest.Focusable = true;
window.Add(keySubclassTest);
TextLabel autoScrollStopMode = new TextLabel("AutoScrollStopMode is finish-loop. PointSize=30");
autoScrollStopMode.Size2D = new Size2D(400, 100);
autoScrollStopMode.Position2D = new Position2D(10, 400);
autoScrollStopMode.PointSize = 30.0f;
autoScrollStopMode.AutoScrollStopMode = AutoScrollStopMode.Immediate;
autoScrollStopMode.AutoScrollLoopDelay = 3.0f;
autoScrollStopMode.EnableAutoScroll = true;
autoScrollStopMode.AutoScrollLoopCount = 0;
window.Add(autoScrollStopMode);
_text = new TextLabel("Hello NUI World");
_text.Position2D = new Position2D(10, 500);
_text.HorizontalAlignment = HorizontalAlignment.Center;
_text.PointSize = 20.0f;
_text.TextColor = Color.Magenta;
window.Add(_text);
_view = new View();
_view.Size2D = new Size2D(100, 100);
_view.SizeWidth = 50;
Tizen.Log.Fatal("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
_animation = new Animation
{
Duration = 2000
};
_animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
_animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
_animation.AnimateBy(_text, "ScaleX", 3, 1000, 1500);
_animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
_animation.EndAction = Animation.EndActions.Discard;
_animation.Finished += AnimationFinished;
_view.SizeWidth = 50;
Tizen.Log.Fatal("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
TextLabelLineWrapModeTest();
ViewLayoutDirectionTest();
textFieldPlaceholderTest.DownFocusableView = keySubclassTest;
keySubclassTest.UpFocusableView = textFieldPlaceholderTest;
FocusManager.Instance.SetCurrentFocusView(keySubclassTest);
}
private View view1, view11, view12, view111, view121;
public void ViewLayoutDirectionTest()
{
view1 = new View();
view1.Name = "view 1";
view1.LayoutDirection = ViewLayoutDirectionType.RTL;
Window.Instance.GetDefaultLayer().Add(view1);
view1.LayoutDirectionChanged += View1_LayoutDirectionChanged;
view11 = new View();
view11.Name = "view 11";
view11.InheritLayoutDirection = true;
view1.Add(view11);
view12 = new View();
view12.Name = "view 12";
view12.LayoutDirection = ViewLayoutDirectionType.LTR;
view1.Add(view12);
view111 = new View();
view111.Name = "view 111";
view111.InheritLayoutDirection = true;
view11.Add(view111);
view121 = new View();
view121.Name = "view 121";
view121.InheritLayoutDirection = true;
view12.Add(view121);
}
private void View1_LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
{
Tizen.Log.Error("NUI", "View1_LayoutDirectionChanged()! e.Type=" + e.Type);
}
public void AnimationFinished(object sender, EventArgs e)
{
Tizen.Log.Fatal("NUI", "AnimationFinished()! cnt=" + (cnt));
if (_animation)
{
Tizen.Log.Fatal("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
}
_view.SizeWidth = 50;
Tizen.Log.Fatal("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
}
int win_test;
public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
{
Tizen.Log.Fatal("NUI", "e.Key.KeyPressedName=" + e.Key.KeyPressedName);
if (e.Key.State == Key.StateType.Down)
{
keySubclassTest.Text = $"DeviceSubClass={e.Key.DeviceSubClass}, DeviceClass={e.Key.DeviceClass}, DeviceName={e.Key.DeviceName}, KeyCode={e.Key.KeyCode}";
switch( e.Key.KeyPressedName )
{
case "Up":
{
if (_animation)
{
_animation.Finished += AnimationFinished;
cnt++;
Tizen.Log.Fatal("NUI", "AnimationFinished added!");
}
Tizen.Log.Fatal("NUI", $"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
}
break;
case "Down":
{
if (_animation)
{
_animation.Finished -= AnimationFinished;
cnt--;
Tizen.Log.Fatal("NUI", "AnimationFinished removed!");
}
Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
Tizen.Log.Fatal("NUI", $"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
}
break;
case "Return":
{
_animation.Play();
Tizen.Log.Fatal("NUI", "_animation play here!");
}
break;
case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}
public void OnWindowTouched(object sender, Window.TouchEventArgs e)
{
if (e.Touch.GetState(0) == PointStateType.Down)
{
_animation.Play();
}
}
private TextLabel myTextLabel;
private TextLabel myTextLabel2;
private TextEditor myTextEditor;
private TextEditor myTextEditor2;
public void TextLabelLineWrapModeTest()
{
Tizen.Log.Fatal("NUI", "WrapModeTest START!");
myTextLabel = new TextLabel();
myTextLabel.Position2D = new Position2D(10, 600);
myTextLabel.Size2D = new Size2D(400, 90);
myTextLabel.BackgroundColor = Color.Blue;
myTextLabel.PointSize = 20;
myTextLabel.TextColor = Color.White;
myTextLabel.MultiLine = true;
myTextLabel.LineWrapMode = LineWrapMode.Character;
myTextLabel.Text = $"[TextLabel LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
Window.Instance.GetDefaultLayer().Add(myTextLabel);
myTextLabel2 = new TextLabel();
myTextLabel2.Position2D = new Position2D(450, 600);
myTextLabel2.Size2D = new Size2D(400, 90);
myTextLabel2.BackgroundColor = Color.Blue;
myTextLabel2.PointSize = 20;
myTextLabel2.TextColor = Color.White;
myTextLabel2.MultiLine = true;
myTextLabel2.LineWrapMode = LineWrapMode.Word;
myTextLabel2.Text = $"[TextLabel LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
Window.Instance.GetDefaultLayer().Add(myTextLabel2);
Tizen.Log.Fatal("NUI", $"TextLabel LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
myTextEditor = new TextEditor();
myTextEditor.Position2D = new Position2D(10, 700);
myTextEditor.Size2D = new Size2D(400, 90);
myTextEditor.BackgroundColor = Color.Red;
myTextEditor.PointSize = 20;
myTextEditor.TextColor = Color.White;
//myTextEditor.MultiLine = true;
myTextEditor.LineWrapMode = LineWrapMode.Character;
myTextEditor.Text = $"[TextEditor LineWrapMode.Character] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
Window.Instance.GetDefaultLayer().Add(myTextEditor);
myTextEditor2 = new TextEditor();
myTextEditor2.Position2D = new Position2D(450, 700);
myTextEditor2.Size2D = new Size2D(400, 90);
myTextEditor2.BackgroundColor = Color.Red;
myTextEditor2.PointSize = 20;
myTextEditor2.TextColor = Color.White;
//myTextEditor2.MultiLine = true;
myTextEditor2.LineWrapMode = LineWrapMode.Word;
myTextEditor2.Text = $"[TextEditor LineWrapMode.Word] hello ABCDEFGHI is my name, it is very very long beautiful hansome awesome name.";
Window.Instance.GetDefaultLayer().Add(myTextEditor2);
Tizen.Log.Fatal("NUI", $"TextEditor LineWrapMode 1st={ myTextEditor?.LineWrapMode} 2nd={ myTextEditor2?.LineWrapMode}");
}
[STAThread]
static void Main(string[] args)
{
Example example = new Example();
example.Run(args);
}
}
}