add timer for hiding tooltip

This commit is contained in:
Matt Parker
2025-10-12 21:29:23 +10:00
parent e126a7d34e
commit 7a290d4254

View File

@@ -10,6 +10,7 @@ using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
using SharpIDE.RazorAccess; using SharpIDE.RazorAccess;
using Task = System.Threading.Tasks.Task; using Task = System.Threading.Tasks.Task;
using Timer = Godot.Timer;
namespace SharpIDE.Godot.Features.CodeEditor; namespace SharpIDE.Godot.Features.CodeEditor;
@@ -98,16 +99,21 @@ public partial class SharpIdeCodeEdit : CodeEdit
return; return;
} }
var popupPanel = new Window(); var tooltipWindow = new Window();
popupPanel.WrapControls = true; tooltipWindow.WrapControls = true;
popupPanel.Unresizable = true; tooltipWindow.Unresizable = true;
popupPanel.Transparent = true; tooltipWindow.Transparent = true;
popupPanel.Borderless = true; tooltipWindow.Borderless = true;
popupPanel.PopupWMHint = true; tooltipWindow.PopupWMHint = true;
popupPanel.MinimizeDisabled = true; tooltipWindow.MinimizeDisabled = true;
popupPanel.MaximizeDisabled = true; tooltipWindow.MaximizeDisabled = true;
var timer = new Timer { WaitTime = 0.5f, OneShot = true, Autostart = false };
tooltipWindow.AddChild(timer);
timer.Timeout += () => tooltipWindow.QueueFree();
popupPanel.MouseExited += () => popupPanel.QueueFree(); tooltipWindow.MouseExited += () => timer.Start();
tooltipWindow.MouseEntered += () => timer.Stop();
var styleBox = new StyleBoxFlat var styleBox = new StyleBoxFlat
{ {
@@ -150,16 +156,16 @@ public partial class SharpIdeCodeEdit : CodeEdit
vboxContainer.AddThemeConstantOverride("separation", 0); vboxContainer.AddThemeConstantOverride("separation", 0);
vboxContainer.AddChild(new Control { CustomMinimumSize = new Vector2I(0, GetLineHeight()) }); vboxContainer.AddChild(new Control { CustomMinimumSize = new Vector2I(0, GetLineHeight()) });
vboxContainer.AddChild(panel); vboxContainer.AddChild(panel);
popupPanel.AddChild(vboxContainer); tooltipWindow.AddChild(vboxContainer);
popupPanel.ChildControlsChanged(); tooltipWindow.ChildControlsChanged();
AddChild(popupPanel); AddChild(tooltipWindow);
var globalSymbolPosition = GetRectAtLineColumn((int)line, (int)column).Position + GetGlobalPosition(); var globalSymbolPosition = GetRectAtLineColumn((int)line, (int)column).Position + GetGlobalPosition();
var globalMousePosition = GetGlobalMousePosition(); var globalMousePosition = GetGlobalMousePosition();
// -1 so that the mouse is inside the popup, otherwise the mouse exit event won't occur if the cursor moves away immediately // -1 so that the mouse is inside the popup, otherwise the mouse exit event won't occur if the cursor moves away immediately
popupPanel.Position = new Vector2I((int)globalMousePosition.X - 1, (int)globalSymbolPosition.Y); tooltipWindow.Position = new Vector2I((int)globalMousePosition.X - 1, (int)globalSymbolPosition.Y);
popupPanel.Popup(); tooltipWindow.Popup();
} }
private void OnCaretChanged() private void OnCaretChanged()