mirror of
https://codeberg.org/armin/sm-26.git
synced 2026-10-11 17:01:53 +02:00
66 lines
No EOL
1.5 KiB
C++
66 lines
No EOL
1.5 KiB
C++
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
|
#include "SynthParams.h"
|
|
|
|
class MenuSystem;
|
|
|
|
struct MenuItem
|
|
{
|
|
enum Kind { Action, Value, Submenu, Separator };
|
|
|
|
juce::String label;
|
|
Kind kind = Action;
|
|
int paramId = -1;
|
|
|
|
std::function<void()> onEnter;
|
|
std::function<void(float delta)> onAdjust;
|
|
std::function<juce::String()> valueText;
|
|
|
|
MenuItem& action (std::function<void()> fn) { onEnter = fn; return *this; }
|
|
MenuItem& param (int id, float lo, float hi) { paramId = id; return *this; }
|
|
MenuItem& value (std::function<juce::String()> fn) { valueText = fn; kind = Value; return *this; }
|
|
MenuItem& submenu() { kind = Submenu; return *this; }
|
|
MenuItem& sep() { kind = Separator; return *this; }
|
|
};
|
|
|
|
struct MenuScreen
|
|
{
|
|
juce::String title;
|
|
std::vector<MenuItem> items;
|
|
int selected = 0;
|
|
};
|
|
|
|
class MenuSystem
|
|
{
|
|
public:
|
|
MenuSystem();
|
|
|
|
void open();
|
|
void close();
|
|
bool isOpen() const { return ! stack.empty(); }
|
|
|
|
void up();
|
|
void down();
|
|
void left();
|
|
void right();
|
|
void enter();
|
|
void escape();
|
|
|
|
const MenuScreen& current() const;
|
|
|
|
void pushScreen (const MenuScreen& screen);
|
|
|
|
using ScreenBuilder = std::function<MenuScreen()>;
|
|
|
|
void setRootScreenBuilder (ScreenBuilder fn);
|
|
|
|
void refreshCurrent();
|
|
|
|
private:
|
|
std::vector<MenuScreen> stack;
|
|
ScreenBuilder rootBuilder;
|
|
bool wasOpen = false;
|
|
|
|
void rebuildRoot();
|
|
}; |