示例#1
0
        /// <summary>
        /// Tries to add the UI Element as a scrollable. Returns true if it succeeded, false if it didn't.
        /// </summary>
        public bool AddScrollable(UIElement uiElement)
        {
            if (uiElement is IScrollable scrollable)
            {
                Scrollables.Add(scrollable);

                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Adds a UI Element and makes it interactable if it implements <see cref="IInteractable"/> and scrollable if it implements <see cref="IScrollable"/>.
        /// </summary>
        /// <typeparam name="T">UIElement descendant of type T.</typeparam>
        /// <param name="uiElement">The UI Element to add.</param>
        /// <returns>Returns the craeted UI Element.</returns>
        public T AddUIElement <T>(T uiElement) where T : UIElement
        {
            UIElements.Add(uiElement);

            if (uiElement is IInteractable interactable)
            {
                Interactables.Add(interactable);
            }

            if (uiElement is IScrollable scrollable)
            {
                Scrollables.Add(scrollable);
            }

            return(uiElement);
        }
示例#3
0
        /// <summary>
        /// Removes the UI Element.
        /// </summary>
        public void RemoveUIElement(UIElement uiElement)
        {
            UIElements.Remove(uiElement);

            if (uiElement is IInteractable interactable)
            {
                Interactables.Remove(interactable);

                //Deactivate forced focus:
                if (ForceFocusedInteractable == interactable)
                {
                    ForceFocusOn             = false;
                    ForceFocusedInteractable = null;
                }

                //Unselect it from the "keyboard":
                if (kb_selectedInteractable == interactable)
                {
                    kb_selectedInteractable = null;
                }

                //Unselect it from the "mouse":
                if (ms_selectedInteractable == interactable)
                {
                    ms_selectedInteractable = null;
                }
            }

            if (uiElement is IScrollable scrollable)
            {
                Scrollables.Remove(scrollable);
            }

            if (uiElement is IContainer container)
            {
                foreach (UIElement child in container.Children)
                {
                    RemoveUIElement(child);
                }
            }

            uiElement.OnDestroy();
        }