/*
 * $Id: menu.h 458 2019-06-17 01:16:35Z true $
 * begin 20190527 true
 */

#ifndef INC_UI_MENU_H_
#define INC_UI_MENU_H_


#include <stdint.h>
#include "disp/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
	const 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_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_ABOUT				0x60



extern MenuItem code *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 code * menu_prev_pop();

void menu_btn_use_std();
void menu_btn_use_none();

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



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

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

// menu_1_name
extern MenuItem code menu_1;
void menu_1_disp(uint8_t idx);
void menu_1_enter(uint8_t idx);

// menu_2_led
extern MenuItem code menu_2;
void menu_2_disp(uint8_t idx);
void menu_2_enter(uint8_t idx);

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

// menu_6_about
extern MenuItem code menu_6;
void menu_6_disp(uint8_t idx);



#endif /* INC_UI_MENU_H_ */
