/// <summary> /// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing /// </summary> /// <param name="user">The functionality user</param> /// <param name="tooltip">The tooltip to show</param> /// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param> /// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the /// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If /// duration is exactly 0, tooltip stays visible until explicitly hidden</param> /// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement /// is specified, we assume the ITooltip is a component and use its own Transform</param> /// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param> public static void ShowTooltip(this IUsesSetTooltipVisibility user, ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null) { #if !FI_AUTOFILL user.provider.ShowTooltip(tooltip, persistent, duration, placement, becameVisible); #endif }
public void Reset() { startTime = default(float); lastModifiedTime = default(float); tooltipUI = default(TooltipUI); persistent = default(bool); duration = default(float); becameVisible = default(Action); placement = default(ITooltipPlacement); orientationWeight = default(float); transitionOffset = default(Vector3); transitionTime = default(float); }
Vector3 GetTooltipOffset(TooltipUI tooltipUI, ITooltipPlacement placement, Vector3 transitionOffset) { if (tooltipUI == null) { return(Vector3.zero); } var offset = Vector3.zero; if (placement != null) { switch (placement.tooltipAlignment) { case TextAlignment.Right: offset = Vector3.left; break; case TextAlignment.Left: offset = Vector3.right; break; } } // The rectTransform expansion is handled in the Tooltip dynamically, based on alignment & text length var rectTransform = tooltipUI.rectTransform; var rect = rectTransform.rect; var halfWidth = rect.width * 0.5f; if (placement != null) { offset *= halfWidth * rectTransform.lossyScale.x; } else { offset = Vector3.back * k_Offset * this.GetViewerScale(); } offset += transitionOffset; return(offset); }
Vector3 GetTooltipOffset(TooltipUI tooltipUI, ITooltipPlacement placement, Vector3 transitionOffset) { if (tooltipUI == null) { return(Vector3.zero); } var offset = Vector3.zero; if (placement != null) { switch (placement.tooltipAlignment) { case TextAlignment.Right: offset = Vector3.left; break; case TextAlignment.Left: offset = Vector3.right; break; } } if (placement != null) { tooltipUI.rectTransform.GetWorldCorners(k_Corners); var halfWidth = (k_Corners[0] - k_Corners[2]).magnitude * 0.5f; offset *= halfWidth; } else { offset = Vector3.back * k_Offset * this.GetViewerScale(); } offset += transitionOffset; return(offset); }
public void ShowTooltip(ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null) { if (!IsValidTooltip(tooltip)) { return; } TooltipData data; if (m_Tooltips.TryGetValue(tooltip, out data)) { // Compare the targets to see if they changed var currentTarget = data.GetTooltipTarget(tooltip); var currentPlacement = data.placement; data.persistent |= persistent; data.placement = placement ?? tooltip as ITooltipPlacement; // Set the text to new text var tooltipUI = data.tooltipUI; if (tooltipUI) { tooltipUI.Show(tooltip.tooltipText, data.placement.tooltipAlignment); var newTarget = data.GetTooltipTarget(tooltip); if (currentTarget != newTarget) { // Get the different between the 'old' tooltip position and 'new' tooltip position, even taking alignment into account var transitionLerp = 1.0f - Mathf.Clamp01((Time.time - data.transitionTime) / k_ChangeTransitionDuration); var currentPosition = currentTarget.TransformPoint(GetTooltipOffset(tooltipUI, currentPlacement, data.transitionOffset * transitionLerp)); var newPosition = newTarget.TransformPoint(GetTooltipOffset(tooltipUI, data.placement, Vector3.zero)); // Store it as an additional offset that we'll quickly lerp from data.transitionOffset = newTarget.InverseTransformVector(currentPosition - newPosition); data.transitionTime = Time.time; } if (duration > 0) { data.duration = duration; data.lastModifiedTime = Time.time; } } return; } // Negative durations only affect existing tooltips if (duration < 0) { return; } var tooltipData = GetTooltipData(); tooltipData.startTime = Time.time; tooltipData.lastModifiedTime = Time.time; tooltipData.persistent = persistent; tooltipData.duration = duration; tooltipData.becameVisible = becameVisible; tooltipData.placement = placement ?? tooltip as ITooltipPlacement; tooltipData.orientationWeight = 0.0f; tooltipData.transitionOffset = Vector3.zero; tooltipData.transitionTime = 0.0f; m_Tooltips[tooltip] = tooltipData; }
/// <summary> /// Show a Tooltip. Calling ShowTooltip on an ITooltip that was just shown will update its placement and timing /// </summary> /// <param name="tooltip">The tooltip to show</param> /// <param name="persistent">Whether the tooltip should stay visible regardless of raycasts</param> /// <param name="duration">If the tooltip is shown persistently, and duration is less than 0, hide after the /// duration, in seconds. If duration greater than 0, placement is updated but timing is not affected. If /// duration is exactly 0, tooltip stays visible until explicitly hidden</param> /// <param name="placement">(Optional) The ITooltipPlacement object used to place the tooltip. If no placement /// is specified, we assume the ITooltip is a component and use its own Transform</param> /// <param name="becameVisible">(Optional) Called as soon as the tooltip becomes visible</param> public static void ShowTooltip(this ISetTooltipVisibility obj, ITooltip tooltip, bool persistent = false, float duration = 0f, ITooltipPlacement placement = null, Action becameVisible = null) { showTooltip(tooltip, persistent, duration, placement, becameVisible); }