private void DoShowToolTip() { if (widgetThatWantsToShowToolTip != null && widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip && widgetThatWasShowingToolTip != widgetThatWantsToShowToolTip) { RectangleDouble screenBoundsShowingTT = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds); if (screenBoundsShowingTT.Contains(mousePosition)) { RemoveToolTip(); widgetThatIsShowingToolTip = null; toolTipText = widgetThatWantsToShowToolTip.ToolTipText; toolTipWidget = new FlowLayoutWidget() { BackgroundColor = Color.White, OriginRelativeParent = new Vector2((int)mousePosition.X, (int)mousePosition.Y), Padding = new BorderDouble(3), Selectable = false, }; toolTipWidget.Name = "ToolTipWidget"; toolTipWidget.AfterDraw += (sender, drawEventHandler) => { drawEventHandler.Graphics2D.Rectangle(toolTipWidget.LocalBounds, Color.Black); }; // Make sure we wrap long text toolTipWidget.AddChild(new WrappedTextWidget(toolTipText) { Width = 350 * GuiWidget.DeviceScale, HAnchor = HAnchor.Fit, }); // Increase the delay to make long text stay on screen long enough to read double RatioOfExpectedText = Math.Max(1, (widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0)); CurrentAutoPopDelay = RatioOfExpectedText * AutoPopDelay; systemWindow.AddChild(toolTipWidget); ToolTipShown?.Invoke(this, new StringEventArgs(CurrentText)); // timeCurrentToolTipHasBeenShowing.Reset(); // timeCurrentToolTipHasBeenShowingWasRunning = true; timeCurrentToolTipHasBeenShowing.Restart(); RectangleDouble toolTipBounds = toolTipWidget.LocalBounds; toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23); Vector2 offset = Vector2.Zero; RectangleDouble systemWindowBounds = systemWindow.LocalBounds; RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent; if (toolTipBoundsRelativeToParent.Right > systemWindowBounds.Right - 3) { offset.X = systemWindowBounds.Right - toolTipBoundsRelativeToParent.Right - 3; } if (toolTipBoundsRelativeToParent.Bottom < systemWindowBounds.Bottom + 3) { offset.Y = screenBoundsShowingTT.Top - toolTipBoundsRelativeToParent.Bottom + 3; } toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset; widgetThatIsShowingToolTip = widgetThatWantsToShowToolTip; widgetThatWantsToShowToolTip = null; widgetThatWasShowingToolTip = null; } } }
private void DoShowToolTip() { if (widgetThatWantsToShowToolTip != null && widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip && widgetThatWasShowingToolTip != widgetThatWantsToShowToolTip) { RectangleDouble screenBoundsShowingTT = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds); if (screenBoundsShowingTT.Contains(mousePosition)) { RemoveToolTip(); widgetThatIsShowingToolTip = null; toolTipText = widgetThatWantsToShowToolTip.ToolTipText; toolTipWidget = new FlowLayoutWidget() { OriginRelativeParent = new Vector2((int)mousePosition.X, (int)mousePosition.Y), Selectable = false, }; toolTipWidget.Name = "ToolTipWidget"; // Make sure we wrap long text toolTipWidget.AddChild(CreateToolTip(toolTipText)); // Increase the delay to make long text stay on screen long enough to read double ratioOfExpectedText = Math.Max(1, widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0); CurrentAutoPopDelay = ratioOfExpectedText * AutoPopDelay; systemWindow.AddChild(toolTipWidget); ToolTipShown?.Invoke(this, new StringEventArgs(CurrentText)); // timeCurrentToolTipHasBeenShowing.Reset(); // timeCurrentToolTipHasBeenShowingWasRunning = true; timeCurrentToolTipHasBeenShowing.Restart(); RectangleDouble toolTipBounds = toolTipWidget.LocalBounds; toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23); Vector2 offset = Vector2.Zero; RectangleDouble systemWindowBounds = systemWindow.LocalBounds; RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent; if (toolTipBoundsRelativeToParent.Right > systemWindowBounds.Right - 3) { offset.X = systemWindowBounds.Right - toolTipBoundsRelativeToParent.Right - 3; } if (toolTipBoundsRelativeToParent.Bottom < systemWindowBounds.Bottom + 3) { offset.Y = screenBoundsShowingTT.Top - toolTipBoundsRelativeToParent.Bottom + 3; } toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset; widgetThatIsShowingToolTip = widgetThatWantsToShowToolTip; widgetThatWantsToShowToolTip = null; widgetThatWasShowingToolTip = null; } } }
protected virtual void OnToolTipShown(AutoCompleteHintEventArgs e) { ToolTipShown?.Invoke(this, e); }