/*
 * menu.h
 * begin 20190527 true
 */

#ifndef INC_UI_MENU_H_
#define INC_UI_MENU_H_


#include <stdint.h>

#include "render/draw_ssd1306.h"		// for OLED support
//#include "driver/efm8ub2_userflash.h"	// flash read/write operations
#include "ui/btn.h"						// for button control


typedef struct MenuItem {
	uint8_t count;						// amount of entries in this menu
	uint8_t flags;						// misc settings for the menu
	struct MenuItem *root;				// menu to return to when going back
	uint8_t root_idx;					// menu index to return to
	void (*dispfn)(uint8_t); 			// function which handles any drawing (idx)
	void (*entryfn)(uint8_t); 			// function to call when entering menu (idx)
} MenuItem;



#define MENU_FLAG_NONE					(0)
#define MENU_FLAG_NO_AUTOCLS			(1 << 0)
#define MENU_FLAG_SCROLL				(1 << 4)
#define MENU_FLAG_SAVE_ON_EXIT			(1 << 7)

#define MENU_BTNSTYLE_MAIN				0x00
#define MENU_BTNSTYLE_MENU				0x02

#define MENU_BTNSTYLE_NAME_IDLE			0x11
#define MENU_BTNSTYLE_NAME_EDIT			0x12

#define MENU_BTNSTYLE_LED_EDIT 			0x21

#define MENU_BTNSTYLE_OPTION_EDIT 		0x51

#define MENU_BTNSTYLE_PROGSIMPLE_IDLE	0xe1
#define MENU_BTNSTYLE_PROGSIMPLE_EDIT	0xe2

#define MENU_BTNSTYLE_ABOUT				0x60



extern MenuItem *menu;
extern uint8_t menu_idx;

extern uint8_t mtick;



void menu_start(uint8_t x);
void menu_stop(uint8_t x);

void menu_tick();

void menu_prev_push(MenuItem *m);
MenuItem * menu_prev_pop();

void menu_btn_use_std();
void menu_btn_use_none();

void menu_btn_exit(uint8_t idx);

void menu_draw_buttons(uint8_t mode, uint8_t indicator_mask);
void menu_draw_tabs(uint8_t active_idx);



// menu_none_nametag
extern const MenuItem menu_none;
void menu_none_disp(uint8_t idx);

// menu_0_root
extern const MenuItem menu_0;
void menu_0_disp(uint8_t idx);
void menu_0_enter(uint8_t idx);

// menu_1_name
extern const MenuItem menu_1_name_setup;
void menu_1_disp(uint8_t idx);
void menu_1_enter(uint8_t idx);

// menu_2_led
extern const MenuItem menu_2_led_setup;
void menu_2_disp(uint8_t idx);
void menu_2_enter(uint8_t idx);

// menu_3_snek
extern const MenuItem menu_3_snek;
void snek_disp(uint8_t idx);

// menu_5_options
extern const MenuItem menu_5_options;
void menu_5_disp(uint8_t idx);
void menu_5_enter(uint8_t idx);

// menu_6_about
extern const MenuItem menu_6_about;
void menu_6_disp(uint8_t idx);



#endif /* INC_UI_MENU_H_ */
