eurorack/midi2cv/menu/menu.h

64 lines
1.3 KiB
C
Raw Normal View History

2020-01-03 21:09:11 +00:00
#pragma once
#include "menu_items.h"
2020-02-23 10:15:27 +00:00
#include <U8g2lib.h>
2020-01-03 21:09:11 +00:00
#define MAXIMUM_MENU_ITEM_COUNT 16
class Menu {
private:
AbstractMenuItem* items[MAXIMUM_MENU_ITEM_COUNT];
uint8_t itemCount;
uint8_t selectedItem;
uint8_t currentScrollStart; // index we start rendering the menu from (for scrolling)
int8_t currentEditingItem;
uint8_t width, height;
2020-01-03 21:09:11 +00:00
public:
Menu()
2020-01-03 21:09:11 +00:00
: selectedItem(0)
, currentScrollStart(0)
, currentEditingItem(-1)
, width(10)
, height(10) {};
2020-01-03 21:09:11 +00:00
void up();
void down();
2020-02-23 10:15:27 +00:00
bool back(); // returns true true if nothing happened here and the action can be delegated to up
bool enter(); // returns true if it wants to give up control
2020-01-03 21:09:11 +00:00
void add_item(AbstractMenuItem* item)
{
if (itemCount < MAXIMUM_MENU_ITEM_COUNT) {
items[itemCount++] = item;
}
}
uint8_t visible_item_count()
{
uint8_t count = 0;
for (size_t i = 0; i < itemCount; i++) {
if (items[i]->visible())
count++;
}
return count;
}
uint8_t visible_item_count_before_selection()
{
uint8_t count = 0;
for (size_t i = 0; i <= selectedItem; i++) {
if (items[i]->visible())
count++;
}
return count;
}
2020-02-23 10:15:27 +00:00
void render(U8G2* u8g2_, uint8_t x, uint8_t y, uint8_t width, uint8_t height);
2020-01-03 21:09:11 +00:00
};