#ifndef WIDGET_H_
#define WIDGET_H_

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT

#include "nuklear.h"

#define WIDGET_TYPE_SELECT       1
#define WIDGET_TYPE_SLIDER       2
#define WIDGET_TYPE_TOGGLE       3
#define WIDGET_TYPE_LABEL        4
#define WIDGET_TYPE_STRING       5
#define WIDGET_TYPE_STRING_INPUT 6
#define WIDGET_TYPE_STRING_SCAN  7

#define WIDGET_DATA_TYPE_INT    1
#define WIDGET_DATA_TYPE_DOUBLE 2
#define WIDGET_DATA_TYPE_STRING 3

#define WIDGET_FONT_NORMAL      1
#define WIDGET_FONT_SMALL       2
#define WIDGET_FONT_BIG         3
#define WIDGET_FONT_ATARI       4

#define WIDGET_ALIGN_LEFT       1
#define WIDGET_ALIGN_CENTER     2
#define WIDGET_ALIGN_RIGHT      3

/* Size of the scratch buffer a select value formatter writes into. Shared so
   widget_select's local buffer and any formatter's snprintf cap stay in sync. */
#define WIDGET_VALUE_STR_SIZE   128

struct option_widget {
    int widget_type;
    int data_type;
    int font_type;
    void *data;
    void *list_head;  /* For input widgets: head of the t_input_common linked list */
    char label[96];
    int min;
    int max;
    int menu_next;
    int menu_prev;
    int accept_input;
    int divider;
    int show_as_disabled;
    int input_empty_row;
    void *input_player; /* For player input widgets: owning t_player_input */
    unsigned long long *p_mask;
    unsigned long long *p_source_mask;
    unsigned long long mask_value;
    char * (*get_string)(struct option_widget *, char *);
    void (*run_task)(struct option_widget *, void *);
};

void widget_push_select_button_style(struct nk_context *ctx);
void widget_pop_select_button_style(struct nk_context *ctx);
int widget_slider(struct nk_context *ctx, struct option_widget *wgt, int selected);
int widget_toggle(struct nk_context *ctx, struct option_widget *wgt, int selected);
int widget_select(struct nk_context *ctx, struct option_widget *wgt, int selected);
int widget_label(struct nk_context *ctx, struct option_widget *wgt, int selected,
                 int allow_child_caret);
int widget_string(struct nk_context *ctx, struct option_widget *wgt, int selected);
int widget_string_input(struct nk_context *ctx, struct option_widget *wgt, int selected);
int widget_string_scan(struct nk_context *ctx, struct option_widget *wgt, int selected);
float widget_label_pixel_width(struct nk_context *ctx, struct option_widget *wgt);
float widget_string_pixel_width(struct nk_context *ctx, struct option_widget *wgt);

/* Helper function to convert t_input_common to display string */
struct input_common;
void input_common_to_string(struct input_common *input, char *buf, int buf_size);

#endif
