View.Cursor.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. public partial class View
  4. {
  5. /// <summary>
  6. /// Gets or sets the cursor style to be used when the view is focused. The default is
  7. /// <see cref="CursorVisibility.Invisible"/>.
  8. /// </summary>
  9. public CursorVisibility CursorVisibility { get; set; } = CursorVisibility.Invisible;
  10. /// <summary>
  11. /// Positions the cursor in the right position based on the currently focused view in the chain.
  12. /// </summary>
  13. /// <remarks>
  14. /// <para>
  15. /// Views that are focusable should override <see cref="PositionCursor()"/> to make sure that the cursor is
  16. /// placed in a location that makes sense. Some terminals do not have a way of hiding the cursor, so it can be
  17. /// distracting to have the cursor left at the last focused view. So views should make sure that they place the
  18. /// cursor in a visually sensible place. The default implementation of <see cref="PositionCursor()"/> will place the
  19. /// cursor at either the hotkey (if defined) or <c>0,0</c>.
  20. /// </para>
  21. /// </remarks>
  22. /// <returns>Viewport-relative cursor position. Return <see langword="null"/> to ensure the cursor is not visible.</returns>
  23. public virtual Point? PositionCursor ()
  24. {
  25. if (IsInitialized && CanFocus && HasFocus)
  26. {
  27. // By default, position the cursor at the hotkey (if any) or 0, 0.
  28. Move (TextFormatter.HotKeyPos == -1 ? 0 : TextFormatter.CursorPosition, 0);
  29. }
  30. // Returning null will hide the cursor.
  31. return null;
  32. }
  33. }