form.h (1240B)
1 /* form.h - formularios simples (menus de la app: nueva partida, conectar...). 2 * Los dibuja cada frontend; la logica es comun. */ 3 #ifndef FORM_H 4 #define FORM_H 5 6 #include "input.h" 7 8 enum FieldType { F_BUTTON, F_CHOICE, F_TEXT, F_LABEL }; 9 enum { FORM_NONE = -1, FORM_CANCEL = -2 }; 10 11 typedef struct { 12 uint8_t type; 13 int16_t id; 14 char label[64]; 15 const char *const *choices; 16 uint8_t nchoices; 17 int8_t value; 18 char text[64]; 19 uint8_t maxlen; 20 bool hidden, disabled; 21 } Field; 22 23 typedef struct Form { 24 char title[64]; 25 Field f[20]; 26 int n, cur; 27 char msg[96]; 28 bool msg_err; 29 } Form; 30 31 void form_begin(Form *f, const char *title); 32 Field *form_button(Form *f, int id, const char *label); 33 Field *form_choice(Form *f, int id, const char *label, const char *const *choices, int n, int value); 34 Field *form_text(Form *f, int id, const char *label, const char *init, int maxlen); 35 Field *form_label(Form *f, const char *text); 36 Field *form_get(Form *f, int id); 37 int form_key(Form *f, int key); /* id del boton apretado, FORM_CANCEL o FORM_NONE */ 38 int form_click(Form *f, int index); /* click sobre el campo index */ 39 void form_msg(Form *f, const char *msg, bool err); 40 41 #endif