edo

Experimental text editor.
Log | Files | Refs | LICENSE

ui.h (936B)


      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 #define CELL_POOL_THRESHOLD 8
     31 typedef struct {
     32 	union {
     33 		char text[CELL_POOL_THRESHOLD];
     34 		uint32_t pool_idx;
     35 	} data;
     36 	uint16_t len;
     37 	uint16_t width;
     38 } Cell;
     39 
     40 typedef struct UI UI;
     41 struct UI {
     42 	const char *name;
     43 	TextPool pool;
     44 	void (*init)(void);
     45 	void (*exit)(void);
     46 	void (*frame_start)(void);
     47 	void (*frame_flush)(void);
     48 	int (*text_width)(char *s, int len, int x);
     49 	void (*move_cursor)(int x, int y);
     50 	void (*draw_line)(UI *ui, int x, int y, Cell *cells, int count);
     51 	void (*draw_symbol)(int r, int c, Symbol sym);
     52 	void (*get_window_size)(int *rows, int *cols);
     53 	Event (*next_event)(void);
     54 };
     55 
     56 extern UI ui_tui;
     57 
     58 #endif