Exemplo n.º 1
0
        public void SetContent(ITooltipContent content)
        {
            bool wasVisible = Visible;

            Visible = false;

            Content = content;

            var pos = content.Location;
            var sz  = content.Size;

            SetBounds(pos.X, pos.Y, sz.Width, sz.Height);

            UpdateRegion();

            Refresh();

            if (!wasVisible)
            {
                Show(Owner);
            }
            else
            {
                Visible = true;
            }
        }
Exemplo n.º 2
0
        public bool TryAddContent([CanBeNull] ITooltipContent content)
        {
            if (content == null || content.Text.IsNullOrEmpty())
            {
                return(false);
            }

            var identifierContent = content as IdentifierTooltipContent;

            if (identifierContent != null)
            {
                _identifierContents.Add(identifierContent);
                return(true);
            }

            var issueContent = content as IssueTooltipContent;

            if (issueContent != null)
            {
                _issueContents.Add(issueContent);
                return(true);
            }

            var rsContent = content as MiscTooltipContent;

            if (rsContent != null)
            {
                _miscContents.Add(rsContent);
                return(true);
            }

            return(false);
        }
        public void Show(ITooltipContent content)
        {
            DescriptionText.text = content.GetDescriptionText();
            _descriptionContainer.gameObject.SetActive(true);

            ActionText.text = content.GetActionText();

            if (!string.IsNullOrEmpty(ActionText.text))
            {
                _actionContainer.gameObject.SetActive(true);
            }
        }
Exemplo n.º 4
0
        internal void OnDrawerHovered(ITooltipContent drawer, PointerEventData pointer, bool isHovering)
        {
            // Hide tooltip if it is currently visible
            RuntimeInspectorUtils.HideTooltip();

            if (isHovering)
            {
                hoveredDrawer   = drawer;
                hoveringPointer = pointer;
                hoveredDrawerTooltipShowTime = Time.realtimeSinceStartup + manager.TooltipDelay;
            }
            else if (drawer == null || hoveredDrawer == drawer)
            {
                hoveredDrawer   = null;
                hoveringPointer = null;
            }
        }
Exemplo n.º 5
0
        private void Update()
        {
            // Check if a pointer has remained static over a drawer for a while; if so, show a tooltip
            float time = Time.realtimeSinceStartup;

            if (hoveringPointer != null)
            {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
                // PointerEventData.delta isn't set to (0,0) for static pointers in the new Input System, so we use the active Pointer's delta instead
                // The default value isn't Vector2.zero but Vector2.one because we don't want to show tooltip if there is no pointer
                Vector2 pointerDelta = Pointer.current != null?Pointer.current.delta.ReadValue() : Vector2.one;
#else
                Vector2 pointerDelta = hoveringPointer.delta;
#endif
                if (pointerDelta.x != 0f || pointerDelta.y != 0f)
                {
                    hoveredDrawerTooltipShowTime = time + manager.TooltipDelay;
                }
                else if (time > hoveredDrawerTooltipShowTime)
                {
                    // Make sure that everything is OK
                    if (!hoveredDrawer.IsActive)
                    {
                        hoveredDrawer   = null;
                        hoveringPointer = null;
                    }
                    else
                    {
                        RuntimeInspectorUtils.ShowTooltip(hoveredDrawer.TooltipText, hoveringPointer, manager.Skin, manager.Canvas);

                        // Don't show the tooltip again until the pointer moves
                        hoveredDrawerTooltipShowTime = float.PositiveInfinity;
                    }
                }
            }
        }
Exemplo n.º 6
0
 public void Initialize(TooltipListener tooltipListener, ITooltipContent tooltipContent)
 {
     this.tooltipListener = tooltipListener;
     this.tooltipContent  = tooltipContent;
 }
Exemplo n.º 7
0
        public static void FitContentOnScreen(
            Graphics g, ITooltipContent content,
            ref Font font, ref Point tooltipPosition,
            ref Size tooltipSize
            )
        {
            var  screen       = Screen.FromPoint(tooltipPosition);
            var  screenBounds = screen.WorkingArea;
            var  fontSize     = font.Size;
            Font tempFont     = null;

            // Iterate a few times to shrink the tooltip's font size if it's too big
            for (int i = 0; i < 10; i++)
            {
                var size = content.Measure(g);

                tooltipSize.Width  = size.Width;
                tooltipSize.Height = size.Height;

                if (fontSize <= MinTooltipSizeEm)
                {
                    break;
                }
                if (size.Width < (screenBounds.Width * MaxTooltipWidthPercent / 100) &&
                    size.Height < (screenBounds.Height * MaxTooltipHeightPercent / 100))
                {
                    break;
                }

                fontSize *= FontSizeShrinkMultiplier;
                if (fontSize < MinTooltipSizeEm)
                {
                    fontSize = MinTooltipSizeEm;
                }

                font = new Font(
                    font.FontFamily,
                    Math.Min(fontSize, MinTooltipSizeEm),
                    font.Style
                    );

                if (tempFont != null)
                {
                    tempFont.Dispose();
                }

                tempFont = font;
            }

            var maxWidth  = (screenBounds.Width * MaxTooltipWidthPercent / 100);
            var maxHeight = (screenBounds.Height * MaxTooltipHeightPercent / 100);

            if (tooltipSize.Width > maxWidth)
            {
                tooltipSize.Width = maxWidth;
            }
            if (tooltipSize.Height > maxHeight)
            {
                tooltipSize.Height = maxHeight;
            }

            if (tooltipPosition.X < screenBounds.Left)
            {
                tooltipPosition.X = screenBounds.Left;
            }
            if (tooltipPosition.Y < screenBounds.Top)
            {
                tooltipPosition.Y = screenBounds.Top;
            }

            if ((tooltipPosition.X + tooltipSize.Width) >= screenBounds.Right)
            {
                tooltipPosition.X = (screenBounds.Right - tooltipSize.Width - 1);
            }
            if ((tooltipPosition.Y + tooltipSize.Height) >= screenBounds.Bottom)
            {
                tooltipPosition.Y = (screenBounds.Bottom - tooltipSize.Height - 1);
            }
        }
Exemplo n.º 8
0
        public void SetContent(ITooltipContent content)
        {
            bool wasVisible = Visible;
            Visible = false;

            Content = content;

            var pos = content.Location;
            var sz = content.Size;
            SetBounds(pos.X, pos.Y, sz.Width, sz.Height);

            UpdateRegion();

            Refresh();

            if (!wasVisible)
                Show(Owner);
            else
                Visible = true;
        }
Exemplo n.º 9
0
        public static void FitContentOnScreen(
            Graphics g, ITooltipContent content, 
            ref Font font, ref Point tooltipPosition,
            ref Size tooltipSize
        )
        {
            var screen = Screen.FromPoint(tooltipPosition);
            var screenBounds = screen.WorkingArea;
            var fontSize = font.Size;
            Font tempFont = null;

            // Iterate a few times to shrink the tooltip's font size if it's too big
            for (int i = 0; i < 10; i++) {
                var size = content.Measure(g);

                tooltipSize.Width = size.Width;
                tooltipSize.Height = size.Height;

                if (fontSize <= MinTooltipSizeEm)
                    break;
                if (size.Width < (screenBounds.Width * MaxTooltipWidthPercent / 100) &&
                    size.Height < (screenBounds.Height * MaxTooltipHeightPercent / 100))
                    break;

                fontSize *= FontSizeShrinkMultiplier;
                if (fontSize < MinTooltipSizeEm)
                    fontSize = MinTooltipSizeEm;

                font = new Font(
                    font.FontFamily,
                    Math.Min(fontSize, MinTooltipSizeEm),
                    font.Style
                );

                if (tempFont != null)
                    tempFont.Dispose();

                tempFont = font;
            }

            var maxWidth = (screenBounds.Width * MaxTooltipWidthPercent / 100);
            var maxHeight = (screenBounds.Height * MaxTooltipHeightPercent / 100);

            if (tooltipSize.Width > maxWidth)
                tooltipSize.Width = maxWidth;
            if (tooltipSize.Height > maxHeight)
                tooltipSize.Height = maxHeight;

            if (tooltipPosition.X < screenBounds.Left)
                tooltipPosition.X = screenBounds.Left;
            if (tooltipPosition.Y < screenBounds.Top)
                tooltipPosition.Y = screenBounds.Top;

            if ((tooltipPosition.X + tooltipSize.Width) >= screenBounds.Right)
                tooltipPosition.X = (screenBounds.Right - tooltipSize.Width - 1);
            if ((tooltipPosition.Y + tooltipSize.Height) >= screenBounds.Bottom)
                tooltipPosition.Y = (screenBounds.Bottom - tooltipSize.Height - 1);
        }