Deluge Firmware 1.3.0
Build date: 2025.09.27
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
59 virtual bool hasItem(const MenuItem* item);
60 virtual void setCurrentItem(const MenuItem* item);
61 decltype(items)& getItems() { return items; }
62
63protected:
64 Paging paging;
65 Layout layout{DYNAMIC};
66 int32_t lastSelectedItemPosition{kNoSelection};
67
68 virtual void renderMenuItems(std::span<MenuItem*> items, const MenuItem* currentItem);
69 virtual Paging& preparePaging(std::span<MenuItem*> items, const MenuItem* currentItem);
70 virtual void handleInstrumentButtonPress(std::span<MenuItem*> visible_page_items, const MenuItem* previous,
71 int32_t pressed_button_position);
72 virtual void selectMenuItem(int32_t page_number, int32_t item_pos);
73 virtual void switchVisiblePage(int32_t direction);
74 virtual void switchHorizontalMenu(int32_t direction, std::span<HorizontalMenu* const> chain);
75
76private:
77 void updateSelectedMenuItemLED(int32_t itemNumber) const;
78 static void handleItemAction(MenuItem* menuItem);
79 static void displayNotification(MenuItem* menuItem);
80 static void renderPageCounters(const Paging& paging);
81 static void renderColumnLabel(MenuItem* menuItem, int32_t labelY, int32_t slotStartX, int32_t slotWidth,
82 bool isSelected);
83
84 double currentKnobSpeed{0.0};
85 double calcNextKnobSpeed(int8_t offset);
86};
87} // namespace deluge::gui::menu_item
Base class for all menu items.
Definition menu_item.h:43
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:249
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:476
void renderOLED() override
Root rendering routine for OLED.
Definition horizontal_menu.cpp:90
ActionResult buttonAction(hid::Button b, bool on, bool inCardRoutine) override
Handle an arbitrary button.
Definition horizontal_menu.cpp:58
void endSession() override
Definition horizontal_menu.cpp:506
Definition submenu.h:28
Definition horizontal_menu.h:34