juegos

Juegos de terminal de Pancho: Catan (TUI, GUI, web, servidor, PicoCalc), ajedrez, calculadora y minijuegos
git clone https://git.lu3dhn.xyz/juegos.git
Log | Files | Refs

form.h (1678B)


      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 
     10 /* Campos por formulario. Cada uno pesa ~150 bytes y los formularios van en la pila: la
     11  * PicoCalc se queda con 20; un juego de PC puede pedir mas (-DFORM_MAX_FIELDS=32). */
     12 #ifndef FORM_MAX_FIELDS
     13 #define FORM_MAX_FIELDS 20
     14 #endif
     15 enum { FORM_NONE = -1, FORM_CANCEL = -2 };
     16 
     17 typedef struct {
     18     uint8_t type;
     19     int16_t id;
     20     char    label[64];
     21     const char *const *choices;
     22     uint8_t nchoices;
     23     int8_t  value;
     24     char    text[64];
     25     uint8_t maxlen;
     26     bool    hidden, disabled;
     27     bool    secret;          /* F_TEXT: se muestra con asteriscos (contrasenas) */
     28 } Field;
     29 
     30 typedef struct Form {
     31     char  title[64];
     32     Field f[FORM_MAX_FIELDS];
     33     int   n, cur;
     34     char  msg[96];
     35     bool  msg_err;
     36 } Form;
     37 
     38 void   form_begin(Form *f, const char *title);
     39 Field *form_button(Form *f, int id, const char *label);
     40 Field *form_choice(Form *f, int id, const char *label, const char *const *choices, int n, int value);
     41 Field *form_text(Form *f, int id, const char *label, const char *init, int maxlen);
     42 Field *form_label(Form *f, const char *text);
     43 Field *form_get(Form *f, int id);
     44 int    form_key(Form *f, int key);          /* id del boton apretado, FORM_CANCEL o FORM_NONE */
     45 int    form_click(Form *f, int index);      /* click sobre el campo index */
     46 void   form_msg(Form *f, const char *msg, bool err);
     47 const char *form_shown(const Field *x, char *buf, int n);   /* texto a dibujar (asteriscos si es secret) */
     48 
     49 #endif