#nullable enable
using ImGuiNET;
namespace T3.Editor.Gui.Help;
///
/// A tiny per-frame broker that decouples "what is currently hovered" from the .
/// The graph, the symbol library/browser, and documentation affordances record the topic the mouse is over;
/// the Help window previews it while its hover mode is enabled.
///
///
/// The recorded value carries the frame it was set on so the read tolerates either draw order between the
/// producer (e.g. the graph) and the Help window — a one-frame staleness is imperceptible and avoids a
/// hard ordering dependency in .
///
internal static class HoveredHelpTarget
{
/// Records the operator the mouse is hovering as the help topic for this frame.
internal static void SetOperator(Guid symbolId)
{
_hoveredTopic = HelpTopic.ForOperator(symbolId);
_frameSet = ImGui.GetFrameCount();
}
/// Records the ui: topic the mouse is hovering (a markdown link or documentation icon).
internal static void SetTopic(string keyOrId)
{
_hoveredTopic = HelpTopic.ForUiTopic(keyOrId);
_frameSet = ImGui.GetFrameCount();
}
/// The topic hovered this frame or the previous one, or false if the hover is stale.
internal static bool TryGetHovered(out HelpTopic topic)
{
if (!_hoveredTopic.IsEmpty && ImGui.GetFrameCount() - _frameSet <= 1)
{
topic = _hoveredTopic;
return true;
}
topic = default;
return false;
}
private static HelpTopic _hoveredTopic;
private static int _frameSet = int.MinValue;
}