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;
23 // A spin control (for continously changing values when users can easily predict a set of values)
28 ///Spin CustomView class
30 public class Spin : CustomView
32 private VisualBase _arrowVisual;
33 private TextField _textField;
34 private int _arrowVisualPropertyIndex;
35 private string _arrowImage;
36 private int _currentValue;
37 private int _minValue;
38 private int _maxValue;
39 private int _singleStep;
40 private bool _wrappingEnabled;
41 private string _fontFamily;
42 private string _fontStyle;
43 private int _pointSize;
44 private Color _textColor;
45 private Color _textBackgroundColor;
46 private int _maxTextLength;
48 // Called by DALi Builder if it finds a Spin control in a JSON file
49 static CustomView CreateInstance()
54 // static constructor registers the control type (only runs once)
57 // ViewRegistry registers control type with DALi type registery
58 // also uses introspection to find any properties that need to be registered with type registry
59 ViewRegistry.Instance.Register(CreateInstance, typeof(Spin));
62 public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
68 /// Override method of OnInitialize() for CustomView class.
69 /// This method is called after the Control has been initialized.
70 /// Derived classes should do any second phase initialization by overriding this method.
72 public override void OnInitialize()
74 // Initialize the propertiesControl
75 _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png";
76 _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
83 // Create image visual for the arrow keys
84 _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite);
85 _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
86 RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);
88 // Create a text field
89 _textField = new TextField();
90 _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
91 _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center;
92 _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
93 _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
94 _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f);
95 _textField.PlaceholderText = "----";
96 _textField.BackgroundColor = _textBackgroundColor;
97 _textField.HorizontalAlignment = "Center";
98 _textField.VerticalAlignment = "Center";
99 _textField.Focusable = (true);
100 _textField.Name = "_textField";
102 this.Add(_textField);
104 _textField.FocusGained += TextFieldKeyInputFocusGained;
105 _textField.FocusLost += TextFieldKeyInputFocusLost;
109 /// Override method of GetNaturalSize() for CustomView class.
110 /// Return the natural size of the actor.
112 /// <returns> Natural size of this Spin itself</returns>
113 public override Size GetNaturalSize()
115 return new Size(150.0f, 150.0f, 0.0f);
119 /// Event handler when the TextField in Spin gets the Key focus
120 /// Make sure when the current spin that takes input focus also takes the keyboard focus
121 /// For example, when you tap the spin directly
123 /// <param name="source">Sender of this event</param>
124 /// <param name="e">Event arguments</param>
125 public void TextFieldKeyInputFocusGained(object source, EventArgs e)
127 FocusManager.Instance.SetCurrentFocusView(_textField);
131 /// Event handler when the TextField in Spin looses it's Key focus
133 /// <param name="source"></param>
134 /// <param name="e"></param>
135 public void TextFieldKeyInputFocusLost(object source, EventArgs e)
137 int previousValue = _currentValue;
139 // If the input value is invalid, change it back to the previous valid value
140 if (int.TryParse(_textField.Text, out _currentValue))
142 if (_currentValue < _minValue || _currentValue > _maxValue)
144 _currentValue = previousValue;
149 _currentValue = previousValue;
152 // Otherwise take the new value
153 this.Value = _currentValue;
157 /// Override method of GetNextKeyboardFocusableView() for CustomView class.
158 /// Gets the next key focusable view in this View towards the given direction.
159 /// A View needs to override this function in order to support two dimensional key navigation.
161 /// <param name="currentFocusedView">The current focused view</param>
162 /// <param name="direction">The direction to move the focus towards</param>
163 /// <param name="loopEnabled">Whether the focus movement should be looped within the control</param>
164 /// <returns>The next keyboard focusable view in this control or an empty handle if no view can be focused</returns>
165 public override View GetNextKeyboardFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
167 // Respond to Up/Down keys to change the value while keeping the current spin focused
168 View nextFocusedView = currentFocusedView;
169 if (direction == View.FocusDirection.Up)
171 this.Value += this.Step;
172 nextFocusedView = _textField;
174 else if (direction == View.FocusDirection.Down)
176 this.Value -= this.Step;
177 nextFocusedView = _textField;
181 // Return a native empty handle as nothing can be focused in the left or right
182 nextFocusedView = new View();
183 nextFocusedView.Reset();
186 return nextFocusedView;
190 /// Value to be set in Spin
192 [ScriptableProperty()]
197 return _currentValue;
202 Console.WriteLine("Value set to " + value);
203 _currentValue = value;
205 // Make sure no invalid value is accepted
206 if (_currentValue < _minValue)
208 _currentValue = _minValue;
211 if (_currentValue > _maxValue)
213 _currentValue = _maxValue;
216 _textField.Text = _currentValue.ToString();
221 /// Minimum Value of Spin Value
223 // MinValue property of type int:
224 [ScriptableProperty()]
238 /// Maximum Value of Spin Value
240 // MaxValue property of type int:
241 [ScriptableProperty()]
255 /// Increasing, decresing step of Spin Value when Up or Down key is pressed
257 // Step property of type int:
258 [ScriptableProperty()]
272 /// Wrapping enabled status
274 // WrappingEnabled property of type bool:
275 [ScriptableProperty()]
276 public bool WrappingEnabled
280 return _wrappingEnabled;
284 _wrappingEnabled = value;
289 /// Text point size of Spin Value
291 // TextPointSize property of type int:
292 [ScriptableProperty()]
293 public int TextPointSize
302 _textField.PointSize = _pointSize;
307 /// The color of Spin Value
309 // TextColor property of type Color:
310 [ScriptableProperty()]
311 public Color TextColor
319 Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B);
322 _textField.TextColor = _textColor;
327 /// Maximum text lengh of Spin Value
329 // MaxTextLength property of type int:
330 [ScriptableProperty()]
331 public int MaxTextLength
335 return _maxTextLength;
339 _maxTextLength = value;
340 _textField.MaxLength = _maxTextLength;
345 /// Reference of TextField of Spin
347 public TextField SpinText
360 /// Show indicator image, for example Up/Down Arrow image.
362 // Indicator property of type string:
363 public string IndicatorImage
372 _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150));
373 RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual);