From d3f4f6182ea24a1ddaa0a6aa4e5d37d1a748638c Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Sat, 18 Mar 2017 18:38:46 +0900 Subject: [PATCH] In CustomView handling Actor, changed as View Signed-off-by: dongsug.song Change-Id: I7293c28fce8d1b0dbc827b455b16585e0036c2d6 --- Tizen.NUI/src/internal/ViewWrapperImpl.cs | 12 +- Tizen.NUI/src/public/CustomView.cs | 8 +- Tizen.NUI/src/public/CustomView/Spin.cs | 720 +++++++++++++------------- Tizen.NUI/src/public/CustomView/VisualView.cs | 334 ++++++------ 4 files changed, 537 insertions(+), 537 deletions(-) diff --git a/Tizen.NUI/src/internal/ViewWrapperImpl.cs b/Tizen.NUI/src/internal/ViewWrapperImpl.cs index c1015ef..36ba438 100755 --- a/Tizen.NUI/src/internal/ViewWrapperImpl.cs +++ b/Tizen.NUI/src/internal/ViewWrapperImpl.cs @@ -51,8 +51,8 @@ namespace Tizen.NUI public delegate bool OnAccessibilityZoomDelegate(); public delegate void OnKeyInputFocusGainedDelegate(); public delegate void OnKeyInputFocusLostDelegate(); - public delegate Actor GetNextKeyboardFocusableActorDelegate(Actor currentFocusedActor, View.FocusDirection direction, bool loopEnabled); - public delegate void OnKeyboardFocusChangeCommittedDelegate(Actor commitedFocusableActor); + public delegate View GetNextKeyboardFocusableViewDelegate(View currentFocusedView, View.FocusDirection direction, bool loopEnabled); + public delegate void OnKeyboardFocusChangeCommittedDelegate(View commitedFocusableView); public delegate bool OnKeyboardEnterDelegate(); public delegate void OnPinchDelegate(PinchGesture pinch); public delegate void OnPanDelegate(PanGesture pan); @@ -90,7 +90,7 @@ namespace Tizen.NUI public OnAccessibilityZoomDelegate OnAccessibilityZoom; public OnKeyInputFocusGainedDelegate OnKeyInputFocusGained; public OnKeyInputFocusLostDelegate OnKeyInputFocusLost; - public GetNextKeyboardFocusableActorDelegate GetNextKeyboardFocusableActor; + public GetNextKeyboardFocusableViewDelegate GetNextKeyboardFocusableView; public OnKeyboardFocusChangeCommittedDelegate OnKeyboardFocusChangeCommitted; public OnKeyboardEnterDelegate OnKeyboardEnter; public OnPinchDelegate OnPinch; @@ -450,12 +450,12 @@ namespace Tizen.NUI private global::System.IntPtr DirectorGetNextKeyboardFocusableActor(global::System.IntPtr currentFocusedActor, int direction, bool loopEnabled) { - return Actor.getCPtr(GetNextKeyboardFocusableActor(new Actor(currentFocusedActor, false), (View.FocusDirection)direction, loopEnabled)).Handle; + return Actor.getCPtr(GetNextKeyboardFocusableView(new View(currentFocusedActor, false), (View.FocusDirection)direction, loopEnabled)).Handle; } - private void DirectorOnKeyboardFocusChangeCommitted(global::System.IntPtr commitedFocusableActor) + private void DirectorOnKeyboardFocusChangeCommitted(global::System.IntPtr commitedFocusableView) { - OnKeyboardFocusChangeCommitted(new Actor(commitedFocusableActor, false)); + OnKeyboardFocusChangeCommitted(new View(commitedFocusableView, false)); } private bool DirectorOnKeyboardEnter() diff --git a/Tizen.NUI/src/public/CustomView.cs b/Tizen.NUI/src/public/CustomView.cs index 3a85b1f..1968288 100755 --- a/Tizen.NUI/src/public/CustomView.cs +++ b/Tizen.NUI/src/public/CustomView.cs @@ -56,7 +56,7 @@ namespace Tizen.NUI viewWrapperImpl.OnAccessibilityZoom = new ViewWrapperImpl.OnAccessibilityZoomDelegate(OnAccessibilityZoom); viewWrapperImpl.OnKeyInputFocusGained = new ViewWrapperImpl.OnKeyInputFocusGainedDelegate(OnKeyInputFocusGained); viewWrapperImpl.OnKeyInputFocusLost = new ViewWrapperImpl.OnKeyInputFocusLostDelegate(OnKeyInputFocusLost); - viewWrapperImpl.GetNextKeyboardFocusableActor = new ViewWrapperImpl.GetNextKeyboardFocusableActorDelegate(GetNextKeyboardFocusableActor); + viewWrapperImpl.GetNextKeyboardFocusableView = new ViewWrapperImpl.GetNextKeyboardFocusableViewDelegate(GetNextKeyboardFocusableView); viewWrapperImpl.OnKeyboardFocusChangeCommitted = new ViewWrapperImpl.OnKeyboardFocusChangeCommittedDelegate(OnKeyboardFocusChangeCommitted); viewWrapperImpl.OnKeyboardEnter = new ViewWrapperImpl.OnKeyboardEnterDelegate(OnKeyboardEnter); viewWrapperImpl.OnPinch = new ViewWrapperImpl.OnPinchDelegate(OnPinch); @@ -745,9 +745,9 @@ namespace Tizen.NUI * @param[in] loopEnabled Whether the focus movement should be looped within the control. * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused. */ - public virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, View.FocusDirection direction, bool loopEnabled) + public virtual View GetNextKeyboardFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled) { - return new Actor(); + return new View(); } /** @@ -758,7 +758,7 @@ namespace Tizen.NUI * * @param[in] commitedFocusableActor The commited focusable actor. */ - public virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) + public virtual void OnKeyboardFocusChangeCommitted(View commitedFocusableView) { } diff --git a/Tizen.NUI/src/public/CustomView/Spin.cs b/Tizen.NUI/src/public/CustomView/Spin.cs index ae473ac..79ad32f 100755 --- a/Tizen.NUI/src/public/CustomView/Spin.cs +++ b/Tizen.NUI/src/public/CustomView/Spin.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Samsung Electronics Co., Ltd. +// Copyright (c) 2017 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,363 +15,363 @@ // // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts // Some have been manually changed - -using System; -using System.Runtime.InteropServices; -using Tizen.NUI; - -// A spin control (for continously changing values when users can easily predict a set of values) - -namespace Tizen.NUI -{ - /// - ///Spin CustomView class - /// - public class Spin : CustomView - { - private VisualBase _arrowVisual; - private TextField _textField; - private int _arrowVisualPropertyIndex; - private string _arrowImage; - private int _currentValue; - private int _minValue; - private int _maxValue; - private int _singleStep; - private bool _wrappingEnabled; - private string _fontFamily; - private string _fontStyle; - private int _pointSize; - private Color _textColor; - private Color _textBackgroundColor; - private int _maxTextLength; - - // Called by DALi Builder if it finds a Spin control in a JSON file - static CustomView CreateInstance() - { - return new Spin(); - } - - // static constructor registers the control type (only runs once) - static Spin() - { - // ViewRegistry registers control type with DALi type registery - // also uses introspection to find any properties that need to be registered with type registry - ViewRegistry.Instance.Register(CreateInstance, typeof(Spin)); - } - - public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport) - { - - } - - /// - /// Override method of OnInitialize() for CustomView class. - /// This method is called after the Control has been initialized. - /// Derived classes should do any second phase initialization by overriding this method. - /// - public override void OnInitialize() - { - // Initialize the propertiesControl - _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png"; - _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f); - _currentValue = 0; - _minValue = 0; - _maxValue = 0; - _singleStep = 1; - _maxTextLength = 0; - - // Create image visual for the arrow keys - _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite); - _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150)); - RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual); - - // Create a text field - _textField = new TextField(); - _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center; - _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center; - _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent; - _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent; - _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f); - _textField.PlaceholderText = "----"; - _textField.BackgroundColor = _textBackgroundColor; - _textField.HorizontalAlignment = "Center"; - _textField.VerticalAlignment = "Center"; - _textField.Focusable = (true); - _textField.Name = "_textField"; - - this.Add(_textField); - - _textField.FocusGained += TextFieldKeyInputFocusGained; - _textField.FocusLost += TextFieldKeyInputFocusLost; - } - - /// - /// Override method of GetNaturalSize() for CustomView class. - /// Return the natural size of the actor. - /// - /// Natural size of this Spin itself - public override Size GetNaturalSize() - { - return new Size(150.0f, 150.0f, 0.0f); - } - - /// - /// Event handler when the TextField in Spin gets the Key focus - /// Make sure when the current spin that takes input focus also takes the keyboard focus - /// For example, when you tap the spin directly - /// - /// Sender of this event - /// Event arguments - public void TextFieldKeyInputFocusGained(object source, EventArgs e) - { - FocusManager.Instance.SetCurrentFocusView(_textField); - } - - /// - /// Event handler when the TextField in Spin looses it's Key focus - /// - /// - /// - public void TextFieldKeyInputFocusLost(object source, EventArgs e) - { - int previousValue = _currentValue; - - // If the input value is invalid, change it back to the previous valid value - if (int.TryParse(_textField.Text, out _currentValue)) - { - if (_currentValue < _minValue || _currentValue > _maxValue) - { - _currentValue = previousValue; - } - } - else - { - _currentValue = previousValue; - } - - // Otherwise take the new value - this.Value = _currentValue; - } - - /// - /// Override method of GetNextKeyboardFocusableActor() for CustomView class. - /// Gets the next key focusable actor in this View towards the given direction. - /// A View needs to override this function in order to support two dimensional key navigation. - /// - /// The current focused actor - /// The direction to move the focus towards - /// Whether the focus movement should be looped within the control - /// The next keyboard focusable actor in this control or an empty handle if no actor can be focused - public override Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, View.FocusDirection direction, bool loopEnabled) - { - // Respond to Up/Down keys to change the value while keeping the current spin focused - Actor nextFocusedActor = currentFocusedActor; - if (direction == View.FocusDirection.Up) - { - this.Value += this.Step; - nextFocusedActor = _textField; - } - else if (direction == View.FocusDirection.Down) - { - this.Value -= this.Step; - nextFocusedActor = _textField; - } - else - { - // Return a native empty handle as nothing can be focused in the left or right - nextFocusedActor = new Actor(); - nextFocusedActor.Reset(); - } - - return nextFocusedActor; - } - - /// - /// Value to be set in Spin - /// - [ScriptableProperty()] - public int Value - { - get - { - return _currentValue; - } - set - { - - Console.WriteLine("Value set to " + value); - _currentValue = value; - - // Make sure no invalid value is accepted - if (_currentValue < _minValue) - { - _currentValue = _minValue; - } - - if (_currentValue > _maxValue) - { - _currentValue = _maxValue; - } - - _textField.Text = _currentValue.ToString(); - } - } - - /// - /// Minimum Value of Spin Value - /// - // MinValue property of type int: - [ScriptableProperty()] - public int MinValue - { - get - { - return _minValue; - } - set - { - _minValue = value; - } - } - - /// - /// Maximum Value of Spin Value - /// - // MaxValue property of type int: - [ScriptableProperty()] - public int MaxValue - { - get - { - return _maxValue; - } - set - { - _maxValue = value; - } - } - - /// - /// Increasing, decresing step of Spin Value when Up or Down key is pressed - /// - // Step property of type int: - [ScriptableProperty()] - public int Step - { - get - { - return _singleStep; - } - set - { - _singleStep = value; - } - } - - /// - /// Wrapping enabled status - /// - // WrappingEnabled property of type bool: - [ScriptableProperty()] - public bool WrappingEnabled - { - get - { - return _wrappingEnabled; - } - set - { - _wrappingEnabled = value; - } - } - - /// - /// Text point size of Spin Value - /// - // TextPointSize property of type int: - [ScriptableProperty()] - public int TextPointSize - { - get - { - return _pointSize; - } - set - { - _pointSize = value; - _textField.PointSize = _pointSize; - } - } - - /// - /// The color of Spin Value - /// - // TextColor property of type Color: - [ScriptableProperty()] - public Color TextColor - { - get - { - return _textColor; - } - set - { - Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B); - - _textColor = value; - _textField.TextColor = _textColor; - } - } - - /// - /// Maximum text lengh of Spin Value - /// - // MaxTextLength property of type int: - [ScriptableProperty()] - public int MaxTextLength - { - get - { - return _maxTextLength; - } - set - { - _maxTextLength = value; - _textField.MaxLength = _maxTextLength; - } - } - - /// - /// Reference of TextField of Spin - /// - public TextField SpinText - { - get - { - return _textField; - } - set - { - _textField = value; - } - } - - /// - /// Show indicator image, for example Up/Down Arrow image. - /// - // Indicator property of type string: - public string IndicatorImage - { - get - { - return _arrowImage; - } - set - { - _arrowImage = value; - _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150)); - RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual); - } - } - } + +using System; +using System.Runtime.InteropServices; +using Tizen.NUI; + +// A spin control (for continously changing values when users can easily predict a set of values) + +namespace Tizen.NUI +{ + /// + ///Spin CustomView class + /// + public class Spin : CustomView + { + private VisualBase _arrowVisual; + private TextField _textField; + private int _arrowVisualPropertyIndex; + private string _arrowImage; + private int _currentValue; + private int _minValue; + private int _maxValue; + private int _singleStep; + private bool _wrappingEnabled; + private string _fontFamily; + private string _fontStyle; + private int _pointSize; + private Color _textColor; + private Color _textBackgroundColor; + private int _maxTextLength; + + // Called by DALi Builder if it finds a Spin control in a JSON file + static CustomView CreateInstance() + { + return new Spin(); + } + + // static constructor registers the control type (only runs once) + static Spin() + { + // ViewRegistry registers control type with DALi type registery + // also uses introspection to find any properties that need to be registered with type registry + ViewRegistry.Instance.Register(CreateInstance, typeof(Spin)); + } + + public Spin() : base(typeof(Spin).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport) + { + + } + + /// + /// Override method of OnInitialize() for CustomView class. + /// This method is called after the Control has been initialized. + /// Derived classes should do any second phase initialization by overriding this method. + /// + public override void OnInitialize() + { + // Initialize the propertiesControl + _arrowImage = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/arrow.png"; + _textBackgroundColor = new Color(0.6f, 0.6f, 0.6f, 1.0f); + _currentValue = 0; + _minValue = 0; + _maxValue = 0; + _singleStep = 1; + _maxTextLength = 0; + + // Create image visual for the arrow keys + _arrowVisualPropertyIndex = RegisterProperty("ArrowImage", new PropertyValue(_arrowImage), Tizen.NUI.PropertyAccessMode.ReadWrite); + _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150)); + RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual); + + // Create a text field + _textField = new TextField(); + _textField.ParentOrigin = Tizen.NUI.ParentOrigin.Center; + _textField.AnchorPoint = Tizen.NUI.AnchorPoint.Center; + _textField.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent; + _textField.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent; + _textField.SizeModeFactor = new Vector3(1.0f, 0.45f, 1.0f); + _textField.PlaceholderText = "----"; + _textField.BackgroundColor = _textBackgroundColor; + _textField.HorizontalAlignment = "Center"; + _textField.VerticalAlignment = "Center"; + _textField.Focusable = (true); + _textField.Name = "_textField"; + + this.Add(_textField); + + _textField.FocusGained += TextFieldKeyInputFocusGained; + _textField.FocusLost += TextFieldKeyInputFocusLost; + } + + /// + /// Override method of GetNaturalSize() for CustomView class. + /// Return the natural size of the actor. + /// + /// Natural size of this Spin itself + public override Size GetNaturalSize() + { + return new Size(150.0f, 150.0f, 0.0f); + } + + /// + /// Event handler when the TextField in Spin gets the Key focus + /// Make sure when the current spin that takes input focus also takes the keyboard focus + /// For example, when you tap the spin directly + /// + /// Sender of this event + /// Event arguments + public void TextFieldKeyInputFocusGained(object source, EventArgs e) + { + FocusManager.Instance.SetCurrentFocusView(_textField); + } + + /// + /// Event handler when the TextField in Spin looses it's Key focus + /// + /// + /// + public void TextFieldKeyInputFocusLost(object source, EventArgs e) + { + int previousValue = _currentValue; + + // If the input value is invalid, change it back to the previous valid value + if (int.TryParse(_textField.Text, out _currentValue)) + { + if (_currentValue < _minValue || _currentValue > _maxValue) + { + _currentValue = previousValue; + } + } + else + { + _currentValue = previousValue; + } + + // Otherwise take the new value + this.Value = _currentValue; + } + + /// + /// Override method of GetNextKeyboardFocusableView() for CustomView class. + /// Gets the next key focusable view in this View towards the given direction. + /// A View needs to override this function in order to support two dimensional key navigation. + /// + /// The current focused view + /// The direction to move the focus towards + /// Whether the focus movement should be looped within the control + /// The next keyboard focusable view in this control or an empty handle if no view can be focused + public override View GetNextKeyboardFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled) + { + // Respond to Up/Down keys to change the value while keeping the current spin focused + View nextFocusedView = currentFocusedView; + if (direction == View.FocusDirection.Up) + { + this.Value += this.Step; + nextFocusedView = _textField; + } + else if (direction == View.FocusDirection.Down) + { + this.Value -= this.Step; + nextFocusedView = _textField; + } + else + { + // Return a native empty handle as nothing can be focused in the left or right + nextFocusedView = new View(); + nextFocusedView.Reset(); + } + + return nextFocusedView; + } + + /// + /// Value to be set in Spin + /// + [ScriptableProperty()] + public int Value + { + get + { + return _currentValue; + } + set + { + + Console.WriteLine("Value set to " + value); + _currentValue = value; + + // Make sure no invalid value is accepted + if (_currentValue < _minValue) + { + _currentValue = _minValue; + } + + if (_currentValue > _maxValue) + { + _currentValue = _maxValue; + } + + _textField.Text = _currentValue.ToString(); + } + } + + /// + /// Minimum Value of Spin Value + /// + // MinValue property of type int: + [ScriptableProperty()] + public int MinValue + { + get + { + return _minValue; + } + set + { + _minValue = value; + } + } + + /// + /// Maximum Value of Spin Value + /// + // MaxValue property of type int: + [ScriptableProperty()] + public int MaxValue + { + get + { + return _maxValue; + } + set + { + _maxValue = value; + } + } + + /// + /// Increasing, decresing step of Spin Value when Up or Down key is pressed + /// + // Step property of type int: + [ScriptableProperty()] + public int Step + { + get + { + return _singleStep; + } + set + { + _singleStep = value; + } + } + + /// + /// Wrapping enabled status + /// + // WrappingEnabled property of type bool: + [ScriptableProperty()] + public bool WrappingEnabled + { + get + { + return _wrappingEnabled; + } + set + { + _wrappingEnabled = value; + } + } + + /// + /// Text point size of Spin Value + /// + // TextPointSize property of type int: + [ScriptableProperty()] + public int TextPointSize + { + get + { + return _pointSize; + } + set + { + _pointSize = value; + _textField.PointSize = _pointSize; + } + } + + /// + /// The color of Spin Value + /// + // TextColor property of type Color: + [ScriptableProperty()] + public Color TextColor + { + get + { + return _textColor; + } + set + { + Console.WriteLine("TextColor set to " + value.R + "," + value.G + "," + value.B); + + _textColor = value; + _textField.TextColor = _textColor; + } + } + + /// + /// Maximum text lengh of Spin Value + /// + // MaxTextLength property of type int: + [ScriptableProperty()] + public int MaxTextLength + { + get + { + return _maxTextLength; + } + set + { + _maxTextLength = value; + _textField.MaxLength = _maxTextLength; + } + } + + /// + /// Reference of TextField of Spin + /// + public TextField SpinText + { + get + { + return _textField; + } + set + { + _textField = value; + } + } + + /// + /// Show indicator image, for example Up/Down Arrow image. + /// + // Indicator property of type string: + public string IndicatorImage + { + get + { + return _arrowImage; + } + set + { + _arrowImage = value; + _arrowVisual = VisualFactory.Get().CreateVisual(_arrowImage, new Uint16Pair(150, 150)); + RegisterVisual(_arrowVisualPropertyIndex, _arrowVisual); + } + } + } } \ No newline at end of file diff --git a/Tizen.NUI/src/public/CustomView/VisualView.cs b/Tizen.NUI/src/public/CustomView/VisualView.cs index 8381435..843738b 100755 --- a/Tizen.NUI/src/public/CustomView/VisualView.cs +++ b/Tizen.NUI/src/public/CustomView/VisualView.cs @@ -1,167 +1,167 @@ -// Copyright (c) 2017 Samsung Electronics Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -namespace Tizen.NUI -{ - using System; - using System.Runtime.InteropServices; - using System.Collections.Generic; - using System.Linq; - - /// - /// A visual view control for user add any visual to it. - /// Example: - /// VisualView _visualView = new VisualView(); - /// ImageVisualMap imageVisualMap1 = new ImageVisualMap(); - /// imageVisualMap1.URL = "./NUISample/res/images/image-1.jpg"; - /// imageVisualMap1.VisualSize = new Vector2( 300.0f, 300.0f ); - /// imageVisualMap1.Offset = new Vector2( 50.0f, 50.0f ); - /// imageVisualMap1.OffsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f ); - /// imageVisualMap1.Origin = AlignType.TOP_BEGIN; - /// imageVisualMap1.AnchorPoint = AlignType.TOP_BEGIN; - /// _visualView.AddVisual("imageVisual1", imageVisualMap1); - /// - public class VisualView : CustomView - { - //private LinkedList _visualList = null; - private Dictionary _visualDictionary = null; - private Dictionary _tranformDictionary = null; - - static CustomView CreateInstance() - { - return new VisualView(); - } - - // static constructor registers the control type (for user can add kinds of visuals to it) - static VisualView() - { - // ViewRegistry registers control type with DALi type registery - // also uses introspection to find any properties that need to be registered with type registry - ViewRegistry.Instance.Register(CreateInstance, typeof(VisualView)); - } - - public VisualView() : base(typeof(VisualView).Name, CustomViewBehaviour.ViewBehaviourDefault) - { - } - - /// - /// Override the parent method. - /// - public override void OnInitialize() - { - //Initialize empty - _visualDictionary = new Dictionary(); - _tranformDictionary = new Dictionary(); - } - - /// - /// Add or update a visual to visual view. - /// - /// The name of visual to add. If add a existed visual name, the visual will be replaced. - /// The property map of visual to create. - public void AddVisual(string visualName, VisualMap visualMap) - { - VisualBase visual = null; - int visualIndex = -1; - - /* If the visual had added, then replace it using RegisterVusal. */ - //visual.Name = name; - foreach (var item in _visualDictionary) - { - if (item.Value.Name == visualName) - { - /* Find a existed visual, its key also exited. */ - visualIndex = item.Key; - UnregisterVisual(visualIndex); - _visualDictionary.Remove(visualIndex); - _tranformDictionary.Remove(visualIndex); - break; - } - } - - if (visualIndex == -1) // The visual is a new one, create index for it. */ - { - visualIndex = RegisterProperty(visualName, new PropertyValue(visualName), PropertyAccessMode.ReadWrite); - } - - if (visualIndex > 0) - { - visual = VisualFactory.Get().CreateVisual(visualMap.OutputVisualMap); // Create a visual for the new one. - visual.Name = visualName; - visual.DepthIndex = visualMap.DepthIndex; - - RegisterVisual(visualIndex, visual); - - _visualDictionary.Add(visualIndex, visual); - _tranformDictionary.Add(visualIndex, visualMap.OutputTransformMap); - - RelayoutRequest(); - } - } - - /// - /// Remove a visual by name. - /// - /// The name of visual to remove. - public void RemoveVisual(string visualName) - { - foreach (var item in _visualDictionary) - { - if (item.Value.Name == visualName) - { - EnableVisual(item.Key, false); - UnregisterVisual(item.Key); - _visualDictionary.Remove(item.Key); - } - } - } - - /// - /// A visual view control for user add any visual to it. - /// - /// The number of visuals. - public int NumberOfVisuals() - { - return _visualDictionary.Count; - } - - /// - /// Remove all visuals of visual view. - /// - public void RemoveAll() - { - _visualDictionary.Clear(); - } - - /// - /// Override method of OnRelayout() for CustomView class. - /// Called after the size negotiation has been finished for this control. - /// The control is expected to assign this given size to itself/its children. - /// Should be overridden by derived classes if they need to layout actors differently after certain operations like add or remove actors, resize or after changing specific properties. - /// Note! As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored) - /// - /// The allocated size - /// The control should add actors to this container that it is not able to allocate a size for. - public override void OnRelayout(Vector2 size, RelayoutContainer container) - { - foreach (var item in _visualDictionary) - { - item.Value.SetTransformAndSize(_tranformDictionary[item.Key], size); - EnableVisual(item.Key, true); - } - } - } - -} +// Copyright (c) 2017 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace Tizen.NUI +{ + using System; + using System.Runtime.InteropServices; + using System.Collections.Generic; + using System.Linq; + + /// + /// A visual view control for user add any visual to it. + /// Example: + /// VisualView _visualView = new VisualView(); + /// ImageVisualMap imageVisualMap1 = new ImageVisualMap(); + /// imageVisualMap1.URL = "./NUISample/res/images/image-1.jpg"; + /// imageVisualMap1.VisualSize = new Vector2( 300.0f, 300.0f ); + /// imageVisualMap1.Offset = new Vector2( 50.0f, 50.0f ); + /// imageVisualMap1.OffsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f ); + /// imageVisualMap1.Origin = AlignType.TOP_BEGIN; + /// imageVisualMap1.AnchorPoint = AlignType.TOP_BEGIN; + /// _visualView.AddVisual("imageVisual1", imageVisualMap1); + /// + public class VisualView : CustomView + { + //private LinkedList _visualList = null; + private Dictionary _visualDictionary = null; + private Dictionary _tranformDictionary = null; + + static CustomView CreateInstance() + { + return new VisualView(); + } + + // static constructor registers the control type (for user can add kinds of visuals to it) + static VisualView() + { + // ViewRegistry registers control type with DALi type registery + // also uses introspection to find any properties that need to be registered with type registry + ViewRegistry.Instance.Register(CreateInstance, typeof(VisualView)); + } + + public VisualView() : base(typeof(VisualView).Name, CustomViewBehaviour.ViewBehaviourDefault) + { + } + + /// + /// Override the parent method. + /// + public override void OnInitialize() + { + //Initialize empty + _visualDictionary = new Dictionary(); + _tranformDictionary = new Dictionary(); + } + + /// + /// Add or update a visual to visual view. + /// + /// The name of visual to add. If add a existed visual name, the visual will be replaced. + /// The property map of visual to create. + public void AddVisual(string visualName, VisualMap visualMap) + { + VisualBase visual = null; + int visualIndex = -1; + + /* If the visual had added, then replace it using RegisterVusal. */ + //visual.Name = name; + foreach (var item in _visualDictionary) + { + if (item.Value.Name == visualName) + { + /* Find a existed visual, its key also exited. */ + visualIndex = item.Key; + UnregisterVisual(visualIndex); + _visualDictionary.Remove(visualIndex); + _tranformDictionary.Remove(visualIndex); + break; + } + } + + if (visualIndex == -1) // The visual is a new one, create index for it. */ + { + visualIndex = RegisterProperty(visualName, new PropertyValue(visualName), PropertyAccessMode.ReadWrite); + } + + if (visualIndex > 0) + { + visual = VisualFactory.Get().CreateVisual(visualMap.OutputVisualMap); // Create a visual for the new one. + visual.Name = visualName; + visual.DepthIndex = visualMap.DepthIndex; + + RegisterVisual(visualIndex, visual); + + _visualDictionary.Add(visualIndex, visual); + _tranformDictionary.Add(visualIndex, visualMap.OutputTransformMap); + + RelayoutRequest(); + } + } + + /// + /// Remove a visual by name. + /// + /// The name of visual to remove. + public void RemoveVisual(string visualName) + { + foreach (var item in _visualDictionary) + { + if (item.Value.Name == visualName) + { + EnableVisual(item.Key, false); + UnregisterVisual(item.Key); + _visualDictionary.Remove(item.Key); + } + } + } + + /// + /// A visual view control for user add any visual to it. + /// + /// The number of visuals. + public int NumberOfVisuals() + { + return _visualDictionary.Count; + } + + /// + /// Remove all visuals of visual view. + /// + public void RemoveAll() + { + _visualDictionary.Clear(); + } + + /// + /// Override method of OnRelayout() for CustomView class. + /// Called after the size negotiation has been finished for this control. + /// The control is expected to assign this given size to itself/its children. + /// Should be overridden by derived classes if they need to layout actors differently after certain operations like add or remove actors, resize or after changing specific properties. + /// Note! As this function is called from inside the size negotiation algorithm, you cannot call RequestRelayout (the call would just be ignored) + /// + /// The allocated size + /// The control should add actors to this container that it is not able to allocate a size for. + public override void OnRelayout(Vector2 size, RelayoutContainer container) + { + foreach (var item in _visualDictionary) + { + item.Value.SetTransformAndSize(_tranformDictionary[item.Key], size); + EnableVisual(item.Key, true); + } + } + } + +} -- 2.7.4