mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Implement BoolMenuItem, beautify header
This commit is contained in:
parent
9383e3c4cf
commit
ca4d0cc5e2
5 changed files with 61 additions and 35 deletions
|
@ -12,7 +12,7 @@ void Menu::render(u8g2_t* u8g2_, uint8_t xStart, uint8_t yStart, uint8_t width,
|
|||
uint8_t maxVisibleItems = height / kMenuItemHeight;
|
||||
|
||||
uint8_t itemsToRender = std::min(maxVisibleItems, uint8_t(this->itemCount - currentScrollStart));
|
||||
u8g2_SetFont(u8g2_, u8g2_font_6x12_tf);
|
||||
u8g2_SetFont(u8g2_, u8g2_font_6x10_tf);
|
||||
for (uint8_t i = 0; i < itemsToRender; i++) {
|
||||
bool selected = this->selectedItem == (i + this->currentScrollStart);
|
||||
bool editing = this->currentEditingItem == (i + this->currentScrollStart);
|
||||
|
|
|
@ -102,6 +102,56 @@ class UIntMenuItem : public NumberMenuItem<uint32_t> {
|
|||
: NumberMenuItem(_label, _initialValue, _minimumValue, _maximumValue, _step) {};
|
||||
};
|
||||
|
||||
class IntMenuItem : public NumberMenuItem<int32_t> {
|
||||
private:
|
||||
protected:
|
||||
const char* get_format_string()
|
||||
{
|
||||
return "%d";
|
||||
}
|
||||
|
||||
public:
|
||||
IntMenuItem(const char* _label, int32_t _initialValue, int32_t _minimumValue, int32_t _maximumValue, int32_t _step)
|
||||
: NumberMenuItem(_label, _initialValue, _minimumValue, _maximumValue, _step) {};
|
||||
};
|
||||
|
||||
class FloatMenuItem : public NumberMenuItem<float> {
|
||||
private:
|
||||
protected:
|
||||
const char* get_format_string()
|
||||
{
|
||||
return "%.2f";
|
||||
}
|
||||
|
||||
public:
|
||||
FloatMenuItem(const char* _label, float _initialValue, float _minimumValue, float _maximumValue, float _step)
|
||||
: NumberMenuItem(_label, _initialValue, _minimumValue, _maximumValue, _step) {};
|
||||
};
|
||||
|
||||
class BoolMenuItem : public NumberMenuItem<bool> {
|
||||
|
||||
private:
|
||||
const char* on_string;
|
||||
const char* off_string;
|
||||
|
||||
protected:
|
||||
const char* get_format_string()
|
||||
{
|
||||
bool value = this->get_value();
|
||||
|
||||
if (value)
|
||||
return this->on_string;
|
||||
else
|
||||
return this->off_string;
|
||||
}
|
||||
|
||||
public:
|
||||
BoolMenuItem(const char* _label, bool _initialValue, const char* _on_string, const char* _off_string)
|
||||
: NumberMenuItem(_label, _initialValue, 0, 1, 1)
|
||||
, on_string(_on_string)
|
||||
, off_string(_off_string) {};
|
||||
};
|
||||
|
||||
class MidiNoteMenuItem : public NumberMenuItem<uint8_t> {
|
||||
private:
|
||||
char string_buffer[4];
|
||||
|
@ -139,29 +189,3 @@ class MidiNoteMenuItem : public NumberMenuItem<uint8_t> {
|
|||
note_strings[11] = "B";
|
||||
};
|
||||
};
|
||||
|
||||
class IntMenuItem : public NumberMenuItem<int32_t> {
|
||||
private:
|
||||
protected:
|
||||
const char* get_format_string()
|
||||
{
|
||||
return "%d";
|
||||
}
|
||||
|
||||
public:
|
||||
IntMenuItem(const char* _label, int32_t _initialValue, int32_t _minimumValue, int32_t _maximumValue, int32_t _step)
|
||||
: NumberMenuItem(_label, _initialValue, _minimumValue, _maximumValue, _step) {};
|
||||
};
|
||||
|
||||
class FloatMenuItem : public NumberMenuItem<float> {
|
||||
private:
|
||||
protected:
|
||||
const char* get_format_string()
|
||||
{
|
||||
return "%.2f";
|
||||
}
|
||||
|
||||
public:
|
||||
FloatMenuItem(const char* _label, float _initialValue, float _minimumValue, float _maximumValue, float _step)
|
||||
: NumberMenuItem(_label, _initialValue, _minimumValue, _maximumValue, _step) {};
|
||||
};
|
||||
|
|
|
@ -66,5 +66,7 @@ void MainMenu::render(u8g2_t* u8g2, int x, int y, int width, int height)
|
|||
u8g2_SetDrawColor(u8g2, 1);
|
||||
}
|
||||
|
||||
this->partMenus[this->selectedPart].render(u8g2, x, y + kHeaderHeight, width, height - kHeaderHeight);
|
||||
u8g2_DrawHLine(u8g2, 0, kHeaderHeight + 1, width);
|
||||
|
||||
this->partMenus[this->selectedPart].render(u8g2, x, y + kHeaderHeight + 3, width, height - kHeaderHeight - 3);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
PartMenu::PartMenu()
|
||||
: menu(128, 64)
|
||||
, item_voice_count("Voice Count", 1, 1, 4, 1)
|
||||
, item_voice_detail("Voice Detail", 1, 1, 4, 1)
|
||||
, item_midi_filter_enabled("MIDI Filter Enabled", 0, 0, 1, 1)
|
||||
, item_midi_channel("MIDI Channel", 0, 0, 100, 1)
|
||||
, item_midi_lowest_note("MIDI Lowest Note", 0)
|
||||
, item_midi_highest_note("MIDI Highest Note", 0)
|
||||
, item_voice_count("voice count", 1, 1, 4, 1)
|
||||
, item_voice_detail("voice detail", 1, 1, 4, 1)
|
||||
, item_midi_filter_enabled("MIDI filter", 0, "on", "off")
|
||||
, item_midi_channel("MIDI channel", 0, 0, 100, 1)
|
||||
, item_midi_lowest_note("MIDI lowest", 0)
|
||||
, item_midi_highest_note("MIDI highest", 127)
|
||||
{
|
||||
this->menu.add_item(&this->item_voice_count);
|
||||
this->menu.add_item(&this->item_voice_detail);
|
||||
|
|
|
@ -19,7 +19,7 @@ class PartMenu {
|
|||
Menu menu;
|
||||
UIntMenuItem item_voice_count;
|
||||
UIntMenuItem item_voice_detail;
|
||||
UIntMenuItem item_midi_filter_enabled;
|
||||
BoolMenuItem item_midi_filter_enabled;
|
||||
UIntMenuItem item_midi_channel;
|
||||
MidiNoteMenuItem item_midi_lowest_note;
|
||||
MidiNoteMenuItem item_midi_highest_note;
|
||||
|
|
Loading…
Reference in a new issue