esp32 firmware for a toaster reflow oven WIP!!!!!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
reflower/main/scenes/scene_menu.h

83 lines
1.9 KiB

/**
* Scrollable menu
*
* Created on 2020/01/05.
*/
#ifndef REFLOWER_SCENE_MENU_H
#define REFLOWER_SCENE_MENU_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#define MENUITEM_LABEL_LEN 30
/**
* One item of the menu
*/
struct MenuItem {
// menu label
char label[MENUITEM_LABEL_LEN];
// item tag (useful with dynamically generated menus)
uint32_t tag;
};
struct MenuScene;
/**
* Selection handler.
*
* When an item is selected, this abstract method is fired to determine what should happen.
*
* The selected item is available as scene.selected.
* Return SceneEvent to take, e.g. to close the menu, or to open a sub-scene.
*/
typedef struct SceneEvent (*MenuScene_onSelect_t)(struct MenuScene *scene);
struct MenuScene {
struct Scene base;
// items array
struct MenuItem *items;
// allow wrap-around
bool wraparound;
// items count
size_t items_len;
// Vertical scroll offset (how many steps is the topmost item moved above the screen)
int32_t scroll_up;
// Start X
int x;
// Start Y
int y;
// Selected item number
int32_t selected;
// Horizontal scroll count
int32_t hscroll;
// Horizontal scroll timer
int32_t hscroll_cnt;
// Number of lines visible at a time
uint8_t nlines;
// number of visible characters in a line at a time
uint8_t ncols;
// selection handler
MenuScene_onSelect_t onSelect;
// Extra field for the subclass's private use.
void *extra;
// fp for extra's deinit function
Scene_deinit_t extra_deinit;
};
/**
* Create a new items menu.
*
* This is normally called from a subclass.
*
* @param items - menu items on heap (the MenuScene will free them on close)
* @param items_len - item count
* @return the menu
*/
struct MenuScene *NewScene_Menu(struct MenuItem *items, size_t items_len);
void MenuScene_Paint(struct MenuScene *self);
#endif //REFLOWER_SCENE_MENU_H