1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 // Some have been manually changed
20 using System.Runtime.InteropServices;
22 using Tizen.NUI.UIComponents;
24 // A spin control (for continously changing values when users can easily predict a set of values)
29 ///Spin CustomView class
31 public class Spin : CustomView
33 private VisualBase _arrowVisual;
34 private TextField _textField;
35 private int _arrowVisualPropertyIndex;
36 private string _arrowImage;
37 private int _currentValue;
38 private int _minValue;
39 private int _maxValue;
40 private int _singleStep;
41 private bool _wrappingEnabled;
42 private string _fontFamily;
43 private string _fontStyle;
44 private int _pointSize;
45 private Color _textColor;
46 private Color _textBackgroundColor;
47 private int _maxTextLength;
49 // Called by DALi Builder if it finds a Spin control in a JSON file
50 static CustomView CreateInstance()
55 // static constructor registers the control type (only runs once)
58 // ViewRegistry registers control type with DALi type registery
59 // also uses introspection to find any properties that need to be registered with type registry
60 ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
64 /// Creates an initialized Spin.
66 public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
71 /// Override method of OnInitialize() for CustomView class.<br>
72 /// This method is called after the Control has been initialized.<br>
73 /// Derived classes should do any second phase initialization by overriding this method.<br>
75 public override void OnInitialize()
77 // Initialize the propertiesControl
78 _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";
79 _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
86 // Create image visual for the arrow keys
87 _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);
88 _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
89 RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
91 // Create a text field
92 _textField = new TextField();
93 _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;
94 _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
95 _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
96 _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);
97 _textField.PlaceholderText = "----";
98 _textField.BackgroundColor = _textBackgroundColor;
99 _textField.HorizontalAlignment = HorizontalAlignment.HorizontalAlignCenter;
100 _textField.VerticalAlignment = VerticalAlignment.VerticalAlignCenter;
101 _textField.Focusable = (true);
102 _textField.Name = "_textField";
103 _textField.Position2D = new Position2D(0, 40);
105 this.Add(_textField);
107 _textField.FocusGained += TextFieldKeyInputFocusGained;
108 _textField.FocusLost += TextFieldKeyInputFocusLost;
112 /// Override method of GetNaturalSize() for CustomView class.<br>
113 /// Return the natural size of the actor.<br>
115 /// <returns> Natural size of this Spin itself</returns>
116 public override Size GetNaturalSize()
118 return new Size(150.0f, 150.0f, 0.0f);
122 /// Event handler when the TextField in Spin gets the Key focus.<br>
123 /// Make sure when the current spin that takes input focus also takes the keyboard focus.<br>
124 /// For example, when you tap the spin directly.<br>
126 /// <param name="source">Sender of this event</param>
127 /// <param name="e">Event arguments</param>
128 public void TextFieldKeyInputFocusGained(object source, EventArgs e)
130 FocusManager.Instance.SetCurrentFocusView(_textField);
134 /// Event handler when the TextField in Spin looses it's Key focus
136 /// <param name="source"></param>
137 /// <param name="e"></param>
138 public void TextFieldKeyInputFocusLost(object source, EventArgs e)
140 int previousValue = _currentValue;
142 // If the input value is invalid, change it back to the previous valid value
143 if (int.TryParse(_textField.Text, out _currentValue))
145 if (_currentValue < _minValue || _currentValue > _maxValue)
147 _currentValue = previousValue;
152 _currentValue = previousValue;
155 // Otherwise take the new value
156 this.Value = _currentValue;
160 /// Override method of GetNextKeyboardFocusableView() for CustomView class.<br>
161 /// Gets the next key focusable view in this View towards the given direction.<br>
162 /// A View needs to override this function in order to support two dimensional key navigation.<br>
164 /// <param name="currentFocusedView">The current focused view</param>
165 /// <param name="direction">The direction to move the focus towards</param>
166 /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>
167 /// <returns>The next keyboard focusable view in this control or an empty handle if no view can be focused</returns>
168 public override View GetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
170 // Respond to Up/Down keys to change the value while keeping the current spin focused
171 View nextFocusedView = currentFocusedView;
172 if (direction == View.FocusDirection.Up)
174 this.Value += this.Step;
175 nextFocusedView = _textField;
177 else if (direction == View.FocusDirection.Down)
179 this.Value -= this.Step;
180 nextFocusedView = _textField;
184 // Return a native empty handle as nothing can be focused in the left or right
185 nextFocusedView = new View();
186 nextFocusedView.Reset();
189 return nextFocusedView;
193 /// Value to be set in Spin.
195 [ScriptableProperty()]
200 return _currentValue;
205 Tizen.Log.Debug("NUI", "Value set to " + value);
206 _currentValue = value;
208 // Make sure no invalid value is accepted
209 if (_currentValue < _minValue)
211 _currentValue = _minValue;
214 if (_currentValue > _maxValue)
216 _currentValue = _maxValue;
219 _textField.Text = _currentValue.ToString();
224 /// Minimum Value of Spin Value.
226 // MinValue property of type int:
227 [ScriptableProperty()]
241 /// Maximum Value of Spin Value.
243 // MaxValue property of type int:
244 [ScriptableProperty()]
258 /// Increasing, decresing step of Spin Value when Up or Down key is pressed.
260 // Step property of type int:
261 [ScriptableProperty()]
275 /// Wrapping enabled status.
277 // WrappingEnabled property of type bool:
278 [ScriptableProperty()]
279 public bool WrappingEnabled
283 return _wrappingEnabled;
287 _wrappingEnabled = value;
292 /// Text point size of Spin Value.
294 // TextPointSize property of type int:
295 [ScriptableProperty()]
296 public int TextPointSize
305 _textField.PointSize = _pointSize;
310 /// The color of Spin Value.
312 // TextColor property of type Color:
313 [ScriptableProperty()]
314 public Color TextColor
322 Tizen.Log.Debug("NUI", "TextColor set to " + value.R + "," + value.G + "," + value.B);
325 _textField.TextColor = _textColor;
330 /// Maximum text lengh of Spin Value.
332 // MaxTextLength property of type int:
333 [ScriptableProperty()]
334 public int MaxTextLength
338 return _maxTextLength;
342 _maxTextLength = value;
343 _textField.MaxLength = _maxTextLength;
348 /// Reference of TextField of Spin.
350 public TextField SpinText
363 /// Show indicator image, for example Up/Down Arrow image.
365 // Indicator property of type string:
366 public string IndicatorImage
375 _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
376 RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);