ToolTip.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../GraphicsAPI/GraphicsDefs.h"
  5. #include "../UI/UIElement.h"
  6. namespace Urho3D
  7. {
  8. /// Tooltip %UI element.
  9. class URHO3D_API ToolTip : public UIElement
  10. {
  11. URHO3D_OBJECT(ToolTip, UIElement);
  12. public:
  13. /// Construct.
  14. explicit ToolTip(Context* context);
  15. /// Destruct.
  16. ~ToolTip() override;
  17. /// Register object factory.
  18. /// @nobind
  19. static void RegisterObject(Context* context);
  20. /// Perform UI element update.
  21. void Update(float timeStep) override;
  22. /// Hide tooltip if visible and reset parentage.
  23. void Reset();
  24. /// Add an alternative hover target.
  25. void AddAltTarget(UIElement* target);
  26. /// Set the delay in seconds until the tooltip shows once hovering. Set zero to use the default from the UI subsystem.
  27. /// @property
  28. void SetDelay(float delay);
  29. /// Return the delay in seconds until the tooltip shows once hovering.
  30. /// @property
  31. float GetDelay() const { return delay_; }
  32. private:
  33. /// The element that is being tracked for hovering. Normally the parent element.
  34. WeakPtr<UIElement> target_;
  35. /// Alternative targets. Primarily targets parent.
  36. Vector<WeakPtr<UIElement>> altTargets_;
  37. /// Delay from hover start to displaying the tooltip.
  38. float delay_;
  39. /// Hover countdown has started.
  40. bool hovered_;
  41. /// Point at which the tooltip was set visible.
  42. Timer displayAt_;
  43. /// Original offset position to the parent.
  44. IntVector2 originalPosition_;
  45. };
  46. }