コード例 #1
0
ファイル: Pager.cs プロジェクト: onamoni/edriven-gui
        protected override void CommitProperties()
        {
            base.CommitProperties();

            if (_totalPagesChanged)
            {
                _totalPagesChanged = false;
                UpdateState();
            }

            if (_focusEnabledChanged)
            {
                _focusEnabledChanged = false;

                var fe = base.FocusEnabled;
                _btnDec.FocusEnabled = _btnInc.FocusEnabled = fe;
                _placeholder.Children.ForEach(delegate(DisplayListMember child)
                {
                    InteractiveComponent comp = child as InteractiveComponent;
                    if (null != comp)
                    {
                        comp.FocusEnabled = fe;
                    }
                });
            }
        }
コード例 #2
0
        /// <summary>
        /// NOTE: Recursive!!!
        /// </summary>
        /// <param name="child"></param>
        /// <returns></returns>
        private static bool IsFocusableRecursive(InteractiveComponent child)
        {
            if (child.FocusEnabled)
            {
                return(true);
            }

            foreach (Component component in child.Children)
            {
                if (component.FocusEnabled)
                {
                    return(true);
                }

                return(IsFocusableRecursive(component));
            }

            //if (child is Group)
            //{
            //    Container container = (Container)child;
            //    foreach (Component component in container.Children)
            //    {
            //        if (component.FocusEnabled)
            //            return true;

            //        return IsFocusableRecursive(component);
            //    }
            //}

            return(false);
        }
コード例 #3
0
        private static InteractiveComponent FindRecursive(IEnumerable <DisplayListMember> children, string id)
        {
            InteractiveComponent result = null;

            foreach (var child in children)
            {
                //Debug.Log("child.Id: " + child.Id);
                var ic = child as InteractiveComponent;
                if (null == ic)
                {
                    continue;
                }

                if (child.Id == id)
                {
                    return(ic);
                }

                result = FindRecursive(ic.Children, id);
                if (null != result)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #4
0
 /// <summary>
 /// Returns the tab children
 /// This could be overriden in subclass
 /// </summary>
 /// <returns></returns>
 public virtual List <DisplayListMember> GetTabChildren()
 {
     return(ContentChildren.FindAll(delegate(DisplayListMember child)
     {
         InteractiveComponent c = child as InteractiveComponent;
         //return null != c && c.Enabled && c.Visible && c.FocusEnabled;
         return FocusManager.IsFocusCandidate(c);
     }));
 }
コード例 #5
0
ファイル: Scroller.cs プロジェクト: onamoni/edriven-gui
        private void InstallViewport()
        {
            //Debug.Log("InstallViewport: " + this);
            if (null != Skin && null != Viewport)
            {
                Viewport.ClipAndEnableScrolling = true;
                DisplayListMember dlm = (DisplayListMember)Viewport;
                ((Group)Skin).AddContentChildAt(dlm, 0);
                dlm.AddEventListener(PropertyChangeEvent.PROPERTY_CHANGE, ViewportPropertyChangeHandler);
                InteractiveComponent ic = (InteractiveComponent)Viewport;
                ic.MouseEnabled = true; // because of mouse-wheeling!
            }

            if (null != VerticalScrollBar)
            {
                VerticalScrollBar.Viewport = Viewport;
            }
            if (null != HorizontalScrollBar)
            {
                HorizontalScrollBar.Viewport = Viewport;
            }
        }
コード例 #6
0
ファイル: Pager.cs プロジェクト: onamoni/edriven-gui
        public override System.Collections.Generic.List <DisplayListMember> GetTabChildren()
        {
            System.Collections.Generic.List <DisplayListMember> list = new System.Collections.Generic.List <DisplayListMember>();

            if (FocusManager.IsFocusCandidate(_btnDec))
            {
                list.Add(_btnDec);
            }

            list.AddRange(
                _placeholder.Children.FindAll(delegate(DisplayListMember child)
            {
                InteractiveComponent comp = child as InteractiveComponent;
                return(FocusManager.IsFocusCandidate(comp));
            })
                );

            if (FocusManager.IsFocusCandidate(_btnInc))
            {
                list.Add(_btnInc);
            }

            return(list);
        }
コード例 #7
0
 public bool IsRegistered(InteractiveComponent component)
 {
     return _customDict.ContainsValue(component);
 }
コード例 #8
0
        internal void Register(/*ref */string id, InteractiveComponent component)
        {
            //if (null == id)
            //    throw new ComponentManagerException(ComponentManagerException.CannotRegisterNull);

            if (string.IsNullOrEmpty(id))
                return; // do not register an empty ID

            if (_customDict.ContainsKey(id)) 
                return; // no multiple registration

            if (_customDict.ContainsKey(id))
            {
#if DEBUG
if (DebugMode)
                {
                    Debug.Log(string.Format(ComponentManagerException.IdAlreadyRegistered, id));
                    Debug.Break();
                }
#endif

                throw new ComponentManagerException(string.Format(ComponentManagerException.IdAlreadyRegistered, id));
            }

            _customDict.Add(id, component);

#if DEBUG
if (DebugMode)
            {
                Debug.Log(string.Format(@"Component registered: [{0}] => {1}", id, component));
            }
#endif

        }
コード例 #9
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
 /// <summary>
 /// Gets the info if this is a focus candidate (for tabbing etc.)
 /// </summary>
 /// <param name="comp"></param>
 /// <returns></returns>
 public static bool IsFocusCandidate(InteractiveComponent comp)
 {
     return (null != comp && comp.Enabled && comp.Visible && comp.FocusEnabled);
 }
コード例 #10
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
 /// <summary>
 /// Blurs the referenced component but only if currently in focus
 /// Use this if you really know what you are doing; else you get en exception
 /// </summary>
 /// <param name="component"></param>
 public void Blur(InteractiveComponent component)
 {
     if (_focusedComponent == component)
         Blur();
     else
         throw new FocusManagerException(FocusManagerException.ComponentNotInFocus);
 }
コード例 #11
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
        /// <summary>
        /// Blurs everything
        /// </summary>
        public void Blur()
        {
            //Debug.Log("Blur: " + _focusedComponent);
            //if (null != _focusedComponent)
            //    _focusedComponent.DispatchEvent(new GuiEvent(GuiEvent.FOCUS_OUT));

            //TextFieldFocusHelper.BlurUnityFocus();

            if (null != _focusedComponent)
                _focusedComponent.FocusOutHandler(new FocusEvent(FocusEvent.FOCUS_IN));

            _focusedComponent = null;
        }
コード例 #12
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
        /// <summary>
        /// Sets focus to the component
        /// Blurs previously focused component
        /// Called internaly by InteractiveComponent
        /// </summary>
        /// <param name="component">Component to focus</param>
        private void DoSetFocus(InteractiveComponent component)
        {
            //Debug.Log("DoSetFocus: " + component);

            /**
             * Clicking everywhere outside the text field messes the editor (cursor)
             * However, if the host dialog clicked, and it's SetFocus() routes to the same text field, 
             * the focus should stay intact (and the cursor working)
             * That's why we need to give TextFieldFocusHelper a chance to re-apply the focus
             * (it does it at the end of OnGUI)
             * */
            if (component is TextFieldBase)
                TextFieldFocusHelper.ShouldHandleFocus = true;

            /**
             * 1) If component not focus enabled, go no further
             * */
            if (!component.FocusEnabled)
            {
#if DEBUG
                if (DebugMode)
                    Debug.Log(string.Format("FocusManager: Focus not set to [{0}] because component not FocusEnabled", component));
#endif
                return; // else do nothing
            }

#if DEBUG
            if (DebugMode)
                Debug.Log("FocusManager: Trying to set focus to: " + component);
#endif
            //Debug.Log("_focusedComponent == component: " + (_focusedComponent == component));
            //Debug.Log("component.FocusEnabled: " + (component.FocusEnabled));

            /**
             * 2) If focusing the already focused component, do nothing
             * */
            if (_focusedComponent == component)
            {
#if DEBUG
                if (DebugMode)
                    Debug.Log(string.Format("FocusManager: Focus not set to [{0}] because it is the same component", component));
#endif
                return;
            }

            /**
             * 3) Blur previuosly focused component
             * */
            Blur();

            //Debug.Log("component: " + component);

            /**
             * 4) Set current component as focused component
             * */
            _focusedComponent = component;

#if DEBUG
            if (DebugMode)
                Debug.Log("FocusManager: Focus changed to: " + _focusedComponent);
#endif

            //Debug.Log("FocusManager: Focus changed to: " + _focusedComponent);
            //GUI.FocusControl(component.Uid);
            //if (0 != _focusedComponent.HotControlId)
            //{
            //    if (_focusedComponent is TextField)
            //    {
            //        GUIUtility.keyboardControl = _focusedComponent.HotControlId;
            //        Debug.Log("GUIUtility.keyboardControl: " + GUIUtility.keyboardControl);
            //    }
            //}

            /**
            / * 5) Execute focus on the component
            / * */
            component.FocusInHandler(new FocusEvent(FocusEvent.FOCUS_IN));

            //if (_focusedComponent is TextField)
            //{
            //    Debug.Log("Calling GUI.FocusControl: " + this);
            //    GUI.FocusControl(_focusedComponent.Uid);
            //    //TextEditor t = GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl) as TextEditor;
            //    //if (null != t)
            //    //    t.SelectAll();
            //}
        }
コード例 #13
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
        /// <summary>
        /// Sets focus on a component
        /// </summary>
        /// <param name="component"></param>
        public void SetFocus(InteractiveComponent component)
        {
            DoSetFocus(component);

            /*if (component.Initialized)
            {
                //FocusManager.Instance.TabbedToFocus = true;
                //Debug.Log("Setting focus: " + this);
                DoSetFocus(component);
            }
            else
            {
                component.AddEventListener(FrameworkEvent.CREATION_COMPLETE, SetFocusDelayed);
            }*/
        }
コード例 #14
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
 /// <summary>
 /// Checks if the specified component is in focus
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public bool HasFocusedComponent(InteractiveComponent c)
 {
     return _focusedComponent == c;
 }
コード例 #15
0
ファイル: FocusManager.cs プロジェクト: groov0v/edriven-gui
        /// <summary>
        /// Finds focusable parent or parent's parent
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        internal static InteractiveComponent FindFocusableAncestor(InteractiveComponent component)
        {
            //Debug.Log("FindFocusableAncestor: " + component);

            InteractiveComponent ancestor = null;

            DisplayObjectContainer child = component;

            do
            {
                var ic = child as InteractiveComponent;
                if (null != ic)
                {
                    if (ic.Enabled && ic.FocusEnabled || null != ic.FocusRouting)
                    {
                        ancestor = ic;
                        break;
                    }
                }
                //child = (InteractiveComponent) child.Parent;
                child = child.Parent;
            } 
            while (null != child);

#if DEBUG
if (DebugMode)
            {
                Debug.Log(null != ancestor
                              ? string.Format("Focusable ancestor found: {0}", ancestor)
                              : "Focusable ancestor NOT found");
            }
#endif

            //Debug.Log("ancestor: " + ancestor);
            return ancestor;
        }
コード例 #16
0
        /// <summary>
        /// NOTE: Recursive!!!
        /// </summary>
        /// <param name="child"></param>
        /// <returns></returns>
        private static bool IsFocusableRecursive(InteractiveComponent child)
        {
            if (child.FocusEnabled)
                return true;

            foreach (Component component in child.Children)
            {
                if (component.FocusEnabled)
                    return true;

                return IsFocusableRecursive(component);
            }

            //if (child is Group)
            //{
            //    Container container = (Container)child;
            //    foreach (Component component in container.Children)
            //    {
            //        if (component.FocusEnabled)
            //            return true;

            //        return IsFocusableRecursive(component);
            //    }
            //}

            return false;
        }
コード例 #17
0
        /// <summary>
        /// The focus at the Unity level could change with tabbing etc.
        /// It is important to correct this behaviour, because the FocusManager should handle all the focus logic
        /// This method is being called from StageManager, in each frame, from OnGUI() handler
        /// </summary>
        public static void HandleFocus()
        {
            /**
             * If this is the focused component and focus on this component already handled
             * our work is done, so return
             * */
            if (string.IsNullOrEmpty(NextFocusId) && !_shouldHandleFocus && FocusManager.Instance.FocusedComponent == _previouslyFocusedComponent)
                return;

            /* Reset the "force" flag */
            _shouldHandleFocus = false;

            _previouslyFocusedComponent = FocusManager.Instance.FocusedComponent;
            
            if (!string.IsNullOrEmpty(NextFocusId))
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("Handling focus DIRECTLY with NextFocusId = " + NextFocusId);
                }
#endif
                DoFocusTextField(NextFocusId);
                NextFocusId = null;
                return;
            }

            //Debug.Log("GUIUtility.keyboardControl: " + GUIUtility.keyboardControl);
            _textField = FocusManager.Instance.FocusedComponent as TextFieldBase;

            if (null != _textField && _textField.FocusEnabled && _textField.Enabled)
            {
#if DEBUG
                if (DebugMode)
                {
                    Debug.Log("Handling focus on " + FocusManager.Instance.FocusedComponent + "(" + FocusManager.Instance.FocusedComponent.Uid + ")");
                }
#endif
                // @see http://answers.unity3d.com/questions/17169/select-text-in-gui-textfield.html
                // 'You must first focus something else (doesn't matter what, so long as it exists, "" or null will not suffice). Bit of an ugly kludge, but seems to work.'

                // A. Blur
                //BlurUnityFocus(); // BUG BUG BUG ??? Not needed!

                // B. Focus
                if (_textField.Rendered)
                {
                    DoFocusTextField();
                }
                else
                {
                    _textField.AddEventListener(FrameworkEvent.FIRST_SHOW, delegate
                    {
                        DoFocusTextField();
                    });
                }
            }
            else {
                BlurUnityFocus();
            }

            FocusManager.Instance.TabbedToFocus = false;
        }