edo

Experimental text editor.
Log | Files | Refs | LICENSE

ui.h (1049B)


      1 #ifndef UI_H
      2 #define UI_H
      3 
      4 #include <stdint.h>
      5 #include <stdio.h>
      6 
      7 typedef enum {
      8 	SYM_EMPTYLINE
      9 } Symbol;
     10 
     11 typedef enum {
     12 	EV_KEY,
     13 	EV_UKN
     14 } EventType;
     15 
     16 typedef struct {
     17 	EventType type;
     18 	int key;
     19 	int mod;
     20 	int row;
     21 	int col;
     22 } Event;
     23 
     24 typedef struct {
     25 	char *data;
     26 	size_t cap;
     27 	size_t len;
     28 } TextPool;
     29 
     30 enum CellFlags {
     31 	CELL_DEFAULT,
     32 	CELL_TRUNC_L,
     33 	CELL_TRUNC_R
     34 };
     35 
     36 #define CELL_POOL_THRESHOLD 8
     37 typedef struct {
     38 	union {
     39 		char text[CELL_POOL_THRESHOLD];
     40 		uint32_t pool_idx;
     41 	} data;
     42 	uint16_t len;
     43 	uint16_t width;
     44 	int flags;
     45 } Cell;
     46 
     47 typedef struct UI UI;
     48 struct UI {
     49 	const char *name;
     50 	TextPool pool;
     51 	void (*init)(void);
     52 	void (*exit)(void);
     53 	void (*frame_start)(void);
     54 	void (*frame_flush)(void);
     55 	int (*text_width)(char *s, int len, int x);
     56 	int (*text_len)(char *s, int len);
     57 	void (*move_cursor)(int x, int y);
     58 	void (*draw_line)(UI *ui, int x, int y, Cell *cells, int count);
     59 	void (*draw_symbol)(int r, int c, Symbol sym);
     60 	void (*get_window_size)(int *rows, int *cols);
     61 	Event (*next_event)(void);
     62 };
     63 
     64 extern UI ui_tui;
     65 
     66 #endif