[Tizen] Update Placeholder property of TextField/TextEditor and its sample
[platform/core/csapi/tizenfx.git] / NUISamples / NUISamples / NUISamples.TizenTV / 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.ShowDuration, 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             window.Add(field);
125
126             InputMethod inputMethod = new InputMethod();
127             inputMethod.PanelLayout = InputMethod.PanelLayoutType.Number;
128             inputMethod.ActionButton = InputMethod.ActionButtonTitleType.Go;
129             inputMethod.AutoCapital = InputMethod.AutoCapitalType.Word;
130             inputMethod.Variation = 1;
131
132             field.InputMethodSettings = inputMethod.OutputMap;
133
134             PropertyMap propertyMap = new PropertyMap();
135             propertyMap.Add("placeholderText", new PropertyValue("Placeholder Text"));
136             propertyMap.Add("placeholderTextFocused", new PropertyValue("Placeholder Text Focused"));
137             propertyMap.Add("placeholderColor", new PropertyValue(Color.Red));
138             propertyMap.Add("placeholderPointSize", new PropertyValue(15.0f));
139
140             PropertyMap fontStyleMap = new PropertyMap();
141             fontStyleMap.Add("weight", new PropertyValue("bold"));
142             fontStyleMap.Add("width", new PropertyValue("condensed"));
143             fontStyleMap.Add("slant", new PropertyValue("italic"));
144             propertyMap.Add("placeholderFontStyle", new PropertyValue(fontStyleMap));
145
146             TextEditor editor = new TextEditor();
147             editor.Size2D = new Size2D(400, 100);
148             editor.Position2D = new Position2D(10, 550);
149             editor.BackgroundColor = Color.Magenta;
150             editor.EnableScrollBar = true;
151             editor.EnableSelection = true;
152             editor.Focusable = true;
153             editor.Placeholder = propertyMap;
154             window.Add(editor);
155             editor.TextChanged += (obj, e) => {
156                 Tizen.Log.Debug("NUI", "editor line count: " + e.TextEditor.LineCount);
157             };
158
159             editor.ScrollStateChanged += (obj, e)=> {
160                 Tizen.Log.Debug("NUI", "editor scroll state:" + e.ScrollState);
161             };
162
163             Tizen.Log.Debug("NUI",  "editor id: " + editor.ID);
164
165             FocusManager.Instance.SetCurrentFocusView(editor);
166             editor.UpFocusableView = field;
167             field.DownFocusableView = editor;
168         }
169
170         [STAThread]
171         static void _Main(string[] args)
172         {
173             Example example = new Example();
174             example.Run(args);
175         }
176     }
177 }