primitive.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package tview
  2. import "github.com/gdamore/tcell"
  3. // Primitive is the top-most interface for all graphical primitives.
  4. type Primitive interface {
  5. // Draw draws this primitive onto the screen. Implementers can call the
  6. // screen's ShowCursor() function but should only do so when they have focus.
  7. // (They will need to keep track of this themselves.)
  8. Draw(screen tcell.Screen)
  9. // GetRect returns the current position of the primitive, x, y, width, and
  10. // height.
  11. GetRect() (int, int, int, int)
  12. // SetRect sets a new position of the primitive.
  13. SetRect(x, y, width, height int)
  14. // InputHandler returns a handler which receives key events when it has focus.
  15. // It is called by the Application class.
  16. //
  17. // A value of nil may also be returned, in which case this primitive cannot
  18. // receive focus and will not process any key events.
  19. //
  20. // The handler will receive the key event and a function that allows it to
  21. // set the focus to a different primitive, so that future key events are sent
  22. // to that primitive.
  23. //
  24. // The Application's Draw() function will be called automatically after the
  25. // handler returns.
  26. //
  27. // The Box class provides functionality to intercept keyboard input. If you
  28. // subclass from Box, it is recommended that you wrap your handler using
  29. // Box.WrapInputHandler() so you inherit that functionality.
  30. InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive))
  31. // Focus is called by the application when the primitive receives focus.
  32. // Implementers may call delegate() to pass the focus on to another primitive.
  33. Focus(delegate func(p Primitive))
  34. // Blur is called by the application when the primitive loses focus.
  35. Blur()
  36. // GetFocusable returns the item's Focusable.
  37. GetFocusable() Focusable
  38. // MouseHandler returns a handler which receives mouse events.
  39. // It is called by the Application class.
  40. //
  41. // A value of nil may also be returned to stop the downward propagation of
  42. // mouse events.
  43. //
  44. // The Box class provides functionality to intercept mouse events. If you
  45. // subclass from Box, it is recommended that you wrap your handler using
  46. // Box.WrapMouseHandler() so you inherit that functionality.
  47. MouseHandler() func(action MouseAction, event *tcell.EventMouse, setFocus func(p Primitive)) (consumed bool, capture Primitive)
  48. }