Deluge Firmware 1.3.0
Build date: 2025.08.12
Loading...
Searching...
No Matches
horizontal_menu.h
1/*
2 * Copyright (c) 2024 Nikodemus Siivola, Leonid Burygin
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/menu_item.h"
21#include "gui/menu_item/submenu.h"
22#include "util/containers.h"
23#include <initializer_list>
24#include <span>
25
26namespace deluge::gui::menu_item {
27
28class HorizontalMenu : public Submenu {
29public:
30 friend class HorizontalMenuGroup;
31
32 enum Layout { FIXED, DYNAMIC };
33
34 struct Paging {
35 uint8_t visiblePageNumber;
36 std::span<MenuItem*> visiblePageItems;
37 uint8_t selectedItemPositionOnPage;
38 uint8_t totalPages;
39 };
40
41 using Submenu::Submenu;
42
43 HorizontalMenu(l10n::String newName, std::span<MenuItem*> newItems, Layout layout)
44 : Submenu(newName, newItems), paging{}, layout(layout) {}
45 HorizontalMenu(l10n::String newName, std::initializer_list<MenuItem*> newItems, Layout layout)
46 : Submenu(newName, newItems), paging{}, layout(layout) {}
47 HorizontalMenu(l10n::String newName, l10n::String newTitle, std::initializer_list<MenuItem*> newItems,
48 Layout layout)
49 : Submenu(newName, newTitle, newItems), paging{}, layout(layout) {}
50
51 RenderingStyle renderingStyle() const override;
52 ActionResult buttonAction(hid::Button b, bool on, bool inCardRoutine) override;
53 void selectEncoderAction(int32_t offset) override;
54 void renderOLED() override;
55 MenuPermission checkPermissionToBeginSession(ModControllableAudio* modControllable, int32_t whichThing,
56 ::MultiRange** currentRange) override;
57 void endSession() override;
58 virtual bool hasItem(const MenuItem* item);
59
60protected:
61 Paging paging;
62 Layout layout{DYNAMIC};
63 int32_t lastSelectedItemPosition{kNoSelection};
64
65 virtual void renderMenuItems(std::span<MenuItem*> items, const MenuItem* currentItem);
66 virtual Paging& preparePaging(std::span<MenuItem*> items, const MenuItem* currentItem);
67 virtual void handleInstrumentButtonPress(std::span<MenuItem*> visiblePageItems, const MenuItem* previous,
68 int32_t pressedButtonPosition);
69 virtual void selectMenuItem(int32_t pageNumber, int32_t itemPos);
70 virtual void switchVisiblePage(int32_t direction);
71 virtual void switchHorizontalMenu(int32_t direction, std::span<HorizontalMenu* const> chain,
72 bool forceSelectFirstItem = false);
73
74private:
75 void updateSelectedMenuItemLED(int32_t itemNumber) const;
76 static void handleItemAction(MenuItem* menuItem);
77 static void displayNotification(MenuItem* menuItem);
78 static void renderPageCounters(const Paging& paging);
79 static void renderColumnLabel(MenuItem* menuItem, int32_t labelY, int32_t slotStartX, int32_t slotWidth,
80 bool isSelected);
81
82 double currentKnobSpeed{0.0};
83 double calcNextKnobSpeed(int8_t offset);
84};
85} // namespace deluge::gui::menu_item
Base class for all menu items.
Definition menu_item.h:42
Definition mod_controllable_audio.h:47
Definition multi_range.h:23
Definition horizontal_menu.h:28
void selectEncoderAction(int32_t offset) override
Handle select encoder movement.
Definition horizontal_menu.cpp:222
void updateSelectedMenuItemLED(int32_t itemNumber) const
When updating the selected horizontal menu item, you need to refresh the lit instrument LED's.
Definition horizontal_menu.cpp:472
void renderOLED() override
Root rendering routine for OLED.
Definition horizontal_menu.cpp:89
ActionResult buttonAction(hid::Button b, bool on, bool inCardRoutine) override
Handle an arbitrary button.
Definition horizontal_menu.cpp:56
void endSession() override
Definition horizontal_menu.cpp:502
Definition submenu.h:28
Definition horizontal_menu.h:34