2 * Copyright(c) 2021 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.
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Components;
20 namespace NUITizenGallery
22 public partial class EditorTest2Page : ContentPage
24 public Size2D viewFullSize;
26 public EditorTest2Page()
28 InitializeComponent();
29 viewFullSize = new Size2D(0, 0);
31 // Text set to TextEditor
32 editor.Text = "Event result";
33 editor.Margin = new Extents(20, 20, 20, 0);
35 // Text set to TextEditor
36 editor2.Text = "Input";
37 editor2.Margin = new Extents(20, 20, 20, 0);
40 editor2.TextChanged += OnTextEditorTextChanged;
42 underline.Margin = new Extents(20, 20, 5, 20);
43 underline2.Margin = new Extents(20, 20, 0, 10);
45 // Set focus highlight to underline
46 editor.FocusGained += (s, e) =>
48 underline.BackgroundColor = Color.Cyan;
51 editor.FocusLost += (s, e) =>
53 underline.BackgroundColor = Color.Gray;
56 editor2.FocusGained += (s, e) =>
58 underline2.BackgroundColor = Color.Cyan;
61 editor2.FocusLost += (s, e) =>
63 underline2.BackgroundColor = Color.Gray;
64 editor.Text = "Editing completed";
67 // View size adjustment from ime state
68 InputMethodContext imeEditor = editor.GetInputMethodContext();
69 imeEditor.StatusChanged += OnImeStatusChanged;
70 InputMethodContext imeEditor2 = editor2.GetInputMethodContext();
71 imeEditor2.StatusChanged += OnImeStatusChanged;
74 private void OnTextEditorTextChanged(object sender, TextEditor.TextChangedEventArgs e)
76 editor.Text = editor2.Text;
77 editor.VerticalScrollPosition = 9999;
80 private void OnImeStatusChanged(object sender, InputMethodContext.StatusChangedEventArgs e)
84 // When the virtual keyboard (IME) is shown, StatusChanged is true
85 var resizedIME = sender as InputMethodContext;
86 Rectangle rectangle = resizedIME.GetInputMethodArea();
88 if (rectangle.Height > viewFullSize.Height)
90 viewFullSize = (Size2D)mainView.Size2D.Clone();
93 int width = viewFullSize.Width;
94 int height = viewFullSize.Height - rectangle.Height;
95 mainView.Size2D = new Size2D(width, height);
99 mainView.Size2D = viewFullSize;
102 // Set bounding box for text decoration
103 // This prevents the cursor handle from leaving the valid area.
104 editor.DecorationBoundingBox = new Rectangle(mainView.Position2D.X, mainView.Position2D.Y, mainView.Size2D.Width, mainView.Size2D.Height);
105 editor2.DecorationBoundingBox = new Rectangle(mainView.Position2D.X, mainView.Position2D.Y, mainView.Size2D.Width, mainView.Size2D.Height);