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