public void ShowTooltipForControl(string text, Control control, TooltipLocation location) { Point p; switch (location) { case TooltipLocation.TOP: p = new Point(0, -(control.Height + 20)); break; case TooltipLocation.LEFT: p = new Point(-20, 0); break; case TooltipLocation.RIGHT: p = new Point(control.Width + 5, 0); break; case TooltipLocation.BOTTOM: default: p = new Point(0, (control.Height + 20)); break; } Debug.Assert(control as Form == null); Tooltip.IsBalloon = location == TooltipLocation.TOP; Tooltip.Show(text, control, p, 2000); }
public static void Add(Rect rect, TooltipLocation defaultLocation, params string[] tipLines) { if (tipLines == null || tipLines.Length == 0) return; if (tipLines.All(x => string.IsNullOrEmpty(x))) return; var tip = string.Join(Environment.NewLine, tipLines); AddPrivate(rect, tip, defaultLocation); }
internal static void Show(Rect activatorRect, PopupWindowContent windowContent, TooltipLocation[] locationPriorityOrder) { if (ShouldShowWindow(activatorRect)) { var isInstance = _sEditorWindowWithoutFocus == null; if (isInstance) _sEditorWindowWithoutFocus = CreateInstance<TooltipServiceWindow>(); _sEditorWindowWithoutFocus.Init(activatorRect, windowContent, locationPriorityOrder); } }
private static void AddPrivate(Rect rect, string tip, TooltipLocation defaultLocation) { if (rect.Contains(Event.current.mousePosition)) { currentTip = new Tooltip {rect = rect, tooltip = (tip??"")}; var content = new GUIContent(currentTip.tooltip); var height = defaultStyle.CalcHeight(content, MaxWidth); float minWidth, maxWidth; defaultStyle.CalcMinMaxWidth(content, out minWidth, out maxWidth); currentTip.size = new Vector2(Mathf.Min(MaxWidth, maxWidth+2f), height); currentTip.screenRect = GUIToScreenRect(rect); Open(new Rect(rect.position - new Vector2(0, 6), rect.size + new Vector2(0, 12)), currentTip, defaultLocation); } else if (currentTip != null) { var localRect = ScreenToGUIRect(currentTip.screenRect); if (!localRect.Contains(Event.current.mousePosition)) { TooltipServiceWindow.Hide(); currentTip = null; } } }
private static void Open(Rect rect, Tooltip window, TooltipLocation defaultLocation) { var locationPriorityOrder = new[] { defaultLocation, TooltipLocation.Below, TooltipLocation.Above, TooltipLocation.Right, TooltipLocation.Left }; TooltipServiceWindow.Show(rect, window, locationPriorityOrder); }
public static Rect GetDropDownRect(Rect buttonRect, Vector2 minSize, Vector2 maxSize, object popupContainerWindow, TooltipLocation[] locationPriorityOrder) { if (locationPriorityOrder == null) { var locationArray1 = new TooltipLocation[2]; locationArray1[1] = TooltipLocation.Above; locationPriorityOrder = locationArray1; } var rects = new List<Rect>(); TooltipLocation[] locationArray = locationPriorityOrder; foreach (TooltipLocation location in locationArray) { Rect rect; switch (location) { case TooltipLocation.Below: if (!PopupBelow(buttonRect, minSize, maxSize, popupContainerWindow, out rect)) { break; } return rect; case TooltipLocation.Above: if (!PopupAbove(buttonRect, minSize, maxSize, popupContainerWindow, out rect)) { goto Label_0079; } return rect; case TooltipLocation.Left: if (!PopupLeft(buttonRect, minSize, maxSize, popupContainerWindow, out rect)) { goto Label_0099; } return rect; case TooltipLocation.Right: if (!PopupRight(buttonRect, minSize, maxSize, popupContainerWindow, out rect)) { goto Label_00B9; } return rect; default: { continue; } } rects.Add(rect); continue; Label_0079: rects.Add(rect); continue; Label_0099: rects.Add(rect); continue; Label_00B9: rects.Add(rect); } return GetLargestRect(rects); }
private void Init(Rect activatorRect, PopupWindowContent windowContent, TooltipLocation[] locationPriorityOrder) { m_WindowContent = windowContent; m_WindowContent.GetType() .GetProperty("editorWindow") .GetSetMethod(true) .Invoke(m_WindowContent, new object[] {this}); m_ActivatorRect = GUIToScreenRect(activatorRect); m_LastWantedSize = windowContent.GetWindowSize(); m_LocationPriorityOrder = locationPriorityOrder; Vector2 size = windowContent.GetWindowSize() + new Vector2(m_BorderWidth*2f, m_BorderWidth*2f); var rect = TooltipLocationHelper.GetDropDownRect(m_ActivatorRect, size, size, null, m_LocationPriorityOrder); minSize = size; maxSize = size; position = rect; ShowPopup(); Repaint(); }