[NUI] Add MaxLength property and signal to TextEditor (#1901)
[platform/core/csapi/tizenfx.git] / test / NUITestSample / NUITestSample / examples / text-test.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.Runtime.InteropServices;
20 using Tizen.NUI;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
24
25 namespace TextTest
26 {
27     class Example : NUIApplication
28     {
29         TextLabel _pointLabel;
30         Boolean _colorToggle;
31
32         public Example() : base()
33         {
34         }
35
36         public Example(string stylesheet) : base(stylesheet)
37         {
38         }
39
40         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
41         {
42         }
43
44         protected override void OnCreate()
45         {
46             base.OnCreate();
47             Initialize();
48         }
49
50         private bool LabelTouched(object sender, View.TouchEventArgs e)
51         {
52             if (e.Touch.GetState(0) == PointStateType.Down)
53             {
54                 Animation textColorAnimation = new Animation(1000);
55                 if (_colorToggle)
56                 {
57                     textColorAnimation.AnimateTo(_pointLabel, "TextColorAnimatable", Color.Blue );
58                     _colorToggle = false;
59                 }
60                 else
61                 {
62                      textColorAnimation.AnimateTo(_pointLabel, "TextColorAnimatable", Color.Green );
63                     _colorToggle = true;
64                 }
65                 textColorAnimation.Play();
66             }
67             return true;
68         }
69
70
71         public void Initialize()
72         {
73             Window window = Window.Instance;
74             window.BackgroundColor = Color.White;
75
76             TextLabel pixelLabel = new TextLabel("Test Pixel Size 32.0f");
77             pixelLabel.Position2D = new Position2D(10, 10);
78             pixelLabel.PixelSize = 32.0f;
79             pixelLabel.BackgroundColor = Color.Magenta;
80             window.Add(pixelLabel);
81
82             _pointLabel = new TextLabel("Test Point Size 32.0f");
83             _pointLabel.Position2D = new Position2D(10, 100);
84             _pointLabel.PointSize = 32.0f;
85             _pointLabel.BackgroundColor = Color.Red;
86             //_pointLabel.TextColorAnimatable = Color.Green; // Set initial text color using animatable property
87             _pointLabel.TouchEvent += LabelTouched;
88             _colorToggle = true;
89
90             window.Add(_pointLabel);
91
92
93             TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
94             ellipsis.Size2D = new Size2D(100, 80);
95             ellipsis.Position2D = new Position2D(10, 200);
96             ellipsis.PointSize = 20.0f;
97             ellipsis.Ellipsis = true;
98             ellipsis.BackgroundColor = Color.Cyan;
99             window.Add(ellipsis);
100
101             TextLabel autoScrollStopMode = new TextLabel("AutoScrollStopMode is finish-loop.");
102             autoScrollStopMode.Size2D = new Size2D(400, 50);
103             autoScrollStopMode.Position2D = new Position2D(10, 300);
104             autoScrollStopMode.PointSize = 15.0f;
105             autoScrollStopMode.BackgroundColor = Color.Green;
106             autoScrollStopMode.AutoScrollStopMode = AutoScrollStopMode.FinishLoop;
107             autoScrollStopMode.EnableAutoScroll = true;
108             window.Add(autoScrollStopMode);
109
110             TextField field = new TextField();
111             field.Size2D = new Size2D(400, 100);
112             field.Position2D = new Position2D(10, 400);
113             field.BackgroundColor = Color.Cyan;
114             field.PlaceholderText = "input someth...";
115             field.PlaceholderTextFocused = "input someth... focused";
116             field.Focusable = true;
117             PropertyMap hiddenMap = new PropertyMap();
118             hiddenMap.Add(HiddenInputProperty.Mode, new PropertyValue((int)HiddenInputModeType.ShowLastCharacter));
119             hiddenMap.Add(HiddenInputProperty.ShowLastCharacterDuration, new PropertyValue(2));
120             hiddenMap.Add(HiddenInputProperty.SubstituteCount, new PropertyValue(4));
121             hiddenMap.Add(HiddenInputProperty.SubstituteCharacter, new PropertyValue(0x23));
122             field.HiddenInputSettings = hiddenMap;
123             field.EnableSelection = true;
124             field.EnableShiftSelection = false;
125             window.Add(field);
126
127             InputMethod inputMethod = new InputMethod();
128             inputMethod.PanelLayout = InputMethod.PanelLayoutType.Number;
129             inputMethod.ActionButton = InputMethod.ActionButtonTitleType.Go;
130             inputMethod.AutoCapital = InputMethod.AutoCapitalType.Word;
131             inputMethod.Variation = 1;
132
133             field.InputMethodSettings = inputMethod.OutputMap;
134
135             PropertyMap propertyMap = new PropertyMap();
136             propertyMap.Add("placeholderText", new PropertyValue("Placeholder Text"));
137             propertyMap.Add("placeholderTextFocused", new PropertyValue("Placeholder Text Focused"));
138             propertyMap.Add("placeholderColor", new PropertyValue(Color.Red));
139             propertyMap.Add("placeholderPointSize", new PropertyValue(15.0f));
140
141             PropertyMap fontStyleMap = new PropertyMap();
142             fontStyleMap.Add("weight", new PropertyValue("bold"));
143             fontStyleMap.Add("width", new PropertyValue("condensed"));
144             fontStyleMap.Add("slant", new PropertyValue("italic"));
145             propertyMap.Add("placeholderFontStyle", new PropertyValue(fontStyleMap));
146
147             TextEditor editor = new TextEditor();
148             editor.Size2D = new Size2D(400, 100);
149             editor.Position2D = new Position2D(10, 550);
150             editor.BackgroundColor = Color.Magenta;
151             editor.EnableScrollBar = true;
152             editor.EnableSelection = true;
153             editor.Focusable = true;
154             editor.Placeholder = propertyMap;
155             editor.MaxLength = 10;
156             window.Add(editor);
157             editor.TextChanged += (obj, e) => {
158                 Tizen.Log.Debug("NUI", "editor line count: " + e.TextEditor.LineCount);
159             };
160
161             editor.ScrollStateChanged += (obj, e)=> {
162                 Tizen.Log.Debug("NUI", "editor scroll state:" + e.ScrollState);
163             };
164             editor.MaxLengthReached += (obj, e)=> {
165                 Tizen.Log.Debug("NUI", "editor max length: "+ e.TextEditor.MaxLength);
166             };
167
168             Tizen.Log.Debug("NUI",  "editor id: " + editor.ID);
169
170             FocusManager.Instance.SetCurrentFocusView(editor);
171             editor.UpFocusableView = field;
172             field.DownFocusableView = editor;
173
174             NUILog.Debug($"### field.EnableShiftSelection={field.EnableShiftSelection}, editor.EnableShiftSelection={editor.EnableShiftSelection}");
175
176         }
177
178         [STAThread]
179         static void _Main(string[] args)
180         {
181             Example example = new Example();
182             example.Run(args);
183         }
184     }
185 }