Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
selection.h
1/*
2 * Copyright © 2017-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "gui/menu_item/enumeration.h"
21#include "gui/ui/sound_editor.h"
22#include "util/containers.h"
23#include <string_view>
24
25namespace deluge::gui::menu_item {
26class Selection : public Enumeration {
27public:
28 using Enumeration::Enumeration;
29
30 enum class OptType { FULL, SHORT };
31 virtual deluge::vector<std::string_view> getOptions(OptType optType = OptType::FULL) = 0;
32
33 void drawValue() override;
34
35 void drawPixelsForOled() override;
36 size_t size() override { return this->getOptions().size(); }
37
38 virtual bool isToggle() { return false; }
39
40 void displayToggleValue();
41
42 // renders toggle item type in submenus after the item name
43 void renderSubmenuItemTypeForOled(int32_t yPixel) override;
44
45 // toggles boolean ON / OFF
46 void toggleValue() {
48 setValue(!getValue());
49 writeCurrentValue();
50 };
51
52 // handles toggling a "toggle" selection menu from sub-menu level
53 // or handles going back up a level after making a selection from within selection menu
54 MenuItem* selectButtonPress() override {
55 // this is true if you open a selection menu using grid shortcut
56 // or you enter a selection menu that isn't a toggle
57 if (soundEditor.getCurrentMenuItem() == this) {
58 return nullptr; // go up a level
59 }
60 // you're toggling selection menu from submenu level
61 else {
62 toggleValue();
63 displayToggleValue();
64 return NO_NAVIGATION;
65 }
66 }
67
68 // get's toggle status for rendering checkbox on OLED
69 bool getToggleValue() {
71 return this->getValue();
72 }
73
74 // get's toggle status for rendering dot on 7SEG
75 uint8_t shouldDrawDotOnName() override {
76 if (isToggle()) {
78 return this->getValue() ? 3 : 255;
79 }
80 else {
81 return 255;
82 }
83 }
84
85protected:
86 void getShortOption(StringBuf&) override;
87};
88} // namespace deluge::gui::menu_item
virtual void readCurrentValue()
Like readValueAgain, but does not redraw.
Definition menu_item.h:117
Definition d_string.h:106
An enumeration has a fixed number of items, with values from 1 to n (exclusive)
Definition enumeration.h:9
Definition selection.h:26
MenuItem * selectButtonPress() override
Handle a select button press.
Definition selection.h:54
void drawPixelsForOled() override
Paints the pixels below the standard title block.
Definition selection.cpp:18
void getShortOption(StringBuf &) override
Definition selection.cpp:73
uint8_t shouldDrawDotOnName() override
Get the "draw dot state".
Definition selection.h:75