2
0

View.Cursor.cs 1.6 KB

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